ia64/xen-unstable
changeset 13194:ce4e548f42b8
Implement VM_BAD_POWER_STATE handling.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | Ewan Mellor <ewan@xensource.com> |
---|---|
date | Mon Dec 25 19:29:05 2006 +0000 (2006-12-25) |
parents | 6533ebfc25e1 |
children | d752d8ccd282 |
files | tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendError.py tools/python/xen/xm/messages/en/xen-xm.po |
line diff
1.1 --- a/tools/python/xen/xend/XendAPI.py Mon Dec 25 18:44:27 2006 +0000 1.2 +++ b/tools/python/xen/xend/XendAPI.py Mon Dec 25 19:29:05 2006 +0000 1.3 @@ -260,10 +260,14 @@ def do_vm_func(fn_name, vm_ref, *args, * 1.4 @param *args: more arguments 1.5 @type *args: tuple 1.6 """ 1.7 - xendom = XendDomain.instance() 1.8 - fn = getattr(xendom, fn_name) 1.9 - xendom.do_legacy_api_with_uuid(fn, vm_ref, *args, **kwargs) 1.10 - return xen_api_success_void() 1.11 + try: 1.12 + xendom = XendDomain.instance() 1.13 + fn = getattr(xendom, fn_name) 1.14 + xendom.do_legacy_api_with_uuid(fn, vm_ref, *args, **kwargs) 1.15 + return xen_api_success_void() 1.16 + except VMBadState, exn: 1.17 + return xen_api_error(['VM_BAD_POWER_STATE', vm_ref, exn.expected, 1.18 + exn.actual]) 1.19 1.20 1.21 class XendAPI:
2.1 --- a/tools/python/xen/xend/XendDomain.py Mon Dec 25 18:44:27 2006 +0000 2.2 +++ b/tools/python/xen/xend/XendDomain.py Mon Dec 25 19:29:05 2006 +0000 2.3 @@ -36,6 +36,7 @@ from xen.xend import XendRoot, XendCheck 2.4 from xen.xend.PrettyPrint import prettyprint 2.5 from xen.xend.XendConfig import XendConfig 2.6 from xen.xend.XendError import XendError, XendInvalidDomain, VmError 2.7 +from xen.xend.XendError import VMBadState 2.8 from xen.xend.XendLogging import log 2.9 from xen.xend.XendAPIConstants import XEN_API_VM_POWER_STATE 2.10 from xen.xend.XendConstants import XS_VMROOT 2.11 @@ -782,7 +783,9 @@ class XendDomain: 2.12 raise XendError("Cannot save privileged domain %s" % domname) 2.13 2.14 if dominfo.state != DOM_STATE_RUNNING: 2.15 - raise XendError("Cannot suspend domain that is not running.") 2.16 + raise VMBadState("Domain is not running", 2.17 + POWER_STATE_NAMES[DOM_STATE_RUNNING], 2.18 + POWER_STATE_NAMES[dominfo.state]) 2.19 2.20 dom_uuid = dominfo.get_uuid() 2.21 2.22 @@ -932,7 +935,9 @@ class XendDomain: 2.23 raise XendInvalidDomain(str(domid)) 2.24 2.25 if dominfo.state != DOM_STATE_HALTED: 2.26 - raise XendError("Domain is already running") 2.27 + raise VMBadState("Domain is already running", 2.28 + POWER_STATE_NAMES[DOM_STATE_HALTED], 2.29 + POWER_STATE_NAMES[dominfo.state]) 2.30 2.31 dominfo.start(is_managed = True) 2.32 self._add_domain(dominfo) 2.33 @@ -960,7 +965,9 @@ class XendDomain: 2.34 raise XendInvalidDomain(str(domid)) 2.35 2.36 if dominfo.state != DOM_STATE_HALTED: 2.37 - raise XendError("Domain is still running") 2.38 + raise VMBadState("Domain is still running", 2.39 + POWER_STATE_NAMES[DOM_STATE_HALTED], 2.40 + POWER_STATE_NAMES[dominfo.state]) 2.41 2.42 log.info("Domain %s (%s) deleted." % 2.43 (dominfo.getName(), dominfo.info.get('uuid')))
3.1 --- a/tools/python/xen/xend/XendError.py Mon Dec 25 18:44:27 2006 +0000 3.2 +++ b/tools/python/xen/xend/XendError.py Mon Dec 25 19:29:05 2006 +0000 3.3 @@ -32,6 +32,16 @@ class XendError(Fault): 3.4 def __str__(self): 3.5 return self.value 3.6 3.7 +class VMBadState(XendError): 3.8 + 3.9 + def __init__(self, value, expected, actual): 3.10 + XendError.__init__(self, value) 3.11 + self.expected = expected 3.12 + self.actual = actual 3.13 + 3.14 + def __str__(self): 3.15 + return self.value 3.16 + 3.17 class VmError(XendError): 3.18 """Vm construction error.""" 3.19 pass
4.1 --- a/tools/python/xen/xm/messages/en/xen-xm.po Mon Dec 25 18:44:27 2006 +0000 4.2 +++ b/tools/python/xen/xm/messages/en/xen-xm.po Mon Dec 25 19:29:05 2006 +0000 4.3 @@ -19,7 +19,7 @@ 4.4 msgid "" 4.5 msgstr "" 4.6 "Project-Id-Version: Xen-xm 3.0\n" 4.7 -"PO-Revision-Date: 2006-12-23 11:04+0000\n" 4.8 +"PO-Revision-Date: 2006-12-25 19:24+0000\n" 4.9 "Last-Translator: Ewan Mellor <ewan@xensource.com>\n" 4.10 "Language-Team: xen-devel <xen-devel@lists.xensource.com>\n" 4.11 "MIME-Version: 1.0\n" 4.12 @@ -65,3 +65,5 @@ msgstr "The VM handle %(1)s is invalid." 4.13 msgid "VTPM_HANDLE_INVALID" 4.14 msgstr "The VTPM handle %(1)s is invalid." 4.15 4.16 +msgid "VM_BAD_POWER_STATE" 4.17 +msgstr "The VM must be %(2)s to perform the requested operation (it is currently %(3)s)."