X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FLW-UI.git;a=blobdiff_plain;f=lib%2Fosm%2Fosmclient%2Fclientv2.py;h=0914fb3fc010d2d5efe5ff50a9b59efc54fc3865;hp=8fbb0d2d6f0cddb0d699b3671dfdc30e998c573e;hb=3fcf21a3589d2e9f94b2de318d3dc0404f4be94b;hpb=9ccf7d0ba2132b34df4b70fec183c03911344707 diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index 8fbb0d2..0914fb3 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -37,7 +37,7 @@ class Client(object): self._user_endpoint = 'admin/v1/users' self._host = os.getenv('OSM_SERVER', "localhost") self._so_port = 9999 - self._base_path = "https://{0}:{1}/osm".format(self._host, self._so_port) + self._base_path = 'https://{0}:{1}/osm'.format(self._host, self._so_port) def auth(self, args): result = {'error': True, 'data': ''} @@ -251,12 +251,46 @@ class Client(object): result['data'] = Util.json_loads_byteified(r.text) return result - def nsd_list(self, token): + def nst_details(self, token, id): result = {'error': True, 'data': ''} - headers = {"Content-Type": "application/yaml", "accept": "application/json", + headers = {"Content-Type": "application/json", "accept": "application/json", 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/nst/v1/netslice_templates/{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 == requests.codes.ok: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + + return result - _url = "{0}/nsd/v1/ns_descriptors_content".format(self._base_path) + def nst_content(self, token, id): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "text/plain", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/nst/v1/netslice_templates/{1}/nst".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 == requests.codes.ok: + result['error'] = False + result['data'] = Util.json2yaml(yaml.load(str(r.text))) + + return result + + def nst_list(self, token): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/nst/v1/netslice_templates".format(self._base_path) try: r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) except Exception as e: @@ -269,12 +303,34 @@ class Client(object): return result - def vnfd_list(self, token): + def nsd_list(self, token, filter=None): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/yaml", "accept": "application/json", 'Authorization': 'Bearer {}'.format(token['id'])} + query_path = '' + if filter: + query_path = '?_admin.type='+filter + _url = "{0}/nsd/v1/ns_descriptors_content{1}".format(self._base_path, query_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 == requests.codes.ok: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) - _url = "{0}/vnfpkgm/v1/vnf_packages_content".format(self._base_path) + return result + + def vnfd_list(self, token, filter=None): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + query_path = '' + if filter: + query_path = '?_admin.type='+filter + _url = "{0}/vnfpkgm/v1/vnf_packages_content{1}".format(self._base_path, query_path) try: r = requests.get(_url, params=None, verify=False, stream=True, headers=headers) except Exception as e: @@ -287,6 +343,23 @@ class Client(object): return result + def nsi_list(self, token): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/nsilcm/v1/netslice_instances".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 == requests.codes.ok: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + + return result + def ns_list(self, token): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/yaml", "accept": "application/json", @@ -321,6 +394,40 @@ class Client(object): return result + def pdu_list(self, token): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/pdu/v1/pdu_descriptors".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 == requests.codes.ok: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + + return result + + def nst_delete(self, token, id): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/nst/v1/netslice_templates/{1}?FORCE=True".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 == requests.codes.no_content: + result['error'] = False + + return result + def nsd_delete(self, token, id): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/yaml", "accept": "application/json", @@ -356,6 +463,27 @@ class Client(object): result['data'] = Util.json_loads_byteified(r.text) return result + def nst_onboard(self, token, template): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/gzip", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/nst/v1/netslice_templates_content".format(self._base_path) + try: + fileName, fileExtension = os.path.splitext(template.name) + if fileExtension == '.gz': + headers["Content-Type"] = "application/gzip" + else: + headers["Content-Type"] = "application/yaml" + r = requests.post(_url, data=template, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code == requests.codes.created: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def nsd_onboard(self, token, package): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/gzip", "accept": "application/json", @@ -405,6 +533,7 @@ class Client(object): try: self._create_base_pkg('nsd', pkg_name) + headers['Content-Filename'] = pkg_name + '.tar.gz' r = requests.post(_url, data=open('/tmp/' + pkg_name + '.tar.gz', 'rb'), verify=False, headers=headers) except Exception as e: log.exception(e) @@ -493,6 +622,21 @@ class Client(object): return result + def nst_content_update(self, token, id, template): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/nst/v1/netslice_templates/{1}/nst_content".format(self._base_path,id) + try: + r = requests.put(_url, data=template, 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: + result['error'] = False + return result + def nsd_update(self, token, id, data): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/gzip", "accept": "application/json", @@ -516,6 +660,11 @@ class Client(object): return result if r.status_code == requests.codes.no_content: result['error'] = False + else: + try: + result['data'] = r.json() + except Exception as e: + result['data'] = {} return result @@ -542,6 +691,11 @@ class Client(object): return result if r.status_code == requests.codes.no_content: result['error'] = False + else: + try: + result['data'] = r.json() + except Exception as e: + result['data'] = {} return result @@ -625,7 +779,9 @@ class Client(object): "short-name": str(pkg_name), "vdu": [], "description": "", - "mgmt-interface": {}, + "mgmt-interface": { + "cp": "" + }, "id": str(pkg_name), "version": "1.0", "internal-vld": [], @@ -769,6 +925,24 @@ class Client(object): return result + def nsi_create(self, token, nsi_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/nsilcm/v1/netslice_instances_content".format(self._base_path) + + try: + r = requests.post(_url, json=nsi_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code == requests.codes.ok: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def ns_create(self, token, ns_data): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/yaml", "accept": "application/json", @@ -787,6 +961,24 @@ class Client(object): result['data'] = Util.json_loads_byteified(r.text) return result + def pdu_create(self, token, pdu_data): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/pdu/v1/pdu_descriptors".format(self._base_path) + + try: + r = requests.post(_url, json=pdu_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + if r.status_code == requests.codes.created: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def ns_op_list(self, token, id): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/json", "accept": "application/json", @@ -805,6 +997,24 @@ class Client(object): return result + def nsi_op_list(self, token, id): + 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) + + 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 == requests.codes.ok: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + + return result + def ns_op(self, token, id): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/json", "accept": "application/json", @@ -841,6 +1051,26 @@ class Client(object): result['data'] = Util.json_loads_byteified(r.text) return result + def nsi_delete(self, token, id, force=None): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + query_path = '' + if force: + query_path = '?FORCE=true' + _url = "{0}/nsilcm/v1/netslice_instances_content/{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: + result['error'] = False + if r.status_code != requests.codes.no_content: + result['data'] = Util.json_loads_byteified(r.text) + return result + def ns_delete(self, token, id, force=None): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/yaml", "accept": "application/json", @@ -861,6 +1091,40 @@ class Client(object): result['data'] = Util.json_loads_byteified(r.text) return result + def pdu_delete(self, token, id): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/yaml", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/pdu/v1/pdu_descriptors/{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: + result['error'] = False + if r.status_code != requests.codes.no_content: + result['data'] = Util.json_loads_byteified(r.text) + return result + + def nsi_get(self, token, id): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/nsilcm/v1/netslice_instances/{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 == requests.codes.ok: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def ns_get(self, token, id): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/json", "accept": "application/json", @@ -895,6 +1159,23 @@ class Client(object): result['data'] = Util.json_loads_byteified(r.text) return result + def pdu_get(self, token, id): + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + _url = "{0}/pdu/v1/pdu_descriptors/{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 == requests.codes.ok: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def ns_alarm_create(self, token, id, alarm_payload): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/json", @@ -929,6 +1210,23 @@ class Client(object): 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 == requests.codes.ok: + 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", @@ -946,6 +1244,23 @@ class Client(object): 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 == requests.codes.accepted: + result['error'] = False + else: + result['data'] = r.text + return result + def vim_delete(self, token, id): result = {'error': True, 'data': ''} headers = {"accept": "application/json", @@ -963,6 +1278,24 @@ class Client(object): 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 == requests.codes.ok: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def vim_get(self, token, id): result = {'error': True, 'data': ''} @@ -981,6 +1314,24 @@ class Client(object): 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 == requests.codes.created: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def vim_create(self, token, vim_data): result = {'error': True, 'data': ''}