1 # Copyright (c) 2018 Amdocs
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 from collections import defaultdict
16 from rest_framework import status
23 "passwordCredentials": {
31 SUCCESS_STATE = [status.HTTP_200_OK, status.HTTP_201_CREATED,
32 status.HTTP_202_ACCEPTED]
36 return inspect.stack()[1][3]
39 def jsonResponse(data, encoding='utf-8'):
41 content_type = "application/json"
43 res = json.loads(data, encoding=encoding)
46 content_type = "text/plain"
47 return (res, content_type)
50 class Catalogs(object):
53 self.ct = defaultdict(dict)
55 def storeEndpoint(self, vimid, endpoints):
57 self.ct[vimid].update(endpoints)
59 self.ct.setdefault(vimid, endpoints)
61 def getEndpointBy(self, vimid, serverType, interface='public'):
63 vim = self.ct.get(vimid)
64 return vim.get(serverType).get(interface, "") if vim else ""
67 def verifyKeystoneV2(param):
69 return _walk_json(param, keystoneV2Json)
72 # comapare two json by key
73 def _walk_json(data, data2):
74 if isinstance(data, dict) and isinstance(data2, dict):
75 if set(data.keys()) != set(data2.keys()):
82 if len(v1) != len(v2):
84 for (i, j) in zip(v1, v2):
85 # continue compare key
86 if isinstance(i, dict) and isinstance(j, dict):
87 if not _walk_json(i, j):
98 def keystoneVersion(url, version="v3"):
102 if v not in ["v2.0", "v3"]: