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",
'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',
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:
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", "-"))
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)