From 5387730c3e2176508e096b0cfd401fdbd8e9c449 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 30 Sep 2015 14:32:12 +0200 Subject: [PATCH] Add support for /v1/status Change-Id: I881c9fd4e021b46145a01cc740af1dfaaf73eb8a --- gnocchiclient/shell.py | 2 ++ gnocchiclient/tests/functional/test_status.py | 20 +++++++++++++ gnocchiclient/v1/client.py | 2 ++ gnocchiclient/v1/status.py | 21 ++++++++++++++ gnocchiclient/v1/status_cli.py | 29 +++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 gnocchiclient/tests/functional/test_status.py create mode 100644 gnocchiclient/v1/status.py create mode 100644 gnocchiclient/v1/status_cli.py diff --git a/gnocchiclient/shell.py b/gnocchiclient/shell.py index 4c32d4e..c0e1a9a 100644 --- a/gnocchiclient/shell.py +++ b/gnocchiclient/shell.py @@ -31,11 +31,13 @@ from gnocchiclient.v1 import archive_policy_rule_cli as ap_rule_cli from gnocchiclient.v1 import capabilities_cli from gnocchiclient.v1 import metric_cli from gnocchiclient.v1 import resource_cli +from gnocchiclient.v1 import status_cli from gnocchiclient.version import __version__ class GnocchiCommandManager(commandmanager.CommandManager): SHELL_COMMANDS = { + "status": status_cli.CliStatusShow, "resource list": resource_cli.CliResourceList, "resource show": resource_cli.CliResourceShow, "resource history": resource_cli.CliResourceHistory, diff --git a/gnocchiclient/tests/functional/test_status.py b/gnocchiclient/tests/functional/test_status.py new file mode 100644 index 0000000..f33851b --- /dev/null +++ b/gnocchiclient/tests/functional/test_status.py @@ -0,0 +1,20 @@ +# 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 gnocchiclient.tests.functional import base + + +class MetricClientTest(base.ClientTestBase): + def test_status_scenario(self): + result = self.gnocchi("status") + status = self.details_multiple(result)[0] + self.assertEqual(2, len(status)) diff --git a/gnocchiclient/v1/client.py b/gnocchiclient/v1/client.py index cbda8b2..dbf9e3a 100644 --- a/gnocchiclient/v1/client.py +++ b/gnocchiclient/v1/client.py @@ -18,6 +18,7 @@ from gnocchiclient.v1 import archive_policy_rule from gnocchiclient.v1 import capabilities from gnocchiclient.v1 import metric from gnocchiclient.v1 import resource +from gnocchiclient.v1 import status class Client(object): @@ -38,3 +39,4 @@ class Client(object): archive_policy_rule.ArchivePolicyRuleManager(self)) self.metric = metric.MetricManager(self) self.capabilities = capabilities.CapabilitiesManager(self) + self.status = status.StatusManager(self) diff --git a/gnocchiclient/v1/status.py b/gnocchiclient/v1/status.py new file mode 100644 index 0000000..be6d111 --- /dev/null +++ b/gnocchiclient/v1/status.py @@ -0,0 +1,21 @@ +# +# 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 gnocchiclient.v1 import base + + +class StatusManager(base.Manager): + url = "v1/status" + + def get(self): + """Get Gnocchi status.""" + return self._get(self.url).json() diff --git a/gnocchiclient/v1/status_cli.py b/gnocchiclient/v1/status_cli.py new file mode 100644 index 0000000..877cb0d --- /dev/null +++ b/gnocchiclient/v1/status_cli.py @@ -0,0 +1,29 @@ +# +# 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 + + +class CliStatusShow(show.ShowOne): + def take_action(self, parsed_args): + status = self.app.client.status.get() + + nb_metric = len(status['storage']['measures_to_process']) + nb_measures = ( + sum(status['storage']['measures_to_process'].values()) + ) + + return self.dict2columns({ + "storage/total number of measures to process": nb_measures, + "storage/number of metric having measures to process": nb_metric, + })