summaryrefslogtreecommitdiff
path: root/saharaclient/osc
diff options
context:
space:
mode:
authorVitaly Gridnev <vgridnev@mirantis.com>2016-07-13 15:45:02 +0300
committerVitaly Gridnev <vgridnev@mirantis.com>2016-07-13 17:17:57 +0300
commita90f377cee3ff858db76c44ce94d93691394894e (patch)
treed817d704536381985a37cb4fc9eb5fd5c5327466 /saharaclient/osc
parente4d44d82bc4d44545938cf8e7ead684901c3c6a3 (diff)
downloadpython-saharaclient-a90f377cee3ff858db76c44ce94d93691394894e.tar.gz
support event logs for CLI
provision progress has nested structure, so it's hard display that nicely. so implemented ability to make dump with full event log details Change-Id: I7c14253c8c8724fdad4bd80178cdde74a225f37c
Diffstat (limited to 'saharaclient/osc')
-rw-r--r--saharaclient/osc/v1/clusters.py48
-rw-r--r--saharaclient/osc/v1/utils.py22
2 files changed, 64 insertions, 6 deletions
diff --git a/saharaclient/osc/v1/clusters.py b/saharaclient/osc/v1/clusters.py
index 50fc507..d5fa60d 100644
--- a/saharaclient/osc/v1/clusters.py
+++ b/saharaclient/osc/v1/clusters.py
@@ -20,6 +20,7 @@ from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils as osc_utils
from oslo_log import log as logging
+from oslo_serialization import jsonutils
from saharaclient.osc.v1 import utils
@@ -310,14 +311,40 @@ class ShowCluster(command.ShowOne):
default=False,
help='List additional fields for verifications',
)
+
+ parser.add_argument(
+ '--show-progress',
+ action='store_true',
+ default=False,
+ help='Provides ability to show brief details of event logs.'
+ )
+
+ parser.add_argument(
+ '--full-dump-events',
+ action='store_true',
+ default=False,
+ help='Provides ability to make full dump with event log details.'
+ )
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
client = self.app.client_manager.data_processing
+ kwargs = {}
+ if parsed_args.show_progress or parsed_args.full_dump_events:
+ kwargs['show_progress'] = True
data = utils.get_resource(
- client.clusters, parsed_args.cluster).to_dict()
+ client.clusters, parsed_args.cluster, **kwargs).to_dict()
+ provision_steps = data.get('provision_progress', [])
+ provision_steps = utils.created_at_sorted(provision_steps)
+
+ if parsed_args.full_dump_events:
+ file_name = utils.random_name('event-logs')
+ # making full dump
+ with open(file_name, 'w') as file:
+ jsonutils.dump(provision_steps, file, indent=4)
+ sys.stdout.write('Event log dump saved to file: %s\n' % file_name)
_format_cluster_output(data)
fields = []
@@ -325,9 +352,24 @@ class ShowCluster(command.ShowOne):
ver_data, fields = _prepare_health_checks(data)
data.update(ver_data)
fields.extend(CLUSTER_FIELDS)
- data = utils.prepare_data(data, fields)
- return self.dict2columns(data)
+ data = self.dict2columns(utils.prepare_data(data, fields))
+
+ if parsed_args.show_progress:
+ output_steps = []
+ for step in provision_steps:
+ st_name, st_type = step['step_name'], step['step_type']
+ description = "%s: %s" % (st_type, st_name)
+ if step['successful'] is None:
+ progress = "Step in progress"
+ elif step['successful']:
+ progress = "Step completed successfully"
+ else:
+ progress = 'Step has failed events'
+ output_steps += [(description, progress)]
+ data = utils.extend_columns(data, output_steps)
+
+ return data
class DeleteCluster(command.Command):
diff --git a/saharaclient/osc/v1/utils.py b/saharaclient/osc/v1/utils.py
index 8d37409..fd51450 100644
--- a/saharaclient/osc/v1/utils.py
+++ b/saharaclient/osc/v1/utils.py
@@ -22,11 +22,27 @@ from oslo_utils import uuidutils
from saharaclient.api import base
-def get_resource(manager, name_or_id):
+def get_resource(manager, name_or_id, **kwargs):
if uuidutils.is_uuid_like(name_or_id):
- return manager.get(name_or_id)
+ return manager.get(name_or_id, **kwargs)
else:
- return manager.find_unique(name=name_or_id)
+ resource = manager.find_unique(name=name_or_id)
+ if kwargs:
+ # we really need additional call to apply kwargs
+ resource = manager.get(resource.id, **kwargs)
+ return resource
+
+
+def created_at_sorted(objs, reverse=False):
+ return sorted(objs, key=created_at_key, reverse=reverse)
+
+
+def random_name(prefix=None):
+ return "%s-%s" % (prefix, uuidutils.generate_uuid()[:8])
+
+
+def created_at_key(obj):
+ return timeutils.parse_isotime(obj["created_at"])
def get_resource_id(manager, name_or_id):