Re: [ovirt-users] Tracking asynchronous tasks results in Python SDK

2016-03-08 Thread Juan Hernández
On 03/08/2016 09:45 AM, Sandro Bonazzola wrote:
> 
> 
> On Sat, Mar 5, 2016 at 8:29 PM, James Michels
>  > wrote:
> 
> Greetings
> 
> How can I track asynchronous tasks with python sdk? For instance, I
> want to copy a disk so I use:
> 
>dcdisk = api.disks.get(id='...')
>act =
> params.Action(storage_domain=api.storagedomains.get(name='...'))
>action = dcdisk.copy(act)
> 
> I get a params.Action object. Now how can I know which ID has the
> new copied disk?
> 

In general you can track async tasks using the "job" contained in the
returned action. For example:

  action = dcdisk.copy(act)
  job = action.get_job()
  if job is not None:
job_id = job.get_id()
while True:
  job = api.jobs.get(id=job_id)
  if job is not None and job.get_status().get_state() != 'FINISHED':
break
  time.sleep(5)

However, this isn't reliable, as actions may not return jobs, that
depends on how they are implemented in the backend, and that is outside
of the control of the API. So I don't recommend this approach.

But in your particular case this won't help, as it will tell you when
the disk is created, but not what is the id of the disk. To be able to
get the id of the disk I recommend that you set an unique alias when
creating it:

  copy_alias = "copy-of-%s" % dcdisk.get_id()
  action = params.Action(
disk=params.Disk(
  alias=copy_alias,
),
...
  )
  dcdisk.copy(action)

Then, later, you can search that disk by alias:

  copy_disk = api.disks.list(query="alias=%s" % copy_alias)

A bug was opened recently related to this:

  [RFE] Add support to search VMs by disk id
  https://bugzilla.redhat.com/1315345

That bug is about searching for the VMs that have a disk attached. You
may want to open another bug requesting that the identifier of the
copied disk is returned directly by the "copy" operation.

-- 
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] Tracking asynchronous tasks results in Python SDK

2016-03-08 Thread Sandro Bonazzola
On Sat, Mar 5, 2016 at 8:29 PM, James Michels <
karma.sometimes.hu...@gmail.com> wrote:

> Greetings
>
> How can I track asynchronous tasks with python sdk? For instance, I want
> to copy a disk so I use:
>
>dcdisk = api.disks.get(id='...')
>act = params.Action(storage_domain=api.storagedomains.get(name='...'))
>action = dcdisk.copy(act)
>
> I get a params.Action object. Now how can I know which ID has the new
> copied disk?
>


Adding Juan


>
> Thank you
>
> James
>
> ___
> Users mailing list
> Users@ovirt.org
> http://lists.ovirt.org/mailman/listinfo/users
>
>


-- 
Sandro Bonazzola
Better technology. Faster innovation. Powered by community collaboration.
See how it works at redhat.com
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [ovirt-users] Tracking asynchronous tasks results in Python SDK

2016-03-07 Thread James Michels
I'm not sure if this is the right place to ask about python sdk. If not,
please suggest where should I address this question.

Thank you

2016-03-05 19:29 GMT+00:00 James Michels :

> Greetings
>
> How can I track asynchronous tasks with python sdk? For instance, I want
> to copy a disk so I use:
>
>dcdisk = api.disks.get(id='...')
>act = params.Action(storage_domain=api.storagedomains.get(name='...'))
>action = dcdisk.copy(act)
>
> I get a params.Action object. Now how can I know which ID has the new
> copied disk?
>
> Thank you
>
> James
>
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


[ovirt-users] Tracking asynchronous tasks results in Python SDK

2016-03-05 Thread James Michels
Greetings

How can I track asynchronous tasks with python sdk? For instance, I want to
copy a disk so I use:

   dcdisk = api.disks.get(id='...')
   act = params.Action(storage_domain=api.storagedomains.get(name='...'))
   action = dcdisk.copy(act)

I get a params.Action object. Now how can I know which ID has the new
copied disk?

Thank you

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