Bug in the API trying to start a non-existent container

lince

Member
Apr 10, 2015
78
3
8
Hello,

I think I found a bug in the API. When you call the start command in a container that doesn't exist, it returns "200 OK" and I guess it should return "500".

As you can see below, trying to stop the container return 500 but trying to start it, returns 200. The container with id 175 does not exist.

Here is the result:

# curl -s -D/dev/stderr -k -H "`cat csrf`" -b "`cat proxmox.cookie`" -X POST "" "https://192.168.1.73:8006/api2/json/nodes/pve3/lxc/175/status/stop"

HTTP/1.1 500 CT 175 not running
Cache-Control: max-age=0
Connection: close
Date: Fri, 15 Jul 2016 14:17:22 GMT
Pragma: no-cache
Server: pve-api-daemon/3.0
Content-Length: 13
Content-Type: application/json;charset=UTF-8
Expires: Fri, 15 Jul 2016 14:17:22 GMT

{"data":null}

# curl -s -D/dev/stderr -k -H "`cat csrf`" -b "`cat proxmox.cookie`" -X POST "" "https://192.168.1.73:8006/api2/json/nodes/pve3/lxc/175/status/start"

HTTP/1.1 200 OK
Cache-Control: max-age=0
Connection: close
Connection: Keep-Alive
Date: Fri, 15 Jul 2016 14:17:26 GMT
Pragma: no-cache
Server: pve-api-daemon/3.0
Content-Length: 69
Content-Type: application/json;charset=UTF-8
Expires: Fri, 15 Jul 2016 14:17:26 GMT

{"data":"UPID:pve3:00001BDF:12E2E825:5788F076:vzstart:175:root@pam:"}
 
The reason for this is the asynchronous nature of these tasks: To start the container we need to lock and read the config, since this can be more expensive (in clusters) than querying the list of currently running containers it is done in a background task and the status & error can be read via /api2/json/nodes/$NODE/tasks/$UPID/status
 

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!