htools: abstract a function for displaying warnings
[ganeti-local] / lib / opcodes.py
index b3bb2de..11a1ac2 100644 (file)
@@ -109,8 +109,26 @@ _PNodeGroupAllocPolicy = \
 _PGroupNodeParams = ("ndparams", None, ht.TMaybeDict,
                      "Default node parameters for group")
 
+_PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
+               "Resource(s) to query for")
+
+_PEarlyRelease = ("early_release", False, ht.TBool,
+                  "Whether to release locks as soon as possible")
+
 _PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
 
+#: Do not remember instance state changes
+_PNoRemember = ("no_remember", False, ht.TBool,
+                "Do not remember the state change")
+
+#: Target node for instance migration/failover
+_PMigrationTargetNode = ("target_node", None, ht.TMaybeString,
+                         "Target node for shared-storage instances")
+
+_PStartupPaused = ("startup_paused", False, ht.TBool,
+                   "Pause instance at startup")
+
+
 #: OP_ID conversion regular expression
 _OPID_RE = re.compile("([a-z])([A-Z])")
 
@@ -126,6 +144,13 @@ _TestClusterOsList = ht.TOr(ht.TNone,
 _TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
                          ht.TOr(ht.TNone, ht.TNonEmptyString))
 
+_SUMMARY_PREFIX = {
+  "CLUSTER_": "C_",
+  "GROUP_": "G_",
+  "NODE_": "N_",
+  "INSTANCE_": "I_",
+  }
+
 
 def _NameToId(name):
   """Convert an opcode class name to an OP_ID.
@@ -388,11 +413,17 @@ class OpCode(BaseOpCode):
   # pylint: disable-msg=E1101
   # as OP_ID is dynamically defined
   WITH_LU = True
+  _T_JOB_DEP = \
+    ht.TAnd(ht.TIsLength(2),
+            ht.TItems([ht.TJobId,
+                       ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
   OP_PARAMS = [
     ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
     ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
     ("priority", constants.OP_PRIO_DEFAULT,
      ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
+    ("depends", None, ht.TOr(ht.TNone, ht.TListOf(_T_JOB_DEP)),
+     "Job dependencies"),
     ]
 
   def __getstate__(self):
@@ -460,6 +491,20 @@ class OpCode(BaseOpCode):
       txt = "%s(%s)" % (txt, field_value)
     return txt
 
+  def TinySummary(self):
+    """Generates a compact summary description of the opcode.
+
+    """
+    assert self.OP_ID.startswith("OP_")
+
+    text = self.OP_ID[3:]
+
+    for (prefix, supplement) in _SUMMARY_PREFIX.items():
+      if text.startswith(prefix):
+        return supplement + text[len(prefix):]
+
+    return text
+
 
 # cluster opcodes
 
@@ -485,8 +530,19 @@ class OpClusterQuery(OpCode):
   """Query cluster information."""
 
 
-class OpClusterVerify(OpCode):
-  """Verify the cluster state.
+class OpClusterVerifyConfig(OpCode):
+  """Verify the cluster config.
+
+  """
+  OP_PARAMS = [
+    ("verbose", False, ht.TBool, None),
+    ("error_codes", False, ht.TBool, None),
+    ("debug_simulate_errors", False, ht.TBool, None),
+    ]
+
+
+class OpClusterVerifyGroup(OpCode):
+  """Run verify on a node group from the cluster.
 
   @type skip_checks: C{list}
   @ivar skip_checks: steps to be skipped from the verify process; this
@@ -495,7 +551,9 @@ class OpClusterVerify(OpCode):
                      only L{constants.VERIFY_NPLUSONE_MEM} can be passed
 
   """
+  OP_DSC_FIELD = "group_name"
   OP_PARAMS = [
+    ("group_name", ht.NoDefault, ht.TNonEmptyString, None),
     ("skip_checks", ht.EmptyList,
      ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)), None),
     ("verbose", False, ht.TBool, None),
@@ -638,18 +696,16 @@ class OpClusterRedistConf(OpCode):
 class OpQuery(OpCode):
   """Query for resources/items.
 
-  @ivar what: Resources to query for, must be one of L{constants.QR_OP_QUERY}
+  @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
   @ivar fields: List of fields to retrieve
   @ivar filter: Query filter
 
   """
   OP_PARAMS = [
-    ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY),
-     "Resource(s) to query for"),
+    _PQueryWhat,
     ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
      "Requested fields"),
