[PATCH v3][Kimchi 0/2] Do not delete storage pool with storage volumes assigned to guests

Changes: v3: Just rebase v2: Use path to determine if volume comes from storage pool Do not use "get_disk_used_by". It will be usefull if we start querying by volumes. Since, we cannot list volumes with inactivate storage pools. Ramon Medeiros (2): Issue #836: Allow user change guest graphics type Create test to verify graphics type change API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ tests/test_model.py | 18 +++++++----------- tests/test_rest.py | 10 ++++++++++ 6 files changed, 35 insertions(+), 12 deletions(-) -- 2.5.5

Allow vm to choose between spice and vnc Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/API.json b/API.json index adaa2f7..9ad60a2 100644 --- a/API.json +++ b/API.json @@ -404,6 +404,12 @@ "description": "Life time for the graphics password.", "type": "number", "error": "KCHVM0032E" + }, + "type": { + "description": "Graphics type", + "type": "string", + "enum": ["spice", "vnc"], + "error": "KCHVM0054E" } } }, diff --git a/docs/API.md b/docs/API.md index 15f0007..1c20466 100644 --- a/docs/API.md +++ b/docs/API.md @@ -166,6 +166,7 @@ server. * passwdValidTo *(optional)*: lifetime for the console password. When omitted the password will be valid just for 30 seconds. + * type *(optional)*: graphics type. VNC or Spice. * cpu_info *(optional)*: CPU-specific information. * maxvcpus *(optional)*: The maximum number of vCPUs that can be assigned to the VM. If topology is specified, maxvcpus must be a diff --git a/i18n.py b/i18n.py index 823b88d..47c829e 100644 --- a/i18n.py +++ b/i18n.py @@ -106,7 +106,7 @@ messages = { "KCHVM0051E": _("Cannot reset %(name)s. Virtual machine is already shut off."), "KCHVM0052E": _("Boot order must be a list. Devices accepted: hd, cdrom, fd or network."), "KCHVM0053E": _("Bootmenu must be boolean. Values accepted: true of false."), - + "KCHVM0054E": _("Graphic type not valid. Values accepted: vnc or spice."), "KCHVM0055E": _("Migrate to localhost %(host)s is not allowed."), "KCHVM0056E": _("To migrate a virtual machine to the remote host %(host)s the user %(user)s must have password-less login to the remote host."), "KCHVM0057E": _("Can not migrate virtual machine %(name)s when its in %(state)s state."), diff --git a/model/vms.py b/model/vms.py index f13e605..b889166 100644 --- a/model/vms.py +++ b/model/vms.py @@ -291,6 +291,12 @@ class VMModel(object): # GRAPHICS can be updated offline or online if 'graphics' in params: + + # some parameters cannot change while vm is running + if DOM_STATE_MAP[dom.info()[0]] != 'shutoff': + if 'type' in params['graphics']: + raise InvalidParameter('KCHVM0074E', + {'params': 'graphics type'}) dom = self._update_graphics(dom, params) # Live updates @@ -702,6 +708,10 @@ class VMModel(object): valid_to = time.strftime('%Y-%m-%dT%H:%M:%S', expire_time) graphics.attrib['passwdValidTo'] = valid_to + gtype = params['graphics'].get('type') + if gtype is not None: + graphics.attrib['type'] = gtype + conn = self.conn.get() if not dom.isActive(): return conn.defineXML(ET.tostring(root, encoding="utf-8")) -- 2.5.5

Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- tests/test_model.py | 18 +++++++----------- tests/test_rest.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/test_model.py b/tests/test_model.py index d9ffd5e..05f046c 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -325,25 +325,21 @@ class ModelTests(unittest.TestCase): 'source_media': {'type': 'disk', 'path': UBUNTU_ISO}} inst.templates_create(params) with RollbackContext() as rollback: - params = {'name': 'kimchi-vnc', + params = {'name': 'kimchi-graphics', 'template': '/plugins/kimchi/templates/test'} task1 = inst.vms_create(params) inst.task_wait(task1['id']) - rollback.prependDefer(inst.vm_delete, 'kimchi-vnc') + rollback.prependDefer(inst.vm_delete, 'kimchi-graphics') - info = inst.vm_lookup('kimchi-vnc') + info = inst.vm_lookup('kimchi-graphics') self.assertEquals('vnc', info['graphics']['type']) self.assertEquals('127.0.0.1', info['graphics']['listen']) - graphics = {'type': 'spice', 'listen': '127.0.0.1'} - params = {'name': 'kimchi-spice', - 'template': '/plugins/kimchi/templates/test', - 'graphics': graphics} - task2 = inst.vms_create(params) - inst.task_wait(task2['id']) - rollback.prependDefer(inst.vm_delete, 'kimchi-spice') + graphics = {'type': 'spice'} + params = {'graphics': graphics} + inst.vm_update('kimchi-graphics', params) - info = inst.vm_lookup('kimchi-spice') + info = inst.vm_lookup('kimchi-graphics') self.assertEquals('spice', info['graphics']['type']) self.assertEquals('127.0.0.1', info['graphics']['listen']) diff --git a/tests/test_rest.py b/tests/test_rest.py index b1b9f12..00ad7f3 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -301,6 +301,16 @@ class RestTests(unittest.TestCase): resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd', req, 'PUT') self.assertEquals(400, resp.status) + # change vm graphics type + req = json.dumps({"graphics": {"type": "spice"}}) + resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd', req, 'PUT') + self.assertEquals(json.loads(resp.read())["graphics"]["type"], "spice") + + # try to add a invalid type + req = json.dumps({"graphics": {"type": "test"}}) + resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd', req, 'PUT') + self.assertEquals(400, resp.status) + def test_vm_lifecycle(self): # Create a Template req = json.dumps({'name': 'test', -- 2.5.5

Ignore it please On 09/06/2016 02:07 PM, Ramon Medeiros wrote:
Changes:
v3: Just rebase
v2: Use path to determine if volume comes from storage pool Do not use "get_disk_used_by". It will be usefull if we start querying by volumes. Since, we cannot list volumes with inactivate storage pools.
Ramon Medeiros (2): Issue #836: Allow user change guest graphics type Create test to verify graphics type change
API.json | 6 ++++++ docs/API.md | 1 + i18n.py | 2 +- model/vms.py | 10 ++++++++++ tests/test_model.py | 18 +++++++----------- tests/test_rest.py | 10 ++++++++++ 6 files changed, 35 insertions(+), 12 deletions(-)
-- Ramon Nunes Medeiros Kimchi Developer Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com
participants (1)
-
Ramon Medeiros