[PVE-User] Proxmox API catch response

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Feb 5 17:01:29 CET 2016



On 02/05/2016 04:46 PM, Mohamed Sadok Ben Jazia wrote:
> I think those last lines are good for my work
>> do {
>>     sleep (1)
>>     task = APICALL(get 
>> nodes/nina/tasks/UPID:nina:00007F77:0029667A:56B36272:vncproxy:104:tom at pam:/status)
>> } while (task->{status} != 'stopped')
>>
>>
> Do you think proxmox server can support a lot of pings each a short 
> period of time?

Proxmox normally for sure, your network on the other side may be less 
(latency wise).

As "worker" normally will be used for longer running tasks (a few 
seconds to a few minutes, depends on the action and hardware) i think 
polling once per second should be fast enough enough, and that is surely 
hand-able by PVE.



> On 5 February 2016 at 15:34, Thomas Lamprecht <t.lamprecht at proxmox.com 
> <mailto:t.lamprecht at proxmox.com>> wrote:
>
>     If it's a call where a worker gets forked we have an UPID which
>     represents this action and we have a UPID wait function where you
>     can wait for this task to finish.
>
>     If you're making perl scripts on a PVE host it'd be really easy:
>
>>
>>         use PVE::API2::Qemu;
>>         use PVE::ProcFSTools;
>>
>>         my $params = {
>>         node => $nodename,
>>         vmid => $id,
>>         timeout => $shutdown_timeout,
>>         forceStop => 1,
>>         };
>>
>>         my $upid = PVE::API2::Qemu->vm_shutdown($params);
>>         PVE::ProcFSTools::upid_wait($upid);
>>
>>         # more code here
>
>     But I'm simply guessing you do something else than perl.
>
>     But you get the UPID also when making API calls in another way
>     (through REST calls, e.g.) so you could check on that task.
>     You will almost always need a loop with waits somewhere but you
>     can make one function like upid_wait and use that everywhere.
>
>     To see how the UPID is calculated look at:
>     https://git.proxmox.com/?p=pve-common.git;a=blob;f=src/PVE/Tools.pm;h=9f08aa6fbf0c08da62e2f17078684cc2136d5b14;hb=HEAD#l854
>
>     For an upid_wait function implementation see;
>     https://git.proxmox.com/?p=pve-common.git;a=blob;f=src/PVE/ProcFSTools.pm;h=516c0e8b939791a64771df41c36df362e65c7423;hb=HEAD#l355
>
>     ===== more easier approach ======
>
>     A bit complicated maybe, also polling the task (which is also
>     defined by the UPID) until it has "stopped" as status would be ok:
>
>     Something like (using pseudo code):
>
>
>>     do {
>>         sleep (1)
>>         task = APICALL(get
>>     nodes/nina/tasks/UPID:nina:00007F77:0029667A:56B36272:vncproxy:104:tom at pam:/status)
>>     } while (task->{status} != 'stopped')
>
>
>
>     On 02/05/2016 02:09 PM, Mohamed Sadok Ben Jazia wrote:
>>     Hello list,
>>     i'm using proxmox api to create Containers and managing ressources.
>>     proxmox commands don't have a fixed duration so you need to
>>     refresh calls to see that an action is correctly done..
>>     Are there a method to catch the end of an action when using API
>>     calls?
>>
>>
>>     _______________________________________________
>>     pve-user mailing list
>>     pve-user at pve.proxmox.com <mailto:pve-user at pve.proxmox.com>
>>     http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user
>
>
>     _______________________________________________
>     pve-user mailing list
>     pve-user at pve.proxmox.com <mailto:pve-user at pve.proxmox.com>
>     http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user
>
>
>
>
> _______________________________________________
> pve-user mailing list
> pve-user at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.proxmox.com/pipermail/pve-user/attachments/20160205/f547ae2f/attachment.htm>


More information about the pve-user mailing list