From: garciadeblas Date: Mon, 26 Jun 2023 16:34:45 +0000 (+0200) Subject: Remove unnecessary references to fullclassname after removal of v1 client X-Git-Tag: release-v14.0-start~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=23cc10b85ee953de2a1f5c6d84cffcc816a421d0;p=osm%2Fosmclient.git Remove unnecessary references to fullclassname after removal of v1 client Change-Id: I08aff2dc1eec721465d7504f3e54c155cc1a227a Signed-off-by: garciadeblas --- diff --git a/osmclient/cli_commands/nfpkg.py b/osmclient/cli_commands/nfpkg.py index c69be62..ce7212e 100755 --- a/osmclient/cli_commands/nfpkg.py +++ b/osmclient/cli_commands/nfpkg.py @@ -53,60 +53,54 @@ def vnfd_list(ctx, nf_type, filter, long): else: resp = ctx.obj.vnfd.list() # print(yaml.safe_dump(resp)) - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname == "osmclient.sol005.client.Client": + if long: + table = PrettyTable( + [ + "nfpkg name", + "id", + "desc type", + "vendor", + "version", + "onboarding state", + "operational state", + "usage state", + "date", + "last update", + ] + ) + else: + table = PrettyTable(["nfpkg name", "id", "desc type"]) + for vnfd in resp: + name = vnfd.get("id", vnfd.get("name", "-")) + descriptor_type = "sol006" if "product-name" in vnfd else "rel8" if long: - table = PrettyTable( + onb_state = vnfd["_admin"].get("onboardingState", "-") + op_state = vnfd["_admin"].get("operationalState", "-") + vendor = vnfd.get("provider", vnfd.get("vendor")) + version = vnfd.get("version") + usage_state = vnfd["_admin"].get("usageState", "-") + date = datetime.fromtimestamp(vnfd["_admin"]["created"]).strftime( + "%Y-%m-%dT%H:%M:%S" + ) + last_update = datetime.fromtimestamp(vnfd["_admin"]["modified"]).strftime( + "%Y-%m-%dT%H:%M:%S" + ) + table.add_row( [ - "nfpkg name", - "id", - "desc type", - "vendor", - "version", - "onboarding state", - "operational state", - "usage state", - "date", - "last update", + name, + vnfd["_id"], + descriptor_type, + vendor, + version, + onb_state, + op_state, + usage_state, + date, + last_update, ] ) else: - table = PrettyTable(["nfpkg name", "id", "desc type"]) - for vnfd in resp: - name = vnfd.get("id", vnfd.get("name", "-")) - descriptor_type = "sol006" if "product-name" in vnfd else "rel8" - if long: - onb_state = vnfd["_admin"].get("onboardingState", "-") - op_state = vnfd["_admin"].get("operationalState", "-") - vendor = vnfd.get("provider", vnfd.get("vendor")) - version = vnfd.get("version") - usage_state = vnfd["_admin"].get("usageState", "-") - date = datetime.fromtimestamp(vnfd["_admin"]["created"]).strftime( - "%Y-%m-%dT%H:%M:%S" - ) - last_update = datetime.fromtimestamp( - vnfd["_admin"]["modified"] - ).strftime("%Y-%m-%dT%H:%M:%S") - table.add_row( - [ - name, - vnfd["_id"], - descriptor_type, - vendor, - version, - onb_state, - op_state, - usage_state, - date, - last_update, - ] - ) - else: - table.add_row([name, vnfd["_id"], descriptor_type]) - else: - table = PrettyTable(["nfpkg name", "id"]) - for vnfd in resp: - table.add_row([vnfd["name"], vnfd["id"]]) + table.add_row([name, vnfd["_id"], descriptor_type]) table.align = "l" print(table) diff --git a/osmclient/cli_commands/ns.py b/osmclient/cli_commands/ns.py index 75054fe..80961d5 100755 --- a/osmclient/cli_commands/ns.py +++ b/osmclient/cli_commands/ns.py @@ -210,65 +210,41 @@ def ns_list(ctx, filter, long, output): ] ) for ns in resp: - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname == "osmclient.sol005.client.Client": - nsr = ns - logger.debug("NS info: {}".format(nsr)) - nsr_name = nsr["name"] - nsr_id = nsr["_id"] - date = datetime.fromtimestamp(nsr["create-time"]).strftime( - "%Y-%m-%dT%H:%M:%S" - ) - ns_state = nsr.get("nsState", nsr["_admin"]["nsState"]) - if long: - deployment_status = summarize_deployment_status( - nsr.get("deploymentStatus") - ) - config_status = summarize_config_status(nsr.get("configurationStatus")) - project_id, project_name = utils.get_project(project_list, nsr) - # project = '{} ({})'.format(project_name, project_id) - project = project_name - vim_id = nsr.get("datacenter") - vim_name = utils.get_vim_name(vim_list, vim_id) + nsr = ns + logger.debug("NS info: {}".format(nsr)) + nsr_name = nsr["name"] + nsr_id = nsr["_id"] + date = datetime.fromtimestamp(nsr["create-time"]).strftime("%Y-%m-%dT%H:%M:%S") + ns_state = nsr.get("nsState", nsr["_admin"]["nsState"]) + if long: + deployment_status = summarize_deployment_status(nsr.get("deploymentStatus")) + config_status = summarize_config_status(nsr.get("configurationStatus")) + project_id, project_name = utils.get_project(project_list, nsr) + # project = '{} ({})'.format(project_name, project_id) + project = project_name + vim_id = nsr.get("datacenter") + vim_name = utils.get_vim_name(vim_list, vim_id) - # vim = '{} ({})'.format(vim_name, vim_id) - vim = vim_name - if "currentOperation" in nsr: - current_operation = "{} ({})".format( - nsr["currentOperation"], nsr["currentOperationID"] - ) - else: - current_operation = "{} ({})".format( - nsr["_admin"].get("current-operation", "-"), - nsr["_admin"]["nslcmop"], - ) - error_details = "N/A" - if ( - ns_state == "BROKEN" - or ns_state == "DEGRADED" - or ("currentOperation" not in nsr and nsr.get("errorDescription")) - ): - error_details = "{}\nDetail: {}".format( - nsr["errorDescription"], nsr["errorDetail"] - ) + # vim = '{} ({})'.format(vim_name, vim_id) + vim = vim_name + if "currentOperation" in nsr: + current_operation = "{} ({})".format( + nsr["currentOperation"], nsr["currentOperationID"] + ) else: - nsopdata = ctx.obj.ns.get_opdata(ns["id"]) - nsr = nsopdata["nsr:nsr"] - nsr_name = nsr["name-ref"] - nsr_id = nsr["ns-instance-config-ref"] - date = "-" - project = "-" - deployment_status = ( - nsr["operational-status"] - if "operational-status" in nsr - else "Not found" + current_operation = "{} ({})".format( + nsr["_admin"].get("current-operation", "-"), + nsr["_admin"]["nslcmop"], + ) + error_details = "N/A" + if ( + ns_state == "BROKEN" + or ns_state == "DEGRADED" + or ("currentOperation" not in nsr and nsr.get("errorDescription")) + ): + error_details = "{}\nDetail: {}".format( + nsr["errorDescription"], nsr["errorDetail"] ) - ns_state = deployment_status - config_status = nsr.get("config-status", "Not found") - current_operation = "Unknown" - error_details = nsr.get("detailed-status", "Not found") - if config_status == "config_not_needed": - config_status = "configured (no charms)" if long: table.add_row( @@ -331,13 +307,11 @@ def ns_show(ctx, name, literal, filter, output): if not filter or k in filter: table.add_row([k, utils.wrap_text(text=json.dumps(v, indent=2), width=100)]) - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname != "osmclient.sol005.client.Client": - nsopdata = ctx.obj.ns.get_opdata(ns["id"]) - nsr_optdata = nsopdata["nsr:nsr"] - for k, v in list(nsr_optdata.items()): - if not filter or k in filter: - table.add_row([k, utils.wrap_text(json.dumps(v, indent=2), width=100)]) + nsopdata = ctx.obj.ns.get_opdata(ns["id"]) + nsr_optdata = nsopdata["nsr:nsr"] + for k, v in list(nsr_optdata.items()): + if not filter or k in filter: + table.add_row([k, utils.wrap_text(json.dumps(v, indent=2), width=100)]) print_output.print_output(output, table.field_names, table._rows) diff --git a/osmclient/cli_commands/nspkg.py b/osmclient/cli_commands/nspkg.py index 44f0a4f..be0304d 100755 --- a/osmclient/cli_commands/nspkg.py +++ b/osmclient/cli_commands/nspkg.py @@ -33,51 +33,45 @@ def nsd_list(ctx, filter, long): else: resp = ctx.obj.nsd.list() # print(yaml.safe_dump(resp)) - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname == "osmclient.sol005.client.Client": + if long: + table = PrettyTable( + [ + "nsd name", + "id", + "onboarding state", + "operational state", + "usage state", + "date", + "last update", + ] + ) + else: + table = PrettyTable(["nsd name", "id"]) + for nsd in resp: + name = nsd.get("id", "-") if long: - table = PrettyTable( + onb_state = nsd["_admin"].get("onboardingState", "-") + op_state = nsd["_admin"].get("operationalState", "-") + usage_state = nsd["_admin"].get("usageState", "-") + date = datetime.fromtimestamp(nsd["_admin"]["created"]).strftime( + "%Y-%m-%dT%H:%M:%S" + ) + last_update = datetime.fromtimestamp(nsd["_admin"]["modified"]).strftime( + "%Y-%m-%dT%H:%M:%S" + ) + table.add_row( [ - "nsd name", - "id", - "onboarding state", - "operational state", - "usage state", - "date", - "last update", + name, + nsd["_id"], + onb_state, + op_state, + usage_state, + date, + last_update, ] ) else: - table = PrettyTable(["nsd name", "id"]) - for nsd in resp: - name = nsd.get("id", "-") - if long: - onb_state = nsd["_admin"].get("onboardingState", "-") - op_state = nsd["_admin"].get("operationalState", "-") - usage_state = nsd["_admin"].get("usageState", "-") - date = datetime.fromtimestamp(nsd["_admin"]["created"]).strftime( - "%Y-%m-%dT%H:%M:%S" - ) - last_update = datetime.fromtimestamp( - nsd["_admin"]["modified"] - ).strftime("%Y-%m-%dT%H:%M:%S") - table.add_row( - [ - name, - nsd["_id"], - onb_state, - op_state, - usage_state, - date, - last_update, - ] - ) - else: - table.add_row([name, nsd["_id"]]) - else: - table = PrettyTable(["nsd name", "id"]) - for nsd in resp: - table.add_row([nsd["name"], nsd["id"]]) + table.add_row([name, nsd["_id"]]) table.align = "l" print(table) diff --git a/osmclient/cli_commands/packages.py b/osmclient/cli_commands/packages.py index 4b62743..3853a30 100755 --- a/osmclient/cli_commands/packages.py +++ b/osmclient/cli_commands/packages.py @@ -297,6 +297,3 @@ def upload_package(ctx, filename, skip_charm_build): """ logger.debug("") ctx.obj.package.upload(filename, skip_charm_build=skip_charm_build) - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname != "osmclient.sol005.client.Client": - ctx.obj.package.wait_for_upload(filename) diff --git a/osmclient/cli_commands/utils.py b/osmclient/cli_commands/utils.py index 5ac9931..9ec03f6 100755 --- a/osmclient/cli_commands/utils.py +++ b/osmclient/cli_commands/utils.py @@ -44,14 +44,11 @@ def check_client_version(obj, what, version="sol005"): :raises ClientError: if the specified version does not match the client version """ logger.debug("") + if version == "sol005": + message = f"The following commands or options are only supported with the version v1 of OSM SOL005': {what}" + elif version == "sol005_v2": + message = f"The following commands or options are only supported with the version v2 of OSM SOL005': {what}" fullclassname = obj.__module__ + "." + obj.__class__.__name__ - message = 'The following commands or options are only supported with the option "--sol005": {}'.format( - what - ) - if version == "v1": - message = 'The following commands or options are not supported when using option "--sol005": {}'.format( - what - ) if fullclassname != "osmclient.{}.client.Client".format(version): raise ClientException(message) return diff --git a/osmclient/cli_commands/vim.py b/osmclient/cli_commands/vim.py index d74ea7b..2f7bbfc 100755 --- a/osmclient/cli_commands/vim.py +++ b/osmclient/cli_commands/vim.py @@ -312,9 +312,7 @@ def vim_list(ctx, filter, long, output): if filter: filter = "&".join(filter) utils.check_client_version(ctx.obj, "--filter") - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname == "osmclient.sol005.client.Client": - resp = ctx.obj.vim.list(filter) + resp = ctx.obj.vim.list(filter) if long: table = PrettyTable( ["vim name", "uuid", "project", "operational state", "error details"] diff --git a/osmclient/cli_commands/vnf.py b/osmclient/cli_commands/vnf.py index 974a421..59c8df4 100755 --- a/osmclient/cli_commands/vnf.py +++ b/osmclient/cli_commands/vnf.py @@ -38,8 +38,16 @@ def vnf_list(ctx, ns, filter, long, output): resp = ctx.obj.vnf.list(ns, filter) else: resp = ctx.obj.vnf.list() - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname == "osmclient.sol005.client.Client": + field_names = [ + "vnf id", + "name", + "ns id", + "vnf member index", + "vnfd name", + "vim account id", + "ip address", + ] + if long: field_names = [ "vnf id", "name", @@ -48,54 +56,30 @@ def vnf_list(ctx, ns, filter, long, output): "vnfd name", "vim account id", "ip address", + "date", + "last update", + ] + table = PrettyTable(field_names) + for vnfr in resp: + name = vnfr["name"] if "name" in vnfr else "-" + new_row = [ + vnfr["_id"], + name, + vnfr["nsr-id-ref"], + vnfr["member-vnf-index-ref"], + vnfr["vnfd-ref"], + vnfr["vim-account-id"], + vnfr["ip-address"], ] if long: - field_names = [ - "vnf id", - "name", - "ns id", - "vnf member index", - "vnfd name", - "vim account id", - "ip address", - "date", - "last update", - ] - table = PrettyTable(field_names) - for vnfr in resp: - name = vnfr["name"] if "name" in vnfr else "-" - new_row = [ - vnfr["_id"], - name, - vnfr["nsr-id-ref"], - vnfr["member-vnf-index-ref"], - vnfr["vnfd-ref"], - vnfr["vim-account-id"], - vnfr["ip-address"], - ] - if long: - date = datetime.fromtimestamp(vnfr["_admin"]["created"]).strftime( - "%Y-%m-%dT%H:%M:%S" - ) - last_update = datetime.fromtimestamp( - vnfr["_admin"]["modified"] - ).strftime("%Y-%m-%dT%H:%M:%S") - new_row.extend([date, last_update]) - table.add_row(new_row) - else: - table = PrettyTable(["vnf name", "id", "operational status", "config status"]) - for vnfr in resp: - if "mgmt-interface" not in vnfr: - vnfr["mgmt-interface"] = {} - vnfr["mgmt-interface"]["ip-address"] = None - table.add_row( - [ - vnfr["name"], - vnfr["id"], - vnfr["operational-status"], - vnfr["config-status"], - ] + date = datetime.fromtimestamp(vnfr["_admin"]["created"]).strftime( + "%Y-%m-%dT%H:%M:%S" + ) + last_update = datetime.fromtimestamp(vnfr["_admin"]["modified"]).strftime( + "%Y-%m-%dT%H:%M:%S" ) + new_row.extend([date, last_update]) + table.add_row(new_row) print_output.print_output(output, table.field_names, table._rows)