X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fosm%2Fosmclient%2Fclientv2.py;fp=lib%2Fosm%2Fosmclient%2Fclientv2.py;h=8056d365ed2ebbd37044a044fc5d2d84a0992a6a;hb=3c7234a89c9cea821cd94f38b6de32acc71bfe74;hp=cee0647fd800a866a14d6ee22564073562cd8713;hpb=e96d058fe5c681052f45c1d794ba80b09b162c64;p=osm%2FLW-UI.git diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index cee0647..8056d36 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -114,7 +114,6 @@ class Client(object): 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: @@ -1531,6 +1530,178 @@ class Client(object): 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()