From 85d591b1d88b7e6d174c8eabd41dda14162a8bbc Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Mon, 23 Jul 2012 17:10:27 -0500 Subject: [PATCH] Add call to get hypervisor statistics Adds an admin API call to retrieve the compute node statistics for an entire nova instance. Counts up all hypervisors and sums all their values (vcpus, vcpus_used, etc.). Change-Id: I0a3df235282089f1313d08ae5b89dadbd1db9840 --- novaclient/v1_1/hypervisors.py | 6 ++++++ novaclient/v1_1/shell.py | 6 ++++++ tests/v1_1/fakes.py | 16 ++++++++++++++++ tests/v1_1/test_hypervisors.py | 21 +++++++++++++++++++++ tests/v1_1/test_shell.py | 4 ++++ 5 files changed, 53 insertions(+) diff --git a/novaclient/v1_1/hypervisors.py b/novaclient/v1_1/hypervisors.py index 94301059d..e12380ad6 100644 --- a/novaclient/v1_1/hypervisors.py +++ b/novaclient/v1_1/hypervisors.py @@ -63,3 +63,9 @@ class HypervisorManager(base.Manager): """ return self._get("/os-hypervisors/%s/uptime" % base.getid(hypervisor), "hypervisor") + + def statistics(self): + """ + Get hypervisor statistics over all compute nodes. + """ + return self._get("/os-hypervisors/statistics", "hypervisor_statistics") diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 4200f5f21..daad9b4de 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -1738,6 +1738,12 @@ def do_hypervisor_uptime(cs, args): utils.print_dict(hyper._info.copy()) +def do_hypervisor_stats(cs, args): + """Get hypervisor statistics over all compute nodes.""" + stats = cs.hypervisors.statistics() + utils.print_dict(stats._info.copy()) + + def ensure_service_catalog_present(cs): if not hasattr(cs.client, 'service_catalog'): # Turn off token caching and re-auth diff --git a/tests/v1_1/fakes.py b/tests/v1_1/fakes.py index 73f3e4d3d..e0eb938c7 100644 --- a/tests/v1_1/fakes.py +++ b/tests/v1_1/fakes.py @@ -871,6 +871,22 @@ class FakeHTTPClient(base_client.HTTPClient): 'disk_available_least': 100} ]}) + def get_os_hypervisors_statistics(self, **kw): + return (200, {"hypervisor_statistics": { + 'count': 2, + 'vcpus': 8, + 'memory_mb': 20 * 1024, + 'local_gb': 500, + 'vcpus_used': 4, + 'memory_mb_used': 10 * 1024, + 'local_gb_used': 250, + 'free_ram_mb': 10 * 1024, + 'free_disk_gb': 250, + 'current_workload': 4, + 'running_vms': 4, + 'disk_available_least': 200, + }}) + def get_os_hypervisors_hyper_search(self, **kw): return (200, {'hypervisors': [ {'id': 1234, 'hypervisor_hostname': 'hyper1'}, diff --git a/tests/v1_1/test_hypervisors.py b/tests/v1_1/test_hypervisors.py index 5d0a270f2..732210941 100644 --- a/tests/v1_1/test_hypervisors.py +++ b/tests/v1_1/test_hypervisors.py @@ -147,3 +147,24 @@ class HypervisorsTest(utils.TestCase): cs.assert_called('GET', '/os-hypervisors/1234/uptime') self.compare_to_expected(expected, result) + + def test_hypervisor_statistics(self): + expected = dict( + count=2, + vcpus=8, + memory_mb=20 * 1024, + local_gb=500, + vcpus_used=4, + memory_mb_used=10 * 1024, + local_gb_used=250, + free_ram_mb=10 * 1024, + free_disk_gb=250, + current_workload=4, + running_vms=4, + disk_available_least=200, + ) + + result = cs.hypervisors.statistics() + cs.assert_called('GET', '/os-hypervisors/statistics') + + self.compare_to_expected(expected, result) diff --git a/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py index 0f4689e2f..896959758 100644 --- a/tests/v1_1/test_shell.py +++ b/tests/v1_1/test_shell.py @@ -496,6 +496,10 @@ class ShellTest(utils.TestCase): self.run_command('hypervisor-uptime 1234') self.assert_called('GET', '/os-hypervisors/1234/uptime') + def test_hypervisor_stats(self): + self.run_command('hypervisor-stats') + self.assert_called('GET', '/os-hypervisors/statistics') + def test_quota_show(self): self.run_command('quota-show test') self.assert_called('GET', '/os-quota-sets/test')