__all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
"OS", "Node", "Cluster", "FillDict"]
+_TIMESTAMPS = ["ctime", "mtime"]
def FillDict(defaults_dict, custom_dict):
"""Basic function to apply settings on top a default dict.
(type(self).__name__, name))
return None
- def __setitem__(self, key, value):
- if key not in self.__slots__:
- raise KeyError(key)
- setattr(self, key, value)
-
def __setstate__(self, state):
for name in state:
if name in self.__slots__:
" _ContainerFromDicts" % c_type)
return ret
+ def Copy(self):
+ """Makes a deep copy of the current object and its children.
+
+ """
+ dict_form = self.ToDict()
+ clone_obj = self.__class__.FromDict(dict_form)
+ return clone_obj
+
def __repr__(self):
"""Implement __repr__ for ConfigObjects."""
return repr(self.ToDict())
class ConfigData(ConfigObject):
"""Top-level config object."""
- __slots__ = ["version", "cluster", "nodes", "instances", "serial_no"]
+ __slots__ = (["version", "cluster", "nodes", "instances", "serial_no"] +
+ _TIMESTAMPS)
def ToDict(self):
"""Custom function for top-level config data.
raise errors.ProgrammerError("Disk.RecordGrow called for unsupported"
" disk type %s" % self.dev_type)
+ def UnsetSize(self):
+ """Sets recursively the size to zero for the disk and its children.
+
+ """
+ if self.children:
+ for child in self.children:
+ child.UnsetSize()
+ self.size = 0
+
def SetPhysicalID(self, target_node, nodes_ip):
"""Convert the logical ID to the physical ID.
"disk_template",
"network_port",
"serial_no",
- ]
+ ] + _TIMESTAMPS
def _ComputeSecondaryNodes(self):
"""Compute the list of secondary nodes.
"master_candidate",
"offline",
"drained",
- ]
+ ] + _TIMESTAMPS
class Cluster(TaggableObject):
"nicparams",
"candidate_pool_size",
"modify_etc_hosts",
- ]
+ ] + _TIMESTAMPS
def UpgradeConfig(self):
"""Fill defaults for missing configuration values.
# default_hypervisor is just the first enabled one in 2.1
if self.default_hypervisor is not None:
- self.enabled_hypervisors = [self.default_hypervisor] + \
+ self.enabled_hypervisors = ([self.default_hypervisor] +
[hvname for hvname in self.enabled_hypervisors
- if hvname != self.default_hypervisor]
+ if hvname != self.default_hypervisor])
self.default_hypervisor = None
-
def ToDict(self):
"""Custom function for cluster.