Signed-off-by: CrÃstian Deives <cristiandeives(a)gmail.com>
---
src/kimchi/i18n.py | 3 ++-
src/kimchi/model/vms.py | 24 ++++++++++++++++++------
tests/test_rest.py | 3 ++-
3 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index d2ffa34..c39fe96 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -75,7 +75,6 @@ messages = {
"KCHVM0001E": _("Virtual machine %(name)s already exists"),
"KCHVM0002E": _("Virtual machine %(name)s does not exist"),
- "KCHVM0003E": _("Unable to rename virtual machine %(name)s. The name
%(new_name)s is already in use or the virtual machine is not powered off."),
"KCHVM0004E": _("Unable to retrieve screenshot for stopped virtual
machine %(name)s"),
"KCHVM0005E": _("Remote ISO image is not supported by this
server."),
"KCHVM0006E": _("Screenshot is not supported on virtual machine
%(name)s"),
@@ -118,6 +117,8 @@ messages = {
"KCHVM0045E": _("There are not enough free slots of 1024 Mib in the
guest."),
"KCHVM0046E": _("Host's libvirt version does not support memory
devices. Libvirt must be >= 1.2.14"),
"KCHVM0047E": _("Error attaching memory device. Details:
%(error)s"),
+ "KCHVM0048E": _("Unable to update the following parameters while the
VM is offline: %(params)s"),
+ "KCHVM0049E": _("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 374a5da..a9159e8 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -61,9 +61,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'
@@ -207,6 +212,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('KCHVM0048E',
+ {'params': ',
'.join(ext_params)})
+ else:
+ ext_params = set(params.keys()) - set(VM_ONLINE_UPDATE_PARAMS)
+ if len(ext_params) > 0:
+ raise InvalidParameter('KCHVM0049E',
+ {'params': ',
'.join(ext_params)})
+
self._live_vm_update(dom, params)
dom = self._static_vm_update(dom, params)
return dom.name().decode('utf-8')
@@ -691,11 +708,6 @@ class VMModel(object):
conn = self.conn.get()
try:
if 'name' in params:
- state = DOM_STATE_MAP[dom.info()[0]]
- if state != 'shutoff':
- msg_args = {'name': vm_name, 'new_name':
params['name']}
- raise InvalidParameter("KCHVM0003E", msg_args)
-
lflags = libvirt.VIR_DOMAIN_SNAPSHOT_LIST_ROOTS
dflags = (libvirt.VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
libvirt.VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY)
diff --git a/tests/test_rest.py b/tests/test_rest.py
index c2d142f..945bf79 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"])
--
2.4.3