[PATCH v2][Kimchi 0/3] Issue #857: Support VM description

Changes: Create xml tag when updating a xml that does not have the tag Update messages to use Virtual machine instead of VM Ramon Medeiros (3): Issue #857: Support VM description Update tests Update docs API.json | 20 ++++++++++++++++++++ docs/API.md | 6 ++++++ i18n.py | 2 ++ model/vms.py | 35 ++++++++++++++++++++++++++++++++--- tests/test_mockmodel.py | 3 ++- tests/test_model.py | 3 ++- vmtemplate.py | 5 ++++- 7 files changed, 68 insertions(+), 6 deletions(-) -- 2.5.5

Able Kimchi to add description and title while creating and updating vms Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- API.json | 20 ++++++++++++++++++++ i18n.py | 2 ++ model/vms.py | 35 ++++++++++++++++++++++++++++++++--- vmtemplate.py | 5 ++++- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/API.json b/API.json index 4fdd522..a3af02d 100644 --- a/API.json +++ b/API.json @@ -268,6 +268,16 @@ "pattern": "^[^/]*$", "error": "KCHVM0011E" }, + "title": { + "description": "Title of VM", + "type": "string", + "error": "KCHVM0085E" + }, + "description": { + "description": "Description of VM", + "type": "string", + "error": "KCHVM0086E" + }, "template": { "description": "The URI of a template to use when building a VM", "type": "string", @@ -294,6 +304,16 @@ "minLength": 1, "error": "KCHVM0011E" }, + "title": { + "description": "Title of VM", + "type": "string", + "error": "KCHVM0085E" + }, + "description": { + "description": "Description of VM", + "type": "string", + "error": "KCHVM0086E" + }, "bootorder": { "description": "Boot order", "type": "array", diff --git a/i18n.py b/i18n.py index 7625469..e8d9c05 100644 --- a/i18n.py +++ b/i18n.py @@ -135,6 +135,8 @@ messages = { "KCHVM0082E": _("Either the guest %(name)s did not start to listen to the serial or it is not configured to use the serial console."), "KCHVM0083E": _("Unable to retrieve Virt Viewer file for stopped virtual machine %(name)s"), "KCHVM0084E": _("Error occured while retrieving the Virt Viewer file for virtual machine %(name)s : %(err)s"), + "KCHVM0085E": _("Virtual machine title must be a string"), + "KCHVM0086E": _("Virtual machine description must be a string"), "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/model/vms.py b/model/vms.py index 433770a..061b523 100644 --- a/model/vms.py +++ b/model/vms.py @@ -83,7 +83,8 @@ VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users'] # update parameters which are updatable when the VM is offline VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 'memory', - 'name', 'users', 'bootorder', 'bootmenu'] + 'name', 'users', 'bootorder', 'bootmenu', + 'description', 'title'] XPATH_DOMAIN_DISK = "/domain/devices/disk[@device='disk']/source/@file" XPATH_DOMAIN_DISK_BY_FILE = "./devices/disk[@device='disk']/source[@file='%s']" @@ -98,10 +99,12 @@ XPATH_DOMAIN_DEV_CPU_ID = '/domain/devices/spapr-cpu-socket/@id' XPATH_BOOT = 'os/boot/@dev' XPATH_BOOTMENU = 'os/bootmenu/@enable' XPATH_CPU = './cpu' +XPATH_DESCRIPTION = './description' XPATH_NAME = './name' XPATH_NUMA_CELL = './cpu/numa/cell' XPATH_SNAP_VM_NAME = './domain/name' XPATH_SNAP_VM_UUID = './domain/uuid' +XPATH_TITLE = './title' XPATH_TOPOLOGY = './cpu/topology' XPATH_VCPU = './vcpu' XPATH_MAX_MEMORY = './maxMemory' @@ -138,7 +141,9 @@ class VMsModel(object): t.validate() data = {'name': name, 'template': t, - 'graphics': params.get('graphics', {})} + 'graphics': params.get('graphics', {}), + "title": params.get("title", ""), + "description": params.get("description", "")} taskid = add_task(u'/plugins/kimchi/vms/%s' % name, self._create_task, self.objstore, data) @@ -152,6 +157,8 @@ class VMsModel(object): - name: The name for the new VM """ vm_uuid = str(uuid.uuid4()) + title = params.get('title', '') + description = params.get('description', '') t = params['template'] name, nonascii_name = get_ascii_nonascii_name(params['name']) conn = self.conn.get() @@ -178,7 +185,8 @@ class VMsModel(object): xml = t.to_vm_xml(name, vm_uuid, libvirt_stream_protocols=stream_protocols, graphics=graphics, - mem_hotplug_support=self.caps.mem_hotplug_support) + mem_hotplug_support=self.caps.mem_hotplug_support, + title=title, description=description) cb('Defining new VM') try: @@ -786,6 +794,25 @@ class VMModel(object): name, nonascii_name = get_ascii_nonascii_name(name) new_xml = xml_item_update(new_xml, XPATH_NAME, name, None) + if 'title' in params: + if len(xpath_get_text(new_xml, XPATH_TITLE)) > 0: + new_xml = xml_item_update(new_xml, XPATH_TITLE, params['title'], + None) + else: + et = ET.fromstring(new_xml) + et.append(E.title(params["title"])) + new_xml = ET.tostring(et) + + + if 'description' in params: + if len(xpath_get_text(new_xml, XPATH_DESCRIPTION)) > 0: + new_xml = xml_item_update(new_xml, XPATH_DESCRIPTION, + params['description'], None) + else: + et = ET.fromstring(new_xml) + et.append(E.description(params["description"])) + new_xml = ET.tostring(et) + # Update CPU info cpu_info = params.get('cpu_info', {}) cpu_info = self._update_cpu_info(new_xml, dom, cpu_info) @@ -1267,6 +1294,8 @@ class VMModel(object): else "no" return {'name': name, + 'title': "".join(xpath_get_text(xml, XPATH_TITLE)), + 'description': "".join(xpath_get_text(xml, XPATH_DESCRIPTION)), 'state': state, 'stats': res, 'uuid': dom.UUIDString(), diff --git a/vmtemplate.py b/vmtemplate.py index dc81fe2..79730cf 100644 --- a/vmtemplate.py +++ b/vmtemplate.py @@ -347,7 +347,8 @@ class VMTemplate(object): params['qemu-stream-cmdline'] = '' params['disks'] = self._get_disks_xml(vm_uuid) params['serial'] = get_serial_xml(params) - + params['title'] = kwargs.get('title', '') + params['description'] = kwargs.get('description', '') graphics = dict(self.info['graphics']) graphics.update(kwargs.get('graphics', {})) # Graphics is not supported on s390x, this check will @@ -404,6 +405,8 @@ class VMTemplate(object): <domain type='%(domain)s'> %(qemu-stream-cmdline)s <name>%(name)s</name> + <title>%(title)s</title> + <description>%(description)s</description> <uuid>%(uuid)s</uuid> <memtune> <hard_limit unit='MiB'>%(hard_limit)s</hard_limit> -- 2.5.5

Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- tests/test_mockmodel.py | 3 ++- tests/test_model.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py index 43f6d07..147942c 100644 --- a/tests/test_mockmodel.py +++ b/tests/test_mockmodel.py @@ -163,7 +163,8 @@ class MockModelTests(unittest.TestCase): keys = set(('name', 'state', 'stats', 'uuid', 'memory', 'cpu_info', 'screenshot', 'icon', 'graphics', 'users', 'groups', - 'access', 'persistent', 'bootorder', 'bootmenu')) + 'access', 'persistent', 'bootorder', 'bootmenu', 'title', + 'description')) stats_keys = set(('cpu_utilization', 'mem_utilization', 'net_throughput', 'net_throughput_peak', diff --git a/tests/test_model.py b/tests/test_model.py index 27225f8..4f49ce6 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -127,7 +127,8 @@ class ModelTests(unittest.TestCase): keys = set(('name', 'state', 'stats', 'uuid', 'memory', 'cpu_info', 'screenshot', 'icon', 'graphics', 'users', 'groups', - 'access', 'persistent', 'bootorder', 'bootmenu')) + 'access', 'persistent', 'bootorder', 'bootmenu', 'title', + 'description')) stats_keys = set(('cpu_utilization', 'mem_utilization', 'net_throughput', 'net_throughput_peak', -- 2.5.5

Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- docs/API.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/API.md b/docs/API.md index b07bf16..7bd677f 100644 --- a/docs/API.md +++ b/docs/API.md @@ -90,6 +90,8 @@ server. Independent Computing Environments * null: Graphics is disabled or type not supported * listen: The network which the vnc/spice server listens on. + * description: VM description + * title: VM title ### Resource: Virtual Machine @@ -147,6 +149,8 @@ server. * groups: A list of system groups whose users have permission to access the VM. Default is: empty (i.e. no groups given access). * bootorder: list of devices in boot order + * description: VM description + * title: VM title * **DELETE**: Remove the Virtual Machine * **PUT**: update the parameters of existing VM * name: New name for this VM (only applied for shutoff VM) @@ -177,6 +181,8 @@ server. * threads - The number of threads per core. * bootorder: guest bootorder, types accepted: hd, cdrom, network or fd * bootmenu: prompts guest bootmenu. Bool type. + * description: VM description + * title: VM title * **POST**: *See Virtual Machine Actions* -- 2.5.5

make check-local errors: make check-local make[3]: Entering directory '/home/danielhb/kimchi/wok_all_plugins/src/wok/plugins/kimchi' contrib/check_i18n.py ./i18n.py Checking for invalid i18n string... Checking for invalid i18n string successfully /bin/pep8 --version 1.6.2 /bin/pep8 --filename '*.py,*.py.in' --exclude="*config.py,*i18n.py,*tests/test_config.py" . ./model/vms.py:799:80: E501 line too long (80 > 79 characters) ./model/vms.py:807:9: E303 too many blank lines (2) Makefile:1062: recipe for target 'check-local' failed make[3]: *** [check-local] Error 1 On 08/16/2016 04:29 PM, Ramon Medeiros wrote:
Changes: Create xml tag when updating a xml that does not have the tag Update messages to use Virtual machine instead of VM
Ramon Medeiros (3): Issue #857: Support VM description Update tests Update docs
API.json | 20 ++++++++++++++++++++ docs/API.md | 6 ++++++ i18n.py | 2 ++ model/vms.py | 35 ++++++++++++++++++++++++++++++++--- tests/test_mockmodel.py | 3 ++- tests/test_model.py | 3 ++- vmtemplate.py | 5 ++++- 7 files changed, 68 insertions(+), 6 deletions(-)
participants (2)
-
Daniel Henrique Barboza
-
Ramon Medeiros