Install & Compatibility
Where this runs
tested against v0.6.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 54.6MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 7.4s · import 0.000s · 60MB
58MB installed
● package 58MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MaasClient
✓ import maas
✗ from maas import MaasClient
Demonstrates connecting to a MAAS server using an API key and listing available machines. Uses environment variables for sensitive connection details and provides basic error handling.
import os
from maas.client import MaasClient
from maas.client.enum import LinkMode # Example: for network configuration
# Configure MAAS connection from environment variables or provide directly
MAAS_URL = os.environ.get("MAAS_URL", "https://your.maas.server:5240/MAAS")
MAAS_API_KEY = os.environ.get("MAAS_API_KEY", "your-maas-api-key")
if "your-maas-api-key" in MAAS_API_KEY:
print("Warning: Please set the MAAS_API_KEY environment variable or replace 'your-maas-api-key'.")
if "your.maas.server" in MAAS_URL:
print("Warning: Please set the MAAS_URL environment variable or replace 'your.maas.server'.")
try:
# Initialize the client
client = MaasClient(MAAS_URL, api_key=MAAS_API_KEY)
# Connect to the MAAS API
maas = client.connect()
# Example: List all machines
print("Fetching machines...")
machines = maas.machines.list()
if machines:
print(f"Found {len(machines)} machines:")
for machine in machines[:3]: # Print details for up to 3 machines
print(f" - Hostname: {machine.hostname}, Status: {machine.status}, ID: {machine.system_id}")
if machine.ip_addresses:
print(f" IPs: {[ip.ip for ip in machine.ip_addresses]}")
else:
print(" No IP addresses found.")
else:
print("No machines found in MAAS.")
# Example: Get a specific machine (uncomment and replace with a known system_id)
# machine_id = "your_machine_system_id"
# if machine_id != "your_machine_system_id":
# try:
# specific_machine = maas.machines.get(system_id=machine_id)
# print(f"\nDetails for machine {machine_id}: {specific_machine.hostname}, {specific_machine.status}")
# except Exception as e:
# print(f"\nCould not fetch machine {machine_id}: {e}")
except Exception as e:
print(f"An error occurred: {e}")
Upgrade
Version history
0.6.8latest on PyPI · released Aug 17, 2022
Audit
Dependencies
requestsrequiredHTTP client for API communication.
PyYAMLrequiredUsed for configuration parsing and data serialization (e.g., cloud-init user data).