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.

cli.mddocs/reference/

CLI Tool

Command-line interface for managing MAAS servers from the terminal. The maas command provides comprehensive access to MAAS functionality through subcommands.

Installation

The CLI is installed as part of the python-libmaas package:

pip install python-libmaas

This provides the maas command-line tool.

Basic Usage

# General syntax
maas [--help] <profile> <command> [options]

Profile Management

Login

Create a new profile and authenticate:

maas login <profile-name> <url> [apikey]

Examples:

# Login with interactive prompts
maas login myprofile http://maas.example.com:5240/MAAS/

# Login with API key
maas login myprofile http://maas.example.com:5240/MAAS/ consumer:token:secret

Logout

Remove a profile:

maas logout <profile-name>

List Profiles

maas profiles list

Switch Profile

maas profiles switch <profile-name>

Show Profile

maas profiles show <profile-name>

Machine Commands

List Machines

maas <profile> machines list

Show Machine Details

maas <profile> machine <system-id>

Allocate Machine

maas <profile> machine allocate [options]

Options:

  • --hostname: Specific hostname
  • --architecture: Architecture constraint
  • --cpu-count: Minimum CPU count
  • --mem: Minimum memory in MB
  • --tags: Required tags
  • --zone: Availability zone

Example:

maas prod machine allocate --cpu-count 4 --mem 8192 --tags ssd

Deploy Machine

maas <profile> machine deploy <system-id> [options]

Options:

  • --distro-series: OS release (e.g., 'focal', 'jammy')
  • --hwe-kernel: Hardware enablement kernel

Example:

maas prod machine deploy abc123 --distro-series jammy

Release Machine

maas <profile> machine release <system-id> [options]

Options:

  • --comment: Release comment
  • --erase: Securely erase disks

Power Control

# Power on
maas <profile> machine power-on <system-id>

# Power off
maas <profile> machine power-off <system-id> [--stop-mode soft|hard]

# Reboot
maas <profile> machine reboot <system-id>

Lock/Unlock

# Lock machine
maas <profile> machine lock <system-id> [--comment "text"]

# Unlock machine
maas <profile> machine unlock <system-id>

Node Commands

List All Nodes

maas <profile> nodes list

Device Commands

List Devices

maas <profile> devices list

Controller Commands

List Controllers

maas <profile> controllers list

List Rack Controllers

maas <profile> rack-controllers list

List Region Controllers

maas <profile> region-controllers list

Network Commands

List Fabrics

maas <profile> fabrics list

List VLANs

maas <profile> vlans list

List Subnets

maas <profile> subnets list

List Spaces

maas <profile> spaces list

Other Commands

List Tags

maas <profile> tags list

List Files

maas <profile> files list

List Users

maas <profile> users list

Interactive Shell

Start an interactive Python shell with MAAS API access:

maas <profile> shell

This opens a Python REPL with pre-configured access to the MAAS API:

# Inside the shell
>>> machines = client.machines.list()
>>> for m in machines:
...     print(m.hostname)

Output Formats

Commands output data in various formats:

  • Tables for list commands
  • JSON for detailed information (use --format json where available)
  • Text for status messages

Common Options

Most commands support:

  • --help: Show command help
  • --format: Output format (table, json)
  • --verbose: Verbose output

Entry Point

The CLI entry point is defined in setup.py:

entry_points={
    'console_scripts': [
        'maas = maas.client.flesh:main'
    ]
}

Programmatic Access

The CLI functionality can also be accessed programmatically:

from maas.client.flesh import main
import sys

# Call CLI with arguments
sys.argv = ['maas', 'myprofile', 'machines', 'list']
main(sys.argv[1:])

Base Command Classes

For extending the CLI:

from maas.client.flesh import Command, TableCommand, OriginCommand

class Command:
    """Base command class."""

class TableCommand(Command):
    """Base command for table output."""

class OriginCommand(Command):
    """Base command requiring MAAS profile."""

class OriginTableCommand(OriginCommand, TableCommand):
    """Base table command requiring profile."""

class OriginPagedTableCommand(OriginTableCommand):
    """Base paged table command."""