Creating snapshot of a subset of disks

Hello, I'm trying to see how to create a snapshot of a VM, but only of a subset of its disks (actually it will be only the bootable one) Taking the examples at https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples I can accomodate something like this # Get the reference to the service that manages the virtual machines: vms_service = system_service.vms_service() # Find the virtual machine and put into data_vm vm = vms_service.list( search='name=%s' % MY_VM_NAME, all_content=True, )[0] logging.info( 'Found virtual machine \'%s\', the id is \'%s\'.', vm.name, vm.id, ) # Find the services that manage the data_vm virtual machine: vm_service = vms_service.vm_service(vm.id) # Send the request to create the snapshot. Note that this will return # before the snapshot is completely created, so we will later need to # wait till the snapshot is completely created. snaps_service = vm_service.snapshots_service() snap = snaps_service.add( snapshot=types.Snapshot( description=snap_description, persist_memorystate=False, ), ) This makes a snapshot of all the dsks of the vm. I can previously filter in my case the bootable disk with something like this: # Locate the service that manages the disk attachments of the virtual # machine: disk_attachments_service = vm_service.disk_attachments_service() # Retrieve the list of disks attachments, and print the disk details. disk_attachments = disk_attachments_service.list() for disk_attachment in disk_attachments: disk = connection.follow_link(disk_attachment.disk) print("name: %s" % disk.name) print("id: %s" % disk.id) print("status: %s" % disk.status) print("bootable: %s" % disk_attachment.bootable) print("provisioned_size: %s" % disk.provisioned_size) So in case of an example VM with two disks I get this print out name: padnpro_bootdisk id: c122978a-70d7-48aa-97c5-2f17d4603b1e status: ok bootable: True provisioned_size: 59055800320 name: padnpro_imp_Disk1 id: 5454b137-fb2c-46a7-b345-e6d115802582 status: ok bootable: False provisioned_size: 10737418240 But I haven't found then the syntax to use to specify a disk list in the block where I create the sapshot of the VM snap = snaps_service.add( snapshot=types.Snapshot( description=snap_description, persist_memorystate=False, disxk x x x ? ? ? ), ) Any help in this direction? Tahnsk, Gianluca

You could something like this (IIUC): dead_snap1_params = types.Snapshot( description=SNAPSHOT_DESC_1, persist_memorystate=False, disk_attachments=[ types.DiskAttachment( disk=types.Disk( id=disk.id ) ) ] ) Taken from ovirt-system-tests[1] [1] - https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t... On Thu, Jun 21, 2018 at 2:57 PM Gianluca Cecchi <gianluca.cecchi@gmail.com> wrote:
Hello, I'm trying to see how to create a snapshot of a VM, but only of a subset of its disks (actually it will be only the bootable one)
Taking the examples at https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples
I can accomodate something like this
# Get the reference to the service that manages the virtual machines: vms_service = system_service.vms_service()
# Find the virtual machine and put into data_vm vm = vms_service.list( search='name=%s' % MY_VM_NAME, all_content=True, )[0] logging.info( 'Found virtual machine \'%s\', the id is \'%s\'.', vm.name, vm.id, )
# Find the services that manage the data_vm virtual machine: vm_service = vms_service.vm_service(vm.id)
# Send the request to create the snapshot. Note that this will return # before the snapshot is completely created, so we will later need to # wait till the snapshot is completely created.
snaps_service = vm_service.snapshots_service() snap = snaps_service.add( snapshot=types.Snapshot( description=snap_description, persist_memorystate=False, ), )
This makes a snapshot of all the dsks of the vm.
I can previously filter in my case the bootable disk with something like this:
# Locate the service that manages the disk attachments of the virtual # machine: disk_attachments_service = vm_service.disk_attachments_service()
# Retrieve the list of disks attachments, and print the disk details. disk_attachments = disk_attachments_service.list() for disk_attachment in disk_attachments: disk = connection.follow_link(disk_attachment.disk) print("name: %s" % disk.name) print("id: %s" % disk.id) print("status: %s" % disk.status) print("bootable: %s" % disk_attachment.bootable) print("provisioned_size: %s" % disk.provisioned_size)
So in case of an example VM with two disks I get this print out
name: padnpro_bootdisk id: c122978a-70d7-48aa-97c5-2f17d4603b1e status: ok bootable: True provisioned_size: 59055800320 name: padnpro_imp_Disk1 id: 5454b137-fb2c-46a7-b345-e6d115802582 status: ok bootable: False provisioned_size: 10737418240
But I haven't found then the syntax to use to specify a disk list in the block where I create the sapshot of the VM
snap = snaps_service.add( snapshot=types.Snapshot( description=snap_description, persist_memorystate=False, disxk x x x ? ? ? ), )
Any help in this direction? Tahnsk, Gianluca
_______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/X5I22JVFREERWE...

