tessl install tessl/pypi-python-libmaas@0.6.0Python client library for MAAS 2.0+ with sync/async support, providing machine provisioning, network management, and storage configuration.
Manage virtual machine hosts (KVM, LXD) and compose virtual machines dynamically for flexible resource allocation.
client.pods.list()from maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
# List all pods
pods = client.pods.list()
for pod in pods:
print(f"Pod: {pod.name}, Type: {pod.type}")client.pods.get(id)# Get specific pod
pod = client.pods.get(1)
print(f"Available cores: {pod.available.cores}")
print(f"Available memory: {pod.available.memory} MB")Register KVM or LXD hosts as pods.
client.pods.create(**params)Parameters:
type (str): Pod type ('virsh' for KVM, 'lxd' for LXD)power_address (str): Connection addresspower_user (str, optional): Username for connectionpower_pass (str, optional): Password for connectionname (str, optional): Pod namezone (str, optional): Availability zonepool (str, optional): Resource pooltags (list, optional): Tags to apply# Create KVM pod
pod = client.pods.create(
type='virsh',
power_address='qemu+ssh://user@192.168.1.10/system',
name='kvm-host-1',
zone='default'
)
# Create LXD pod
pod = client.pods.create(
type='lxd',
power_address='https://192.168.1.20:8443',
power_user='admin',
power_pass='password',
name='lxd-host-1'
)id (int): Pod IDname (str): Pod nametype (str): Pod type (virsh, lxd, rsd)architectures (list): Supported architecturescapabilities (list): Pod capabilitieszone (Zone): Availability zonetags (list): Applied tagscpu_over_commit_ratio (float): CPU overcommit ratiomemory_over_commit_ratio (float): Memory overcommit ratiodefault_macvlan_mode (str): Default macvlan modehost (Node): Host node if pod is managed by MAASavailable (dict): Available resources with structure:
cores (int): Available CPU coresmemory (int): Available memory in MBlocal_storage (int): Available local storage in bytesused (dict): Used resources with same structure as availabletotal (dict): Total resources with same structure as availableDynamically create virtual machines from pod resources with specified constraints.
pod.compose(
cores=None,
memory=None,
cpu_speed=None,
architecture=None,
storage=None,
hostname=None,
domain=None,
zone=None,
interfaces=None
)Parameters:
cores (int, optional): Minimum number of CPU coresmemory (int, optional): Minimum amount of memory in MiBcpu_speed (int, optional): Minimum CPU speed in MHzarchitecture (str, optional): Architecture (must be supported by pod)storage (str or list, optional): Storage constraint identifiers in format <label>:<size>(<tag>[,<tag>])[,<label>:...]hostname (str, optional): Hostname for the composed machinedomain (int or str, optional): Domain ID or name for the machinezone (int, str, or Zone, optional): Zone ID, name, or Zone objectinterfaces (str or list, optional): Labeled constraint map for interface matching in format <label>:<key>=<value>[,<key2>=<value2>]Interface Constraint Keys:
id: Match interface with specific IDfabric: Match interface on specified fabricfabric_class: Match interface on fabric with specified classip: Match interface with specified IP addressmode: Match interface with specified mode (e.g., "unconfigured")name: Match interface name (e.g., "eth0")hostname: Match interface on node with specified hostnamesubnet: Match interface on specified subnetspace: Match interface in specified spacesubnet_cidr: Match interface on subnet CIDR (e.g., "192.168.0.0/24")type: Match interface type ("physical", "vlan", "bond", "bridge", "unknown")vlan: Match interface on specified VLANvid: Match interface on VLAN with specified VIDtag: Match interface tagged with specified tagReturns: Machine object
from maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
# Get a pod
pod = client.pods.get(1)
# Simple composition with basic constraints
machine = pod.compose(
cores=4,
memory=8192, # 8GB in MiB
hostname='vm-web-01'
)
# Advanced composition with storage and network constraints
machine = pod.compose(
cores=8,
memory=16384,
cpu_speed=2000,
architecture='amd64/generic',
storage=['root:50(ssd)', 'data:100(hdd)'],
hostname='vm-db-01',
zone='production',
interfaces=['eth0:space=dmz,ip=10.0.1.50']
)
print(f"Composed machine: {machine.hostname} ({machine.system_id})")Retrieve power parameters for a pod.
pod.parameters()# Get power parameters
params = pod.parameters()
print(f"Power parameters: {params}")pod.save()
pod.refresh()
pod.delete()# Update pod tags
pod.tags = ['production', 'kvm']
pod.save()
# Update overcommit ratios
pod.cpu_over_commit_ratio = 2.0
pod.memory_over_commit_ratio = 1.5
pod.save()
# Refresh pod data to get latest resource usage
pod.refresh()
# Delete pod
pod.delete()class Pod:
"""A pod (VM host) in MAAS."""
id: int
type: str
name: str
architectures: list
capabilities: list
zone: Zone
tags: list
cpu_over_commit_ratio: float
memory_over_commit_ratio: float
available: dict
used: dict
total: dict
default_macvlan_mode: str
host: Node
def save(self) -> None: ...
def refresh(self) -> dict: ...
def parameters(self) -> dict: ...
def compose(self, **kwargs) -> Machine: ...
def delete(self) -> None: ...