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 disk partitions on MAAS block devices, including creation, formatting, mounting, and deletion operations.
Retrieve all partitions on a block device.
# Via BlockDevice object
block_device.partitionsfrom maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
# Get a machine and block device
machine = client.machines.get('abc123')
sda = machine.block_devices.get_by_name('sda')
# List all partitions
partitions = sda.partitions
for partition in partitions:
print(f"{partition.path}: {partition.size} bytes")Retrieve a single partition by ID.
Partition.read(node, block_device, id)# Get partition by ID
partition = await Partition.read(machine, sda, 1)Create a new partition on a block device.
Partitions.create(block_device, size)# Create a 100 GB partition
partition = await sda.partitions.create(
sda,
size=107374182400 # 100 GB in bytes
)
# Create a partition using all available space
# First check available space
available = sda.available_size
partition = await sda.partitions.create(sda, size=available)Remove a partition from a block device.
partition.delete()# Delete a partition
partition = sda.partitions[0]
await partition.delete()Format a partition with a filesystem.
partition.format(fstype, uuid=None)# Format partition as ext4
partition = sda.partitions[0]
await partition.format('ext4')
# Format with specific UUID
await partition.format('xfs', uuid='12345678-1234-1234-1234-123456789abc')
# Supported filesystem types:
# - ext2, ext3, ext4
# - xfs
# - btrfs
# - swap
# - fat32
# - vfatRemove filesystem from a partition.
partition.unformat()# Remove filesystem
partition = sda.partitions[0]
await partition.unformat()Mount a formatted partition to a mount point.
partition.mount(mount_point, mount_options=None)# Mount to /var
partition = sda.partitions[0]
await partition.mount('/var')
# Mount with options
await partition.mount('/var', mount_options='noatime,nodiratime')
# Common mount points:
# - /var
# - /home
# - /tmp
# - /srv
# - /optUnmount a mounted partition.
partition.umount()# Unmount partition
partition = sda.partitions[0]
await partition.umount()Here's a complete example of partitioning and configuring a disk:
from maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
# Get machine and block device
machine = client.machines.get('abc123')
sdb = machine.block_devices.get_by_name('sdb')
# Create boot partition (1 GB)
boot_partition = await sdb.partitions.create(sdb, size=1073741824)
await boot_partition.format('ext4')
await boot_partition.mount('/boot')
# Create swap partition (8 GB)
swap_partition = await sdb.partitions.create(sdb, size=8589934592)
await swap_partition.format('swap')
# Create root partition (remaining space)
remaining = sdb.available_size
root_partition = await sdb.partitions.create(sdb, size=remaining)
await root_partition.format('ext4')
await root_partition.mount('/')Partitions have the following properties:
id (int, readonly): Unique partition identifierblock_device (BlockDevice, readonly): Parent block deviceuuid (str, readonly): Partition UUIDpath (str, readonly): Device path (e.g., '/dev/sda1')size (int, readonly): Partition size in bytesused_for (str, readonly): Description of current usagefilesystem (Filesystem, readonly): Filesystem if formatted