X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/4c1a504b93287ef72ab343c266432085f6a37a3b..6bb65e3a3d84fb9ea3daeae596bbc9463edda8b8:/lib/objects.py diff --git a/lib/objects.py b/lib/objects.py index 83ed133..7fb7d5b 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -109,16 +109,27 @@ class ConfigObject(object): setattr(self, k, v) def __getattr__(self, name): - if name not in self.__slots__: + if name not in self._all_slots(): raise AttributeError("Invalid object attribute %s.%s" % (type(self).__name__, name)) return None def __setstate__(self, state): + slots = self._all_slots() for name in state: - if name in self.__slots__: + if name in slots: setattr(self, name, state[name]) + @classmethod + def _all_slots(cls): + """Compute the list of all declared slots for a class. + + """ + slots = [] + for parent in cls.__mro__: + slots.extend(getattr(parent, "__slots__", [])) + return slots + def ToDict(self): """Convert to a dict holding only standard python types. @@ -130,7 +141,7 @@ class ConfigObject(object): """ result = {} - for name in self.__slots__: + for name in self._all_slots(): value = getattr(self, name, None) if value is not None: result[name] = value @@ -223,7 +234,7 @@ class TaggableObject(ConfigObject): """An generic class supporting tags. """ - __slots__ = ConfigObject.__slots__ + ["tags"] + __slots__ = ["tags"] VALID_TAG_RE = re.compile("^[\w.+*/:@-]+$") @classmethod @@ -635,7 +646,7 @@ class Disk(ConfigObject): class Instance(TaggableObject): """Config object representing an instance.""" - __slots__ = TaggableObject.__slots__ + [ + __slots__ = [ "name", "primary_node", "os", @@ -815,7 +826,7 @@ class OS(ConfigObject): class Node(TaggableObject): """Config object representing a node.""" - __slots__ = TaggableObject.__slots__ + [ + __slots__ = [ "name", "primary_ip", "secondary_ip", @@ -828,7 +839,7 @@ class Node(TaggableObject): class Cluster(TaggableObject): """Config object representing the cluster.""" - __slots__ = TaggableObject.__slots__ + [ + __slots__ = [ "serial_no", "rsahostkeypub", "highest_used_port",