Implement VM_BAD_POWER_STATE handling.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
Ewan Mellor committed 2006-12-25 19:29:05 +00:00
1 parent 17afe524e1
commit 894243ac7b
4 files changed
+31 -8

No files matched your search

+8 -4
View File
@@ -260,10 +260,14 @@ def do_vm_func(fn_name, vm_ref, *args, **kwargs):
@param *args: more arguments
@type *args: tuple
"""
xendom = XendDomain.instance()
fn = getattr(xendom, fn_name)
xendom.do_legacy_api_with_uuid(fn, vm_ref, *args, **kwargs)
return xen_api_success_void()
try:
xendom = XendDomain.instance()
fn = getattr(xendom, fn_name)
xendom.do_legacy_api_with_uuid(fn, vm_ref, *args, **kwargs)
return xen_api_success_void()
except VMBadState, exn:
return xen_api_error(['VM_BAD_POWER_STATE', vm_ref, exn.expected,
exn.actual])
class XendAPI:
+10 -3
View File
@@ -36,6 +36,7 @@ from xen.xend import XendRoot, XendCheckpoint, XendDomainInfo
from xen.xend.PrettyPrint import prettyprint
from xen.xend.XendConfig import XendConfig
from xen.xend.XendError import XendError, XendInvalidDomain, VmError
from xen.xend.XendError import VMBadState
from xen.xend.XendLogging import log
from xen.xend.XendAPIConstants import XEN_API_VM_POWER_STATE
from xen.xend.XendConstants import XS_VMROOT
@@ -782,7 +783,9 @@ class XendDomain:
raise XendError("Cannot save privileged domain %s" % domname)
if dominfo.state != DOM_STATE_RUNNING:
raise XendError("Cannot suspend domain that is not running.")
raise VMBadState("Domain is not running",
POWER_STATE_NAMES[DOM_STATE_RUNNING],
POWER_STATE_NAMES[dominfo.state])
dom_uuid = dominfo.get_uuid()
@@ -932,7 +935,9 @@ class XendDomain:
raise XendInvalidDomain(str(domid))
if dominfo.state != DOM_STATE_HALTED:
raise XendError("Domain is already running")
raise VMBadState("Domain is already running",
POWER_STATE_NAMES[DOM_STATE_HALTED],
POWER_STATE_NAMES[dominfo.state])
dominfo.start(is_managed = True)
self._add_domain(dominfo)
@@ -960,7 +965,9 @@ class XendDomain:
raise XendInvalidDomain(str(domid))
if dominfo.state != DOM_STATE_HALTED:
raise XendError("Domain is still running")
raise VMBadState("Domain is still running",
POWER_STATE_NAMES[DOM_STATE_HALTED],
POWER_STATE_NAMES[dominfo.state])
log.info("Domain %s (%s) deleted." %
(dominfo.getName(), dominfo.info.get('uuid')))
+10
View File
@@ -32,6 +32,16 @@ class XendError(Fault):
def __str__(self):
return self.value
class VMBadState(XendError):
def __init__(self, value, expected, actual):
XendError.__init__(self, value)
self.expected = expected
self.actual = actual
def __str__(self):
return self.value
class VmError(XendError):
"""Vm construction error."""
pass
+3 -1
View File
@@ -19,7 +19,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Xen-xm 3.0\n"
"PO-Revision-Date: 2006-12-23 11:04+0000\n"
"PO-Revision-Date: 2006-12-25 19:24+0000\n"
"Last-Translator: Ewan Mellor <ewan@xensource.com>\n"
"Language-Team: xen-devel <xen-devel@lists.xensource.com>\n"
"MIME-Version: 1.0\n"
@@ -65,3 +65,5 @@ msgstr "The VM handle %(1)s is invalid."
msgid "VTPM_HANDLE_INVALID"
msgstr "The VTPM handle %(1)s is invalid."
msgid "VM_BAD_POWER_STATE"
msgstr "The VM must be %(2)s to perform the requested operation (it is currently %(3)s)."
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.