diff --git a/vitrageclient/common/utils.py b/vitrageclient/common/utils.py index bdff905..a8aae92 100644 --- a/vitrageclient/common/utils.py +++ b/vitrageclient/common/utils.py @@ -25,3 +25,8 @@ def args_to_dict(args, attrs): return {(attr, value) for attr, value in [(attr, getattr(args, attr)) for attr in attrs] if value is not None} + + +def list2cols(cols, objs): + return cols, [tuple([o[k] for k in cols]) + for o in objs] diff --git a/vitrageclient/shell.py b/vitrageclient/shell.py index 38ba32b..966f270 100644 --- a/vitrageclient/shell.py +++ b/vitrageclient/shell.py @@ -29,6 +29,7 @@ from keystoneauth1 import loading import client import noauth +from v1.cli import alarms from v1.cli import resource from v1.cli import topology from vitrageclient import __version__ @@ -39,6 +40,7 @@ class VitrageCommandManager(commandmanager.CommandManager): "topology show": topology.TopologyShow, "resource show": resource.ResourceShow, "resource list": resource.ResourceList, + "alarms list": alarms.AlarmsList, } def load_commands(self, namespace): diff --git a/vitrageclient/v1/alarms.py b/vitrageclient/v1/alarms.py new file mode 100644 index 0000000..9c53ba3 --- /dev/null +++ b/vitrageclient/v1/alarms.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 Resource(object): + url = "v1/alarms/" + + def __init__(self, api): + self.api = api + + def list(self, entity_id): + """Get a all alarms on entity + + :param entity_id: the id for the entity + """ + params = dict(entity_id=entity_id) + return self.api.get(self.url, params=params).json() diff --git a/vitrageclient/v1/cli/alarms.py b/vitrageclient/v1/cli/alarms.py new file mode 100644 index 0000000..abb0500 --- /dev/null +++ b/vitrageclient/v1/cli/alarms.py @@ -0,0 +1,30 @@ +# 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 lister + +from vitrageclient.common import utils + + +class AlarmsList(lister.Lister): + """List alarms on entity""" + + def get_parser(self, prog_name): + parser = super(AlarmsList, self).get_parser(prog_name) + parser.add_argument("id", metavar="", help="The entity id") + + return parser + + def take_action(self, parsed_args): + entity_id = parsed_args.id + alarms = self.app.client.alarms.list(entity_id=entity_id) + return utils.list2cols([], alarms)