On 08/16/2016 02:02 PM, Paulo Ricardo Paz Vital wrote:
On Aug 16 01:24PM, Ramon Medeiros wrote:
> Able Kimchi to add description and title while creating and updating vms
>
> Signed-off-by: Ramon Medeiros <ramonn(a)linux.vnet.ibm.com>
> ---
> API.json | 20 ++++++++++++++++++++
> i18n.py | 2 ++
> model/vms.py | 24 +++++++++++++++++++++---
> vmtemplate.py | 5 ++++-
> 4 files changed, 47 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": {
Just a conceptual question: what's a title?
Better: What's the difference between title and name?
name is used by the
commands. Title can be a verbose name for vm. ex:
name: centos_13932193
title: Web Server based on CentOs
> + "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..fd4b6db 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": _("VM Title must be a string"),
> + "KCHVM0086E": _("VM Description must be a string"),
I did not checked all KCHVM* messages, but I think we are not using the
term 'VM' but 'virtual machine'. If so, need change here and also in
patch 3/3.
Both ways can be found:
"KCHVM0040E": _("Unable to resume VM '%(name)s'. Details:
%(err)s"),
"KCHVM0033E": _("Virtual machine '%(name)s' must be stopped
before
cloning it."),
If you prefer Virtual machine, i can change it
> "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..2c6c63c 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,14 @@ 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:
> + new_xml = xml_item_update(new_xml, XPATH_TITLE,
params['title'],
> + None)
> +
> + if 'description' in params:
> + new_xml = xml_item_update(new_xml, XPATH_DESCRIPTION,
> + params['description'], None)
> +
> # Update CPU info
> cpu_info = params.get('cpu_info', {})
> cpu_info = self._update_cpu_info(new_xml, dom, cpu_info)
> @@ -1267,6 +1283,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
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel(a)ovirt.org
>
http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>
--
Ramon Nunes Medeiros
Kimchi Developer
Linux Technology Center Brazil
IBM Systems & Technology Group
Phone : +55 19 2132 7878
ramonn(a)br.ibm.com