-    ("filter", None, ht.TOr(ht.TNone,
-                            ht.TListOf(ht.TOr(ht.TNonEmptyString, ht.TList))),
+    ("filter", None, ht.TOr(ht.TNone, ht.TListOf),
      "Query filter"),
     ]
 
@@ -657,23 +713,30 @@ class OpQuery(OpCode):
 class OpQueryFields(OpCode):
   """Query for available resource/item fields.
 
-  @ivar what: Resources to query for, must be one of L{constants.QR_OP_QUERY}
+  @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
   @ivar fields: List of fields to retrieve
 
   """
   OP_PARAMS = [
-    ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY), None),
-    ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), None),
+    _PQueryWhat,
+    ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
+     "Requested fields; if not given, all are returned"),
     ]
 
 
 class OpOobCommand(OpCode):
   """Interact with OOB."""
   OP_PARAMS = [
-    ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
-    ("command", None, ht.TElemOf(constants.OOB_COMMANDS), None),
-    ("timeout", constants.OOB_TIMEOUT, ht.TInt, None),
-    ("ignore_status", False, ht.TBool, None),
+    ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
+     "List of nodes to run the OOB command against"),
+    ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
+     "OOB command to be run"),
+    ("timeout", constants.OOB_TIMEOUT, ht.TInt,
+     "Timeout before the OOB helper will be terminated"),
+    ("ignore_status", False, ht.TBool,
+     "Ignores the node offline status for power off"),
+    ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
+     "Time in seconds to wait between powering on nodes"),
     ]
 
 
@@ -828,18 +891,22 @@ class OpNodeMigrate(OpCode):
     _PNodeName,
     _PMigrationMode,
     _PMigrationLive,
+    _PMigrationTargetNode,
     ("iallocator", None, ht.TMaybeString,
      "Iallocator for deciding the target node for shared-storage instances"),
     ]
 
 
-class OpNodeEvacStrategy(OpCode):
-  """Compute the evacuation strategy for a list of nodes."""
-  OP_DSC_FIELD = "nodes"
+class OpNodeEvacuate(OpCode):
+  """Evacuate instances off a number of nodes."""
+  OP_DSC_FIELD = "node_name"
   OP_PARAMS = [
-    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None),
-    ("remote_node", None, ht.TMaybeString, None),
-    ("iallocator", None, ht.TMaybeString, None),
+    _PEarlyRelease,
+    _PNodeName,
+    ("remote_node", None, ht.TMaybeString, "New secondary node"),
+    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
+    ("mode", ht.NoDefault, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES),
+     "Node evacuation mode"),
     ]
 
 
@@ -914,6 +981,7 @@ class OpInstanceCreate(OpCode):
     ("src_node", None, ht.TMaybeString, "Source node for import"),
     ("src_path", None, ht.TMaybeString, "Source directory for import"),
     ("start", True, ht.TBool, "Whether to start instance after creation"),
+    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"),
     ]
 
 
@@ -959,6 +1027,8 @@ class OpInstanceStartup(OpCode):
     ("hvparams", ht.EmptyDict, ht.TDict,
      "Temporary hypervisor parameters, hypervisor-dependent"),
     ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
+    _PNoRemember,
+    _PStartupPaused,
     ]
 
 
@@ -970,6 +1040,7 @@ class OpInstanceShutdown(OpCode):
     _PIgnoreOfflineNodes,
     ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
      "How long to wait for instance to shut down"),
+    _PNoRemember,
     ]
 
 
@@ -991,6 +1062,7 @@ class OpInstanceReplaceDisks(OpCode):
   OP_DSC_FIELD = "instance_name"
   OP_PARAMS = [
     _PInstanceName,
+    _PEarlyRelease,
     ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
      "Replacement mode"),
     ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
@@ -998,8 +1070,6 @@ class OpInstanceReplaceDisks(OpCode):
     ("remote_node", None, ht.TMaybeString, "New secondary node"),
     ("iallocator", None, ht.TMaybeString,
      "Iallocator for deciding new secondary node"),
