Merge "Add hypervisor details to hypervisors list if requested"
This commit is contained in:
commit
4ab1dac7a5
@ -937,14 +937,23 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
return self._list(_server_group.ServerGroup, paginated=False, **query)
|
||||
|
||||
def hypervisors(self):
|
||||
def hypervisors(self, details=False):
|
||||
"""Return a generator of hypervisor
|
||||
|
||||
:param bool details: When set to the default, ``False``,
|
||||
:class:`~openstack.compute.v2.hypervisor.Hypervisor`
|
||||
instances will be returned. ``True`` will cause
|
||||
:class:`~openstack.compute.v2.hypervisor.HypervisorDetail`
|
||||
instances to be returned.
|
||||
:returns: A generator of hypervisor
|
||||
:rtype: class: `~openstack.compute.v2.hypervisor.Hypervisor`
|
||||
"""
|
||||
if details:
|
||||
hypervisor = _hypervisor.HypervisorDetail
|
||||
else:
|
||||
hypervisor = _hypervisor.Hypervisor
|
||||
|
||||
return self._list(_hypervisor.Hypervisor, paginated=False)
|
||||
return self._list(hypervisor, paginated=False)
|
||||
|
||||
def find_hypervisor(self, name_or_id, ignore_missing=True):
|
||||
"""Find a hypervisor from name or id to get the corresponding info
|
||||
|
@ -65,3 +65,11 @@ class Hypervisor(resource.Resource):
|
||||
host_ip = resource.Body('host_ip')
|
||||
#: Disk space available to the scheduler
|
||||
disk_available = resource.Body("disk_available_least")
|
||||
|
||||
|
||||
class HypervisorDetail(Hypervisor):
|
||||
base_path = '/os-hypervisors/detail'
|
||||
|
||||
# capabilities
|
||||
allow_get = False
|
||||
allow_list = True
|
||||
|
@ -76,3 +76,12 @@ class TestHypervisor(base.TestCase):
|
||||
self.assertEqual(EXAMPLE['disk_available_least'], sot.disk_available)
|
||||
self.assertEqual(EXAMPLE['local_gb'], sot.local_disk_size)
|
||||
self.assertEqual(EXAMPLE['free_ram_mb'], sot.memory_free)
|
||||
|
||||
def test_detail(self):
|
||||
sot = hypervisor.HypervisorDetail()
|
||||
self.assertEqual('hypervisor', sot.resource_key)
|
||||
self.assertEqual('hypervisors', sot.resources_key)
|
||||
self.assertEqual('/os-hypervisors/detail', sot.base_path)
|
||||
self.assertEqual('compute', sot.service.service_type)
|
||||
self.assertFalse(sot.allow_get)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
@ -482,10 +482,15 @@ class TestComputeProxy(test_proxy_base.TestProxyBase):
|
||||
self.verify_list(self.proxy.server_groups, server_group.ServerGroup,
|
||||
paginated=False)
|
||||
|
||||
def test_hypervisors(self):
|
||||
self.verify_list_no_kwargs(self.proxy.hypervisors,
|
||||
hypervisor.Hypervisor,
|
||||
paginated=False)
|
||||
def test_hypervisors_not_detailed(self):
|
||||
self.verify_list(self.proxy.hypervisors, hypervisor.Hypervisor,
|
||||
paginated=False,
|
||||
method_kwargs={"details": False})
|
||||
|
||||
def test_hypervisors_detailed(self):
|
||||
self.verify_list(self.proxy.hypervisors, hypervisor.HypervisorDetail,
|
||||
paginated=False,
|
||||
method_kwargs={"details": True})
|
||||
|
||||
def test_find_hypervisor(self):
|
||||
self.verify_find(self.proxy.find_hypervisor,
|
||||
|
Loading…
Reference in New Issue
Block a user