From 86f34ebb30004d122935fbc64e43fc97b236f805 Mon Sep 17 00:00:00 2001 From: Tyler Smith Date: Wed, 2 Aug 2017 16:52:13 -0400 Subject: [PATCH] Changes to support new alarm counts api in vitrage This change is to support the new api as introduced by the alarm-counts-api blueprint. - There is a new cli added as well to expose the new api: vitrage alarm count - The bash completion file was also updated Change-Id: I47b5b2cbb32c742ca15478ee294d341c0137e0b5 Depends-On: I6061b63c068580dcd25df5c624d9b3bd88f30cca Implements: blueprint alarm-counts-api Signed-off-by: Tyler Smith --- tools/vitrage.bash_completion | 3 ++- vitrageclient/shell.py | 1 + vitrageclient/v1/alarm.py | 8 ++++++++ vitrageclient/v1/cli/alarm.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) mode change 100644 => 100755 tools/vitrage.bash_completion mode change 100644 => 100755 vitrageclient/shell.py mode change 100644 => 100755 vitrageclient/v1/alarm.py mode change 100644 => 100755 vitrageclient/v1/cli/alarm.py diff --git a/tools/vitrage.bash_completion b/tools/vitrage.bash_completion old mode 100644 new mode 100755 index b569af5..f9d9895 --- a/tools/vitrage.bash_completion +++ b/tools/vitrage.bash_completion @@ -6,8 +6,9 @@ _vitrage() # Command data: cmds='alarm complete event healthcheck help rca resource template topology' - cmds_alarm='list' + cmds_alarm='list count' cmds_alarm_list='-h --help -f --format -c --column --max-width --print-empty --noindent --quote --all-tenants' + cmds_alarm_count='-h --help -f --format -c --column --max-width --print-empty --noindent --quote --all-tenants' cmds_complete='-h --help --name --shell' cmds_event='post' cmds_event_post='-h --help --type --time --details' diff --git a/vitrageclient/shell.py b/vitrageclient/shell.py old mode 100644 new mode 100755 index f904080..d1e88fd --- a/vitrageclient/shell.py +++ b/vitrageclient/shell.py @@ -51,6 +51,7 @@ class VitrageCommandManager(commandmanager.CommandManager): 'resource show': resource.ResourceShow, 'resource list': resource.ResourceList, 'alarm list': alarm.AlarmList, + 'alarm count': alarm.AlarmCount, 'rca show': rca.RcaShow, 'template validate': template.TemplateValidate, 'template list': template.TemplateList, diff --git a/vitrageclient/v1/alarm.py b/vitrageclient/v1/alarm.py old mode 100644 new mode 100755 index 08c67f0..d121440 --- a/vitrageclient/v1/alarm.py +++ b/vitrageclient/v1/alarm.py @@ -26,3 +26,11 @@ class Alarm(object): params = dict(vitrage_id=vitrage_id, all_tenants=all_tenants) return self.api.get(self.url, params=params).json() + + def count(self, all_tenants=False): + """Get a count of all alarms present + + :param all_tenants: should return all tenants alarms + """ + params = dict(all_tenants=all_tenants) + return self.api.get(self.url + 'count/', params=params).json() diff --git a/vitrageclient/v1/cli/alarm.py b/vitrageclient/v1/cli/alarm.py old mode 100644 new mode 100755 index 07ad2d5..5999ecc --- a/vitrageclient/v1/cli/alarm.py +++ b/vitrageclient/v1/cli/alarm.py @@ -11,6 +11,7 @@ # under the License. from cliff import lister +from cliff import show from vitrageclient.common import utils @@ -49,3 +50,31 @@ class AlarmList(lister.Lister): 'vitrage_aggregated_severity', 'vitrage_operational_severity', 'update_timestamp'), alarms) + + +# noinspection PyAbstractClass +class AlarmCount(show.ShowOne): + """Show a count of all alarms""" + + def get_parser(self, prog_name): + parser = super(AlarmCount, self).get_parser(prog_name) + parser.add_argument('--all-tenants', + default=False, + dest='all_tenants', + action='store_true', + help='Shows counts for alarms of all ' + 'the tenants') + + return parser + + @property + def formatter_default(self): + return 'json' + + def take_action(self, parsed_args): + all_tenants = parsed_args.all_tenants + + counts = utils.get_client(self).alarm.count( + all_tenants=all_tenants) + + return self.dict2columns(counts)