Smart Proxmox VE API wrapper for managing resources automatically
Project description
ProxmoxManager
Introduction
ProxmoxManager is a smart Python wrapper for Proxmox VE API. It's purpose is to allow easy automatic management for many users with many virtual machines and LCX containers. The idea is that users from external website would unknowingly be registered in Proxmox environment, which will allow them to seamlessly use virtucal machines and containers.
ProxmoxManager is based on proxmoxer library and requires it as a dependency.
Required version of Python: >=3.7
Installation
pip install proxmoxmanager
Useful info
Proxmox VE is a virtualization platfrom that supports both containers and virtual machines.
Nodes
Node is a real computer on which Proxmox runs. Proxmox can run on multiple nodes which are united into cluster.
Each node has it's own unique string ID.
Users
Proxmox VE has a complex user and permission system. There are two realms in which users are created: PAM (build-in Linux authentication, primarily used for root user) and PVE (Proxmox VE authentication).
This library only supports PVE users, because not all API features are availible for PAM users.
Usernames are unique string values in format username@pam
or username@pve
. Because this library only supports PVE realm, @pve
is appended automatically to usernames.
Users are NOT linked to specific nodes, and they can have access to any VMs/containers.
Permissions
Each user has a set of permissions, which consist of a path (e.g., /vms/100
) and a permission name (e.g. Administrator
). Each role itself contains a set of permissions.
Proxmox allows to give root permissions (with path /
) or permissions to all VMs/containers (with path like /vms
), but this library for the sake of simplicity only allows to give permissions for specific user to specific VM/container.
Virtual machines and containers
Each VM/container is located on it's own node and has a unique integer ID (100-99999999), which has to be unique for ALL the nodes.
Despite being different objects, VMs and containers cannot share the same ID.
This library allows to pass VM/container IDs both as integers and strings, but internally they are always hadnled as strings for the sake of simplicity.
Use
ProxmoxManager library features a ProxmoxManager class that contains all of the library's functionality. To start using it, you will need to generate API key with root access and full permissions.
Creating ProxmoxManager
instance:
from proxmoxmanager import ProxmoxManager
proxmox_manager = ProxmoxManager(host="example.com:8006", user="root@pam", token_name = "TOKEN_NAME", token_value = "SECRET_VALUE")
ProxmoxManager
class contains separate classes for nodes, users, virtual machines and containers, which contain methods needed for managing them.
By calling nodes
, users
, vms
or containers
field of ProxmoxManager
object you will get a collection of respective objects that behaves like a Python dict and has some additional features.
Example of usage for nodes
Listing all nodes:
proxmox_manager.nodes
Accessing specific node:
proxmox_manager.nodes["node_id"]
Randomly choosing a node (useful for distributing loads evenly):
proxmox_manager.nodes.choose_at_random()
Choose node with most free memory (in %) and get it's id:
id = proxmox_manager.nodes.choose_by_most_free_ram(absolute=False).id
Example of usage for users
Listing all users:
proxmox_manager.users
Creating new user:
proxmox_manager.users.create("username", "password")
Accessing specific user:
proxmox_manager.users["username"]
Getting auth and csrf tokens of user:
proxmox_manager.users["username"].get_tokens("password")
Changing user password:
proxmox_manager.users["username"].change_password("password", "better_new_password")
Deleting user:
proxmox_manager.users["username"].delete()
Example of usage for virtual machines (containers are almost exactly the same)
Listing all VMs:
proxmox_manager.vms
Accessing specific VM:
proxmox_manager.vms["100"]
It can also be accesed by integer ID:
proxmox_manager.vms[100]
Check if VM is a template:
proxmox_manager.vms["100"].is_template()
Start VM:
proxmox_manager.vms["100"].start()
Shutdown VM with timeout of 10 seconds after which it will be stopped by force:
proxmox_manager.vms["100"].start(timeout=10)
Add permission for user to use this VM:
proxmox_manager.vms["100"].add_permission(user="username", role="SomeRoleName")
Clone VM to the same node and choose ID that is not taken:
proxmox_manager.vms["100"].clone(newid=proxmox_manager.smallest_free_vmid())
Clone VM to node with most free memory:
proxmox_manager.vms["100"].clone(newid="101", newnode=proxmox_manager.nodes.choose_by_most_free_ram())
Delete VM:
proxmox_manager.vms["100"].delete()
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
Built Distribution
File details
Details for the file proxmoxmanager-1.0.4.tar.gz
.
File metadata
- Download URL: proxmoxmanager-1.0.4.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d041539d4d230d700b4466c1ac9ca82eecd77c90a8a371f8f3c14ae9ed5137f |
|
MD5 | 737b95a563711ad1f2bfbc1fc3e384ed |
|
BLAKE2b-256 | e27b1e9713e302b0df3221e458e5274f4b955b45b9d252cc6810e0df1841249a |
File details
Details for the file proxmoxmanager-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: proxmoxmanager-1.0.4-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 826b2aa41e1baae0e6ebb7be75d38616baacfaef241e7cad582b40f8e694b20f |
|
MD5 | dc29f64c2caf3f24f574353c6b8a2f8d |
|
BLAKE2b-256 | 8af6e99e1c8ad3eefd7ac644e1db310566309ac1fe5c289e3fbaa17e0627526c |