Commit ec29fe40 authored by Iustin Pop's avatar Iustin Pop
Browse files

Change class hierarchy in objects.py

It makes sense to make the TaggableObject a child of the ConfigObject,
since in this case we can derive the Instance, Node and Cluster objects
only from the TaggableObject and have a cleaner hierarchy.

For consistency child classes will have to declare their slots by adding
their parents on top.

Reviewed-by: imsnah,ultrotter
parent 89e1fc26
...@@ -148,11 +148,11 @@ class ConfigObject(object): ...@@ -148,11 +148,11 @@ class ConfigObject(object):
return ConfigObject.Load(StringIO(data)) return ConfigObject.Load(StringIO(data))
class TaggableObject(object): class TaggableObject(ConfigObject):
"""An generic class supporting tags. """An generic class supporting tags.
""" """
__slots__ = [] __slots__ = ConfigObject.__slots__ + ["tags"]
@staticmethod @staticmethod
def ValidateTag(tag): def ValidateTag(tag):
...@@ -287,9 +287,9 @@ class Disk(ConfigObject): ...@@ -287,9 +287,9 @@ class Disk(ConfigObject):
return result return result
class Instance(ConfigObject, TaggableObject): class Instance(TaggableObject):
"""Config object representing an instance.""" """Config object representing an instance."""
__slots__ = [ __slots__ = TaggableObject.__slots__ + [
"name", "name",
"primary_node", "primary_node",
"os", "os",
...@@ -299,7 +299,6 @@ class Instance(ConfigObject, TaggableObject): ...@@ -299,7 +299,6 @@ class Instance(ConfigObject, TaggableObject):
"nics", "nics",
"disks", "disks",
"disk_template", "disk_template",
"tags",
] ]
def _ComputeSecondaryNodes(self): def _ComputeSecondaryNodes(self):
...@@ -407,14 +406,18 @@ class OS(ConfigObject): ...@@ -407,14 +406,18 @@ class OS(ConfigObject):
] ]
class Node(ConfigObject, TaggableObject): class Node(TaggableObject):
"""Config object representing a node.""" """Config object representing a node."""
__slots__ = ["name", "primary_ip", "secondary_ip", "tags"] __slots__ = TaggableObject.__slots__ + [
"name",
"primary_ip",
"secondary_ip",
]
class Cluster(ConfigObject, TaggableObject): class Cluster(TaggableObject):
"""Config object representing the cluster.""" """Config object representing the cluster."""
__slots__ = [ __slots__ = TaggableObject.__slots__ + [
"config_version", "config_version",
"serial_no", "serial_no",
"rsahostkeypub", "rsahostkeypub",
...@@ -423,7 +426,6 @@ class Cluster(ConfigObject, TaggableObject): ...@@ -423,7 +426,6 @@ class Cluster(ConfigObject, TaggableObject):
"mac_prefix", "mac_prefix",
"volume_group_name", "volume_group_name",
"default_bridge", "default_bridge",
"tags",
] ]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment