Fix a typo in InitCluster
[ganeti-local] / lib / opcodes.py
index 689ccb4..6a86477 100644 (file)
@@ -142,14 +142,9 @@ class OpCode(BaseOpCode):
       raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
     op_id = data["OP_ID"]
     op_class = None
-    for item in globals().values():
-      if (isinstance(item, type) and
-          issubclass(item, cls) and
-          hasattr(item, "OP_ID") and
-          getattr(item, "OP_ID") == op_id):
-        op_class = item
-        break
-    if op_class is None:
+    if op_id in OP_MAPPING:
+      op_class = OP_MAPPING[op_id]
+    else:
       raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
                        op_id)
     op = op_class()
@@ -171,6 +166,8 @@ class OpCode(BaseOpCode):
     return txt
 
 
+# cluster opcodes
+
 class OpDestroyCluster(OpCode):
   """Destroy the cluster.
 
@@ -207,7 +204,7 @@ class OpVerifyDisks(OpCode):
 
   Parameters: none
 
-  Result: two lists:
+  Result: a tuple of four elements:
     - list of node names with bad data returned (unreachable, etc.)
     - dict of node names with broken volume groups (values: error msg)
     - list of instances with degraded disks (that should be activated)
@@ -227,10 +224,30 @@ class OpVerifyDisks(OpCode):
   __slots__ = []
 
 
-class OpDumpClusterConfig(OpCode):
-  """Dump the cluster configuration."""
-  OP_ID = "OP_CLUSTER_DUMPCONFIG"
-  __slots__ = []
+class OpRepairDiskSizes(OpCode):
+  """Verify the disk sizes of the instances and fixes configuration
+  mimatches.
+
+  Parameters: optional instances list, in case we want to restrict the
+  checks to only a subset of the instances.
+
+  Result: a list of tuples, (instance, disk, new-size) for changed
+  configurations.
+
+  In normal operation, the list should be empty.
+
+  @type instances: list
+  @ivar instances: the list of instances to check, or empty for all instances
+
+  """
+  OP_ID = "OP_CLUSTER_REPAIR_DISK_SIZES"
+  __slots__ = ["instances"]
+
+
+class OpQueryConfigValues(OpCode):
+  """Query cluster configuration values."""
+  OP_ID = "OP_CLUSTER_CONFIG_QUERY"
+  __slots__ = ["output_fields"]
 
 
 class OpRenameCluster(OpCode):
@@ -255,9 +272,23 @@ class OpSetClusterParams(OpCode):
 
   """
   OP_ID = "OP_CLUSTER_SET_PARAMS"
-  __slots__ = ["vg_name"]
+  __slots__ = [
+    "vg_name",
+    "enabled_hypervisors",
+    "hvparams",
+    "beparams",
+    "candidate_pool_size",
+    ]
 
 
+class OpRedistributeConfig(OpCode):
+  """Force a full push of the cluster configuration.
+
+  """
+  OP_ID = "OP_CLUSTER_REDIST_CONF"
+  __slots__ = [
+    ]
+
 # node opcodes
 
 class OpRemoveNode(OpCode):
@@ -303,7 +334,7 @@ class OpAddNode(OpCode):
 class OpQueryNodes(OpCode):
   """Compute the list of nodes."""
   OP_ID = "OP_NODE_QUERY"
-  __slots__ = ["output_fields", "names"]
+  __slots__ = ["output_fields", "names", "use_locking"]
 
 
 class OpQueryNodeVolumes(OpCode):
@@ -312,6 +343,18 @@ class OpQueryNodeVolumes(OpCode):
   __slots__ = ["nodes", "output_fields"]
 
 
+class OpSetNodeParams(OpCode):
+  """Change the parameters of a node."""
+  OP_ID = "OP_NODE_SET_PARAMS"
+  OP_DSC_FIELD = "node_name"
+  __slots__ = [
+    "node_name",
+    "force",
+    "master_candidate",
+    "offline",
+    "drained",
+    ]
+
 # instance opcodes
 
 class OpCreateInstance(OpCode):
@@ -319,14 +362,14 @@ class OpCreateInstance(OpCode):
   OP_ID = "OP_INSTANCE_CREATE"
   OP_DSC_FIELD = "instance_name"
   __slots__ = [
-    "instance_name", "mem_size", "disk_size", "os_type", "pnode",
-    "disk_template", "snode", "swap_size", "mode",
-    "vcpus", "ip", "bridge", "src_node", "src_path", "start",
-    "wait_for_sync", "ip_check", "mac",
-    "kernel_path", "initrd_path", "hvm_boot_order", "hvm_acpi",
-    "hvm_pae", "hvm_cdrom_image_path", "vnc_bind_address",
+    "instance_name", "os_type", "pnode",
+    "disk_template", "snode", "mode",
+    "disks", "nics",
+    "src_node", "src_path", "start",
+    "wait_for_sync", "ip_check",
     "file_storage_dir", "file_driver",
-    "iallocator", "hvm_nic_type", "hvm_disk_type",
+    "iallocator",
+    "hypervisor", "hvparams", "beparams",
     ]
 
 
