Creating templates in a blocking fashion from Python SDK

Hi there, I use the following Python SDK snippet to create a template from an existing VM: templ = ovirt.templates.add( ovirtsdk.xml.Template(vm=vm, name=vm.name) ) This seems to launch a template creation task in a non-blocking manner, which makes the next command I run, which tries to delete the VM, fail because the VM is still locked by the template creation task. Is there a way to block on the template creation task and not return to the code until it finishes? Thanks, -- Barak Korren bkorren@redhat.com RHEV-CI Team

On Sun, Apr 10, 2016 at 10:43 AM, Barak Korren <bkorren@redhat.com> wrote:
Hi there, I use the following Python SDK snippet to create a template from an existing VM:
templ = ovirt.templates.add( ovirtsdk.xml.Template(vm=vm, name=vm.name) )
This seems to launch a template creation task in a non-blocking manner, which makes the next command I run, which tries to delete the VM, fail because the VM is still locked by the template creation task.
Is there a way to block on the template creation task and not return to the code until it finishes?
I don't think so, but you can loop waiting, see e.g.: http://www.ovirt.org/develop/api/pythonapi/#create-a-template-from-vm -- Didi

On Sun, Apr 10, 2016 at 11:02 AM, Yedidyah Bar David <didi@redhat.com> wrote:
On Sun, Apr 10, 2016 at 10:43 AM, Barak Korren <bkorren@redhat.com> wrote:
Hi there, I use the following Python SDK snippet to create a template from an existing VM:
templ = ovirt.templates.add( ovirtsdk.xml.Template(vm=vm, name=vm.name) )
This seems to launch a template creation task in a non-blocking manner, which makes the next command I run, which tries to delete the VM, fail because the VM is still locked by the template creation task.
Is there a way to block on the template creation task and not return to the code until it finishes?
I don't think so, but you can loop waiting, see e.g.:
http://www.ovirt.org/develop/api/pythonapi/#create-a-template-from-vm
I wish we could have an extra parameters on the Python SDK that would do this exact loop for us, since essentially most use cases require this. I'm not sure it is relevant only for template creation, btw. What is also more annoying, is that this loop (IIRC) will never break, if something bad happens and the template ends up in a state != down (such as locked). (Same issue I've just had with host installation - Iv'e waited endlessly for it to be in 'up' state, only to find out it ended in 'installed_failed' state). Y.
-- Didi _______________________________________________ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users

On Sun, Apr 10, 2016 at 1:16 PM, Yaniv Kaul <ykaul@redhat.com> wrote:
On Sun, Apr 10, 2016 at 11:02 AM, Yedidyah Bar David <didi@redhat.com> wrote:
On Sun, Apr 10, 2016 at 10:43 AM, Barak Korren <bkorren@redhat.com> wrote:
Hi there, I use the following Python SDK snippet to create a template from an existing VM:
templ = ovirt.templates.add( ovirtsdk.xml.Template(vm=vm, name=vm.name) )
This seems to launch a template creation task in a non-blocking manner, which makes the next command I run, which tries to delete the VM, fail because the VM is still locked by the template creation task.
Is there a way to block on the template creation task and not return to the code until it finishes?
I don't think so, but you can loop waiting, see e.g.:
http://www.ovirt.org/develop/api/pythonapi/#create-a-template-from-vm
I wish we could have an extra parameters on the Python SDK that would do this exact loop for us, since essentially most use cases require this. I'm not sure it is relevant only for template creation, btw. What is also more annoying, is that this loop (IIRC) will never break, if something bad happens and the template ends up in a state != down (such as locked). (Same issue I've just had with host installation - Iv'e waited endlessly for it to be in 'up' state, only to find out it ended in 'installed_failed' state).
What we need is way to wait for events. For example, perform a request that never completes, sending events as json/xml fragments and chunked encoding. Here is an example: https://dev.twitter.com/streaming/overview Nir

