Proxmox VE API
Jump to navigation
Jump to search
Using API
https://pve.proxmox.com/pve-docs/api-viewer/
Use pyproxmox
https://github.com/Daemonthread/pyproxmox/blob/master/src/pyproxmox.py
If using pip install pyproxmox you will want to replace pyproxmox.py file with latest from github. pip package has not been updated recently and has api issues with some functions.
https://raw.githubusercontent.com/Daemonthread/pyproxmox/master/src/pyproxmox.py
!/usr/bin/env python3
Simple example of some code for testing, please use valid certs or import certs
export PYTHONWARNINGS="ignore:Unverified HTTPS request"
from pyproxmox import * from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
auth = prox_auth('pve1','myuser@pve','mypassword')
px = pyproxmox(auth)
status = px.getClusterStatus()
print(status)
all_nodes = [ 'pve1', 'pve2'] src_nodes = [ 'pve1', 'pve2'] dst_node = 'pve3' move_vmname = 'vnname'
for src_node in src_nodes:
vms = px.getNodeVirtualIndex(src_node)['data']
print(src_node)
for vm in vms:
vmname = vm['name']
vmid = vm['vmid']
if vmname == move_vmname:
print(vmname)
print(vmid)
print(dst_node)
r = px.migrateVirtualMachine(src_node,vmid,dst_node)
print(r)