Generate a shared HMAC key at cluster init time
[ganeti-local] / lib / opcodes.py
index 541bbc0..e7d34a8 100644 (file)
@@ -103,11 +103,13 @@ class OpCode(BaseOpCode):
   from this class should override OP_ID.
 
   @cvar OP_ID: The ID of this opcode. This should be unique amongst all
-               childre of this class.
+               children of this class.
+  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
+                 the check steps
 
   """
   OP_ID = "OP_ABSTRACT"
-  __slots__ = BaseOpCode.__slots__ + []
+  __slots__ = BaseOpCode.__slots__ + ["dry_run"]
 
   def __getstate__(self):
     """Specialized getstate for opcodes.
@@ -142,14 +144,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()
@@ -602,3 +599,7 @@ class OpTestAllocator(OpCode):
     "mem_size", "disks", "disk_template",
     "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"))])