Fix bug 1230: show Helm and Juju status when listing K8s clusters 58/9858/3
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 23 Sep 2020 11:03:41 +0000 (11:03 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 26 Nov 2020 15:14:10 +0000 (15:14 +0000)
Added --long option to k8scluster_list and moved some fields there

Change-Id: I24d660b571e44e861f218063c22339923315baed
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/scripts/osm.py

index 0ff195f..71506cd 100755 (executable)
@@ -3129,8 +3129,9 @@ def k8scluster_delete(ctx, name, force):
               help='restricts the list to the K8s clusters matching the filter')
 @click.option('--literal', is_flag=True,
               help='print literally, no pretty table')
+@click.option('--long', is_flag=True, help='get more details')
 @click.pass_context
-def k8scluster_list(ctx, filter, literal):
+def k8scluster_list(ctx, filter, literal, long):
     """list all K8s clusters"""
     # try:
     check_client_version(ctx.obj, ctx.command.name)
@@ -3140,11 +3141,23 @@ def k8scluster_list(ctx, filter, literal):
     if literal:
         print(yaml.safe_dump(resp, indent=4, default_flow_style=False))
         return
-    table = PrettyTable(['Name', 'Id', 'Version', 'VIM', 'K8s-nets', 'Operational State', 'Description'])
+    if long:
+        table = PrettyTable(['Name', 'Id', 'Version', 'VIM', 'K8s-nets', 'Operational State', 'Op. state (details)',
+                             'Description', 'Detailed status'])
+    else:
+        table = PrettyTable(['Name', 'Id', 'VIM', 'Operational State', 'Op. state details'])
     for cluster in resp:
-        table.add_row([cluster['name'], cluster['_id'], cluster['k8s_version'], cluster['vim_account'],
-                       json.dumps(cluster['nets']), cluster["_admin"]["operationalState"],
-                       trunc_text(cluster.get('description') or '', 40)])
+        op_state_details = "Helm: {}\nJuju: {}".format(
+                           cluster["_admin"].get("helm-chart", "-").get("operationalState", "-"),
+                           cluster["_admin"].get("juju-bundle", "-").get("operationalState", "-"))
+        if long:
+            detailed_status = cluster["_admin"].get("detailedStatus","-")
+            table.add_row([cluster['name'], cluster['_id'], cluster['k8s_version'], cluster['vim_account'],
+                           json.dumps(cluster['nets']), cluster["_admin"]["operationalState"],
+                           op_state_details, trunc_text(cluster.get('description') or '', 40), detailed_status])
+        else:
+            table.add_row([cluster['name'], cluster['_id'], cluster['vim_account'],
+                           cluster["_admin"]["operationalState"], op_state_details])
     table.align = 'l'
     print(table)
     # except ClientException as e: