X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=lib%2Fosm%2Fosmclient%2Fclientv2.py;h=1820d2fc8547db24ac79e407d2e38a7f6b0f2444;hb=refs%2Fchanges%2F18%2F8318%2F1;hp=384eeaad8de8fa67fbe9ea1683a11fa1d1673d1d;hpb=8da2313d9791c27c6e67511bb0e392aec73ec7c4;p=osm%2FLW-UI.git diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index 384eeaa..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) @@ -113,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: @@ -153,15 +153,14 @@ class Client(object): _url = "{0}/admin/v1/roles/{1}".format(self._base_path, id) try: - r = requests.delete(_url, params=None, verify=False, headers=headers) + 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 - else: - result['data'] = Util.json_loads_byteified(r.text) + result['data'] = Util.json_loads_byteified(r.text) return result def user_list(self, token): @@ -252,6 +251,27 @@ class Client(object): 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", @@ -314,7 +334,7 @@ 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) @@ -827,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 @@ -1092,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) @@ -1510,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()