summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-12-14 08:25:17 -0700
committerspisarski <s.pisarski@cablelabs.com>2017-12-14 08:25:17 -0700
commit2f32a84057a7562524cda9f224b13ba0a394d7ce (patch)
treedf9891e9800ca8b725416ba80ba2907eee582737
parentf4bf5f90437db30ee44013414810054624b73359 (diff)
Added utility function to retrieve the names of all hosts with a hypervisor.
Change-Id: I25b91c6eee78ebf35785c4884dded7c9ab2cc412 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--snaps/openstack/utils/nova_utils.py15
-rw-r--r--snaps/openstack/utils/tests/nova_utils_tests.py10
2 files changed, 25 insertions, 0 deletions
diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py
index 2d569e6..8297db9 100644
--- a/snaps/openstack/utils/nova_utils.py
+++ b/snaps/openstack/utils/nova_utils.py
@@ -475,6 +475,21 @@ def get_availability_zone_hosts(nova, zone_name='nova'):
return out
+def get_hypervisor_hosts(nova):
+ """
+ Returns the host names of all nova nodes with active hypervisors
+ :param nova: the Nova client
+ :return: a list of hypervisor host names
+ """
+ out = list()
+ hypervisors = nova.hypervisors.list()
+ for hypervisor in hypervisors:
+ if hypervisor.state == "up":
+ out.append(hypervisor.hypervisor_hostname)
+
+ return out
+
+
def delete_vm_instance(nova, vm_inst):
"""
Deletes a VM instance
diff --git a/snaps/openstack/utils/tests/nova_utils_tests.py b/snaps/openstack/utils/tests/nova_utils_tests.py
index c4bc9cb..c7be5ef 100644
--- a/snaps/openstack/utils/tests/nova_utils_tests.py
+++ b/snaps/openstack/utils/tests/nova_utils_tests.py
@@ -53,6 +53,16 @@ class NovaSmokeTests(OSComponentTestCase):
# This should not throw an exception
nova.flavors.list()
+ def test_nova_get_hypervisor_hosts(self):
+ """
+ Tests to ensure that get_hypervisors() function works.
+ """
+ nova = nova_utils.nova_client(self.os_creds)
+
+ hosts = nova_utils.get_hypervisor_hosts(nova)
+ # This should not throw an exception
+ self.assertGreaterEqual(len(hosts), 1)
+
def test_nova_connect_fail(self):
"""
Tests to ensure that the improper credentials cannot connect.