summaryrefslogtreecommitdiff
path: root/ceilometerclient
diff options
context:
space:
mode:
authorZhiQiang Fan <aji.zqfan@gmail.com>2014-11-08 13:24:28 +0800
committerZhiQiang Fan <zhiqiang.fan@huawei.com>2015-04-04 18:05:33 +0800
commitfc4c0eb3af306ab678600e6005f626cd3615481c (patch)
tree90098924d4188c06ec7154afb5c30ccaf47e6085 /ceilometerclient
parentc40d67cf97d9e4bfdde4e6d3ee28a31d61c8cafe (diff)
downloadpython-ceilometerclient-fc4c0eb3af306ab678600e6005f626cd3615481c.tar.gz
Add CLI for Capabilities REST API
Implements blueprint capability-cli Change-Id: I23fe9c0bc9c27e04e3e0133fc84da7cf1f87321f
Diffstat (limited to 'ceilometerclient')
-rw-r--r--ceilometerclient/tests/unit/v2/test_shell.py43
-rw-r--r--ceilometerclient/tests/v2/test_capabilities.py58
-rw-r--r--ceilometerclient/v2/capabilities.py29
-rw-r--r--ceilometerclient/v2/client.py2
-rw-r--r--ceilometerclient/v2/shell.py13
5 files changed, 145 insertions, 0 deletions
diff --git a/ceilometerclient/tests/unit/v2/test_shell.py b/ceilometerclient/tests/unit/v2/test_shell.py
index 84a884b..d60b41b 100644
--- a/ceilometerclient/tests/unit/v2/test_shell.py
+++ b/ceilometerclient/tests/unit/v2/test_shell.py
@@ -27,6 +27,7 @@ from ceilometerclient import shell as base_shell
from ceilometerclient.tests.unit import test_shell
from ceilometerclient.tests.unit import utils
from ceilometerclient.v2 import alarms
+from ceilometerclient.v2 import capabilities
from ceilometerclient.v2 import events
from ceilometerclient.v2 import samples
from ceilometerclient.v2 import shell as ceilometer_shell
@@ -1181,3 +1182,45 @@ class ShellShadowedArgsTest(test_shell.ShellTestBase):
kwargs.get('project_id'))
self.assertEqual('the-user-id-i-want-to-set',
kwargs.get('user_id'))
+
+
+class ShellCapabilityShowTest(utils.BaseTestCase):
+
+ CAPABILITIES = {
+ "alarm_storage": {
+ "storage:production_ready": True
+ },
+ "api": {
+ "alarms:query:complex": True,
+ "alarms:query:simple": True
+ },
+ "event_storage": {
+ "storage:production_ready": True
+ },
+ "storage": {
+ "storage:production_ready": True
+ },
+ }
+
+ def setUp(self):
+ super(ShellCapabilityShowTest, self).setUp()
+ self.cc = mock.Mock()
+ self.args = mock.Mock()
+
+ @mock.patch('sys.stdout', new=six.StringIO())
+ def test_capability_show(self):
+ _cap = capabilities.Capabilities(mock.Mock, self.CAPABILITIES)
+ self.cc.capabilities.get.return_value = _cap
+
+ ceilometer_shell.do_capabilities(self.cc, self.args)
+ self.assertEqual('''\
++---------------+----------------------------------+
+| Property | Value |
++---------------+----------------------------------+
+| alarm_storage | "storage:production_ready": true |
+| api | "alarms:query:complex": true, |
+| | "alarms:query:simple": true |
+| event_storage | "storage:production_ready": true |
+| storage | "storage:production_ready": true |
++---------------+----------------------------------+
+''', sys.stdout.getvalue())
diff --git a/ceilometerclient/tests/v2/test_capabilities.py b/ceilometerclient/tests/v2/test_capabilities.py
new file mode 100644
index 0000000..32468cb
--- /dev/null
+++ b/ceilometerclient/tests/v2/test_capabilities.py
@@ -0,0 +1,58 @@
+# Copyright 2014 Huawei Technologies Co., Ltd.
+#
+# 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.
+
+import testtools
+
+from ceilometerclient.openstack.common.apiclient import client
+from ceilometerclient.openstack.common.apiclient import fake_client
+from ceilometerclient.v2 import capabilities
+
+
+CAPABILITIES = {
+ "alarm_storage": {
+ "storage:production_ready": True
+ },
+ "api": {
+ "alarms:query:complex": True,
+ "alarms:query:simple": True
+ },
+ "event_storage": {
+ "storage:production_ready": True
+ },
+ "storage": {
+ "storage:production_ready": True
+ },
+}
+
+FIXTURES = {
+ '/v2/capabilities': {
+ 'GET': (
+ {},
+ CAPABILITIES
+ ),
+ },
+}
+
+
+class CapabilitiesManagerTest(testtools.TestCase):
+ def setUp(self):
+ super(CapabilitiesManagerTest, self).setUp()
+ self.http_client = fake_client.FakeHTTPClient(fixtures=FIXTURES)
+ self.api = client.BaseClient(self.http_client)
+ self.mgr = capabilities.CapabilitiesManager(self.api)
+
+ def test_capabilities_get(self):
+ capabilities = self.mgr.get()
+ self.http_client.assert_called('GET', '/v2/capabilities')
+ self.assertEqual(True, capabilities.api['alarms:query:complex'])
diff --git a/ceilometerclient/v2/capabilities.py b/ceilometerclient/v2/capabilities.py
new file mode 100644
index 0000000..9a0f528
--- /dev/null
+++ b/ceilometerclient/v2/capabilities.py
@@ -0,0 +1,29 @@
+#
+# Copyright 2014 Huawei, Inc
+#
+# 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 ceilometerclient.common import base
+
+
+class Capabilities(base.Resource):
+ def __repr__(self):
+ return "<Capabilities %s>" % self._info
+
+
+class CapabilitiesManager(base.Manager):
+ resource_class = Capabilities
+
+ def get(self):
+ path = "/v2/capabilities"
+ return Capabilities(self, self.api.get(path).json())
diff --git a/ceilometerclient/v2/client.py b/ceilometerclient/v2/client.py
index a4a3619..31e8144 100644
--- a/ceilometerclient/v2/client.py
+++ b/ceilometerclient/v2/client.py
@@ -18,6 +18,7 @@
from ceilometerclient import client as ceiloclient
from ceilometerclient.openstack.common.apiclient import client
from ceilometerclient.v2 import alarms
+from ceilometerclient.v2 import capabilities
from ceilometerclient.v2 import event_types
from ceilometerclient.v2 import events
from ceilometerclient.v2 import meters
@@ -80,3 +81,4 @@ class Client(object):
self.http_client)
self.query_alarm_history = query.QueryAlarmHistoryManager(
self.http_client)
+ self.capabilities = capabilities.CapabilitiesManager(self.http_client)
diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py
index e2bec46..4e8e2d2 100644
--- a/ceilometerclient/v2/shell.py
+++ b/ceilometerclient/v2/shell.py
@@ -22,6 +22,7 @@ import argparse
import functools
import json
+from oslo.serialization import jsonutils
from oslo.utils import strutils
import six
@@ -1155,3 +1156,15 @@ def do_query_alarm_history(cc, args):
utils.print_list(alarm_history, fields, field_labels,
formatters={'rule': alarm_change_detail_formatter},
sortby=None)
+
+
+def do_capabilities(cc, args):
+ """Print Ceilometer capabilities."""
+ capabilities = cc.capabilities.get().to_dict()
+ # Capability is a nested dict, and has no user defined data,
+ # so it is safe to format here with json tools.
+ for key in capabilities:
+ # remove the leading and trailing pair of {}
+ capabilities[key] = jsonutils.dumps(capabilities[key],
+ sort_keys=True, indent=0)[2:-2]
+ utils.print_dict(capabilities)