[ovirt-users] Migrate oVirtBackup to sdk v4: How to create a snapshot

Ondra Machacek omachace at redhat.com
Sun Nov 6 11:28:47 UTC 2016


On 11/04/2016 09:42 PM, gregor wrote:
> Hi,
>
> I'm started the migration of my backup tool [1] from sdk v3 to v4.
> Whats the correct REST URI to create a snapshost from a given VM and how
> can this be done with the SnapshotsService.add(...) method?

Please take a look at following example:

 
https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/examples/add_vm_snapshot.py#L45

>
> This method needs a "snapshot" object, but currently I don't know how to
> obtain one from a given VM or initialize one which works with the
> SnapshotsService class.
>
> A REST way will also be interesting because the Python SDK is horrible
> documented and I plan to move to basic REST. Also the Python SDK has
> lots of bug's which consumes many of the migration time. For example a
> obtained VmService object get by the VmsService.list(with filter) method
> has no information about the ID but iterating over all objects from
> list() without filter result in usable VmService objects. This will
> later be documented, meanwhile I wrote a workaround.

VmsService.list doesn't return list of VmService objects, but list of 
types.Vm object.

So what you will see in above add_vm_snapshot example is follwoing:

# Obtain types.Vm object which is actually a Python representation of
# XML, which oVirt API returns, when you send request like this:
# ovirt-engine/api/vms?search=name=myvm
vm = vms_service.list(search='name=myvm')[0]

# Locate the service that manages the snapshots of the virtual machine,
# which we have found in previous step:
snapshots_service = vms_service.vm_service(vm.id).snapshots_service()

# Add the new snapshot to that VM:
snapshots_service.add(
   types.Snapshot(
     description='My snapshot',
   ),
)

Everything works here as expected. Can you please tell us what is
confusing and what should be better documented?

The documentation of SnapshotsService class is here:

 
https://machacekondra.github.io/ovirt-engine-sdk/v4.0/latest/services.m.html#ovirtsdk4.services.SnapshotsService

We want to improve, so the pages will contain also Python examples and 
maybe some tutorial.

  https://machacekondra.github.io/ovirt-engine-sdk/

>
> cheers
> gregor
>
> [1] https://github.com/wefixit-AT/oVirtBackup
> _______________________________________________
> Users mailing list
> Users at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/users
>



More information about the Users mailing list