X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/acec9d51f4aea4b4571fcee477bea935487b8b83..da961187f97344fde390140ebb2f10d10d334d51:/lib/objects.py diff --git a/lib/objects.py b/lib/objects.py index 424c198..aebe959 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -29,6 +29,7 @@ pass to and from external parties. import ConfigParser import re +import copy from cStringIO import StringIO from ganeti import errors @@ -49,7 +50,7 @@ class ConfigObject(object): as None instead of raising an error Classes derived from this must always declare __slots__ (we use many - config objects and the memory reduction is useful. + config objects and the memory reduction is useful) """ __slots__ = [] @@ -178,7 +179,7 @@ class TaggableObject(ConfigObject): constants.MAX_TAG_LEN) if not tag: raise errors.TagError("Tags cannot be empty") - if not re.match("^[ \w.+*/:-]+$", tag): + if not re.match("^[\w.+*/:-]+$", tag): raise errors.TagError("Tag contains invalid characters") def GetTags(self): @@ -237,7 +238,7 @@ class TaggableObject(ConfigObject): class ConfigData(ConfigObject): """Top-level config object.""" - __slots__ = ["cluster", "nodes", "instances"] + __slots__ = ["version", "cluster", "nodes", "instances", "serial_no"] def ToDict(self): """Custom function for top-level config data. @@ -273,17 +274,15 @@ class NIC(ConfigObject): class Disk(ConfigObject): """Config object representing a block device.""" __slots__ = ["dev_type", "logical_id", "physical_id", - "children", "iv_name", "size"] + "children", "iv_name", "size", "mode"] def CreateOnSecondary(self): """Test if this device needs to be created on a secondary node.""" - return self.dev_type in (constants.LD_DRBD7, constants.LD_DRBD8, - constants.LD_LV) + return self.dev_type in (constants.LD_DRBD8, constants.LD_LV) def AssembleOnSecondary(self): """Test if this device needs to be assembled on a secondary node.""" - return self.dev_type in (constants.LD_DRBD7, constants.LD_DRBD8, - constants.LD_LV) + return self.dev_type in (constants.LD_DRBD8, constants.LD_LV) def OpenOnSecondary(self): """Test if this device needs to be opened on a secondary node.""" @@ -326,8 +325,7 @@ class Disk(ConfigObject): devices needs to (or can) be assembled. """ - if self.dev_type in [constants.LD_LV, constants.LD_MD_R1, - constants.LD_FILE]: + if self.dev_type in [constants.LD_LV, constants.LD_FILE]: result = [node] elif self.dev_type in constants.LDS_DRBD: result = [self.logical_id[0], self.logical_id[1]] @@ -390,6 +388,50 @@ class Disk(ConfigObject): raise errors.ProgrammerError("Disk.RecordGrow called for unsupported" " disk type %s" % self.dev_type) + def SetPhysicalID(self, target_node, nodes_ip): + """Convert the logical ID to the physical ID. + + This is used only for drbd, which needs ip/port configuration. + + The routine descends down and updates its children also, because + this helps when the only the top device is passed to the remote + node. + + Arguments: + - target_node: the node we wish to configure for + - nodes_ip: a mapping of node name to ip + + The target_node must exist in in nodes_ip, and must be one of the + nodes in the logical ID for each of the DRBD devices encountered + in the disk tree. + + """ + if self.children: + for child in self.children: + child.SetPhysicalID(target_node, nodes_ip) + + if self.logical_id is None and self.physical_id is not None: + return + if self.dev_type in constants.LDS_DRBD: + pnode, snode, port, pminor, sminor, secret = self.logical_id + if target_node not in (pnode, snode): + raise errors.ConfigurationError("DRBD device not knowing node %s" % + target_node) + pnode_ip = nodes_ip.get(pnode, None) + snode_ip = nodes_ip.get(snode, None) + if pnode_ip is None or snode_ip is None: + raise errors.ConfigurationError("Can't find primary or secondary node" + " for %s" % str(self)) + p_data = (pnode_ip, port) + s_data = (snode_ip, port) + if pnode == target_node: + self.physical_id = p_data + s_data + (pminor, secret) + else: # it must be secondary, we tested above + self.physical_id = s_data + p_data + (sminor, secret) + else: + self.physical_id = self.logical_id + return + def ToDict(self): """Disk-specific conversion to standard python types. @@ -417,6 +459,10 @@ class Disk(ConfigObject): obj.logical_id = tuple(obj.logical_id) if obj.physical_id and isinstance(obj.physical_id, list): obj.physical_id = tuple(obj.physical_id) + if obj.dev_type in constants.LDS_DRBD: + # we need a tuple of length six here + if len(obj.logical_id) < 6: + obj.logical_id += (None,) * (6 - len(obj.logical_id)) return obj def __str__(self): @@ -426,10 +472,8 @@ class Disk(ConfigObject): if self.dev_type == constants.LD_LV: val = "