nicer cli tables for resource list and alarm list

Change-Id: Icbba61af3c9512dcb8def021b753d6156167cd22
This commit is contained in:
Idan Hefetz 2018-01-02 13:17:10 +00:00
parent bf718e0e99
commit bbcea6372c
3 changed files with 25 additions and 12 deletions

View File

@ -24,6 +24,13 @@ def list2cols(cols, objs):
for o in objs]
def list2cols_with_rename(names_and_keys, objs):
cols = [i[0] for i in names_and_keys]
keys = [i[1] for i in names_and_keys]
return cols, [tuple([o[k] for k in keys])
for o in objs]
def get_client(obj):
if hasattr(obj.app, 'client_manager'):
return obj.app.client_manager.rca

View File

@ -42,14 +42,16 @@ class AlarmList(lister.Lister):
alarms = utils.get_client(self).alarm.list(vitrage_id=vitrage_id,
all_tenants=all_tenants)
return utils.list2cols(('vitrage_id',
'vitrage_type',
'name',
'vitrage_resource_type',
'vitrage_resource_id',
'vitrage_aggregated_severity',
'vitrage_operational_severity',
'update_timestamp'), alarms)
return utils.list2cols_with_rename(
(
('ID', 'vitrage_id'),
('Type', 'vitrage_type'),
('Name', 'name'),
('Resource Type', 'vitrage_resource_type'),
('Resource ID', 'vitrage_resource_id'),
('Severity', 'vitrage_operational_severity'),
('Update Time', 'update_timestamp'),
), alarms)
# noinspection PyAbstractClass

View File

@ -34,9 +34,6 @@ class ResourceShow(show.ShowOne):
class ResourceList(lister.Lister):
"""List resources"""
RESOURCE_PROPERTIES = \
('vitrage_id', 'vitrage_type', 'id', 'state',
'vitrage_aggregated_state', 'metadata')
METADATA = ('name', 'project_id', 'update_timestamp')
def get_parser(self, prog_name):
@ -67,4 +64,11 @@ class ResourceList(lister.Lister):
{item: resource[item] for item in self.METADATA
if item in resource}
return utils.list2cols(self.RESOURCE_PROPERTIES, resources)
return utils.list2cols_with_rename(
(
('ID', 'vitrage_id'),
('Type', 'vitrage_type'),
('Data Source ID', 'id'),
('State', 'vitrage_operational_state'),
('Metadata', 'metadata'),
), resources)