On 01/18/2016 02:49 PM, Algirdas Žemaitis wrote:
> Hello,
> I was playing with Ovirt API/python-sdk for a week or so and stuck in
> one from first sight simple yet unsolvable spot…
> Ovirt web GUI has option to clone VM from snapshot, to new(other)
> storage domain. Is it possible to do so with API ?
> The point is, I’m using backup script (already modified a lot of it to
> suit our needs), once it is cloning from snapshot into new VM, it will
> use same storage, and causing a lot of load on already stressed domain,
> idea is to create VM (allocate disk before exporting it as backup) on
> other storage domain, in this way significantly reducing impact on live
> storage domain. What do you think ?
> Original : https://github.com/wefixit-AT/oVirtBackup
> Thank you for your time, and sorry for reaching directly, Ovirt lacks
> for an forum or something similar… or I just couldn’t find it…

I'm adding the users@ovirt.org list, there is where you can send your

In order to clone a VM from an snapshot you have to use the "add"
operation of the "vms" service, passing as a parameter a "vm" object
that contains the identifier of the snapshot and the explicit mapping of
disk to storage domain. In XML it should look like this:


  <!-- This is how you indicate what snapshot to clone: -->
   <snapshot id="266742a5-6a65-483c-816d-d2ce49746680"/>

  <!-- This is how you indicate how to map disks to storage
       domains. -->
        <storage_domain id="9cb6cb0a-cf1d-41c2-92ca-5a6d665649c9"/>


With the Python SDK it should look like this:

# Find the VM:
vm = api.vms.get(name="myvm")

# Find the snapshot:
snapshot = None
for current in vm.snapshots.list():
  if current.get_description() == 'mysnap':
    snapshot = current
    break # Should probably end here, with an error.

# Find the image identifiers of the disks of the snapshot, as
# we need them in order to explicitly indicate that we want
# them created in a different storage domain:
disk_ids = []
for current in snapshot.disks.list():

# Find the storage domain where the disks should be created:
sd = api.storagedomains.get(name="yourdata")

# Prepare the list of disks for the operation to create the
# snapshot,explicitly indicating for each of them the storage
# domain where it should be created:
disk_list = []
for disk_id in disk_ids:
  disk = params.Disk(

# Create the VM from the snapshot:

This should work for you.

However, I have to say that I find a bit strange that we use the
"image_id" attribute as the key of the disk in this case, instead of
just the "id". Allon, do you know if this is on purpose? I mean, when we
clone a VM from a template we use do like this:

  <disk id="the_key">

But in this case we do like this:


Is there any reason for these two different ways to specify the
identifier of the disk?

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.
Users mailing list

Reply via email to