[SOLVED] Proxmox API POST /api2/json/nodes/{node}/execute

snowpoke

Renowned Member
Nov 15, 2014
13
0
66
Hello, I searched everywhere, even in github search in all repos for samples but I can't find example how to use /api2/json/nodes/{node}/execute.
I'm using API with this simple and easy PHP class: https://github.com/CpuID/pve2-api-php-client. So far every command works OK but not this one in subject.

At http://pve.proxmox.com/pve2-api-doc/ there is required parameter "commands", I'm providing there json encoded array for example:

$params = array(
"commands" =>
json_encode(array(
"/nodes/node1/openvz/101/status/stop",
"/nodes/node1/openvz/101/status/start"
)));

But I get errors:
/nodes/node1/openvz/101/status/stop is not a valid command at /usr/share/perl5/PVE/API2/Nodes.pm line 389
/nodes/node1/openvz/101/status/start is not a valid command at /usr/share/perl5/PVE/API2/Nodes.pm line 389

What should I enter in commands array? Documentation doesn't have any POST examples.
 
Last edited:
Thx for reply :)
I know how to use one command, but I need to execute few in queue. I need this to:
- turn off CT
- unmount
- destroy CT
- create CT

Execute sounds good because then I don't need to check task status after each command, which is more effective, faster and there is less error possibility.
 
Thx for reply :)
I know how to use one command, but I need to execute few in queue. I need this to:
- turn off CT
- unmount
- destroy CT
- create CT

Execute sounds good because then I don't need to check task status after each command, which is more effective, faster and there is less error possibility.
You don't have to check each return value, but the status needed to make sure the FINAL result.
For example: you need to check if the VM stopped successfully after STOP command, otherwise CREATE command will be fail (because VM ID already exist).
 
I don't see your point. Each step must success to make next. To make clean CT you must stop it, then make sure it's unmounted, destroy works only when container is unmounted.
If i think correctly, execute API will make each step for me without worrying about them, I just need to wait and check when it's done.
 
In real world, things not always running fine.

For example. When you execute STOP command, sometime the result is not Success, then your next DESTROY command will not success too (because you can not delete a running VM). That is why Proxmox API give us a return value for each command.

Another example: using API you REMOVE VM 100, but before its finished another API run to REMOVE VM 101. If the REMOVE process of VM 100 taking longer time that VM 101 will get Timeout error (mean REMOVE VM 101 command fail) . It is our script responsibility to check each return value of Proxmox API.
 
Ok, I understand now. I changed my code to wait few seconds after command and check status of VPS. Now I think that execute API is not reliable, and step by step and checking status is better :)
Thanks for valuable lesson :) Now I can change this thread to [SOLVED].
 

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!