Skip to content
Snippets Groups Projects
Commit d63479b5 authored by Iustin Pop's avatar Iustin Pop
Browse files

objects.Cluster: add method to get hv defaults


Currently the FillHV method is the one that does the cluster hvparams +
os hvparams merger. However, in some cases we need to do just this,
without adding the instance hvparams on top.

This patch adds a function to compute just this (hv + os hvp
combination) default dict, and modifies FillHV to use it to build the
final dict.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 0af0f641
No related branches found
No related tags found
No related merge requests found
...@@ -933,6 +933,30 @@ class Cluster(TaggableObject): ...@@ -933,6 +933,30 @@ class Cluster(TaggableObject):
obj.tcpudp_port_pool = set(obj.tcpudp_port_pool) obj.tcpudp_port_pool = set(obj.tcpudp_port_pool)
return obj return obj
def GetHVDefaults(self, hypervisor, os_name=None, skip_keys=None):
"""Get the default hypervisor parameters for the cluster.
@param hypervisor: the hypervisor name
@param os_name: if specified, we'll also update the defaults for this OS
@param skip_keys: if passed, list of keys not to use
@return: the defaults dict
"""
if skip_keys is None:
skip_keys = []
fill_stack = [self.hvparams.get(hypervisor, {})]
if os_name is not None:
os_hvp = self.os_hvp.get(os_name, {}).get(hypervisor, {})
fill_stack.append(os_hvp)
ret_dict = {}
for o_dict in fill_stack:
ret_dict = FillDict(ret_dict, o_dict, skip_keys=skip_keys)
return ret_dict
def FillHV(self, instance, skip_globals=False): def FillHV(self, instance, skip_globals=False):
"""Fill an instance's hvparams dict. """Fill an instance's hvparams dict.
...@@ -951,18 +975,9 @@ class Cluster(TaggableObject): ...@@ -951,18 +975,9 @@ class Cluster(TaggableObject):
else: else:
skip_keys = [] skip_keys = []
# We fill the list from least to most important override def_dict = self.GetHVDefaults(instance.hypervisor, instance.os,
fill_stack = [ skip_keys=skip_keys)
self.hvparams.get(instance.hypervisor, {}), return FillDict(def_dict, instance.hvparams, skip_keys=skip_keys)
self.os_hvp.get(instance.os, {}).get(instance.hypervisor, {}),
instance.hvparams,
]
ret_dict = {}
for o_dict in fill_stack:
ret_dict = FillDict(ret_dict, o_dict, skip_keys=skip_keys)
return ret_dict
def FillBE(self, instance): def FillBE(self, instance):
"""Fill an instance's beparams dict. """Fill an instance's beparams dict.
......
...@@ -79,6 +79,16 @@ class TestClusterObject(unittest.TestCase): ...@@ -79,6 +79,16 @@ class TestClusterObject(unittest.TestCase):
self.fake_cl = objects.Cluster(hvparams=hvparams, os_hvp=os_hvp) self.fake_cl = objects.Cluster(hvparams=hvparams, os_hvp=os_hvp)
self.fake_cl.UpgradeConfig() self.fake_cl.UpgradeConfig()
def testGetHVDefaults(self):
cl = self.fake_cl
self.failUnlessEqual(cl.GetHVDefaults(constants.HT_FAKE),
cl.hvparams[constants.HT_FAKE])
self.failUnlessEqual(cl.GetHVDefaults(None), {})
self.failUnlessEqual(cl.GetHVDefaults(constants.HT_XEN_PVM,
os_name="lenny-image"),
cl.os_hvp["lenny-image"][constants.HT_XEN_PVM])
def testFillHvFullMerge(self): def testFillHvFullMerge(self):
inst_hvparams = { inst_hvparams = {
"blah": "blubb", "blah": "blubb",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment