A package to automate Proxmox VE tasks
Project description
pveautomate
Proxmox VE API
Missing a function you need?
Feel free to open a PR or Issue, but be aware API implementation has been prioritized for Alchemicode's own software that relies on this package.
Want to hire us?
If you need features in this package, or any other software/hosting/sysadmin tasks, please check out our website!
Example Usage:
Cloning a range setup for multiple users
from pveautomate.automate import ProxmoxManager
from getpass import getpass
# Create a ProxmoxManager object
pm = ProxmoxManager(
"https://proxmox.foo.bar/api2/json",
"root@pam",
getpass("Enter password: "),
"node1",
)
# Assuming these users already exist
for user in ['matt@pve', 'dave@pve', 'kris@pve']:
pm.create_range([100,101,102], user) # assuming 100,101,102 are template VMs that you want each user to have a copy of
Usage Docs:
pveautomate
pveautomate.automate
ProxmoxManager Objects
class ProxmoxManager()
__init__
def __init__(proxmox_url,
proxmox_user,
proxmox_password,
node,
verify_ssl=False)
Initialize the ProxmoxManager with the required parameters.
Arguments:
proxmox_urlstr - The URL of the Proxmox VE server.proxmox_userstr - The username to authenticate with.proxmox_passwordstr - The password to authenticate with.nodestr - The Proxmox VE node to manage.verify_sslbool - Whether to verify SSL certificates. Defaults to False.
write_vm_data
def write_vm_data()
Write VM data to a CSV file.
This method is usually internal and is used to dump data on range VMs to a CSV file.
read_vm_data
def read_vm_data()
Read VM data from a CSV file.
This method is usually internal and is used to load data on range VMs from a CSV file.
authenticate
def authenticate(username=None, password=None)
Authenticate with the Proxmox VE host and obtain a ticket and CSRF token.
This method is usually internal and is used to authorize with the PVE host.
Returns:
tuple- A tuple containing the ticket and CSRF token.
validate_creds
def validate_creds(username, password)
Validate arbitrary credentials
Returns:
bool- True if credentials were accepted, otherwise false
get_next_vm_id
def get_next_vm_id(ticket=None)
Get the next available VMID for clone/create operations.
Arguments:
ticketstr, optional - The authentication ticket.
Returns:
int- The next available VMID.
clone_vm
def clone_vm(template_id, new_name, new_id)
Clone a VM or template to a new VMID and assign a new name.
Arguments:
template_idint - The ID of the template to clone.new_namestr - The new name for the cloned VM.new_idint - The new VMID for the cloned VM.
Returns:
dict- The response data from the clone operation.
assign_admin_vm_permissions
def assign_admin_vm_permissions(vm_id, user)
Assign admin permissions to a user for a given VMID.
Arguments:
vm_idint - The ID of the VM.userstr - The user to assign admin permissions to.
set_vm_desc
def set_vm_desc(vm_id, desc)
Set the description (Notes) of a VMID.
Arguments:
vm_idint - The ID of the VM.descstr - The description to set for the VM.
destroy_vm
def destroy_vm(vmid)
Destroy a VM by its ID.
Arguments:
vmidint - The ID of the VM to destroy.
create_user
def create_user(new_username, new_password, realm, name=None)
Create a new user in the given realm
Arguments:
new_usernamestr - The username (typically short and lowercase, e.g 'john')new_passwordstr - The user's new passwordrealmstr - Which realm the user belongs to (typically 'pve' or 'pam' unless your cluster has external authentication sources configured)namestr, optional - Human-readable long name for user (e.g. 'John Doe')
set_user_group
def set_user_group(user, group)
Set the group of a user
Arguments:
userstr - The username of the user (include realm, e.g. 'john@pve')groupstr - The group to assign to the user
list_users
def list_users()
Internal method. Returns data array about active users in the cluster
check_if_user
def check_if_user(find_userid)
Check wether or not given username exists in given realm
Arguments:
find_useridstr - user id to search for (full userid, e.g. 'foo@pve')
destroy_range
def destroy_range()
Destroy all range VMs.
create_range
def create_range(ids, user)
Create cloned VMs for a given username.
Arguments:
idslist - A list of VMIDs to clone.userstr - The username to assign to the cloned VMs. Defaults to None.
apply_sdn
def apply_sdn()
Apply SDN settings to the cluster.
add_subnet_to_vnet
def add_subnet_to_vnet(vnet_id, subnet_cidr, subnet_gateway)
Add a subnet to a given VNET ID.
Arguments:
vnet_idint - The ID of the VNET.subnet_cidrstr - The CIDR notation of the subnet to add.
destroy_subnet
def destroy_subnet(vnet, subnet_cidr)
Destroy a subnet from a given VNET ID.
Arguments:
vnetint - The ID of the VNET.subnet_cidrstr - The CIDR notation of the subnet to add.
set_vm_power_status
def set_vm_power_status(vmid, state)
Set the power state of a VM
Arguments:
vmidint - The ID of the VMstatestr - The desired state of the VM. One of "start", "stop", "reset", "shutdown", "suspend", "resume", or "reboot"
set_password
def set_password(user, passw)
Set the password of a user
Arguments:
userstr - The username of the user (include realm, e.g. 'john@pve')passwstr - The new
snapshot_vm
def snapshot_vm(vmid,
snapshot_name,
description=None,
vmstate=False,
snode=None)
Create a snapshot for a given VMID.
Arguments:
vmidint - The ID of the VM.snapshot_namestr - The name of the snapshot.descriptionstr, optional - The description of the snapshot.vmstatebool, optional - Whether to save the VM state (RAM). Defaults to False.snodestr, optional - Node that the VM is on (if different than the API node)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pveautomate-0.3.2.tar.gz.
File metadata
- Download URL: pveautomate-0.3.2.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2be11cbf8c3d9b339ccc26a5662986fba67dc64eba3e4e049458629bf1734a3e
|
|
| MD5 |
6eff744c6a22f26d26b2a0cc437e7384
|
|
| BLAKE2b-256 |
87937dae685a0e5a3261d7720c85709f410636b0a664260fdb94904441429f9b
|
File details
Details for the file pveautomate-0.3.2-py3-none-any.whl.
File metadata
- Download URL: pveautomate-0.3.2-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6d98234db78ad97b4cc87e6b4edbb85a4e593c65ac81c1d08e1bf2e75e29068
|
|
| MD5 |
2402860e4e65a7425d214561d86a3b69
|
|
| BLAKE2b-256 |
aa76e37948702f07f5ebc5ba3acf07293d8a13740818881b32be7d6402ce1ad4
|