[Kimchi-devel] [PATCH 2/4] Transient VM POST request handling

Christy Perez christy at linux.vnet.ibm.com
Tue Jan 27 18:39:08 UTC 2015


Do not call GET for PowerOff, Shutdown, and Reset actions for
transient VMs.

Also return an error for Delete of transient VMs, since
libvirt does not support this operation.

Signed-off-by: Christy Perez <christy at linux.vnet.ibm.com>
---
 src/kimchi/control/vms.py | 10 ++++++----
 src/kimchi/i18n.py        |  1 +
 src/kimchi/model/vms.py   |  3 +++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py
index 1a84b6c..dda4b31 100644
--- a/src/kimchi/control/vms.py
+++ b/src/kimchi/control/vms.py
@@ -21,7 +21,6 @@
 from kimchi.control.utils import internal_redirect, UrlSubNode
 from kimchi.control.vm import sub_nodes
 
-
 @UrlSubNode('vms', True)
 class VMs(Collection):
     def __init__(self, model):
@@ -40,9 +39,12 @@ def __init__(self, model, ident):
         for ident, node in sub_nodes.items():
             setattr(self, ident, node(model, self.ident))
         self.start = self.generate_action_handler('start')
-        self.poweroff = self.generate_action_handler('poweroff')
-        self.shutdown = self.generate_action_handler('shutdown')
-        self.reset = self.generate_action_handler('reset')
+        self.poweroff = self.generate_action_handler('poweroff',
+            destructive=True)
+        self.shutdown = self.generate_action_handler('shutdown',
+            destructive=True)
+        self.reset = self.generate_action_handler('reset',
+            destructive=True)
         self.connect = self.generate_action_handler('connect')
         self.clone = self.generate_action_handler_task('clone')
 
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 4eccc3e..4ab08d1 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -106,6 +106,7 @@
     "KCHVM0033E": _("Virtual machine '%(name)s' must be stopped before cloning it."),
     "KCHVM0034E": _("Insufficient disk space to clone virtual machine '%(name)s'"),
     "KCHVM0035E": _("Unable to clone VM '%(name)s'. Details: %(err)s"),
+    "KCHVM0036E": _("Invalid operation for non-persistent virtual machine %(name)s"),
 
     "KCHVMHDEV0001E": _("VM %(vmid)s does not contain directly assigned host device %(dev_name)s."),
     "KCHVMHDEV0002E": _("The host device %(dev_name)s is not allowed to directly assign to VM."),
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index 9987786..86a2a1f 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -836,6 +836,9 @@ def get_vm(name, conn):
     def delete(self, name):
         conn = self.conn.get()
         dom = self.get_vm(name, self.conn)
+        if not dom.isPersistent():
+            raise InvalidOperation("KCHVM0036E", {'name': name})
+
         self._vmscreenshot_delete(dom.UUIDString())
         paths = self._vm_get_disk_paths(dom)
         info = self.lookup(name)
-- 
1.9.3




More information about the Kimchi-devel mailing list