[ovirt-users] Python API question

Colin Coe colin.coe at gmail.com
Sat Jan 16 05:07:19 UTC 2016


Hi again all

I've just noticed that the snapshot status appears not to update.

Consider the code below:
---
api.vms.get(VM_NAME).snapshots.add(params.Snapshot(description=SNAPSHOT_NAME,
vm=api.vms.get(VM_NAME), persist_memorystate=True))

# Wait for snapshot to finish
snap = api.vms.get(name=VM_NAME).snapshots.list()[-1]
while (snap.get_snapshot_status() == 'locked'):
   print "Waiting for snapshot creation to finish (status is %s)" %
snap.get_snapshot_status()
---

What I find is that even though the WebUI reports the snapshot is created,
snap.get_snapshot_status() still reports 'locked'.

I'm using RHEV 3.5.7 with RHEL-H 7.1 hosts with vdsm-4.16.30-1.el7ev.x86_64.

Am I misunderstanding how this works or have I found a bug?

Thanks

On Fri, Jan 15, 2016 at 6:04 PM, Juan Hernández <jhernand at redhat.com> wrote:

> On 01/15/2016 05:23 AM, Colin Coe wrote:
> > Hi all
> >
> > I've written a Python script to take nightly snapshots of VMs which are
> > kept for x days.  After x days the snapshot is deleted.
> >
> > I can't work out how to wait for the snapshot deletion to complete.  I
> > know how to do it for creating the snapshot but I've not been able to
> > get it right for the deletion.
> >
> >
> >
> api.vms.get(VM_NAME).snapshots.add(params.Snapshot(description=SNAPSHOT_NAME,
> > vm=api.vms.get(VM_NAME), persist_memorystate=True))
> >       while api.vms.get(VM_NAME).status.state == 'image_locked':
> >           sleep(1)
> >
> > Any ideas?
> >
> > Thanks
> >
> > CC
> >
> >
>
> The more reliable way to wait till the snapshot is effectively deleted
> is just to try to get it, and finish when the result is "None":
>
>   snapshot.delete()
>
>   while vm.snapshots.get(id=snapshot.get_id()) is not None:
>     sleep(1)
>
> Alternatively you can use the return of the delete operation. It returns
> an "Action" object, that contains a reference to the job that was
> started to delete the snapshot. The XML representation looks like this:
>
>   <action>
>     <job href="/api/jobs/f6e4279a-a8e1-44a3-86db-d53336b0eb5a"
> id="f6e4279a-a8e1-44a3-86db-d53336b0eb5a"/>
>     <status>
>       <state>complete</state>
>     </status>
>   </action>
>
> As you can see that contains a link to the job. With the Python SDK you
> can use it as follows:
>
>   # Get the id of the job:
>   action = snapshot.delete()
>   job_id = action.get_job().get_id()
>
>   # Wait till the job is finished:
>   while api.jobs.get(id=job_id).get_status().get_state() != 'FINISHED':
>     time.sleep(1)
>
> This is less reliable, because actions may or may not return a job, and
> that depends on how the action is implemented in the engine, and there
> is no backwards compatibility guarantee for that. A minor change in the
> engine may result in the job not being returned.
>
> So my suggestion is to use the simple loop to check if the snapshot exists.
>
> --
> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/users/attachments/20160116/0d1cd058/attachment-0001.html>


More information about the Users mailing list