GetFilledHvStateParams returns node hv state params for the default
hypervisor. This function provides the same hv_state as one provided
by the same haskell function.

Also update iallocator mock object.

Signed-off-by: Oleg Ponomarev <[email protected]>
---
 lib/config/__init__.py                        | 32 ++++++++++++++++++++++++++-
 test/py/ganeti.masterd.iallocator_unittest.py |  2 ++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/lib/config/__init__.py b/lib/config/__init__.py
index 17b5d6e..c47d71c 100644
--- a/lib/config/__init__.py
+++ b/lib/config/__init__.py
@@ -222,6 +222,30 @@ class ConfigWriter(object):
     """
     return self._UnlockedGetNdParams(node)
 
+  def _UnlockedGetFilledHvStateParams(self, node):
+    cfg = self._ConfigData()
+    cluster_hv_state = cfg.cluster.hv_state_static
+    def_hv = self._UnlockedGetHypervisorType()
+    cluster_fv = constants.HVST_DEFAULTS if def_hv not in cluster_hv_state \
+                                         else cluster_hv_state[def_hv]
+    group_hv_state = self._UnlockedGetNodeGroup(node.group).hv_state_static
+    group_fv = cluster_fv if def_hv not in group_hv_state else \
+               objects.FillDict(cluster_fv, group_hv_state[def_hv])
+    node_fv = group_fv if def_hv not in node.hv_state_static else \
+              objects.FillDict(group_fv, node.hv_state_static[def_hv])
+    return {def_hv: node_fv}
+
+  @ConfigSync(shared=1)
+  def GetFilledHvStateParams(self, node):
+    """Get the node params populated with cluster defaults.
+
+    @type node: L{objects.Node}
+    @param node: The node we want to know the params for
+    @return: A dict with the filled in node hv_state params for the default hv
+
+    """
+    return self._UnlockedGetFilledHvStateParams(node)
+
   @ConfigSync(shared=1)
   def GetNdGroupParams(self, nodegroup):
     """Get the node groups params populated with cluster defaults.
@@ -1291,12 +1315,18 @@ class ConfigWriter(object):
     """
     return self._ConfigData().cluster.gluster_storage_dir
 
+  def _UnlockedGetHypervisorType(self):
+    """Get the hypervisor type for this cluster.
+
+    """
+    return self._ConfigData().cluster.enabled_hypervisors[0]
+
   @ConfigSync(shared=1)
   def GetHypervisorType(self):
     """Get the hypervisor type for this cluster.
 
     """
-    return self._ConfigData().cluster.enabled_hypervisors[0]
+    return self._UnlockedGetHypervisorType()
 
   @ConfigSync(shared=1)
   def GetRsaHostKey(self):
diff --git a/test/py/ganeti.masterd.iallocator_unittest.py 
b/test/py/ganeti.masterd.iallocator_unittest.py
index d92e572..bf4d2b2 100755
--- a/test/py/ganeti.masterd.iallocator_unittest.py
+++ b/test/py/ganeti.masterd.iallocator_unittest.py
@@ -101,6 +101,8 @@ class TestIARequestBase(unittest.TestCase):
 class _FakeConfigWithNdParams:
   def GetNdParams(self, _):
     return None
+  def GetFilledHvStateParams(self, _):
+    return None
 
 
 class TestComputeBasicNodeData(unittest.TestCase):
-- 
2.6.0.rc2.230.g3dd15c0

Reply via email to