Automated VM creation using API

K

kusman

Guest
I require a way to create new VMs (openVZ) from templates automatically using proxmox API. I looked at the openVZ section of the API and I couldn't find a possibility to create new VMs. Is this possible? If yes, what is the API call to do it?

Thanks.
 
PUSH /nodes/{node}/openvz -ostemplate <string> -vmid <integer> [OPTIONS]

Thank you very much. I have checked the api page and indeed the POST method has this, I was looking at GET options only. This is very nice.
 
You can use 'pvesh' for testing the api:

# pvesh help /nodes/localhost/openvz
help [path] [--verbose]
cd [path]
ls [path]

create /nodes/{node}/openvz -ostemplate <string> -vmid <integer> [OPTIONS]
delete /nodes/{node}/openvz/{vmid}

To create container 555 use:

# pvesh create /nodes/localhost/openvz -ostemplate local:vztmpl/debian-6.0-standard_6.0-4_i386.tar.gz -vmid 555

To list all templates on local storage:

# pvesm list local -content vztmpl
local:vztmpl/centos-5-standard_5.6-1_i386.tar.gz tgz 181390534
local:vztmpl/debian-6.0-joomla_1.6-3_i386.tar.gz tgz 182693140
local:vztmpl/debian-6.0-standard_6.0-4_i386.tar.gz tgz 143694277

And finally delete the container:

# pvesh delete /nodes/localhost/openvz/555
 
You can also run pvesh interactively:

# pvesh

and explore the API that way (cd, ls, get, help)
 
You can use 'pvesh' for testing the api:

# pvesh help /nodes/localhost/openvz
help [path] [--verbose]
cd [path]
ls [path]

create /nodes/{node}/openvz -ostemplate <string> -vmid <integer> [OPTIONS]
delete /nodes/{node}/openvz/{vmid}

To create container 555 use:

# pvesh create /nodes/localhost/openvz -ostemplate local:vztmpl/debian-6.0-standard_6.0-4_i386.tar.gz -vmid 555

To list all templates on local storage:

# pvesm list local -content vztmpl
local:vztmpl/centos-5-standard_5.6-1_i386.tar.gz tgz 181390534
local:vztmpl/debian-6.0-joomla_1.6-3_i386.tar.gz tgz 182693140
local:vztmpl/debian-6.0-standard_6.0-4_i386.tar.gz tgz 143694277

And finally delete the container:

# pvesh delete /nodes/localhost/openvz/555

Thank you, this is extremely helpful. I have reviewed the POST api a bit more with pvesh as well and it seems to be full featured and a lot is possible.

Your support is also top notch, thank you for helping.
 

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!