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 <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 0af0f641
......@@ -933,6 +933,30 @@ class Cluster(TaggableObject):
obj.tcpudp_port_pool = set(obj.tcpudp_port_pool)
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, {})
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):
"""Fill an instance's hvparams dict.
......@@ -951,18 +975,9 @@ class Cluster(TaggableObject):
skip_keys = []
# We fill the list from least to most important override
fill_stack = [
self.hvparams.get(instance.hypervisor, {}),
self.os_hvp.get(instance.os, {}).get(instance.hypervisor, {}),
ret_dict = {}
for o_dict in fill_stack:
ret_dict = FillDict(ret_dict, o_dict, skip_keys=skip_keys)
return ret_dict
def_dict = self.GetHVDefaults(instance.hypervisor, instance.os,
return FillDict(def_dict, instance.hvparams, skip_keys=skip_keys)
def FillBE(self, instance):
"""Fill an instance's beparams dict.
......@@ -79,6 +79,16 @@ class TestClusterObject(unittest.TestCase):
self.fake_cl = objects.Cluster(hvparams=hvparams, os_hvp=os_hvp)
def testGetHVDefaults(self):
cl = self.fake_cl
self.failUnlessEqual(cl.GetHVDefaults(None), {})
def testFillHvFullMerge(self):
inst_hvparams = {
"blah": "blubb",
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