add alarms api

Change-Id: Ib1e9f13c5fd370ede384a02d93f9dc9e719ad5c3
This commit is contained in:
Eyal
2016-01-28 11:07:36 +02:00
parent 6db6113566
commit 80a4ba1cbe
4 changed files with 63 additions and 0 deletions

View File

@@ -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]

View File

@@ -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):

View File

@@ -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()

View File

@@ -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="<entity id>", 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)