[Kimchi-devel] [PATCH v2 4/4] Check if the VM update params are valid for the current state
Jose Ricardo Ziviani
joserz at linux.vnet.ibm.com
Wed Sep 16 18:26:09 UTC 2015
From: Crístian Deives <cristiandeives at gmail.com>
Signed-off-by: Crístian Deives <cristiandeives at gmail.com>
Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 2 ++
src/kimchi/model/vms.py | 19 ++++++++++++++++++-
tests/test_rest.py | 3 ++-
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 1004aa4..5efeabe 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -122,6 +122,8 @@ messages = {
"KCHVM0049E": _("Cannot power off %(name)s. Virtual machine is shut off."),
"KCHVM0050E": _("Cannot shutdown %(name)s. Virtual machine is shut off."),
"KCHVM0051E": _("Cannot reset %(name)s. Virtual machine is already shut off."),
+ "KCHVM0052E": _("Unable to update the following parameters while the VM is offline: %(params)s"),
+ "KCHVM0053E": _("Unable to update the following parameters while the VM is online: %(params)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 6e4579d..f4d15af 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -64,9 +64,14 @@ DOM_STATE_MAP = {0: 'nostate',
7: 'pmsuspended'}
VM_STATIC_UPDATE_PARAMS = {'name': './name'}
-
VM_LIVE_UPDATE_PARAMS = {}
+# update parameters which are updatable when the VM is online
+VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users']
+# update parameters which are updatable when the VM is offline
+VM_OFFLINE_UPDATE_PARAMS = ['cpus', 'graphics', 'groups', 'memory', 'name',
+ 'users']
+
XPATH_DOMAIN_DISK = "/domain/devices/disk[@device='disk']/source/@file"
XPATH_DOMAIN_DISK_BY_FILE = "./devices/disk[@device='disk']/source[@file='%s']"
XPATH_DOMAIN_NAME = '/domain/name'
@@ -226,6 +231,18 @@ class VMModel(object):
with lock:
dom = self.get_vm(name, self.conn)
+
+ if DOM_STATE_MAP[dom.info()[0]] == 'shutoff':
+ ext_params = set(params.keys()) - set(VM_OFFLINE_UPDATE_PARAMS)
+ if len(ext_params) > 0:
+ raise InvalidParameter('KCHVM0052E',
+ {'params': ', '.join(ext_params)})
+ else:
+ ext_params = set(params.keys()) - set(VM_ONLINE_UPDATE_PARAMS)
+ if len(ext_params) > 0:
+ raise InvalidParameter('KCHVM0053E',
+ {'params': ', '.join(ext_params)})
+
self._live_vm_update(dom, params)
vm_name, dom = self._static_vm_update(name, dom, params)
return vm_name
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 7e726b0..0eb43f8 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -154,7 +154,7 @@ class RestTests(unittest.TestCase):
req = json.dumps({'cpus': 3})
resp = self.request('/vms/vm-1', req, 'PUT')
- self.assertEquals(200, resp.status)
+ self.assertEquals(400, resp.status)
# Check if there is support to memory hotplug, once vm is running
resp = self.request('/config/capabilities').read()
@@ -168,6 +168,7 @@ class RestTests(unittest.TestCase):
req = json.dumps({"graphics": {'passwd': "abcdef"}})
resp = self.request('/vms/vm-1', req, 'PUT')
+ self.assertEquals(200, resp.status)
info = json.loads(resp.read())
self.assertEquals('abcdef', info["graphics"]["passwd"])
self.assertEquals(None, info["graphics"]["passwdValidTo"])
--
1.9.1
More information about the Kimchi-devel
mailing list