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] 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): def get_client(obj):
if hasattr(obj.app, 'client_manager'): if hasattr(obj.app, 'client_manager'):
return obj.app.client_manager.rca 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, alarms = utils.get_client(self).alarm.list(vitrage_id=vitrage_id,
all_tenants=all_tenants) all_tenants=all_tenants)
return utils.list2cols(('vitrage_id', return utils.list2cols_with_rename(
'vitrage_type', (
'name', ('ID', 'vitrage_id'),
'vitrage_resource_type', ('Type', 'vitrage_type'),
'vitrage_resource_id', ('Name', 'name'),
'vitrage_aggregated_severity', ('Resource Type', 'vitrage_resource_type'),
'vitrage_operational_severity', ('Resource ID', 'vitrage_resource_id'),
'update_timestamp'), alarms) ('Severity', 'vitrage_operational_severity'),
('Update Time', 'update_timestamp'),
), alarms)
# noinspection PyAbstractClass # noinspection PyAbstractClass

View File

@ -34,9 +34,6 @@ class ResourceShow(show.ShowOne):
class ResourceList(lister.Lister): class ResourceList(lister.Lister):
"""List resources""" """List resources"""
RESOURCE_PROPERTIES = \
('vitrage_id', 'vitrage_type', 'id', 'state',
'vitrage_aggregated_state', 'metadata')
METADATA = ('name', 'project_id', 'update_timestamp') METADATA = ('name', 'project_id', 'update_timestamp')
def get_parser(self, prog_name): def get_parser(self, prog_name):
@ -67,4 +64,11 @@ class ResourceList(lister.Lister):
{item: resource[item] for item in self.METADATA {item: resource[item] for item in self.METADATA
if item in resource} 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)