Merge "Adds separate class for Hypervisor Stats"

This commit is contained in:
Jenkins 2015-01-27 02:20:41 +00:00 committed by Gerrit Code Review
commit a9223d314e
4 changed files with 29 additions and 1 deletions

View File

@ -168,3 +168,11 @@ class HypervisorsTest(utils.FixturedTestCase):
self.assert_called('GET', '/os-hypervisors/statistics')
self.compare_to_expected(expected, result)
def test_hypervisor_statistics_data_model(self):
result = self.cs.hypervisor_stats.statistics()
self.assert_called('GET', '/os-hypervisors/statistics')
# Test for Bug #1370415, the line below used to raise AttributeError
self.assertEqual("<HypervisorStats: 2 Hypervisors>",
result.__repr__())

View File

@ -151,6 +151,7 @@ class Client(object):
self.aggregates = aggregates.AggregateManager(self)
self.hosts = hosts.HostManager(self)
self.hypervisors = hypervisors.HypervisorManager(self)
self.hypervisor_stats = hypervisors.HypervisorStatsManager(self)
self.services = services.ServiceManager(self)
self.fixed_ips = fixed_ips.FixedIPsManager(self)
self.floating_ips_bulk = floating_ips_bulk.FloatingIPBulkManager(self)

View File

@ -66,6 +66,25 @@ class HypervisorManager(base.ManagerWithFind):
return self._get("/os-hypervisors/%s/uptime" % base.getid(hypervisor),
"hypervisor")
def statistics(self):
"""
Get hypervisor statistics over all compute nodes.
Kept for backwards compatibility, new code should call
hypervisor_stats.statistics() instead of hypervisors.statistics()
"""
return self.api.hypervisor_stats.statistics()
class HypervisorStats(base.Resource):
def __repr__(self):
return ("<HypervisorStats: %d Hypervisor%s>" %
(self.count, "s" if self.count != 1 else ""))
class HypervisorStatsManager(base.Manager):
resource_class = HypervisorStats
def statistics(self):
"""
Get hypervisor statistics over all compute nodes.

View File

@ -3631,7 +3631,7 @@ def do_hypervisor_uptime(cs, args):
def do_hypervisor_stats(cs, args):
"""Get hypervisor statistics over all compute nodes."""
stats = cs.hypervisors.statistics()
stats = cs.hypervisor_stats.statistics()
utils.print_dict(stats._info.copy())