From: garciaale Date: Mon, 2 Nov 2020 19:42:56 +0000 (-0300) Subject: Updates SOL006 branch with master, and configures osmclient for SOL006 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F31%2F9931%2F2;p=osm%2Fosmclient.git Updates SOL006 branch with master, and configures osmclient for SOL006 Change-Id: I37e96a6c85033a12d40cb013c4e5b1c5b8a7790a Signed-off-by: garciaale --- diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index 3ef81ac..3083087 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -474,10 +474,10 @@ def pkg_repo_list(ctx, pkgtype, filter, repo, long): else: table = PrettyTable(['nfpkg name', 'repository']) for vnfd in resp: - name = vnfd.get('name', '-') + name = vnfd.get('product-name', '-') repository = vnfd.get('repository') if long: - vendor = vnfd.get('vendor') + vendor = vnfd.get('provider') version = vnfd.get('version') description = vnfd.get('description') latest = vnfd.get('latest') @@ -523,7 +523,7 @@ def vnfd_list(ctx, nf_type, filter, long): if long: onb_state = vnfd['_admin'].get('onboardingState','-') op_state = vnfd['_admin'].get('operationalState','-') - vendor = vnfd.get('vendor') + vendor = vnfd.get('provider') version = vnfd.get('version') usage_state = vnfd['_admin'].get('usageState','-') date = datetime.fromtimestamp(vnfd['_admin']['created']).strftime("%Y-%m-%dT%H:%M:%S") diff --git a/osmclient/sol005/nsd.py b/osmclient/sol005/nsd.py index 9aca930..5caad68 100644 --- a/osmclient/sol005/nsd.py +++ b/osmclient/sol005/nsd.py @@ -26,7 +26,6 @@ import magic from os.path import basename import logging import os.path -#from os import stat class Nsd(object): @@ -40,7 +39,6 @@ class Nsd(object): self._apiResource = '/ns_descriptors' self._apiBase = '{}{}{}'.format(self._apiName, self._apiVersion, self._apiResource) - #self._apiBase='/nsds' def list(self, filter=None): self._logger.debug("") @@ -49,7 +47,6 @@ class Nsd(object): if filter: filter_string = '?{}'.format(filter) _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase, filter_string)) - #print(yaml.safe_dump(resp)) if resp: return json.loads(resp) return list() @@ -75,7 +72,6 @@ class Nsd(object): # It is redundant, since the previous one already gets the whole nsdinfo # The only difference is that a different primitive is exercised _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nsd['_id'])) - #print(yaml.safe_dump(resp)) if resp: return json.loads(resp) except NotFound: @@ -89,19 +85,11 @@ class Nsd(object): headers = self._client._headers headers['Accept'] = 'application/binary' http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nsd['_id'], thing)) - #print('HTTP CODE: {}'.format(http_code)) - #print('RESP: {}'.format(resp)) - #if http_code in (200, 201, 202, 204): if resp: - #store in a file return json.loads(resp) else: msg = resp or "" - # if resp: - # try: - # msg = json.loads(resp) - # except ValueError: - # msg = resp + raise ClientException("failed to get {} from {} - {}".format(thing, name, msg)) def get_descriptor(self, name, filename): @@ -123,55 +111,46 @@ class Nsd(object): if force: querystring = '?FORCE=True' http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase, - nsd['_id'], querystring)) - #print('HTTP CODE: {}'.format(http_code)) - #print('RESP: {}'.format(resp)) + nsd['_id'], querystring)) + if http_code == 202: print('Deletion in progress') elif http_code == 204: print('Deleted') else: msg = resp or "" - # if resp: - # try: - # msg = json.loads(resp) - # except ValueError: - # msg = resp raise ClientException("failed to delete nsd {} - {}".format(name, msg)) def create(self, filename, overwrite=None, update_endpoint=None, skip_charm_build=False): self._logger.debug("") if os.path.isdir(filename): filename = filename.rstrip('/') - filename = self._client.package_tool.build(filename, skip_validation=False, skip_charm_build=skip_charm_build) + filename = self._client.package_tool.build(filename, skip_validation=False, + skip_charm_build=skip_charm_build) self.create(filename, overwrite=overwrite, update_endpoint=update_endpoint) else: self._client.get_token() mime_type = magic.from_file(filename, mime=True) if mime_type is None: raise ClientException( - "Unexpected MIME type for file {}: MIME type {}".format( - filename, mime_type) - ) - headers= self._client._headers + "Unexpected MIME type for file {}: MIME type {}".format( + filename, mime_type) + ) + headers = self._client._headers + headers['Content-Filename'] = basename(filename) if mime_type in ['application/yaml', 'text/plain', 'application/json']: headers['Content-Type'] = 'text/plain' elif mime_type in ['application/gzip', 'application/x-gzip']: headers['Content-Type'] = 'application/gzip' - #headers['Content-Type'] = 'application/binary' - # Next three lines are to be removed in next version - #headers['Content-Filename'] = basename(filename) - #file_size = stat(filename).st_size - #headers['Content-Range'] = 'bytes 0-{}/{}'.format(file_size - 1, file_size) else: raise ClientException( - "Unexpected MIME type for file {}: MIME type {}".format( - filename, mime_type) - ) + "Unexpected MIME type for file {}: MIME type {}".format( + filename, mime_type) + ) headers["Content-File-MD5"] = utils.md5(filename) - http_header = ['{}: {}'.format(key,val) - for (key,val) in list(headers.items())] + http_header = ['{}: {}'.format(key, val) + for (key, val) in list(headers.items())] self._http.set_http_header(http_header) if update_endpoint: http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename) @@ -182,10 +161,9 @@ class Nsd(object): self._apiResource = '/ns_descriptors_content' self._apiBase = '{}{}{}'.format(self._apiName, self._apiVersion, self._apiResource) - endpoint = '{}{}'.format(self._apiBase,ow_string) + endpoint = '{}{}'.format(self._apiBase, ow_string) http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename) - #print('HTTP CODE: {}'.format(http_code)) - #print('RESP: {}'.format(resp)) + if http_code in (200, 201, 202): if resp: resp = json.loads(resp) @@ -194,18 +172,9 @@ class Nsd(object): print(resp['id']) elif http_code == 204: print('Updated') - # else: - # msg = "Error {}".format(http_code) - # if resp: - # try: - # msg = "{} - {}".format(msg, json.loads(resp)) - # except ValueError: - # msg = "{} - {}".format(msg, resp) - # raise ClientException("failed to create/update nsd - {}".format(msg)) def update(self, name, filename): self._logger.debug("") nsd = self.get(name) endpoint = '{}/{}/nsd_content'.format(self._apiBase, nsd['_id']) self.create(filename=filename, update_endpoint=endpoint) - diff --git a/osmclient/sol005/vnfd.py b/osmclient/sol005/vnfd.py index ac44495..c7e8e6b 100644 --- a/osmclient/sol005/vnfd.py +++ b/osmclient/sol005/vnfd.py @@ -43,7 +43,6 @@ class Vnfd(object): self._apiResource = '/vnf_packages' self._apiBase = '{}{}{}'.format(self._apiName, self._apiVersion, self._apiResource) - #self._apiBase='/vnfds' def list(self, filter=None): self._logger.debug("") @@ -51,7 +50,8 @@ class Vnfd(object): filter_string = '' if filter: filter_string = '?{}'.format(filter) - _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string)) + _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase, filter_string)) + if resp: return json.loads(resp) return list() @@ -65,7 +65,7 @@ class Vnfd(object): return vnfd else: for vnfd in self.list(): - if 'name' in vnfd and name == vnfd['name']: + if 'product-name' in vnfd and name == vnfd['product-name']: return vnfd raise NotFound("vnfd {} not found".format(name)) @@ -76,7 +76,6 @@ class Vnfd(object): # The only difference is that a different primitive is exercised try: _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, vnfd['_id'])) - #print(yaml.safe_dump(resp)) if resp: return json.loads(resp) except NotFound: @@ -89,20 +88,10 @@ class Vnfd(object): headers = self._client._headers headers['Accept'] = 'application/binary' http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, vnfd['_id'], thing)) - #print('HTTP CODE: {}'.format(http_code)) - #print('RESP: {}'.format(resp)) - #if http_code in (200, 201, 202, 204): + if resp: - #store in a file return json.loads(resp) - #else: - # msg = "" - # if resp: - # try: - # msg = json.loads(resp) - # except ValueError: - # msg = resp - # raise ClientException("failed to get {} from {} - {}".format(thing, name, msg)) + def get_descriptor(self, name, filename): self._logger.debug("") @@ -124,20 +113,14 @@ class Vnfd(object): if force: querystring = '?FORCE=True' http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase, - vnfd['_id'], querystring)) - #print('HTTP CODE: {}'.format(http_code)) - #print('RESP: {}'.format(resp)) + vnfd['_id'], querystring)) + if http_code == 202: print('Deletion in progress') elif http_code == 204: print('Deleted') else: msg = resp or "" - # if resp: - # try: - # msg = json.loads(resp) - # except ValueError: - # msg = resp raise ClientException("failed to delete vnfd {} - {}".format(name, msg)) def create(self, filename, overwrite=None, update_endpoint=None, skip_charm_build=False, @@ -145,7 +128,9 @@ class Vnfd(object): self._logger.debug("") if os.path.isdir(filename): filename = filename.rstrip('/') - filename = self._client.package_tool.build(filename, skip_validation=False, skip_charm_build=skip_charm_build) + filename = self._client.package_tool.build(filename, skip_validation=False, + skip_charm_build=skip_charm_build) + print('Uploading package {}'.format(filename)) self.create(filename, overwrite=overwrite, update_endpoint=update_endpoint, override_epa=override_epa, override_nonepa=override_nonepa, @@ -164,19 +149,15 @@ class Vnfd(object): headers['Content-Type'] = 'text/plain' elif mime_type in ['application/gzip', 'application/x-gzip']: headers['Content-Type'] = 'application/gzip' - #headers['Content-Type'] = 'application/binary' - # Next three lines are to be removed in next version - #headers['Content-Filename'] = basename(filename) - #file_size = stat(filename).st_size - #headers['Content-Range'] = 'bytes 0-{}/{}'.format(file_size - 1, file_size) else: raise ClientException( - "Unexpected MIME type for file {}: MIME type {}".format( - filename, mime_type) - ) - special_ow_string = '' + "Unexpected MIME type for file {}: MIME type {}".format( + filename, mime_type) + ) + + special_override_string = '' if override_epa or override_nonepa or override_paravirt: - # If override for EPA, non-EPA or paravirt is required, get the descriptor data + # If override for EPA, non-EPA or paravirt is required, get the descriptor data descriptor_data = None if mime_type in ['application/yaml', 'text/plain', 'application/json']: with open(filename) as df: @@ -197,75 +178,100 @@ class Vnfd(object): tar_object.close() if not descriptor_data: raise ClientException('Descriptor could not be read') - desc_type, vnfd = validation_im.yaml_validation(self, descriptor_data) - validation_im.pyangbind_validation(self, desc_type, vnfd) + desc_type, vnfd = validation_im().yaml_validation(descriptor_data) + validation_im().pyangbind_validation(desc_type, vnfd) + vnfd = yaml.safe_load(descriptor_data) + vcd_list = [] vdu_list = [] for k in vnfd: # Get only the first descriptor in case there are many in the yaml file - # k can be vnfd:vnfd-catalog or vnfd-catalog. This check is skipped - first_vnfd = vnfd[k]['vnfd'][0] - vdu_list = first_vnfd.get('vdu',[]) - break; - for vdu_number, vdu in enumerate(vdu_list): + # k can be vnfd or etsi-nfv-vnfd:vnfd. This check is skipped + first_vnfd = vnfd.get(k, {}) + vcd_list = first_vnfd.get('virtual-compute-desc', []) + vdu_list = first_vnfd.get('vdu', []) + break + + for vcd_number, vcd in enumerate(vcd_list): if override_epa: - guest_epa = {} - guest_epa["mempage-size"] = "LARGE" - guest_epa["cpu-pinning-policy"] = "DEDICATED" - guest_epa["cpu-thread-pinning-policy"] = "PREFER" - guest_epa["numa-node-policy"] = {} - guest_epa["numa-node-policy"]["node-cnt"] = 1 - guest_epa["numa-node-policy"]["mem-policy"] = "STRICT" - #guest_epa["numa-node-policy"]["node"] = [] - #guest_epa["numa-node-policy"]["node"].append({"id": "0", "paired-threads": {"num-paired-threads": 1} }) - special_ow_string = "{}vdu.{}.guest-epa={};".format(special_ow_string,vdu_number,quote(yaml.safe_dump(guest_epa))) + virtual_memory = { + "mempage-size": "LARGE", + "numa-node-policy": { + "node-cnt": 1, + "mem-policy": "STRICT" + } + } + virtual_cpu = { + "pinning": { + "policy": "DEDICATED", + "thread-policy": "PREFER" + } + } + + memory_override_string = "virtual-compute-desc.{}.virtual-cpu={};"\ + .format(vcd_number, quote(yaml.safe_dump(virtual_cpu))) + cpu_override_string = "virtual-compute-desc.{}.virtual-memory={};"\ + .format(vcd_number, quote(yaml.safe_dump(virtual_memory))) + special_override_string = "{}{}{}".format(special_override_string, + cpu_override_string, memory_override_string) + headers['Query-String-Format'] = 'yaml' if override_nonepa: - special_ow_string = "{}vdu.{}.guest-epa=;".format(special_ow_string,vdu_number) - if override_paravirt: - for iface_number in range(len(vdu['interface'])): - special_ow_string = "{}vdu.{}.interface.{}.virtual-interface.type=PARAVIRT;".format( - special_ow_string,vdu_number,iface_number) - special_ow_string = special_ow_string.rstrip(";") + virtual_memory = { + "mempage-size": "", + "numa-node-policy": {} + } + virtual_cpu = { + "pinning": {} + } + + memory_override_string = "virtual-compute-desc.{}.virtual-cpu={};"\ + .format(vcd_number, quote(yaml.safe_dump(virtual_cpu))) + cpu_override_string = "virtual-compute-desc.{}.virtual-memory={};"\ + .format(vcd_number, quote(yaml.safe_dump(virtual_memory))) + special_override_string = "{}{}{}".format(special_override_string, + cpu_override_string, memory_override_string) + + if override_paravirt: + for vdu_number, vdu in enumerate(vdu_list): + for cpd_number, cpd in enumerate(vdu["int-cpd"]): + for vnir_number, vnir in enumerate(cpd['virtual-network-interface-requirement']): + special_override_string = "{}vdu.{}.int-cpd.{}.virtual-network-interface-" \ + "requirement.{}.virtual-interface.type=PARAVIRT;"\ + .format(special_override_string, vdu_number, cpd_number, vnir_number) + + special_override_string = special_override_string.rstrip(";") headers["Content-File-MD5"] = utils.md5(filename) - http_header = ['{}: {}'.format(key,val) - for (key,val) in list(headers.items())] + http_header = ['{}: {}'.format(key, val) + for (key, val) in list(headers.items())] + self._http.set_http_header(http_header) if update_endpoint: http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename) else: ow_string = '' - if special_ow_string: + if special_override_string: if overwrite: - overwrite = "{};{}".format(overwrite,special_ow_string) + overwrite = "{};{}".format(overwrite, special_override_string) else: - overwrite = special_ow_string + overwrite = special_override_string if overwrite: ow_string = '?{}'.format(overwrite) self._apiResource = '/vnf_packages_content' self._apiBase = '{}{}{}'.format(self._apiName, self._apiVersion, self._apiResource) - endpoint = '{}{}'.format(self._apiBase,ow_string) + endpoint = '{}{}'.format(self._apiBase, ow_string) http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename) - #print('HTTP CODE: {}'.format(http_code)) - #print('RESP: {}'.format(resp)) + if http_code in (200, 201, 202): if resp: resp = json.loads(resp) if not resp or 'id' not in resp: - raise ClientException('unexpected response from server: {}'.format(resp)) + raise ClientException('unexpected response from server: {}'.format(resp)) print(resp['id']) elif http_code == 204: print('Updated') - # else: - # msg = "Error {}".format(http_code) - # if resp: - # try: - # msg = "{} - {}".format(msg, json.loads(resp)) - # except ValueError: - # msg = "{} - {}".format(msg, resp) - # raise ClientException("failed to create/update vnfd - {}".format(msg)) def update(self, name, filename): self._logger.debug("") @@ -273,4 +279,3 @@ class Vnfd(object): vnfd = self.get(name) endpoint = '{}/{}/package_content'.format(self._apiBase, vnfd['_id']) self.create(filename=filename, update_endpoint=endpoint) -