Commit 0fbedb7a authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

objects.Cluster: Add property for primary hypervisor

This is useful for working with a node's hypervisor state, where only
the primary hypervisor will be authoritative.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent 43e11798
...@@ -1350,6 +1350,15 @@ class Cluster(TaggableObject): ...@@ -1350,6 +1350,15 @@ class Cluster(TaggableObject):
self.diskparams = UpgradeDiskParams(self.diskparams) self.diskparams = UpgradeDiskParams(self.diskparams)
def primary_hypervisor(self):
"""The first hypervisor is the primary.
Useful, for example, for L{Node}'s hv/disk state.
return self.enabled_hypervisors[0]
def ToDict(self): def ToDict(self):
"""Custom function for cluster. """Custom function for cluster.
...@@ -195,6 +195,17 @@ class TestClusterObject(unittest.TestCase): ...@@ -195,6 +195,17 @@ class TestClusterObject(unittest.TestCase):
self.assertEqual(node_ndparams, self.assertEqual(node_ndparams,
self.fake_cl.FillND(fake_node, fake_group)) self.fake_cl.FillND(fake_node, fake_group))
def testPrimaryHypervisor(self):
assert self.fake_cl.enabled_hypervisors is None
self.fake_cl.enabled_hypervisors = [constants.HT_XEN_HVM]
self.assertEqual(self.fake_cl.primary_hypervisor, constants.HT_XEN_HVM)
self.fake_cl.enabled_hypervisors = [constants.HT_XEN_PVM, constants.HT_KVM]
self.assertEqual(self.fake_cl.primary_hypervisor, constants.HT_XEN_PVM)
self.fake_cl.enabled_hypervisors = sorted(constants.HYPER_TYPES)
self.assertEqual(self.fake_cl.primary_hypervisor, constants.HT_CHROOT)
class TestOS(unittest.TestCase): class TestOS(unittest.TestCase):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment