Skip to main content

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 softwware that relies on this package.

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_url str - The URL of the Proxmox VE server.
  • proxmox_user str - The username to authenticate with.
  • proxmox_password str - The password to authenticate with.
  • node str - The Proxmox VE node to manage.
  • verify_ssl bool - 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()

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.

get_next_vm_id

def get_next_vm_id(ticket=None)

Get the next available VMID for clone/create operations.

Arguments:

  • ticket str, 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_id int - The ID of the template to clone.
  • new_name str - The new name for the cloned VM.
  • new_id int - 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_id int - The ID of the VM.
  • user str - 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_id int - The ID of the VM.
  • desc str - The description to set for the VM.

destroy_vm

def destroy_vm(vmid)

Destroy a VM by its ID.

Arguments:

  • vmid int - 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_username str - The username (typically short and lowercase, e.g 'john')
  • new_password str - The user's new password
  • realm str - Which realm the user belongs to (typically 'pve' or 'pam' unless your cluster has external authentication sources configured)
  • name str, optional - Human-readable long name for user (e.g. 'John Doe')

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_userid str - 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:

  • ids list - A list of VMIDs to clone.
  • user str - 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_id int - The ID of the VNET.
  • subnet_cidr str - 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:

  • vnet int - The ID of the VNET.
  • subnet_cidr str - The CIDR notation of the subnet to add.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pveautomate-0.2.4.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pveautomate-0.2.4-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file pveautomate-0.2.4.tar.gz.

File metadata

  • Download URL: pveautomate-0.2.4.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for pveautomate-0.2.4.tar.gz
Algorithm Hash digest
SHA256 bf61f15469dc4be6c49b70785b533732ea8f33c684e3896381580c93f6af2436
MD5 d0f3a8186431e0bd080da7bdbe1841c8
BLAKE2b-256 b07bc6e742ecc8f101dfee937aaff934f80960be3e772a4bcfe71f195dcf3f3a

See more details on using hashes here.

File details

Details for the file pveautomate-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: pveautomate-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for pveautomate-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 11c88a3cf68b4fb030967c79dfb503b0c4dcd10923804ecb0fae1f03826d7eb7
MD5 116f9d9cceb5a26032dc4abbe1a8d0e5
BLAKE2b-256 26609d14bac1f61351a2b7c07dca6906c27ba1c1a28006b308adfc36852fc08a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page