Description of problem: Using the python SDK4, I'm trying to set some parameters for a template creation. The goal is to have the template with QCOW2/Thin Disks irrespective of the base VM configuration. However, it looks like the DiskAttachments list is ignored on the Template instance passed to TemplatesService.add(). Example 1: new_template = templates_service.add( types.Template( name = template_name, vm = types.Vm( name=vm.name, ), disk_attachments = [] ) ) Results in this: DEBUG:root:POST /ovirt-engine/api/templates HTTP/1.1 DEBUG:root:<template> DEBUG:root: <name>da_pipeline_template_210220171613</name> DEBUG:root: <vm> DEBUG:root: <name>Test</name> DEBUG:root: </vm> DEBUG:root: <disk_attachments/> <--- empty DEBUG:root:</template> But the created template was created with the disks of VM 'Test'. Doesn't sound right. Example 2 (what we actually want to do): template_disks = [] disk_attachments_service = vm_service.disk_attachments_service() for disk_attachment in disk_attachments_service.list(): new_attachment = disk_attachment new_attachment.disk.sparse=True new_attachment.disk.format=types.DiskFormat.COW template_disks.append(new_attachment) # Add Template print "3. Adding template %s based on VM %s" % (template_name,vm.name) new_template = templates_service.add( types.Template( name = template_name, vm = types.Vm( name=vm.name, ), disk_attachments = template_disks ) ) Results in this: DEBUG:root:POST /ovirt-engine/api/templates HTTP/1.1 DEBUG:root: <name>da_pipeline_template_200220171706</name> DEBUG:root: <vm> DEBUG:root: <name>Test</name> DEBUG:root: </vm> DEBUG:root: <disk_attachments> DEBUG:root: <disk_attachment href="/ovirt-engine/api/vms/3a902fae-8d8b-4f42-afda-9297cc214682/diskattachments/559083c3-56af-4948-9247-d4921cc139cd" id="559083c3-56af-4948-9247-d4921cc139cd"> DEBUG:root: <active>true</active> DEBUG:root: <bootable>true</bootable> DEBUG:root: <interface>virtio</interface> DEBUG:root: <disk href="/ovirt-engine/api/disks/559083c3-56af-4948-9247-d4921cc139cd" id="559083c3-56af-4948-9247-d4921cc139cd"> DEBUG:root: <format>cow</format> DEBUG:root: <sparse>true</sparse> DEBUG:root: </disk> DEBUG:root: <vm href="/ovirt-engine/api/vms/3a902fae-8d8b-4f42-afda-9297cc214682" id="3a902fae-8d8b-4f42-afda-9297cc214682"/> DEBUG:root: </disk_attachment> DEBUG:root: </disk_attachments> DEBUG:root:</template> Which looks correct. But the result is not. format=cow and sparse=True are not honored. The template has the exact configuration of the base VM. From these two examples, it looks like disk_attachments is completely ignored when creating a template, empty or not, configured or not, the result is always the same. I assume this is a bug, or is there a catch somewhere? Version-Release number of selected component (if applicable): rhevm-4.0.6.3-0.1.el7ev.noarch How reproducible: 100%
Can you have a look?
The way to customize the disks of the template is to use the 'template.vm.disk_attachments.disk' attribute, not 'template.disk_attachments.disk'. For example, if you are using directly the API: POST /ovirt-engine/api/templates <template> <name>mytemplate</name> <vm id="0957c87d-c933-4d28-9ce4-635fa4d8c711"> <disk_attachments> <disk_attachment> <disk id="db7594bd-102b-4a72-8c90-900f3609f0eb"> <format>cow</format> <sparse>true</sparse> </disk> </disk_attachment> </disk_attachments> </vm> </template> With the Python SDK it should be something like this: ---8<--- # Find the original virtual machine: vms_service = system_service.vms_service() vm = vms_service.list(search='name=myvm')[0] # Get the identifiers of the disks attached to the virtual machine. We # need this because we want to tell the server to create the disks of # the template using a format different to the format used by the # original disks. attachments = connection.follow_link(vm.disk_attachments) disk_ids = [ attachment.disk.id for attachment in attachments ] # Send the request to create the template. Note that the way to specify # the original virtual machine, and the customizations, is to use the # 'vm' attribute of the 'Template' type. In the customization we # explicitly indicate that we want COW disks, regardless of what format # the original disks had. templates_service = system_service.templates_service() template = templates_service.add( template=types.Template( name='mytemplate', vm=types.Vm( id=vm.id, disk_attachments=[ types.DiskAttachment( disk=types.Disk( id=disk_id, sparse=True, format=types.DiskFormat.COW ) ) for disk_id in disk_ids ] ) ) ) --->8--- Please try that. If it works correctly I think you can close the bug as NOTABUG.
So that the attachments must be set in template.vm.disk_attachments and not in template.disk_attachments. I would never have guessed it. But it works, thanks a lot!
I admit that is confusing. I am trying to clarify that in the specification of the API: Document template disk customization https://gerrit.ovirt.org/75272 I kindly invite you all to participate in the improvement of that documentation. when you have a question, and you find the answer somewhere other than the documentation, please consider updating it.
Hi Juan, Much appreciated your DOC improvement efforts! It's much better now and the examples are also very useful. (In reply to Juan Hernández from comment #4) > I kindly invite you all to participate in the improvement of that > documentation. when you have a question, and you find the answer somewhere > other than the documentation, please consider updating it. Thanks, I will. There is one more thing though, I think I found a bug related to this. Since it's not the exact same subject of this BZ (DOCs) I decided to open BZ#1439970.