@@ -354,7 +397,7 @@ class OpStartupInstance(OpCode):
   """Startup an instance."""
   OP_ID = "OP_INSTANCE_STARTUP"
   OP_DSC_FIELD = "instance_name"
-  __slots__ = ["instance_name", "force", "extra_args"]
+  __slots__ = ["instance_name", "force", "hvparams", "beparams"]
 
 
 class OpShutdownInstance(OpCode):
@@ -368,8 +411,7 @@ class OpRebootInstance(OpCode):
   """Reboot an instance."""
   OP_ID = "OP_INSTANCE_REBOOT"
   OP_DSC_FIELD = "instance_name"
-  __slots__ = ["instance_name", "reboot_type", "extra_args",
-               "ignore_secondaries" ]
+  __slots__ = ["instance_name", "reboot_type", "ignore_secondaries" ]
 
 
 class OpReplaceDisks(OpCode):
@@ -386,6 +428,20 @@ class OpFailoverInstance(OpCode):
   __slots__ = ["instance_name", "ignore_consistency"]
 
 
+class OpMigrateInstance(OpCode):
+  """Migrate an instance.
+
+  This migrates (without shutting down an instance) to its secondary
+  node.
+
+  @ivar instance_name: the name of the instance
+
+  """
+  OP_ID = "OP_INSTANCE_MIGRATE"
+  OP_DSC_FIELD = "instance_name"
+  __slots__ = ["instance_name", "live", "cleanup"]
+
+
 class OpConnectConsole(OpCode):
   """Connect to an instance's console."""
   OP_ID = "OP_INSTANCE_CONSOLE"
@@ -397,7 +453,7 @@ class OpActivateInstanceDisks(OpCode):
   """Activate an instance's disks."""
   OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
   OP_DSC_FIELD = "instance_name"
-  __slots__ = ["instance_name"]
+  __slots__ = ["instance_name", "ignore_size"]
 
 
 class OpDeactivateInstanceDisks(OpCode):
@@ -410,13 +466,13 @@ class OpDeactivateInstanceDisks(OpCode):
 class OpQueryInstances(OpCode):
   """Compute the list of instances."""
   OP_ID = "OP_INSTANCE_QUERY"
-  __slots__ = ["output_fields", "names"]
+  __slots__ = ["output_fields", "names", "use_locking"]
 
 
 class OpQueryInstanceData(OpCode):
   """Compute the run-time status of instances."""
   OP_ID = "OP_INSTANCE_QUERY_DATA"
-  __slots__ = ["instances"]
+  __slots__ = ["instances", "static"]
 
 
 class OpSetInstanceParams(OpCode):
@@ -424,10 +480,9 @@ class OpSetInstanceParams(OpCode):
   OP_ID = "OP_INSTANCE_SET_PARAMS"
   OP_DSC_FIELD = "instance_name"
   __slots__ = [
-    "instance_name", "mem", "vcpus", "ip", "bridge", "mac",
-    "kernel_path", "initrd_path", "hvm_boot_order", "hvm_acpi",
-    "hvm_pae", "hvm_cdrom_image_path", "vnc_bind_address",
-    "hvm_nic_type", "hvm_disk_type", "force"
+    "instance_name",
+    "hvparams", "beparams", "force",
+    "nics", "disks",
     ]
 
 
@@ -435,7 +490,7 @@ class OpGrowDisk(OpCode):
   """Grow a disk of an instance."""
   OP_ID = "OP_INSTANCE_GROW_DISK"
   OP_DSC_FIELD = "instance_name"
-  __slots__ = ["instance_name", "disk", "amount"]
+  __slots__ = ["instance_name", "disk", "amount", "wait_for_sync"]
 
 
 # OS opcodes
@@ -449,7 +504,7 @@ class OpDiagnoseOS(OpCode):
 class OpQueryExports(OpCode):
   """Compute the list of exported images."""
   OP_ID = "OP_BACKUP_QUERY"
-  __slots__ = ["nodes"]
+  __slots__ = ["nodes", "use_locking"]
 
 
 class OpExportInstance(OpCode):
@@ -536,5 +591,9 @@ class OpTestAllocator(OpCode):
   __slots__ = [
     "direction", "mode", "allocator", "name",
     "mem_size", "disks", "disk_template",
-    "os", "tags", "nics", "vcpus",
+    "os", "tags", "nics", "vcpus", "hypervisor",
     ]
+
+OP_MAPPING = dict([(v.OP_ID, v) for v in globals().values()
+                   if (isinstance(v, type) and issubclass(v, OpCode) and
+                       hasattr(v, "OP_ID"))])