From ed9c28867bf433628ba0a57779159a9bbb72aa50 Mon Sep 17 00:00:00 2001 From: Idan Hefetz Date: Tue, 2 Jan 2018 12:32:15 +0000 Subject: [PATCH] add alarm show to client Depends-On: Ia675c6d74ec947729d4520007eac1423cdf58ce9 Change-Id: I4be7ebc7e977ae8ea0a2daf86777ba08f1d4ad61 Implements: blueprint add-alarm-show-api --- .../notes/add_alarm_show_api-9a9d91cf69c45a8e.yaml | 4 ++++ tools/vitrage.bash_completion | 3 ++- vitrageclient/shell.py | 1 + vitrageclient/v1/alarm.py | 8 ++++++++ vitrageclient/v1/cli/alarm.py | 14 ++++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add_alarm_show_api-9a9d91cf69c45a8e.yaml diff --git a/releasenotes/notes/add_alarm_show_api-9a9d91cf69c45a8e.yaml b/releasenotes/notes/add_alarm_show_api-9a9d91cf69c45a8e.yaml new file mode 100644 index 0000000..40f9f31 --- /dev/null +++ b/releasenotes/notes/add_alarm_show_api-9a9d91cf69c45a8e.yaml @@ -0,0 +1,4 @@ +--- +features: + - Created a new API to show all alarm properties, with a mandatory parameter + ``vitrage_id`` of the alarm. The path for the api is ``/v1/alarm/_id_``. diff --git a/tools/vitrage.bash_completion b/tools/vitrage.bash_completion index f9d9895..211d490 100755 --- a/tools/vitrage.bash_completion +++ b/tools/vitrage.bash_completion @@ -6,9 +6,10 @@ _vitrage() # Command data: cmds='alarm complete event healthcheck help rca resource template topology' - cmds_alarm='list count' + cmds_alarm='list show 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_alarm_show='-h --help' 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 index d1e88fd..fc603ce 100755 --- 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 show': alarm.AlarmShow, 'alarm count': alarm.AlarmCount, 'rca show': rca.RcaShow, 'template validate': template.TemplateValidate, diff --git a/vitrageclient/v1/alarm.py b/vitrageclient/v1/alarm.py index d121440..a8ea11f 100755 --- a/vitrageclient/v1/alarm.py +++ b/vitrageclient/v1/alarm.py @@ -27,6 +27,14 @@ class Alarm(object): all_tenants=all_tenants) return self.api.get(self.url, params=params).json() + def get(self, vitrage_id): + """Get an alarm + + :param vitrage_id: the vitrage_id of the alarm + """ + url = self.url + vitrage_id + return self.api.get(url).json() + def count(self, all_tenants=False): """Get a count of all alarms present diff --git a/vitrageclient/v1/cli/alarm.py b/vitrageclient/v1/cli/alarm.py index 5999ecc..12debef 100755 --- a/vitrageclient/v1/cli/alarm.py +++ b/vitrageclient/v1/cli/alarm.py @@ -52,6 +52,20 @@ class AlarmList(lister.Lister): 'update_timestamp'), alarms) +class AlarmShow(show.ShowOne): + """Show an alarm""" + + def get_parser(self, prog_name): + parser = super(AlarmShow, self).get_parser(prog_name) + parser.add_argument("vitrage_id", help="Vitrage id of the alarm") + return parser + + def take_action(self, parsed_args): + vitrage_id = parsed_args.vitrage_id + alarm = utils.get_client(self).alarm.get(vitrage_id=vitrage_id) + return self.dict2columns(alarm) + + # noinspection PyAbstractClass class AlarmCount(show.ShowOne): """Show a count of all alarms"""