WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Implement VM_BAD_POWER_STATE handling.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Implement VM_BAD_POWER_STATE handling.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 26 Dec 2006 12:30:08 -0800
Delivery-date: Tue, 26 Dec 2006 12:30:41 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1167074945 0
# Node ID ce4e548f42b89f0c716f2fbe812c9172b28e7469
# Parent  6533ebfc25e13b7dcce82e486f22b7c3ab9ed4d3
Implement VM_BAD_POWER_STATE handling.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py          |   12 ++++++++----
 tools/python/xen/xend/XendDomain.py       |   13 ++++++++++---
 tools/python/xen/xend/XendError.py        |   10 ++++++++++
 tools/python/xen/xm/messages/en/xen-xm.po |    4 +++-
 4 files changed, 31 insertions(+), 8 deletions(-)

diff -r 6533ebfc25e1 -r ce4e548f42b8 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Mon Dec 25 18:44:27 2006 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Mon Dec 25 19:29:05 2006 +0000
@@ -260,10 +260,14 @@ def do_vm_func(fn_name, vm_ref, *args, *
     @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:
diff -r 6533ebfc25e1 -r ce4e548f42b8 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Mon Dec 25 18:44:27 2006 +0000
+++ b/tools/python/xen/xend/XendDomain.py       Mon Dec 25 19:29:05 2006 +0000
@@ -36,6 +36,7 @@ from xen.xend.PrettyPrint import prettyp
 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')))
diff -r 6533ebfc25e1 -r ce4e548f42b8 tools/python/xen/xend/XendError.py
--- a/tools/python/xen/xend/XendError.py        Mon Dec 25 18:44:27 2006 +0000
+++ b/tools/python/xen/xend/XendError.py        Mon Dec 25 19:29:05 2006 +0000
@@ -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
diff -r 6533ebfc25e1 -r ce4e548f42b8 tools/python/xen/xm/messages/en/xen-xm.po
--- a/tools/python/xen/xm/messages/en/xen-xm.po Mon Dec 25 18:44:27 2006 +0000
+++ b/tools/python/xen/xm/messages/en/xen-xm.po Mon Dec 25 19:29:05 2006 +0000
@@ -19,7 +19,7 @@ msgid ""
 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@xxxxxxxxxxxxx>\n"
 "Language-Team: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>\n"
 "MIME-Version: 1.0\n"
@@ -65,3 +65,5 @@ msgid "VTPM_HANDLE_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)."

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Implement VM_BAD_POWER_STATE handling., Xen patchbot-unstable <=