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 storage block devices on MAAS machines, including physical disks, virtual block devices, formatting, partitioning, and mounting operations.
Retrieve all block devices for a machine.
# Via Machine object
machine.block_devicesfrom 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']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')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']
)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()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()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()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
# - vfatRemove filesystem from a block device.
block_device.unformat()# Remove filesystem
sdb = machine.block_devices.get_by_name('sdb')
await sdb.unformat()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')Unmount a mounted block device.
block_device.unmount()# Unmount block device
sdb = machine.block_devices.get_by_name('sdb')
await sdb.unmount()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 devices have the following properties:
id (int, readonly): Unique block device identifiernode (Node, readonly): Parent machinetype (BlockDeviceType, readonly): Device type (physical or virtual)name (str): Device name (e.g., 'sda', 'vda')model (str): Device modelserial (str): Device serial numberid_path (str): Unique device path identifiersize (int): Total device size in bytesblock_size (int): Block size in bytesuuid (str): Device UUIDtags (list): List of tagsavailable_size (int, readonly): Available space in bytesused_size (int, readonly): Used space in bytesused_for (str, readonly): Description of current usagepartition_table_type (PartitionTableType, readonly): Partition table type (MBR or GPT)partitions (Partitions): Collection of partitions on this devicefilesystem (Filesystem, readonly): Filesystem if formatted directlyfrom 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