<div dir="ltr">Hi again all<div><br></div><div>I've just noticed that the snapshot status appears not to update.</div><div><br></div><div>Consider the code below:</div><div>---</div><div><div>api.vms.get(VM_NAME).snapshots.add(params.Snapshot(description=SNAPSHOT_NAME, vm=api.vms.get(VM_NAME), persist_memorystate=True))</div><div><br></div><div># Wait for snapshot to finish</div><div>snap = api.vms.get(name=VM_NAME).snapshots.list()[-1]</div><div>while (snap.get_snapshot_status() == 'locked'):<br></div><div> print "Waiting for snapshot creation to finish (status is %s)" % snap.get_snapshot_status()</div><div>---<br></div></div><div><br></div><div>What I find is that even though the WebUI reports the snapshot is created, snap.get_snapshot_status() still reports 'locked'.</div><div><br></div><div>I'm using RHEV 3.5.7 with RHEL-H 7.1 hosts with vdsm-4.16.30-1.el7ev.x86_64.</div><div><br></div><div>Am I misunderstanding how this works or have I found a bug?</div><div><br></div><div>Thanks</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 15, 2016 at 6:04 PM, Juan Hernández <span dir="ltr"><<a href="mailto:jhernand@redhat.com" target="_blank">jhernand@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 01/15/2016 05:23 AM, Colin Coe wrote:<br>
> Hi all<br>
><br>
> I've written a Python script to take nightly snapshots of VMs which are<br>
> kept for x days. After x days the snapshot is deleted.<br>
><br>
> I can't work out how to wait for the snapshot deletion to complete. I<br>
> know how to do it for creating the snapshot but I've not been able to<br>
> get it right for the deletion.<br>
><br>
><br>
> api.vms.get(VM_NAME).snapshots.add(params.Snapshot(description=SNAPSHOT_NAME,<br>
> vm=api.vms.get(VM_NAME), persist_memorystate=True))<br>
> while api.vms.get(VM_NAME).status.state == 'image_locked':<br>
> sleep(1)<br>
><br>
> Any ideas?<br>
><br>
> Thanks<br>
><br>
> CC<br>
><br>
><br>
<br>
</div></div>The more reliable way to wait till the snapshot is effectively deleted<br>
is just to try to get it, and finish when the result is "None":<br>
<br>
snapshot.delete()<br>
<br>
while vm.snapshots.get(id=snapshot.get_id()) is not None:<br>
sleep(1)<br>
<br>
Alternatively you can use the return of the delete operation. It returns<br>
an "Action" object, that contains a reference to the job that was<br>
started to delete the snapshot. The XML representation looks like this:<br>
<br>
<action><br>
<job href="/api/jobs/f6e4279a-a8e1-44a3-86db-d53336b0eb5a"<br>
id="f6e4279a-a8e1-44a3-86db-d53336b0eb5a"/><br>
<status><br>
<state>complete</state><br>
</status><br>
</action><br>
<br>
As you can see that contains a link to the job. With the Python SDK you<br>
can use it as follows:<br>
<br>
# Get the id of the job:<br>
action = snapshot.delete()<br>
job_id = action.get_job().get_id()<br>
<br>
# Wait till the job is finished:<br>
while api.jobs.get(id=job_id).get_status().get_state() != 'FINISHED':<br>
time.sleep(1)<br>
<br>
This is less reliable, because actions may or may not return a job, and<br>
that depends on how the action is implemented in the engine, and there<br>
is no backwards compatibility guarantee for that. A minor change in the<br>
engine may result in the job not being returned.<br>
<br>
So my suggestion is to use the simple loop to check if the snapshot exists.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta<br>
3ºD, 28016 Madrid, Spain<br>
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.<br>
</font></span></blockquote></div><br></div>