diff --git a/openstack/compute/v2/_proxy.py b/openstack/compute/v2/_proxy.py index a9cb8c2f9..fc0f2747e 100644 --- a/openstack/compute/v2/_proxy.py +++ b/openstack/compute/v2/_proxy.py @@ -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 diff --git a/openstack/compute/v2/hypervisor.py b/openstack/compute/v2/hypervisor.py index 1c532b9ad..e28cb095a 100644 --- a/openstack/compute/v2/hypervisor.py +++ b/openstack/compute/v2/hypervisor.py @@ -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 diff --git a/openstack/tests/unit/compute/v2/test_hypervisor.py b/openstack/tests/unit/compute/v2/test_hypervisor.py index e6bccba67..9ef80b4cd 100644 --- a/openstack/tests/unit/compute/v2/test_hypervisor.py +++ b/openstack/tests/unit/compute/v2/test_hypervisor.py @@ -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) diff --git a/openstack/tests/unit/compute/v2/test_proxy.py b/openstack/tests/unit/compute/v2/test_proxy.py index d4b1713cf..75aa892d9 100644 --- a/openstack/tests/unit/compute/v2/test_proxy.py +++ b/openstack/tests/unit/compute/v2/test_proxy.py @@ -475,10 +475,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,