From 614e7e26400002388156aac12e352d06fffebda8 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 27 Oct 2010 17:11:05 +0200 Subject: [PATCH] Add a CheckNodeVmCapable helper in cmdlib 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 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 1fbdf095d..ffcb400d0 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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): -- GitLab