On 06/09/2015 05:41 PM, Philip Strömbäck wrote:
Hi,
I have a question about python-SDK for Ovirt Engine API. When creating a
new VM from a template in Clone/Independent-mode, I'm not unable to
select storage domain for the new disk. It seems like it always get
created on the same disk at the template. I can move the disk after
creation but it's a little bit time consuming.
Example:
vm_params = params.VM ( name = vm_name, cluster = api.clusters.get (
"Cluster-1" ), template = api.templates.get ( "RHEL7" ),
storage_domain
= api.storagedomains.get ( "iscsi1" ), disks = params.Disks ( clone =
True ) )
try:
api.vms.add ( vm_params )
except Exception, e:
raise SystemExit ( "Could not create VM from template: %s" % ( e ) )
The VM is added correctly but the disk is located on iscsi0 ( the same
as the template ).
Have anybody an idea how to get this sorted out?
Best regards,
Philip
To do this you need to specify the target storage domain for each of the
disks of the template that you want in an different storage domain. In
plain XML that would look like this:
POST /vms
<vm>
<name>mynewvm</name>
<cluster>
<name>mycluster</name>
</cluster>
<template>
<name>mytemplate</name>
</template>
<disks>
<clone>true</clone>
<disk id="the-id-of-the-disk-of-the-template">
<storage_domains>
<storage_domain id="the-id-of-the-target-storage-domain"/>
</storage_domains>
</disk>
</disks>
</vm>
To do the same with the Python SDK you need something like this:
api.vms.add(
params.VM(
name="mynewvm",
template=params.Template(
name="mytemplate"
),
cluster=params.Cluster(
name="mycluster"
),
disks=params.Disks(
clone=True,
disk=[
params.Disk(
id="the-id-of-the-disk-of-the-template",
storage_domains=params.StorageDomains(
storage_domain=[
params.StorageDomain(
id="the-id-of-the-storage-domain"
)
]
)
)
]
)
)
)
--
Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
3ºD, 28016 Madrid, Spain
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.