X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=lib%2Fosm%2Fosmclient%2Fclientv2.py;h=1820d2fc8547db24ac79e407d2e38a7f6b0f2444;hb=70f9629aef040ce2bd6fba9c082f15d33ac00ef1;hp=f82bf4d29a43a7cdc3618f2f83ded6e938eeb6a6;hpb=cf3a1f01c2b7ef2e76f8090fc995b74e95835306;p=osm%2FLW-UI.git diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index f82bf4d..1820d2f 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -22,6 +22,7 @@ import StringIO from lib.util import Util import hashlib import os +import re from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) @@ -49,7 +50,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -66,13 +67,102 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result + def role_list(self, token): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/roles".format(self._base_path) + try: + r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + + return result + + def role_create(self, token, role_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/admin/v1/roles".format(self._base_path) + + try: + r = requests.post(_url, json=role_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + + def role_update(self, token, role_id, role_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/admin/v1/roles/{1}".format(self._base_path, role_id) + try: + r = requests.patch(_url, json=role_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + else: + result['data'] = Util.json_loads_byteified(r.text) + return result + + def role_delete(self, token, id, force=None): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + query_path = '' + if force: + query_path = '?FORCE=true' + _url = "{0}/admin/v1/roles/{1}{2}".format(self._base_path, id, query_path) + try: + r = requests.delete(_url, params=None, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + else: + result['data'] = Util.json_loads_byteified(r.text) + return result + + def role_get(self, token, id): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/roles/{1}".format(self._base_path, id) + try: + r = requests.get(_url, params=None, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def user_list(self, token): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/json", "accept": "application/json", @@ -85,7 +175,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -104,7 +194,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -121,7 +211,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = Util.json_loads_byteified(r.text) @@ -139,7 +229,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = Util.json_loads_byteified(r.text) @@ -156,11 +246,32 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result + def get_projects(self, token, uuids): + result = {'error': False, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + projects = [] + try: + for uuid in uuids: + _url = "{0}/admin/v1/projects/{1}".format(self._base_path, uuid) + r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) + if r.status_code not in (200, 201, 202, 204): + raise Exception() + projects.append(Util.json_loads_byteified(r.text)) + except Exception as e: + log.exception(e) + result['error'] = True + result['data'] = str(e) + return result + result['data'] = projects + return result + def project_list(self, token): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/yaml", "accept": "application/json", @@ -173,7 +284,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -190,7 +301,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -209,7 +320,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -223,14 +334,13 @@ class Client(object): _url = "{0}/admin/v1/projects/{1}".format(self._base_path, id) try: - r = requests.put(_url, json=project_data, verify=False, headers=headers) + r = requests.patch(_url, json=project_data, verify=False, headers=headers) except Exception as e: log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False - result['data'] = Util.json_loads_byteified(r.text) return result def project_delete(self, token, id): @@ -245,7 +355,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = Util.json_loads_byteified(r.text) @@ -262,7 +372,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -279,7 +389,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json2yaml(yaml.load(str(r.text))) @@ -297,7 +407,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -317,7 +427,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -337,7 +447,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -354,7 +464,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -371,7 +481,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -388,7 +498,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -405,7 +515,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -423,7 +533,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False return result @@ -440,9 +550,10 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r: result['error'] = False - result['data'] = Util.json_loads_byteified(r.text) + if r.status_code != requests.codes.no_content: + result['data'] = Util.json_loads_byteified(r.text) return result def vnfd_delete(self, token, id): @@ -479,7 +590,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -499,7 +610,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -519,7 +630,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -539,7 +650,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['data'] = r.json() result['error'] = False if r.status_code == requests.codes.conflict: @@ -560,7 +671,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['data'] = r.json() result['error'] = False if r.status_code == requests.codes.conflict: @@ -587,7 +698,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False if r.status_code == requests.codes.conflict: result['data'] = "Invalid ID." @@ -615,7 +726,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False if r.status_code == requests.codes.conflict: result['data'] = "Invalid ID." @@ -633,7 +744,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False return result @@ -658,7 +769,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: try: @@ -689,7 +800,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: try: @@ -711,7 +822,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False tarf = StringIO.StringIO(r.content) return tarf @@ -728,7 +839,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False tarf = StringIO.StringIO(r.content) return tarf @@ -736,10 +847,10 @@ class Client(object): def _descriptor_update(self, tarf, data): # extract the package on a tmp directory - tarf.extractall('/tmp') - + tarf.extractall('/tmp') + regex = re.compile(r"^[^/]+(/[^/]+\.(yaml|yml))$", re.U) for name in tarf.getnames(): - if name.endswith(".yaml") or name.endswith(".yml"): + if regex.match(name): with open('/tmp/' + name, 'w') as outfile: yaml.safe_dump(data, outfile, default_flow_style=False) break @@ -850,7 +961,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False return yaml.load(r.text) else: @@ -871,7 +982,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False return yaml.load(r.text) else: @@ -892,7 +1003,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = r.text else: @@ -914,7 +1025,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = r.text else: @@ -938,7 +1049,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -956,7 +1067,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -974,7 +1085,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -991,7 +1102,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -1001,7 +1112,7 @@ class Client(object): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/json", "accept": "application/json", 'Authorization': 'Bearer {}'.format(token['id'])} - _url = "{0}/nsilcm/v1/nsi_lcm_op_occs/?nsInstanceId={1}".format(self._base_path, id) + _url = "{0}/nsilcm/v1/nsi_lcm_op_occs/?netsliceInstanceId={1}".format(self._base_path, id) try: r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) @@ -1009,7 +1120,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -1027,7 +1138,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -1046,7 +1157,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1120,7 +1231,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1137,7 +1248,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1154,7 +1265,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1171,7 +1282,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1187,7 +1298,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False # result['data'] = Util.json_loads_byteified(r.text) result['data'] = r.text @@ -1204,12 +1315,29 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False # result['data'] = Util.json_loads_byteified(r.text) result['data'] = r.text return result + def wim_list(self, token): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/admin/v1/wim_accounts".format(self._base_path) + try: + r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + + return result + def vim_list(self, token): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/yaml", "accept": "application/json", @@ -1221,12 +1349,29 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result + def wim_delete(self, token, id): + result = {'error': True, 'data': ''} + headers = {"accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/admin/v1/wim_accounts/{1}".format(self._base_path, id) + try: + r = requests.delete(_url, params=None, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + else: + result['data'] = r.text + return result + def vim_delete(self, token, id): result = {'error': True, 'data': ''} headers = {"accept": "application/json", @@ -1238,12 +1383,30 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.accepted: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = r.text return result + def wim_get(self, token, id): + + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/admin/v1/wim_accounts/{1}".format(self._base_path, id) + + try: + r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def vim_get(self, token, id): result = {'error': True, 'data': ''} @@ -1257,7 +1420,25 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + + def wim_create(self, token, wim_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/wim_accounts".format(self._base_path) + + try: + r = requests.post(_url, json=wim_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1276,7 +1457,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1292,7 +1473,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1308,7 +1489,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.accepted: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = r.text @@ -1326,7 +1507,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1344,11 +1525,183 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + + def k8sc_get(self, token, id): + result = {'error': True, 'data': ''} + headers = {"accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/admin/v1/k8sclusters/{1}".format(self._base_path, id) + try: + r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + + def k8sc_list(self, token): + result = {'error': True, 'data': ''} + headers = {"accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/admin/v1/k8sclusters".format(self._base_path) + try: + r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + + def k8sc_create(self, token, cluster_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/k8sclusters".format(self._base_path) + + try: + r = requests.post(_url, json=cluster_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + + def k8sc_update(self, token, id, cluster_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/k8sclusters/{1}".format(self._base_path, id) + try: + r = requests.patch(_url, json=cluster_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + else: + result['data'] = Util.json_loads_byteified(r.text) + return result + + def k8sc_delete(self, token, id): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/k8sclusters/{1}".format(self._base_path, id) + try: + r = requests.delete(_url, params=None, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + else: + result['data'] = Util.json_loads_byteified(r.text) + return result + + def k8sr_get(self, token, id): + result = {'error': True, 'data': ''} + headers = {"accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/admin/v1/k8srepos/{1}".format(self._base_path, id) + try: + r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + + def k8sr_list(self, token): + result = {'error': True, 'data': ''} + headers = {"accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/admin/v1/k8srepos".format(self._base_path) + try: + r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result + def k8sr_create(self, token, cluster_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/k8srepos".format(self._base_path) + + try: + r = requests.post(_url, json=cluster_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + + def k8sr_update(self, token, id, cluster_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/k8srepos/{1}".format(self._base_path, id) + try: + r = requests.patch(_url, json=cluster_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + else: + result['data'] = Util.json_loads_byteified(r.text) + return result + + def k8sr_delete(self, token, id): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/k8srepos/{1}".format(self._base_path, id) + try: + r = requests.delete(_url, params=None, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code in (200, 201, 202, 204): + result['error'] = False + else: + result['data'] = Util.json_loads_byteified(r.text) + return result + @staticmethod def md5(f): hash_md5 = hashlib.md5()