or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/python-libmaas@0.6.x

docs

index.md
tile.json

tessl/pypi-python-libmaas

tessl install tessl/pypi-python-libmaas@0.6.0

Python client library for MAAS 2.0+ with sync/async support, providing machine provisioning, network management, and storage configuration.

users.mddocs/reference/

Account and User Management

Manage user accounts, API credentials, and SSH keys for authentication and access control.

Capabilities

Current Account

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)

User Management

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): Username
  • email (str): Email address
  • password (str): Password
  • is_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 address
  • is_superuser (bool, readonly): Superuser/admin status
  • is_local (bool, readonly): Local user vs external authentication
  • sshkeys_count (int, readonly): Number of SSH keys associated with user

Important notes about User objects:

  • User objects are read-only after creation. There are no save() or delete() methods available.
  • Users can only be created via the API, not modified or deleted.
  • To manage a user's SSH keys, use the SSH Keys API (see below).
  • The relationship between Users and SSH keys is one-to-many: one user can have multiple SSH keys.

SSH Key Management

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 identifier
  • key (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)