El 2016-04-10 11:16, Yaniv Kaul escribió:
On Sun, Apr 10, 2016 at 11:02 AM, Yedidyah Bar David <didi@redhat.com> wrote:
Hi there, I use the following Python SDK snippet to create a template from an existing VM:
templ = ovirt.templates.add( ovirtsdk.xml.Template(vm=vm, name=vm.name [1]) )
This seems to launch a template creation task in a non-blocking manner, which makes the next command I run, which tries to delete
On Sun, Apr 10, 2016 at 10:43 AM, Barak Korren <bkorren@redhat.com> wrote: the
VM, fail because the VM is still locked by the template creation task.
Is there a way to block on the template creation task and not return to the code until it finishes?
I don't think so, but you can loop waiting, see e.g.:
http://www.ovirt.org/develop/api/pythonapi/#create-a-template-from-vm
[2]
I wish we could have an extra parameters on the Python SDK that would do this exact loop for us, since essentially most use cases require this. I'm not sure it is relevant only for template creation, btw. What is also more annoying, is that this loop (IIRC) will never break, if something bad happens and the template ends up in a state != down (such as locked). (Same issue I've just had with host installation - Iv'e waited endlessly for it to be in 'up' state, only to find out it ended in 'installed_failed' state). Y.
I have had some issues related to this, I've opened a couple of BZs (for different issues, though): https://bugzilla.redhat.com/show_bug.cgi?id=1245630 https://bugzilla.redhat.com/show_bug.cgi?id=1315874 Currently the "poorman's wait method" that I detailed on the second BZ is the method I'm following to check whether state is "Ok". Regards.
-- Didi
_______________________________________________ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users [3]
Links: ------ [1] http://vm.name [2] http://www.ovirt.org/develop/api/pythonapi/#create-a-template-from-vm [3] http://lists.ovirt.org/mailman/listinfo/users
_______________________________________________ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users

Is there a way to block on the template creation task and not return to the code until it finishes?
I don't think so, but you can loop waiting, see e.g.:
http://www.ovirt.org/develop/api/pythonapi/#create-a-template-from-vm [2]
I wish we could have an extra parameters on the Python SDK that would do this exact loop for us, since essentially most use cases require this.
I see most SDK action-creating methods have an optional "correlation_id" string argument, could that be used to somehow track the task and figure out when it is done? -- Barak Korren bkorren@redhat.com RHEV-CI Team

On 04/10/2016 12:16 PM, Yaniv Kaul wrote:
On Sun, Apr 10, 2016 at 11:02 AM, Yedidyah Bar David <didi@redhat.com <mailto:didi@redhat.com>> wrote:
On Sun, Apr 10, 2016 at 10:43 AM, Barak Korren <bkorren@redhat.com <mailto:bkorren@redhat.com>> wrote: > Hi there, I use the following Python SDK snippet to create a template > from an existing VM: > > templ = ovirt.templates.add( > ovirtsdk.xml.Template(vm=vm, name=vm.name <http://vm.name>) > ) > > This seems to launch a template creation task in a non-blocking > manner, which makes the next command I run, which tries to delete the > VM, fail because the VM is still locked by the template creation task. > > Is there a way to block on the template creation task and not return > to the code until it finishes?
I don't think so, but you can loop waiting, see e.g.:
http://www.ovirt.org/develop/api/pythonapi/#create-a-template-from-vm
I wish we could have an extra parameters on the Python SDK that would do this exact loop for us, since essentially most use cases require this. I'm not sure it is relevant only for template creation, btw. What is also more annoying, is that this loop (IIRC) will never break, if something bad happens and the template ends up in a state != down (such as locked). (Same issue I've just had with host installation - Iv'e waited endlessly for it to be in 'up' state, only to find out it ended in 'installed_failed' state). Y.
The API already has mechanisms to run operations in a synchronous fashion, and they caused more problems than they solved. For example, all actions have an "async" parameter, that indicates, when the values is "false", if the API should wait for all the reported backend activities to finish. The problem is that the meaning of "reported backend activities" may be different from what you expect: some backend activities aren't reported, see bug 1199011. In addition the backend doesn't have any commitment to keep reporting activities in a backwards compatible fashion. What is reported in version 3.5 may not be reported in version 3.6. So the only reliable mechanism to wait for activities to finish is to check them explicitly, looping and checking the status. This is the only mechanism that we can support and recommend. -- 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.
participants (6)
-
Barak Korren
-
Juan Hernández
-
nicolas@devels.es
-
Nir Soffer
-
Yaniv Kaul
-
Yedidyah Bar David