From ba5f71feccf19f361c3d8b73a5606dd66fca7c57 Mon Sep 17 00:00:00 2001 From: Eyal Date: Mon, 1 Jul 2019 12:55:49 +0300 Subject: [PATCH] Add new api vitrage status To Check if vitrage is ready then you can check its status some users don't want to check on every api call if vitrage is ready, in that case you can check ad hoc Change-Id: I0817016538a6b286816b99176339262c6453dc08 --- doc/source/contributor/cli.rst | 11 ++++++++ .../notes/add_status-e3fdc1e61696ade0.yaml | 3 +++ setup.cfg | 1 + tools/vitrage.bash_completion | 5 ++-- vitrageclient/shell.py | 4 ++- vitrageclient/v1/cli/status.py | 23 +++++++++++++++++ vitrageclient/v1/client.py | 2 ++ vitrageclient/v1/status.py | 25 +++++++++++++++++++ 8 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/add_status-e3fdc1e61696ade0.yaml create mode 100644 vitrageclient/v1/cli/status.py create mode 100644 vitrageclient/v1/status.py diff --git a/doc/source/contributor/cli.rst b/doc/source/contributor/cli.rst index 708fa00..fd2d344 100644 --- a/doc/source/contributor/cli.rst +++ b/doc/source/contributor/cli.rst @@ -1117,6 +1117,17 @@ webhook add +--------------+--------------------------------------+ +Status Example +-------------- +:: + vitrage status + + +--------+-------+ + | Field | Value | + +--------+-------+ + | reason | OK | + +--------+-------+ + Python API ---------- diff --git a/releasenotes/notes/add_status-e3fdc1e61696ade0.yaml b/releasenotes/notes/add_status-e3fdc1e61696ade0.yaml new file mode 100644 index 0000000..c2a9085 --- /dev/null +++ b/releasenotes/notes/add_status-e3fdc1e61696ade0.yaml @@ -0,0 +1,3 @@ +--- +features: + - Added a new API to show vitrage status. \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 8ba121a..1354f1d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,6 +63,7 @@ openstack.rca.v1 = rca_webhook_list = vitrageclient.v1.cli.webhook:WebhookList rca_webhook_show = vitrageclient.v1.cli.webhook:WebhookShow rca_service_list = vitrageclient.v1.cli.service:ServiceList + rca_status = vitrageclient.v1.cli.status:Status vitrageclient.formatter.show = graphml = vitrageclient.common.formatters:GraphMLFormatter diff --git a/tools/vitrage.bash_completion b/tools/vitrage.bash_completion index b321bea..ea821fe 100755 --- a/tools/vitrage.bash_completion +++ b/tools/vitrage.bash_completion @@ -5,7 +5,7 @@ _vitrage() _get_comp_words_by_ref -n : cur prev words # Command data: - cmds='alarm complete event healthcheck help rca resource service template topology webhook' + cmds='alarm complete event healthcheck help rca resource service status template topology webhook' cmds_alarm='count history list show' cmds_alarm_count='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --all-tenants' cmds_alarm_history='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --all-tenants --limit --marker --start --end' @@ -24,8 +24,9 @@ _vitrage() cmds_resource_show='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty' cmds_service='list' cmds_service_list='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column' + cmds_status='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty' cmds_template='add delete list show validate versions' - cmds_template_add='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --path --type --params --wait' + cmds_template_add='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --path --type --params --wait --overwrite' cmds_template_delete='-h --help --wait' cmds_template_list='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column' cmds_template_show='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty' diff --git a/vitrageclient/shell.py b/vitrageclient/shell.py index 1541abc..83c4963 100755 --- a/vitrageclient/shell.py +++ b/vitrageclient/shell.py @@ -39,6 +39,7 @@ from vitrageclient.v1.cli import healthcheck from vitrageclient.v1.cli import rca from vitrageclient.v1.cli import resource from vitrageclient.v1.cli import service +from vitrageclient.v1.cli import status from vitrageclient.v1.cli import template from vitrageclient.v1.cli import topology from vitrageclient.v1.cli import webhook @@ -70,7 +71,8 @@ class VitrageCommandManager(commandmanager.CommandManager): 'webhook add': webhook.WebhookAdd, 'webhook list': webhook.WebhookList, 'webhook show': webhook.WebhookShow, - 'service list': service.ServiceList + 'service list': service.ServiceList, + 'status': status.Status, } def load_commands(self, namespace): diff --git a/vitrageclient/v1/cli/status.py b/vitrageclient/v1/cli/status.py new file mode 100644 index 0000000..2aa57bf --- /dev/null +++ b/vitrageclient/v1/cli/status.py @@ -0,0 +1,23 @@ +# Copyright 2019 - Nokia Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from cliff import show + + +# noinspection PyAbstractClass +class Status(show.ShowOne): + """Check api health status""" + + def take_action(self, parsed_args): + return self.dict2columns(self.app.client.status.get()) diff --git a/vitrageclient/v1/client.py b/vitrageclient/v1/client.py index fe9cb01..87309e1 100644 --- a/vitrageclient/v1/client.py +++ b/vitrageclient/v1/client.py @@ -19,6 +19,7 @@ from vitrageclient.v1 import healthcheck from vitrageclient.v1 import rca from vitrageclient.v1 import resource from vitrageclient.v1 import service +from vitrageclient.v1 import status from vitrageclient.v1 import template from vitrageclient.v1 import topology from vitrageclient.v1 import webhook @@ -39,3 +40,4 @@ class Client(object): self.healthcheck = healthcheck.HealthCheck(self._api) self.webhook = webhook.Webhook(self._api) self.service = service.Service(self._api) + self.status = status.Status(self._api) diff --git a/vitrageclient/v1/status.py b/vitrageclient/v1/status.py new file mode 100644 index 0000000..8e76178 --- /dev/null +++ b/vitrageclient/v1/status.py @@ -0,0 +1,25 @@ +# Copyright 2019 - Nokia Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +class Status(object): + URL = 'v1/status/' + + def __init__(self, api): + self.api = api + + def get(self): + """Get Status result""" + resp = self.api.get(self.URL) + return resp.json()