Add a CheckNodeVmCapable helper in cmdlib
authorIustin Pop <iustin@google.com>
Wed, 27 Oct 2010 15:11:05 +0000 (17:11 +0200)
committerIustin Pop <iustin@google.com>
Thu, 28 Oct 2010 11:51:07 +0000 (13:51 +0200)
Also changes the error code for the other CheckNode* helpers to
ECODE_STATE, not ECODE_INVAL: ECODE_INVAL is for requests that are
invalid (e.g. create drbd instance with one node), whereas ECODE_STATE
denote requests that are not satisfiable due to cluster/node/instance
state.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/cmdlib.py

index 1fbdf09..ffcb400 100644 (file)
@@ -603,7 +603,7 @@ def _CheckNodeOnline(lu, node):
   """
   if lu.cfg.GetNodeInfo(node).offline:
     raise errors.OpPrereqError("Can't use offline node %s" % node,
-                               errors.ECODE_INVAL)
+                               errors.ECODE_STATE)
 
 
 def _CheckNodeNotDrained(lu, node):
@@ -616,7 +616,20 @@ def _CheckNodeNotDrained(lu, node):
   """
   if lu.cfg.GetNodeInfo(node).drained:
     raise errors.OpPrereqError("Can't use drained node %s" % node,
-                               errors.ECODE_INVAL)
+                               errors.ECODE_STATE)
+
+
+def _CheckNodeVmCapable(lu, node):
+  """Ensure that a given node is vm capable.
+
+  @param lu: the LU on behalf of which we make the check
+  @param node: the node to check
+  @raise errors.OpPrereqError: if the node is not vm capable
+
+  """
+  if not lu.cfg.GetNodeInfo(node).vm_capable:
+    raise errors.OpPrereqError("Can't use non-vm_capable node %s" % node,
+                               errors.ECODE_STATE)
 
 
 def _CheckNodeHasOS(lu, node, os_name, force_variant):