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 user accounts, API credentials, and SSH keys for authentication and access control.
Manage credentials for the currently authenticated user.
client.account.create_credentials()
client.account.delete_credentials(credentials)from maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
# Create new API credentials
new_creds = client.account.create_credentials()
print(f"Consumer Key: {new_creds.consumer_key}")
print(f"Token Key: {new_creds.token_key}")
print(f"Token Secret: {new_creds.token_secret}")
# Delete credentials
client.account.delete_credentials(new_creds)Manage MAAS user accounts. User objects are read-only after creation - they cannot be modified or deleted via the API.
client.users.list()
client.users.whoami()
client.users.create(**params)
User.read(username)Parameters for user creation:
username (str): Usernameemail (str): Email addresspassword (str): Passwordis_superuser (bool, optional): Grant superuser privileges (default: False)# Get current user
current_user = client.users.whoami()
print(f"Current user: {current_user.username}")
# List all users
users = client.users.list()
for user in users:
print(f"{user.username}: {user.email}")
if user.is_superuser:
print(f" Admin user")
# Create new user
new_user = client.users.create(
username='newuser',
email='newuser@example.com',
password='securepassword',
is_superuser=False
)
# Read specific user by username
from maas.client.viscera import User
user = await User.read('admin')
print(f"User: {user.username}, Email: {user.email}")User properties:
username (str, readonly): Username (primary key)email (str, readonly): Email addressis_superuser (bool, readonly): Superuser/admin statusis_local (bool, readonly): Local user vs external authenticationsshkeys_count (int, readonly): Number of SSH keys associated with userImportant notes about User objects:
save() or delete() methods available.Manage SSH public keys for user authentication.
client.ssh_keys.list()
client.ssh_keys.get(id)
SSHKey.read(id)
client.ssh_keys.create(key)
ssh_key.delete()# List SSH keys
keys = client.ssh_keys.list()
for key in keys:
print(f"Key ID: {key.id}")
print(f"Key: {key.key[:50]}...")
if key.keysource:
print(f"Source: {key.keysource}")
# Add SSH key from string
ssh_key_content = """ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC... user@host"""
new_key = await client.ssh_keys.create(key=ssh_key_content)
# Add SSH key from file
with open('/home/user/.ssh/id_rsa.pub', 'r') as f:
key_content = f.read()
new_key = await client.ssh_keys.create(key=key_content)
# Get specific key by ID
key = client.ssh_keys.get(1)
# Or use SSHKey.read()
from maas.client.viscera import SSHKey
key = await SSHKey.read(1)
# Delete SSH key
await key.delete()SSH key properties:
id (int, readonly): Unique key identifierkey (str, readonly): Full SSH public key content (includes algorithm, key data, and optional comment)keysource (str, readonly): Source of the key (e.g., 'lp:username' for Launchpad import, None for manually added)