diff --git a/vitrageclient/shell.py b/vitrageclient/shell.py index 966f270..8514701 100644 --- a/vitrageclient/shell.py +++ b/vitrageclient/shell.py @@ -30,6 +30,7 @@ import client import noauth from v1.cli import alarms +from v1.cli import rca from v1.cli import resource from v1.cli import topology from vitrageclient import __version__ @@ -41,6 +42,7 @@ class VitrageCommandManager(commandmanager.CommandManager): "resource show": resource.ResourceShow, "resource list": resource.ResourceList, "alarms list": alarms.AlarmsList, + "rca show": rca.RcaShow, } def load_commands(self, namespace): diff --git a/vitrageclient/v1/cli/rca.py b/vitrageclient/v1/cli/rca.py new file mode 100644 index 0000000..d96f3d5 --- /dev/null +++ b/vitrageclient/v1/cli/rca.py @@ -0,0 +1,28 @@ +# 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 RcaShow(show.ShowOne): + """Show an RCA""" + + def get_parser(self, prog_name): + parser = super(RcaShow, self).get_parser(prog_name) + parser.add_argument("alarm_id", help="ID of an alarm") + return parser + + def take_action(self, parsed_args): + alarm_id = parsed_args.alarm_id + alarm = self.app.client.rca.get(alarm_id=alarm_id) + return self.dict2columns(alarm) diff --git a/vitrageclient/v1/client.py b/vitrageclient/v1/client.py index d714001..5fa1546 100644 --- a/vitrageclient/v1/client.py +++ b/vitrageclient/v1/client.py @@ -9,9 +9,11 @@ # 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 vitrageclient import client from vitrageclient.v1 import alarms +from vitrageclient.v1 import rca from vitrageclient.v1 import resource from vitrageclient.v1 import topology @@ -24,3 +26,4 @@ class Client(object): self.topology = topology.Topology(self._api) self.resource = resource.Resource(self._api) self.alarms = alarms.Alarm(self._api) + self.rca = rca.Rca(self._api) diff --git a/vitrageclient/v1/rca.py b/vitrageclient/v1/rca.py new file mode 100644 index 0000000..dec3fe6 --- /dev/null +++ b/vitrageclient/v1/rca.py @@ -0,0 +1,26 @@ +# 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 Rca(object): + url = "v1/rca/" + + def __init__(self, api): + self.api = api + + def get(self, alarm_id): + """Get RCA for an alarm + + :param alarm_id: the id of the alarm + """ + url = self.url + alarm_id + return self.api.get(url).json()