proxmox API example for dummies

P1fFpeaWf

Member
Feb 23, 2020
5
0
21
116
Hi there,

I do not have a degree in computer science nor did I developed web applications for the last 100 years.
So, let's say that proxmox's api - documentation is a quite overwhelming to me.

I found this post in this forum (how to create a lxc container with php)
https://forum.proxmox.com/threads/proxmox-php-api-create-lxc-container.39036/

But this did not helped, because I just do not know where to start.

What I was able to do, was to get some response from the node when sending a request via curl

Bash:
curl -k -d 'username=USER@pve' --data-urlencode 'password=PASSWORD' https://NODE_URL:8006/api2/json/access/ticket

I get a "TICKET"

Code:
{"data":
{
"CSRFPreventionToken":"123456:SOME_SHORT_CRYPTICSTRING",
"username":"USERNAME@pve",
"ticket":"PVE:USERNAME@pve:12345556::SOME_VERYLONG_CRYPTICSTRING",
"cap":{"sdn":{},"nodes":{},"storage":{},"dc":{},"access":{},"vms":{"VM.Monitor":1,"VM.PowerMgmt":1
}}}}

So, what now?
How can I use this to start / stop a LXC or a VM?

BTW: My weapons of choice are bash scripts.
 
Bash really isn't great for that as you will have to do a lot of json parsing and string manipulations. Would be much easier to use a scripting language like python that got build in functions to do all this stuff.
 
Since your weapon of choice is Bash, have you tried the Proxmox command line tools like qm?

I’ve been able to do everything I’ve wanted to do with Bash and qm (or a few of the other standard PVE tools).

If your goal is just starting and stopping, qm will do that perfectly.

Manual for qm:
https://pve.proxmox.com/pve-docs/qm.1.html
Yeah, qm (and pct) work fine, when I am logged into the proxmox node ( "qm start/stop 123" ).
My problem is, that I would like to start/stop VMs and LXCs from remote (local network).

hmm, a workaround would be to use
Bash:
ssh root@NODE 'qm start/stop 123'
But I (probably) would not get the current status of the VM/LXC (?).
 
Last edited:
Thanks.

After some ssh-key-coping I could run
Bash:
ssh root@NODE "pct status 123"
, which returned a (correct)
Bash:
status: stopped
.

@Dunuin : Thanks, "qm list" is quite a neat command to get a nice overview.

@moderator: Since running a the command through ssh is absolutely suitable for my needs, I consider this thread as 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!