Difference between revisions of "Proxmox VE API"
Line 1: | Line 1: | ||
+ | # Use Command line | ||
+ | |||
+ | ``` | ||
+ | #!/usr/bin/env bash | ||
+ | |||
+ | for vmid in $(qm list | grep -v VMID | awk '{print $1}'); do | ||
+ | echo $vmid | ||
+ | pvesh create /nodes/pve1/qemu/$vmid/migrate --target pve2 --online | ||
+ | done | ||
+ | ``` | ||
+ | |||
# Using API | # Using API | ||
Latest revision as of 05:24, 21 July 2019
Use Command line
#!/usr/bin/env bash for vmid in $(qm list | grep -v VMID | awk '{print $1}'); do echo $vmid pvesh create /nodes/pve1/qemu/$vmid/migrate --target pve2 --online done
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 and fix print statements without "()".
pip package appears to have 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)