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.

block-devices.mddocs/reference/

Block Device Management

Manage storage block devices on MAAS machines, including physical disks, virtual block devices, formatting, partitioning, and mounting operations.

Capabilities

Listing Block Devices

Retrieve all block devices for a machine.

# Via Machine object
machine.block_devices
from maas.client import connect

client = connect('http://maas.example.com:5240/MAAS/', apikey='key')

# Get a machine
machine = client.machines.get('abc123')

# List all block devices
block_devices = machine.block_devices
for bd in block_devices:
    print(f"{bd.name}: {bd.size} bytes - {bd.model}")

# Access by name
sda = machine.block_devices.by_name['sda']

Getting Specific Block Device

Retrieve a single block device by ID or name.

BlockDevice.read(node, id)
machine.block_devices.get_by_name(name)
# Get block device by ID
block_device = await BlockDevice.read(machine, 10)

# Get block device by name
sda = machine.block_devices.get_by_name('sda')

Creating Block Devices

Create a new physical block device on a machine.

BlockDevices.create(
    node,
    name,
    model=None,
    serial=None,
    id_path=None,
    size=None,
    block_size=512,
    tags=None
)

Important: It is recommended to use the MAAS commissioning process to discover block devices. Creating them manually requires accurate hardware information.

# Create block device with model/serial
block_device = await machine.block_devices.create(
    machine,
    name='sdc',
    model='Samsung SSD 850',
    serial='S3Z1NB0K123456',
    size=512000000000,  # 512 GB in bytes
    block_size=512,
    tags=['ssd', 'fast']
)

# Create block device with id_path (when model/serial not available)
block_device = await machine.block_devices.create(
    machine,
    name='sdd',
    id_path='/dev/disk/by-id/ata-WDC_WD10EZEX',
    size=1000000000000,  # 1 TB in bytes
    tags=['hdd', 'storage']
)

Updating Block Device Properties

Modify block device attributes and save changes.

block_device.save()
# Update block device properties
sda = machine.block_devices.get_by_name('sda')
sda.name = 'boot-disk'
sda.tags = ['boot', 'system']
sda.uuid = 'new-uuid-value'

# Save changes
await sda.save()

Deleting Block Devices

Remove a block device from a machine.

block_device.delete()
# Delete block device
block_device = machine.block_devices.get_by_name('sdc')
await block_device.delete()

Setting Boot Disk

Designate a block device as the boot disk for the machine.

block_device.set_as_boot_disk()
# Set as boot disk
sda = machine.block_devices.get_by_name('sda')
await sda.set_as_boot_disk()

Formatting Block Devices

Format a block device with a filesystem.

block_device.format(fstype, uuid=None)
# Format as ext4
sdb = machine.block_devices.get_by_name('sdb')
await sdb.format('ext4')

# Format with specific UUID
await sdb.format('ext4', uuid='12345678-1234-1234-1234-123456789abc')

# Other supported filesystem types:
# - ext2, ext3, ext4
# - xfs
# - btrfs
# - swap
# - fat32
# - vfat

Unformatting Block Devices

Remove filesystem from a block device.

block_device.unformat()
# Remove filesystem
sdb = machine.block_devices.get_by_name('sdb')
await sdb.unformat()

Mounting Block Devices

Mount a formatted block device to a mount point.

block_device.mount(mount_point, mount_options=None)
# Mount to /data
sdb = machine.block_devices.get_by_name('sdb')
await sdb.mount('/data')

# Mount with options
await sdb.mount('/data', mount_options='noatime,nodiratime')

Unmounting Block Devices

Unmount a mounted block device.

block_device.unmount()
# Unmount block device
sdb = machine.block_devices.get_by_name('sdb')
await sdb.unmount()

Working with Partitions

Block devices can be partitioned for more flexible storage management.

# Access partitions on a block device
sda = machine.block_devices.get_by_name('sda')
partitions = sda.partitions

# Create a new partition (size in bytes)
partition = await sda.partitions.create(sda, size=107374182400)  # 100 GB

# Format and mount partition
await partition.format('ext4')
await partition.mount('/var')

See Partition Management for complete partition documentation.

Block Device Properties

Block devices have the following properties:

  • id (int, readonly): Unique block device identifier
  • node (Node, readonly): Parent machine
  • type (BlockDeviceType, readonly): Device type (physical or virtual)
  • name (str): Device name (e.g., 'sda', 'vda')
  • model (str): Device model
  • serial (str): Device serial number
  • id_path (str): Unique device path identifier
  • size (int): Total device size in bytes
  • block_size (int): Block size in bytes
  • uuid (str): Device UUID
  • tags (list): List of tags
  • available_size (int, readonly): Available space in bytes
  • used_size (int, readonly): Used space in bytes
  • used_for (str, readonly): Description of current usage
  • partition_table_type (PartitionTableType, readonly): Partition table type (MBR or GPT)
  • partitions (Partitions): Collection of partitions on this device
  • filesystem (Filesystem, readonly): Filesystem if formatted directly

Types

from maas.client.enum import BlockDeviceType, PartitionTableType

class BlockDeviceType:
    """Block device type enumeration."""
    PHYSICAL = "physical"  # Physical disk
    VIRTUAL = "virtual"    # Virtual disk

class PartitionTableType:
    """Partition table type enumeration."""
    MBR = "mbr"  # Master Boot Record
    GPT = "gpt"  # GUID Partition Table