Merge "support event logs for CLI"
This commit is contained in:
commit
0def46533c
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
features:
|
||||
- Providing ability to make dump of event logs for clusters.
|
||||
Also displaying shorten version of event logs by option.
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue