From: garciadeblas Date: Wed, 23 Sep 2020 12:12:50 +0000 (+0000) Subject: Fix bug 1232: k8scluster-list now shows the vim name it belongs to X-Git-Tag: release-v9.0-start~12 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F60%2F9860%2F3;p=osm%2Fosmclient.git Fix bug 1232: k8scluster-list now shows the vim name it belongs to VIM name is shown instead of VIM ID. Similar code was already used in different places, so it has been properly refactored through the function get_vim_name Change-Id: I46137f0e17762786036b1cacbbbc043fad0d488f Signed-off-by: garciadeblas --- diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index 1df00d6..054bbd1 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -84,6 +84,15 @@ def get_project(project_list, item): return project_id, project_name +def get_vim_name(vim_list, vim_id): + vim_name = '-' + for v in vim_list: + if v['uuid'] == vim_id: + vim_name = v['name'] + break + return vim_name + + @click.group(context_settings=dict(help_option_names=['-h', '--help'], max_content_width=160)) @click.option('--hostname', default="127.0.0.1", @@ -342,7 +351,10 @@ def ns_list(ctx, filter, long): 'deployment status', 'configuration status']) project_list = ctx.obj.project.list() - vim_list = ctx.obj.vim.list() + try: + vim_list = ctx.obj.vim.list() + except: + vim_list = [] else: table = PrettyTable( ['ns instance name', @@ -363,20 +375,11 @@ def ns_list(ctx, filter, long): if long: deployment_status = summarize_deployment_status(nsr.get('deploymentStatus')) config_status = summarize_config_status(nsr.get('configurationStatus')) - project_id = nsr.get('_admin').get('projects_read')[0] - project_name = '-' - for p in project_list: - if p['_id'] == project_id: - project_name = p['name'] - break + project_id, project_name = get_project(project_list, nsr) #project = '{} ({})'.format(project_name, project_id) project = project_name vim_id = nsr.get('datacenter') - vim_name = '-' - for v in vim_list: - if v['uuid'] == vim_id: - vim_name = v['name'] - break + vim_name = get_vim_name(vim_list, vim_id) #vim = '{} ({})'.format(vim_name, vim_id) vim = vim_name if 'currentOperation' in nsr: @@ -3155,7 +3158,14 @@ def k8scluster_list(ctx, filter, literal, long): project_list = ctx.obj.project.list() else: table = PrettyTable(['Name', 'Id', 'VIM', 'Operational State', 'Op. state details']) + try: + vim_list = ctx.obj.vim.list() + except: + vim_list = [] for cluster in resp: + vim_name = get_vim_name(vim_list, cluster['vim_account']) + #vim_info = '{} ({})'.format(vim_name,cluster['vim_account']) + vim_info = vim_name op_state_details = "Helm: {}\nJuju: {}".format( cluster["_admin"].get("helm-chart", "-").get("operationalState", "-"), cluster["_admin"].get("juju-bundle", "-").get("operationalState", "-")) @@ -3166,12 +3176,12 @@ def k8scluster_list(ctx, filter, literal, long): project_info = project_name detailed_status = cluster["_admin"].get("detailed-status","-") table.add_row([cluster['name'], cluster['_id'], project_info, - cluster['k8s_version'], cluster['vim_account'], + cluster['k8s_version'], vim_info, json.dumps(cluster['nets']), cluster["_admin"]["operationalState"], op_state_details, trunc_text(cluster.get('description') or '', 40), wrap_text(text=detailed_status, width=40)]) else: - table.add_row([cluster['name'], cluster['_id'], cluster['vim_account'], + table.add_row([cluster['name'], cluster['_id'], vim_info, cluster["_admin"]["operationalState"], op_state_details]) table.align = 'l' print(table)