Add ComputeNodeList.get_by_hypervisor_type()

This lets us pull ComputeNode objects from the DB by hypervisor type.
Note that this is not remotable, so no version bump needed until/unless
we make it so.

Change-Id: I36f7b3386510a64df77b61409f3b4e6530ed3f90
This commit is contained in:
Dan Smith 2017-09-06 08:59:13 -07:00
parent 10661dc5e2
commit 3414410132
2 changed files with 30 additions and 0 deletions

View File

@ -451,3 +451,16 @@ class ComputeNodeList(base.ObjectListBase, base.NovaObject):
compute_uuids)
return base.obj_make_list(context, cls(context), objects.ComputeNode,
db_computes)
@staticmethod
@db.select_db_reader_mode
def _db_compute_node_get_by_hv_type(context, hv_type):
db_computes = context.session.query(models.ComputeNode).filter(
models.ComputeNode.hypervisor_type == hv_type).all()
return db_computes
@classmethod
def get_by_hypervisor_type(cls, context, hv_type):
db_computes = cls._db_compute_node_get_by_hv_type(context, hv_type)
return base.obj_make_list(context, cls(context), objects.ComputeNode,
db_computes)

View File

@ -106,3 +106,20 @@ class ComputeNodeTestCase(test.TestCase):
[cn1.uuid, cn2.uuid,
uuidsentinel.noexists])
self.assertEqual(2, len(cns))
def test_get_by_hypervisor_type(self):
cn1 = fake_compute_obj.obj_clone()
cn1._context = self.context
cn1.hypervisor_type = 'ironic'
cn1.create()
cn2 = fake_compute_obj.obj_clone()
cn2._context = self.context
cn2.hypervisor_type = 'libvirt'
cn2.host += '-alt'
cn2.create()
cns = objects.ComputeNodeList.get_by_hypervisor_type(self.context,
'ironic')
self.assertEqual(1, len(cns))
self.assertEqual(cn1.uuid, cns[0].uuid)