-    ("early_release", False, ht.TBool,
-     "Whether to release locks as soon as possible"),
     ]
 
 
@@ -1010,10 +1080,9 @@ class OpInstanceFailover(OpCode):
     _PInstanceName,
     _PShutdownTimeout,
     _PIgnoreConsistency,
+    _PMigrationTargetNode,
     ("iallocator", None, ht.TMaybeString,
      "Iallocator for deciding the target node for shared-storage instances"),
-    ("target_node", None, ht.TMaybeString,
-     "Target node for shared-storage instances"),
     ]
 
 
@@ -1032,12 +1101,13 @@ class OpInstanceMigrate(OpCode):
     _PInstanceName,
     _PMigrationMode,
     _PMigrationLive,
+    _PMigrationTargetNode,
     ("cleanup", False, ht.TBool,
      "Whether a previously failed migration should be cleaned up"),
     ("iallocator", None, ht.TMaybeString,
      "Iallocator for deciding the target node for shared-storage instances"),
-    ("target_node", None, ht.TMaybeString,
-     "Target node for shared-storage instances"),
+    ("allow_failover", False, ht.TBool,
+     "Whether we can fallback to failover if migration is not possible"),
     ]
 
 
@@ -1056,6 +1126,7 @@ class OpInstanceMove(OpCode):
     _PInstanceName,
     _PShutdownTimeout,
     ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
+    _PIgnoreConsistency,
     ]
 
 
@@ -1092,6 +1163,8 @@ class OpInstanceRecreateDisks(OpCode):
     _PInstanceName,
     ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
      "List of disk indexes"),
+    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
+     "New instance nodes, if relocation is desired"),
     ]
 
 
@@ -1108,8 +1181,12 @@ class OpInstanceQuery(OpCode):
 class OpInstanceQueryData(OpCode):
   """Compute the run-time status of instances."""
   OP_PARAMS = [
-    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
-    ("static", False, ht.TBool, None),
+    _PUseLocking,
+    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
+     "Instance names"),
+    ("static", False, ht.TBool,
+     "Whether to only return configuration data without querying"
+     " nodes"),
     ]
 
 
@@ -1138,6 +1215,8 @@ class OpInstanceSetParams(OpCode):
     ("os_name", None, ht.TMaybeString,
      "Change instance's OS name. Does not reinstall the instance."),
     ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
+    ("wait_for_sync", True, ht.TBool,
+     "Whether to wait for the disk to synchronize, when changing template"),
     ]
 
 
@@ -1354,7 +1433,7 @@ class OpTestDelay(OpCode):
   """
   OP_DSC_FIELD = "duration"
   OP_PARAMS = [
-    ("duration", ht.NoDefault, ht.TFloat, None),
+    ("duration", ht.NoDefault, ht.TNumber, None),
     ("on_master", True, ht.TBool, None),
     ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
     ("repeat", 0, ht.TPositiveInt, None),
@@ -1379,18 +1458,24 @@ class OpTestAllocator(OpCode):
     ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
     ("name", ht.NoDefault, ht.TNonEmptyString, None),
     ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf(
-     ht.TDictOf(ht.TElemOf(["mac", "ip", "bridge"]),
+     ht.TDictOf(ht.TElemOf([constants.INIC_MAC, constants.INIC_IP, "bridge"]),
                 ht.TOr(ht.TNone, ht.TNonEmptyString)))), None),
     ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None),
     ("hypervisor", None, ht.TMaybeString, None),
     ("allocator", None, ht.TMaybeString, None),
     ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
-    ("mem_size", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
+    ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
     ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
     ("os", None, ht.TMaybeString, None),
     ("disk_template", None, ht.TMaybeString, None),
     ("evac_nodes", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
      None),
+    ("instances", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
+     None),
+    ("evac_mode", None,
+     ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
+    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
+     None),
     ]
 
 
@@ -1414,6 +1499,7 @@ class OpTestDummy(OpCode):
     ("result", ht.NoDefault, ht.NoType, None),
     ("messages", ht.NoDefault, ht.NoType, None),
     ("fail", ht.NoDefault, ht.NoType, None),
+    ("submit_jobs", None, ht.NoType, None),
     ]
   WITH_LU = False