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
This commit is contained in:
Kevin L. Mitchell 2012-07-23 17:10:27 -05:00
parent 186a38cbc6
commit 85d591b1d8
5 changed files with 53 additions and 0 deletions

View File

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

View File

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

View File

@ -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'},

View File

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

View File

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