Skip to content

Commit

Permalink
Issue #857: Support VM description
Browse files Browse the repository at this point in the history
Able Kimchi to add description and title while creating and updating vms

Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com>
  • Loading branch information
Ramon Medeiros authored and danielhb committed Aug 17, 2016
1 parent 351917d commit 6a37e55
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
20 changes: 20 additions & 0 deletions API.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
"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."),
Expand Down
34 changes: 31 additions & 3 deletions model/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@

# 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']"
Expand All @@ -98,10 +99,12 @@
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'
Expand Down Expand Up @@ -138,7 +141,9 @@ def create(self, params):

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)

Expand All @@ -152,6 +157,8 @@ def _create_task(self, cb, params):
- 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()
Expand All @@ -178,7 +185,8 @@ def _create_task(self, cb, params):
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:
Expand Down Expand Up @@ -786,6 +794,24 @@ def _static_vm_update(self, vm_name, dom, params):
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)
Expand Down Expand Up @@ -1267,6 +1293,8 @@ def lookup(self, name):
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(),
Expand Down
5 changes: 4 additions & 1 deletion vmtemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ def to_vm_xml(self, vm_name, vm_uuid, **kwargs):
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
Expand Down Expand Up @@ -404,6 +405,8 @@ def to_vm_xml(self, vm_name, vm_uuid, **kwargs):
<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>
Expand Down

0 comments on commit 6a37e55

Please sign in to comment.