From 76b66d904d5347950e6dda6be770de27ae85b39e Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Thu, 25 Jul 2019 11:15:29 +0200 Subject: [PATCH] mgr/orchestrator: better format `service ls` Signed-off-by: Sebastian Wagner --- src/pybind/mgr/orchestrator_cli/module.py | 33 ++++++++++++++++------- src/pybind/mgr/rook/module.py | 9 +++++++ src/pybind/mgr/rook/rook_cluster.py | 3 ++- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index 7d3265bf925..20791959614 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -1,6 +1,8 @@ import errno import json +from prettytable import PrettyTable + try: from typing import Dict, List except ImportError: @@ -132,8 +134,10 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): orchestrator.raise_if_exception(completion) services = completion.result + def ukn(s): + return '' if s is None else s # Sort the list for display - services.sort(key=lambda s: (s.service_type, s.nodename, s.service_instance)) + services.sort(key=lambda s: (ukn(s.service_type), ukn(s.nodename), ukn(s.service_instance))) if len(services) == 0: return HandleCommandResult(stdout="No services reported") @@ -141,22 +145,31 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): data = [s.to_json() for s in services] return HandleCommandResult(stdout=json.dumps(data)) else: - lines = [] + table = PrettyTable( + ['type', 'id', 'host', 'container', 'version', 'status', 'description'], + border=False) for s in services: - if s.service == None: + if s.service is None: service_id = s.service_instance else: service_id = "{0}.{1}".format(s.service, s.service_instance) - - lines.append("{0} {1} {2} {3} {4} {5}".format( + status = { + -1: 'error', + 0: 'stopped', + 1: 'running', + None: '' + }[s.status] + + table.add_row(( s.service_type, service_id, - s.nodename, - s.container_id, - s.version, - s.rados_config_location)) + ukn(s.nodename), + ukn(s.container_id), + ukn(s.version), + status, + ukn(s.status_desc))) - return HandleCommandResult(stdout="\n".join(lines)) + return HandleCommandResult(stdout=table.get_string()) @_write_cli('orchestrator osd create', "name=svc_arg,type=CephString,req=false", diff --git a/src/pybind/mgr/rook/module.py b/src/pybind/mgr/rook/module.py index c801e7db760..f92feed4080 100644 --- a/src/pybind/mgr/rook/module.py +++ b/src/pybind/mgr/rook/module.py @@ -346,6 +346,15 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): sd.nodename = p['nodename'] sd.container_id = p['name'] sd.service_type = p['labels']['app'].replace('rook-ceph-', '') + status = { + 'Pending': -1, + 'Running': 1, + 'Succeeded': 0, + 'Failed': -1, + 'Unknown': -1, + }[p['phase']] + sd.status = status + sd.status_desc = p['phase'] if sd.service_type == "osd": sd.service_instance = "%s" % p['labels']["ceph-osd-id"] diff --git a/src/pybind/mgr/rook/rook_cluster.py b/src/pybind/mgr/rook/rook_cluster.py index adc508d89a5..1d49033ee3f 100644 --- a/src/pybind/mgr/rook/rook_cluster.py +++ b/src/pybind/mgr/rook/rook_cluster.py @@ -309,7 +309,8 @@ class RookCluster(object): pods_summary.append({ "name": d['metadata']['name'], "nodename": d['spec']['node_name'], - "labels": d['metadata']['labels'] + "labels": d['metadata']['labels'], + 'phase': d['status']['phase'] }) return pods_summary -- 2.39.5