Add ParseCpuMask() utility function
[ganeti-local] / lib / objects.py
index 185bb48..be6f2d7 100644 (file)
@@ -340,6 +340,21 @@ class ConfigData(ConfigObject):
     obj.instances = cls._ContainerFromDicts(obj.instances, dict, Instance)
     return obj
 
+  def HasAnyDiskOfType(self, dev_type):
+    """Check if in there is at disk of the given type in the configuration.
+
+    @type dev_type: L{constants.LDS_BLOCK}
+    @param dev_type: the type to look for
+    @rtype: boolean
+    @return: boolean indicating if a disk of the given type was found or not
+
+    """
+    for instance in self.instances.values():
+      for disk in instance.disks:
+        if disk.IsBasedOnDiskType(dev_type):
+          return True
+    return False
+
   def UpgradeConfig(self):
     """Fill defaults for missing configuration values.
 
@@ -349,6 +364,12 @@ class ConfigData(ConfigObject):
       node.UpgradeConfig()
     for instance in self.instances.values():
       instance.UpgradeConfig()
+    if self.cluster.drbd_usermode_helper is None:
+      # To decide if we set an helper let's check if at least one instance has
+      # a DRBD disk. This does not cover all the possible scenarios but it
+      # gives a good approximation.
+      if self.HasAnyDiskOfType(constants.LD_DRBD8):
+        self.cluster.drbd_usermode_helper = constants.DEFAULT_DRBD_HELPER
 
 
 class NIC(ConfigObject):
@@ -437,6 +458,21 @@ class Disk(ConfigObject):
       return 0
     return -1
 
+  def IsBasedOnDiskType(self, dev_type):
+    """Check if the disk or its children are based on the given type.
+
+    @type dev_type: L{constants.LDS_BLOCK}
+    @param dev_type: the type to look for
+    @rtype: boolean
+    @return: boolean indicating if a device of the given type was found or not
+
+    """
+    if self.children:
+      for child in self.children:
+        if child.IsBasedOnDiskType(dev_type):
+          return True
+    return self.dev_type == dev_type
+
   def GetNodes(self, node):
     """This function returns the nodes this device lives on.
 
@@ -862,6 +898,7 @@ class Cluster(TaggableObject):
     "tcpudp_port_pool",
     "mac_prefix",
     "volume_group_name",
+    "drbd_usermode_helper",
     "default_bridge",
     "default_hypervisor",
     "master_node",
@@ -880,6 +917,7 @@ class Cluster(TaggableObject):
     "modify_ssh_setup",
     "maintain_node_health",
     "uid_pool",
+    "default_iallocator",
     ] + _TIMESTAMPS + _UUID
 
   def UpgradeConfig(self):
@@ -938,6 +976,9 @@ class Cluster(TaggableObject):
     if self.uid_pool is None:
       self.uid_pool = []
 
+    if self.default_iallocator is None:
+      self.default_iallocator = ""
+
   def ToDict(self):
     """Custom function for cluster.