On Thu, Jun 21, 2018 at 2:00 PM, Benny Zlotnik <bzlotnik@redhat.com> wrote:
You could something like this (IIUC): dead_snap1_params = types.Snapshot( description=SNAPSHOT_DESC_1, persist_memorystate=False, disk_attachments=[ types.DiskAttachment( disk=types.Disk( id=disk.id ) ) ] )
Taken from ovirt-system-tests[1]
[1] - https://github.com/oVirt/ovirt-system-tests/blob/ master/basic-suite-master/test-scenarios/004_basic_sanity.py#L340
Hi, thanks for your input! It seems I was able to reach my target What I've done # Locate the service that manages the disk attachments of the virtual # machine: disk_attachments_service = vm_service.disk_attachments_service() # Retrieve the list of disk attachments and then the bootable disk disk_attachments = disk_attachments_service.list() bootdisk = None for disk_attachment in disk_attachments: disk = connection.follow_link(disk_attachment.disk) if disk_attachment.bootable == True: bootdisk = connection.follow_link(disk_attachment.disk) break snaps_service = vm_service.snapshots_service() snap = snaps_service.add( snapshot=types.Snapshot( description=snap_description, persist_memorystate=False, disk_attachments=[ types.DiskAttachment( disk=types.Disk( id=bootdisk.id ) ) ] ), ) logging.info( 'Sent request to create snapshot \'%s\', the id is \'%s\'.', snap.description, snap.id, ) It seems also the monitor function already present in backup.py of the sdk examples linked in my previous message is working ok, # Poll and wait till the status of the snapshot is 'ok', which means # that it is completely created: snap_service = snaps_service.snapshot_service(snap.id) while snap.snapshot_status != types.SnapshotStatus.OK: logging.info( 'Waiting till the snapshot is created, the status is now \'%s\'.', snap.snapshot_status, ) time.sleep(1) snap = snap_service.get() logging.info('The snapshot is now complete.') In fact in the log file I have INFO:root:Sent request to create snapshot 'padnpro_imp-backup-0e0c7064-bec5-429b-9ad7-cd8d1e5b25be', the id is '4135e8cb-87e8-4f09-82f5-b9ad0ed2f5be'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:The snapshot is now complete. What if I would like to emit an event if for any reason the creation of the snapshot doesn't complete in a predefined elapsed time and manage it? I think I have also to manage the case when for any reason no disk is marked as bootable inside the VM I'm backing up... Gianluca

On Thu, Jun 21, 2018 at 3:06 PM, Gianluca Cecchi <gianluca.cecchi@gmail.com> wrote:
bootdisk = None for disk_attachment in disk_attachments: disk = connection.follow_link(disk_attachment.disk) if disk_attachment.bootable == True: bootdisk = connection.follow_link(disk_attachment.disk) break
As I already have the disk, it is better this one: bootdisk = None for disk_attachment in disk_attachments: disk = connection.follow_link(disk_attachment.disk) if disk_attachment.bootable == True: bootdisk = disk_attachment.disk break
What if I would like to emit an event if for any reason the creation of the snapshot doesn't complete in a predefined elapsed time and manage it? I think I have also to manage the case when for any reason no disk is marked as bootable inside the VM I'm backing up...
Gianluca
Still interesting to have feedback on these two latest points. Thanks Gianluca

I can refer again to what we do in the ovirt-system-tests: testlib.assert_true_within_long( lambda: vm1_snapshots_service.list()[-1].snapshot_status == types.SnapshotStatus.OK ) Which tests whether the status change to desirable one within a given period of time (I think ten minutes in case of assert_true_within_long), the assert code itself is in ovirtlago: https://github.com/lago-project/lago-ost-plugin/blob/130bed27a04c9b63161d6fc... So instead of just asserting you can modify it to do whatever you need On Thu, Jun 21, 2018 at 4:06 PM Gianluca Cecchi <gianluca.cecchi@gmail.com> wrote:
On Thu, Jun 21, 2018 at 2:00 PM, Benny Zlotnik <bzlotnik@redhat.com> wrote:
You could something like this (IIUC): dead_snap1_params = types.Snapshot( description=SNAPSHOT_DESC_1, persist_memorystate=False, disk_attachments=[ types.DiskAttachment( disk=types.Disk( id=disk.id ) ) ] )
Taken from ovirt-system-tests[1]
[1] - https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t...
Hi, thanks for your input! It seems I was able to reach my target
What I've done
# Locate the service that manages the disk attachments of the virtual # machine: disk_attachments_service = vm_service.disk_attachments_service()
# Retrieve the list of disk attachments and then the bootable disk disk_attachments = disk_attachments_service.list()
bootdisk = None for disk_attachment in disk_attachments: disk = connection.follow_link(disk_attachment.disk) if disk_attachment.bootable == True: bootdisk = connection.follow_link(disk_attachment.disk) break
snaps_service = vm_service.snapshots_service() snap = snaps_service.add( snapshot=types.Snapshot( description=snap_description, persist_memorystate=False, disk_attachments=[ types.DiskAttachment( disk=types.Disk( id=bootdisk.id ) ) ] ), ) logging.info( 'Sent request to create snapshot \'%s\', the id is \'%s\'.', snap.description, snap.id, )
It seems also the monitor function already present in backup.py of the sdk examples linked in my previous message is working ok,
# Poll and wait till the status of the snapshot is 'ok', which means # that it is completely created: snap_service = snaps_service.snapshot_service(snap.id) while snap.snapshot_status != types.SnapshotStatus.OK: logging.info( 'Waiting till the snapshot is created, the status is now \'%s\'.', snap.snapshot_status, ) time.sleep(1) snap = snap_service.get() logging.info('The snapshot is now complete.')
In fact in the log file I have
INFO:root:Sent request to create snapshot 'padnpro_imp-backup-0e0c7064-bec5-429b-9ad7-cd8d1e5b25be', the id is '4135e8cb-87e8-4f09-82f5-b9ad0ed2f5be'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:Waiting till the snapshot is created, the status is now 'locked'. INFO:root:The snapshot is now complete.
What if I would like to emit an event if for any reason the creation of the snapshot doesn't complete in a predefined elapsed time and manage it? I think I have also to manage the case when for any reason no disk is marked as bootable inside the VM I'm backing up...
Gianluca
participants (2)
-
Benny Zlotnik
-
Gianluca Cecchi