X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/02691904fad3df9d657d65b980dfca6893b6e3f4..b86a6bcd476e420269a24a9b3d6289bebba69442:/lib/objects.py diff --git a/lib/objects.py b/lib/objects.py index 6c74876..2104156 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -50,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__ = [] @@ -58,6 +58,7 @@ class ConfigObject(object): def __init__(self, **kwargs): for k, v in kwargs.iteritems(): setattr(self, k, v) + self.UpgradeConfig() def __getattr__(self, name): if name not in self.__slots__: @@ -157,6 +158,15 @@ class ConfigObject(object): """Implement __repr__ for ConfigObjects.""" return repr(self.ToDict()) + def UpgradeConfig(self): + """Fill defaults for missing configuration values. + + This method will be called at object init time, and its implementation will + be object dependent. + + """ + pass + class TaggableObject(ConfigObject): """An generic class supporting tags. @@ -179,7 +189,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): @@ -274,7 +284,7 @@ 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.""" @@ -472,6 +482,7 @@ class Disk(ConfigObject): if self.dev_type == constants.LD_LV: val = "