Waiting for a container to be created to start it

Thomesc

New Member
Jul 26, 2016
13
0
1
27
Hi there,
I'm currently trying to create a web interface with my proxmox server with this API : https://github.com/CpuID/pve2-api-php-client, this interface is to create and configure openvz containers automaticly,
I already managed to create and start containers with the API, but I would like to make it automatic that's why I need to know when the containers is done being created so I can launch the start command.
Is there a way to catch datas such as the TASK OK we can see in the proxmox interface ?

I hope this is the right place to post and I thank you in advance for your answers.
 
you are probably looking for either

Code:
GET /api2/json/nodes/{node}/tasks/{upid}/status

or

Code:
GET /api2/json/nodes/{node}/tasks/{upid}/log

where upid is the task ID.
 
I was using GET /api2/json/nodes/{node}/tasks/{upid}/status to try to get some infos but the status is always the same during and after the creation,
I'm going to try with GET /api2/json/nodes/{node}/tasks/{upid}/log but I can't figure out what upid is, where can I found it for the create task ?
 
the UPID is contained in the response for the API call that starts the worker (i.e., the POST to "/api2/json/nodes/{node}/lxc") (vzcreate works the same, it's the same API call ;))

for example:
Code:
{"data":"UPID:myhost:00004D26:00044B89:57986E1F:vzrestore:50001:root@pam:","success":1}

then you can query the status with "GET /nodes/myhost/tasks/UPID:myhost:00004D26:00044B89:57986E1F:vzrestore:50001:root@pam:/status":
Code:
{
   "id" : "50001",
   "node" : "myhost",
   "pid" : 19750,
   "pstart" : 281481,
   "starttime" : 1469607455,
   "status" : "running",
   "type" : "vzrestore",
   "upid" : "UPID:myhost:00004D26:00044B89:57986E1F:vzrestore:50001:root@pam:",
   "user" : "root@pam"
}

as you can see the status is "running", so the task worker has not finished yet. after waiting a little longer, the same request returns different output:

Code:
{
   "exitstatus" : "OK",
   "id" : "50001",
   "node" : "myhost",
   "pid" : 19750,
   "pstart" : 281481,
   "starttime" : 1469607455,
   "status" : "stopped",
   "type" : "vzrestore",
   "upid" : "UPID:myhost:00004D26:00044B89:57986E1F:vzrestore:50001:root@pam:",
   "user" : "root@pam"
}

note the "exitstatus" and "status" elements.

this works for all the API calls that spawn a worker to do the actual long running task.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!