+ def UpgradeConfig(self):
+ """Fill defaults for missing configuration values.
+
+ """
+ # pylint: disable-msg=E0203
+ # because these are "defined" via slots, not manually
+ if self.master_capable is None:
+ self.master_capable = True
+
+ if self.vm_capable is None:
+ self.vm_capable = True
+
+ if self.ndparams is None:
+ self.ndparams = {}
+
+ if self.powered is None:
+ self.powered = True
+
+
+class NodeGroup(TaggableObject):
+ """Config object representing a node group."""
+ __slots__ = [
+ "name",
+ "members",
+ "ndparams",
+ "serial_no",
+ "alloc_policy",
+ ] + _TIMESTAMPS + _UUID
+
+ def ToDict(self):
+ """Custom function for nodegroup.
+
+ This discards the members object, which gets recalculated and is only kept
+ in memory.
+
+ """
+ mydict = super(NodeGroup, self).ToDict()
+ del mydict["members"]
+ return mydict
+
+ @classmethod
+ def FromDict(cls, val):
+ """Custom function for nodegroup.
+
+ The members slot is initialized to an empty list, upon deserialization.
+
+ """
+ obj = super(NodeGroup, cls).FromDict(val)
+ obj.members = []
+ return obj
+
+ def UpgradeConfig(self):
+ """Fill defaults for missing configuration values.
+
+ """
+ if self.ndparams is None:
+ self.ndparams = {}
+
+ if self.serial_no is None:
+ self.serial_no = 1
+
+ if self.alloc_policy is None:
+ self.alloc_policy = constants.ALLOC_POLICY_PREFERRED
+
+ # We only update mtime, and not ctime, since we would not be able to provide
+ # a correct value for creation time.
+ if self.mtime is None:
+ self.mtime = time.time()
+
+ def FillND(self, node):
+ """Return filled out ndparams for L{objects.Node}
+
+ @type node: L{objects.Node}
+ @param node: A Node object to fill
+ @return a copy of the node's ndparams with defaults filled
+
+ """
+ return self.SimpleFillND(node.ndparams)
+
+ def SimpleFillND(self, ndparams):
+ """Fill a given ndparams dict with defaults.
+
+ @type ndparams: dict
+ @param ndparams: the dict to fill
+ @rtype: dict
+ @return: a copy of the passed in ndparams with missing keys filled
+ from the node group defaults
+
+ """
+ return FillDict(self.ndparams, ndparams)
+