Re: [ovirt-users] Python API question

2016-01-16 Thread Karli Sjöberg
Noticed that the code I wrote turned out a little wonky with a really misplaced 
"while" after the "snap" variable but I hope you understand what I was trying 
to get at.


#copy-paste fail :)


/K



Från: users-boun...@ovirt.org  för Karli Sjöberg 

Skickat: den 16 januari 2016 10:13
Till: Colin Coe; Juan Hernández
Kopia: Users@ovirt.org
Ämne: Re: [ovirt-users] Python API question



Hi Colin,


I´ve also noticed that behaviour, you need to redefine the variable in the loop 
as well, seems that "snap == 'locked'" forever otherwise:


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()
   snap = api.vms.get(name=VM_NAME).snapshots.list()[-1] while 
(snap.get_snapshot_status() == 'locked'):
   time.sleep(1)

/K


Från: users-boun...@ovirt.org  för Colin Coe 

Skickat: den 16 januari 2016 06:07
Till: Juan Hernández
Kopia: Users@ovirt.org
Ämne: Re: [ovirt-users] Python API question

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 
mailto:jhern...@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:

  


  complete

  

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.
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [ovirt-users] Python API question

2016-01-16 Thread Karli Sjöberg

Hi Colin,


I´ve also noticed that behaviour, you need to redefine the variable in the loop 
as well, seems that "snap == 'locked'" forever otherwise:


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()
   snap = api.vms.get(name=VM_NAME).snapshots.list()[-1] while 
(snap.get_snapshot_status() == 'locked'):
   time.sleep(1)

/K


Från: users-boun...@ovirt.org  för Colin Coe 

Skickat: den 16 januari 2016 06:07
Till: Juan Hernández
Kopia: Users@ovirt.org
Ämne: Re: [ovirt-users] Python API question

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 
mailto:jhern...@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:

  


  complete

  

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.
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [ovirt-users] Python API question

2016-01-15 Thread Colin Coe
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  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:
>
>   
>  id="f6e4279a-a8e1-44a3-86db-d53336b0eb5a"/>
> 
>   complete
> 
>   
>
> 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.
>
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [ovirt-users] Python API question

2016-01-15 Thread Juan Hernández
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:

  


  complete

  

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.
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [ovirt-users] Python API question

2016-01-14 Thread Karli Sjöberg
fre 2016-01-15 klockan 12:23 +0800 skrev Colin Coe:
> 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?

We take a snapshot just after a VM creation, just to have a point of
origin to roll back to in case of total f-up:) Looks like this:

while api.vms.get(VM_NAME).snapshots.list()[1].get_snapshot_status() ==
'locked':

In our case, we only have one snapshot at that time though, since the VM
has just been created. Your code would have to be more complex to find
the most recent one, I´d think.

HTH

/K
> 
> 
> Thanks
> 
> 
> CC
> ___
> Users mailing list
> Users@ovirt.org
> http://lists.ovirt.org/mailman/listinfo/users

___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


[ovirt-users] Python API question

2016-01-14 Thread Colin Coe
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
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users