Commit 154b9580 authored by Balazs Lecz's avatar Balazs Lecz Committed by Iustin Pop
Browse files

Fix __slots__ definitions

According to http://docs.python.org/reference/datamodel.html#slots



* The action of a __slots__ declaration is limited to the class where it
  is defined. As a result, subclasses will have a __dict__ unless they
  also define __slots__ (which must only contain names of any
  /additional/ slots).

* If a class defines a slot also defined in a base class, the instance
  variable defined by the base class slot is inaccessible (except by
  retrieving its descriptor directly from the base class). This renders
  the meaning of the program undefined. In the future, a check may be
  added to prevent this.
Signed-off-by: default avatarBalazs Lecz <leczb@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
Signed-off-by: default avatarIustin Pop <iustin@google.com>
parent 4c1a504b
......@@ -216,7 +216,7 @@ class SingleNotifyPipeCondition(_BaseCondition):
"""
__slots__ = _BaseCondition.__slots__ + [
__slots__ = [
"_poller",
"_read_fd",
"_write_fd",
......@@ -309,7 +309,7 @@ class PipeCondition(_BaseCondition):
there are any waiting threads.
"""
__slots__ = _BaseCondition.__slots__ + [
__slots__ = [
"_nwaiters",
"_single_condition",
]
......
......@@ -223,7 +223,7 @@ class TaggableObject(ConfigObject):
"""An generic class supporting tags.
"""
__slots__ = ConfigObject.__slots__ + ["tags"]
__slots__ = ["tags"]
VALID_TAG_RE = re.compile("^[\w.+*/:@-]+$")
@classmethod
......@@ -635,7 +635,7 @@ class Disk(ConfigObject):
class Instance(TaggableObject):
"""Config object representing an instance."""
__slots__ = TaggableObject.__slots__ + [
__slots__ = [
"name",
"primary_node",
"os",
......@@ -815,7 +815,7 @@ class OS(ConfigObject):
class Node(TaggableObject):
"""Config object representing a node."""
__slots__ = TaggableObject.__slots__ + [
__slots__ = [
"name",
"primary_ip",
"secondary_ip",
......@@ -828,7 +828,7 @@ class Node(TaggableObject):
class Cluster(TaggableObject):
"""Config object representing the cluster."""
__slots__ = TaggableObject.__slots__ + [
__slots__ = [
"serial_no",
"rsahostkeypub",
"highest_used_port",
......
......@@ -109,7 +109,7 @@ class OpCode(BaseOpCode):
"""
OP_ID = "OP_ABSTRACT"
__slots__ = BaseOpCode.__slots__ + ["dry_run"]
__slots__ = ["dry_run"]
def __getstate__(self):
"""Specialized getstate for opcodes.
......@@ -178,7 +178,7 @@ class OpPostInitCluster(OpCode):
"""
OP_ID = "OP_CLUSTER_POST_INIT"
__slots__ = OpCode.__slots__ + []
__slots__ = []
class OpDestroyCluster(OpCode):
......@@ -189,13 +189,13 @@ class OpDestroyCluster(OpCode):
"""
OP_ID = "OP_CLUSTER_DESTROY"
__slots__ = OpCode.__slots__ + []
__slots__ = []
class OpQueryClusterInfo(OpCode):
"""Query cluster information."""
OP_ID = "OP_CLUSTER_QUERY"
__slots__ = OpCode.__slots__ + []
__slots__ = []
class OpVerifyCluster(OpCode):
......@@ -209,8 +209,8 @@ class OpVerifyCluster(OpCode):
"""
OP_ID = "OP_CLUSTER_VERIFY"
__slots__ = OpCode.__slots__ + ["skip_checks", "verbose", "error_codes",
"debug_simulate_errors"]
__slots__ = ["skip_checks", "verbose", "error_codes",
"debug_simulate_errors"]
class OpVerifyDisks(OpCode):
......@@ -235,7 +235,7 @@ class OpVerifyDisks(OpCode):
"""
OP_ID = "OP_CLUSTER_VERIFY_DISKS"
__slots__ = OpCode.__slots__ + []
__slots__ = []
class OpRepairDiskSizes(OpCode):
......@@ -261,7 +261,7 @@ class OpRepairDiskSizes(OpCode):
class OpQueryConfigValues(OpCode):
"""Query cluster configuration values."""
OP_ID = "OP_CLUSTER_CONFIG_QUERY"
__slots__ = OpCode.__slots__ + ["output_fields"]
__slots__ = ["output_fields"]
class OpRenameCluster(OpCode):
......@@ -275,7 +275,7 @@ class OpRenameCluster(OpCode):
"""
OP_ID = "OP_CLUSTER_RENAME"
OP_DSC_FIELD = "name"
__slots__ = OpCode.__slots__ + ["name"]
__slots__ = ["name"]
class OpSetClusterParams(OpCode):
......@@ -286,7 +286,7 @@ class OpSetClusterParams(OpCode):
"""
OP_ID = "OP_CLUSTER_SET_PARAMS"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"vg_name",
"enabled_hypervisors",
"hvparams",
......@@ -301,8 +301,7 @@ class OpRedistributeConfig(OpCode):
"""
OP_ID = "OP_CLUSTER_REDIST_CONF"
__slots__ = OpCode.__slots__ + [
]
__slots__ = []
# node opcodes
......@@ -316,7 +315,7 @@ class OpRemoveNode(OpCode):
"""
OP_ID = "OP_NODE_REMOVE"
OP_DSC_FIELD = "node_name"
__slots__ = OpCode.__slots__ + ["node_name"]
__slots__ = ["node_name"]
class OpAddNode(OpCode):
......@@ -343,27 +342,25 @@ class OpAddNode(OpCode):
"""
OP_ID = "OP_NODE_ADD"
OP_DSC_FIELD = "node_name"
__slots__ = OpCode.__slots__ + [
"node_name", "primary_ip", "secondary_ip", "readd",
]
__slots__ = ["node_name", "primary_ip", "secondary_ip", "readd"]
class OpQueryNodes(OpCode):
"""Compute the list of nodes."""
OP_ID = "OP_NODE_QUERY"
__slots__ = OpCode.__slots__ + ["output_fields", "names", "use_locking"]
__slots__ = ["output_fields", "names", "use_locking"]
class OpQueryNodeVolumes(OpCode):
"""Get list of volumes on node."""
OP_ID = "OP_NODE_QUERYVOLS"
__slots__ = OpCode.__slots__ + ["nodes", "output_fields"]
__slots__ = ["nodes", "output_fields"]
class OpQueryNodeStorage(OpCode):
"""Get information on storage for node(s)."""
OP_ID = "OP_NODE_QUERY_STORAGE"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"nodes",
"storage_type",
"name",
......@@ -374,7 +371,7 @@ class OpQueryNodeStorage(OpCode):
class OpModifyNodeStorage(OpCode):
"""Modifies the properies of a storage unit"""
OP_ID = "OP_NODE_MODIFY_STORAGE"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"node_name",
"storage_type",
"name",
......@@ -386,7 +383,7 @@ class OpRepairNodeStorage(OpCode):
"""Repairs the volume group on a node."""
OP_ID = "OP_REPAIR_NODE_STORAGE"
OP_DSC_FIELD = "node_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"node_name",
"storage_type",
"name",
......@@ -398,7 +395,7 @@ class OpSetNodeParams(OpCode):
"""Change the parameters of a node."""
OP_ID = "OP_NODE_SET_PARAMS"
OP_DSC_FIELD = "node_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"node_name",
"force",
"master_candidate",
......@@ -411,7 +408,7 @@ class OpPowercycleNode(OpCode):
"""Tries to powercycle a node."""
OP_ID = "OP_NODE_POWERCYCLE"
OP_DSC_FIELD = "node_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"node_name",
"force",
]
......@@ -421,7 +418,7 @@ class OpEvacuateNode(OpCode):
"""Relocate secondary instances from a node."""
OP_ID = "OP_NODE_EVACUATE"
OP_DSC_FIELD = "node_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"node_name", "remote_node", "iallocator",
]
......@@ -430,7 +427,7 @@ class OpMigrateNode(OpCode):
"""Migrate all instances from a node."""
OP_ID = "OP_NODE_MIGRATE"
OP_DSC_FIELD = "node_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"node_name",
"live",
]
......@@ -442,7 +439,7 @@ class OpCreateInstance(OpCode):
"""Create an instance."""
OP_ID = "OP_INSTANCE_CREATE"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name", "os_type", "force_variant",
"pnode", "disk_template", "snode", "mode",
"disks", "nics",
......@@ -459,14 +456,14 @@ class OpReinstallInstance(OpCode):
"""Reinstall an instance's OS."""
OP_ID = "OP_INSTANCE_REINSTALL"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + ["instance_name", "os_type", "force_variant"]
__slots__ = ["instance_name", "os_type", "force_variant"]
class OpRemoveInstance(OpCode):
"""Remove an instance."""
OP_ID = "OP_INSTANCE_REMOVE"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name",
"ignore_failures",
"shutdown_timeout",
......@@ -476,7 +473,7 @@ class OpRemoveInstance(OpCode):
class OpRenameInstance(OpCode):
"""Rename an instance."""
OP_ID = "OP_INSTANCE_RENAME"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name", "ignore_ip", "new_name",
]
......@@ -485,7 +482,7 @@ class OpStartupInstance(OpCode):
"""Startup an instance."""
OP_ID = "OP_INSTANCE_STARTUP"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name", "force", "hvparams", "beparams",
]
......@@ -494,14 +491,14 @@ class OpShutdownInstance(OpCode):
"""Shutdown an instance."""
OP_ID = "OP_INSTANCE_SHUTDOWN"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + ["instance_name", "timeout"]
__slots__ = ["instance_name", "timeout"]
class OpRebootInstance(OpCode):
"""Reboot an instance."""
OP_ID = "OP_INSTANCE_REBOOT"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name", "reboot_type", "ignore_secondaries", "shutdown_timeout",
]
......@@ -510,7 +507,7 @@ class OpReplaceDisks(OpCode):
"""Replace the disks of an instance."""
OP_ID = "OP_INSTANCE_REPLACE_DISKS"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name", "remote_node", "mode", "disks", "iallocator",
]
......@@ -519,7 +516,7 @@ class OpFailoverInstance(OpCode):
"""Failover an instance."""
OP_ID = "OP_INSTANCE_FAILOVER"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name", "ignore_consistency", "shutdown_timeout",
]
......@@ -535,7 +532,7 @@ class OpMigrateInstance(OpCode):
"""
OP_ID = "OP_INSTANCE_MIGRATE"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + ["instance_name", "live", "cleanup"]
__slots__ = ["instance_name", "live", "cleanup"]
class OpMoveInstance(OpCode):
......@@ -550,56 +547,56 @@ class OpMoveInstance(OpCode):
"""
OP_ID = "OP_INSTANCE_MOVE"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name", "target_node", "shutdown_timeout",
]
]
class OpConnectConsole(OpCode):
"""Connect to an instance's console."""
OP_ID = "OP_INSTANCE_CONSOLE"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + ["instance_name"]
__slots__ = ["instance_name"]
class OpActivateInstanceDisks(OpCode):
"""Activate an instance's disks."""
OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + ["instance_name", "ignore_size"]
__slots__ = ["instance_name", "ignore_size"]
class OpDeactivateInstanceDisks(OpCode):
"""Deactivate an instance's disks."""
OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + ["instance_name"]
__slots__ = ["instance_name"]
class OpRecreateInstanceDisks(OpCode):
"""Deactivate an instance's disks."""
OP_ID = "OP_INSTANCE_RECREATE_DISKS"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + ["instance_name", "disks"]
__slots__ = ["instance_name", "disks"]
class OpQueryInstances(OpCode):
"""Compute the list of instances."""
OP_ID = "OP_INSTANCE_QUERY"
__slots__ = OpCode.__slots__ + ["output_fields", "names", "use_locking"]
__slots__ = ["output_fields", "names", "use_locking"]
class OpQueryInstanceData(OpCode):
"""Compute the run-time status of instances."""
OP_ID = "OP_INSTANCE_QUERY_DATA"
__slots__ = OpCode.__slots__ + ["instances", "static"]
__slots__ = ["instances", "static"]
class OpSetInstanceParams(OpCode):
"""Change the parameters of an instance."""
OP_ID = "OP_INSTANCE_SET_PARAMS"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name",
"hvparams", "beparams", "force",
"nics", "disks",
......@@ -610,7 +607,7 @@ class OpGrowDisk(OpCode):
"""Grow a disk of an instance."""
OP_ID = "OP_INSTANCE_GROW_DISK"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name", "disk", "amount", "wait_for_sync",
]
......@@ -619,21 +616,21 @@ class OpGrowDisk(OpCode):
class OpDiagnoseOS(OpCode):
"""Compute the list of guest operating systems."""
OP_ID = "OP_OS_DIAGNOSE"
__slots__ = OpCode.__slots__ + ["output_fields", "names"]
__slots__ = ["output_fields", "names"]
# Exports opcodes
class OpQueryExports(OpCode):
"""Compute the list of exported images."""
OP_ID = "OP_BACKUP_QUERY"
__slots__ = OpCode.__slots__ + ["nodes", "use_locking"]
__slots__ = ["nodes", "use_locking"]
class OpExportInstance(OpCode):
"""Export an instance."""
OP_ID = "OP_BACKUP_EXPORT"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"instance_name", "target_node", "shutdown", "shutdown_timeout",
]
......@@ -642,7 +639,7 @@ class OpRemoveExport(OpCode):
"""Remove an instance's export."""
OP_ID = "OP_BACKUP_REMOVE"
OP_DSC_FIELD = "instance_name"
__slots__ = OpCode.__slots__ + ["instance_name"]
__slots__ = ["instance_name"]
# Tags opcodes
......@@ -650,26 +647,26 @@ class OpGetTags(OpCode):
"""Returns the tags of the given object."""
OP_ID = "OP_TAGS_GET"
OP_DSC_FIELD = "name"
__slots__ = OpCode.__slots__ + ["kind", "name"]
__slots__ = ["kind", "name"]
class OpSearchTags(OpCode):
"""Searches the tags in the cluster for a given pattern."""
OP_ID = "OP_TAGS_SEARCH"
OP_DSC_FIELD = "pattern"
__slots__ = OpCode.__slots__ + ["pattern"]
__slots__ = ["pattern"]
class OpAddTags(OpCode):
"""Add a list of tags on a given object."""
OP_ID = "OP_TAGS_SET"
__slots__ = OpCode.__slots__ + ["kind", "name", "tags"]
__slots__ = ["kind", "name", "tags"]
class OpDelTags(OpCode):
"""Remove a list of tags from a given object."""
OP_ID = "OP_TAGS_DEL"
__slots__ = OpCode.__slots__ + ["kind", "name", "tags"]
__slots__ = ["kind", "name", "tags"]
# Test opcodes
......@@ -696,7 +693,7 @@ class OpTestDelay(OpCode):
"""
OP_ID = "OP_TEST_DELAY"
OP_DSC_FIELD = "duration"
__slots__ = OpCode.__slots__ + ["duration", "on_master", "on_nodes"]
__slots__ = ["duration", "on_master", "on_nodes"]
class OpTestAllocator(OpCode):
......@@ -712,7 +709,7 @@ class OpTestAllocator(OpCode):
"""
OP_ID = "OP_TEST_ALLOCATOR"
OP_DSC_FIELD = "allocator"
__slots__ = OpCode.__slots__ + [
__slots__ = [
"direction", "mode", "allocator", "name",
"mem_size", "disks", "disk_template",
"os", "tags", "nics", "vcpus", "hypervisor",
......
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