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.
Configure and manage software RAID arrays on MAAS machines for redundancy and performance.
Retrieve all RAID arrays configured on a machine.
# Via Machine object
machine.raidsfrom maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
# Get a machine
machine = client.machines.get('abc123')
# List all RAID arrays
raids = machine.raids
for raid in raids:
print(f"{raid.name}: RAID {raid.level} - {raid.size} bytes")
# Access by name
md0 = machine.raids.by_name['md0']Retrieve a single RAID array by ID or name.
Raid.read(node, id)
machine.raids.get_by_name(name)# Get RAID by ID
raid = await Raid.read(machine, 5)
# Get RAID by name
md0 = machine.raids.get_by_name('md0')Create a new software RAID array from block devices or partitions.
Raids.create(
node,
level,
devices,
name=None,
uuid=None,
spare_devices=None
)from maas.client.enum import RaidLevel
# Get block devices
sdb = machine.block_devices.get_by_name('sdb')
sdc = machine.block_devices.get_by_name('sdc')
# Create RAID 1 (mirror) array
raid1 = await machine.raids.create(
machine,
RaidLevel.RAID_1,
devices=[sdb, sdc],
name='md0'
)
# Create RAID 0 (stripe) array with partitions
sdd = machine.block_devices.get_by_name('sdd')
sde = machine.block_devices.get_by_name('sde')
# Create partitions first
partition1 = await sdd.partitions.create(sdd, size=sdd.available_size)
partition2 = await sde.partitions.create(sde, size=sde.available_size)
raid0 = await machine.raids.create(
machine,
RaidLevel.RAID_0,
devices=[partition1, partition2],
name='md1'
)
# Create RAID 5 with spare devices
sdf = machine.block_devices.get_by_name('sdf')
sdg = machine.block_devices.get_by_name('sdg')
sdh = machine.block_devices.get_by_name('sdh')
sdi = machine.block_devices.get_by_name('sdi')
raid5 = await machine.raids.create(
machine,
RaidLevel.RAID_5,
devices=[sdf, sdg, sdh],
spare_devices=[sdi],
name='md2'
)Modify RAID array attributes and save changes.
raid.save()# Update RAID properties
md0 = machine.raids.get_by_name('md0')
md0.name = 'raid-storage'
md0.uuid = 'new-uuid-value'
# Save changes
await md0.save()Remove a RAID array from a machine.
raid.delete()# Delete RAID array
md0 = machine.raids.get_by_name('md0')
await md0.delete()Once created, RAID arrays can be formatted and mounted like block devices.
# Create RAID array
raid = await machine.raids.create(
machine,
RaidLevel.RAID_1,
devices=[sdb, sdc],
name='md0'
)
# Format the RAID array
virtual_device = raid.virtual_device
await virtual_device.format('ext4')
await virtual_device.mount('/data')MAAS supports the following RAID levels:
Stripes data across multiple disks for improved performance. No redundancy.
raid0 = await machine.raids.create(
machine,
RaidLevel.RAID_0,
devices=[sdb, sdc]
)Mirrors data across multiple disks for redundancy.
raid1 = await machine.raids.create(
machine,
RaidLevel.RAID_1,
devices=[sdb, sdc]
)Stripes data with distributed parity for performance and redundancy.
raid5 = await machine.raids.create(
machine,
RaidLevel.RAID_5,
devices=[sdb, sdc, sdd]
)Stripes data with double parity, can tolerate two disk failures.
raid6 = await machine.raids.create(
machine,
RaidLevel.RAID_6,
devices=[sdb, sdc, sdd, sde]
)Combines mirroring and striping for both performance and redundancy.
raid10 = await machine.raids.create(
machine,
RaidLevel.RAID_10,
devices=[sdb, sdc, sdd, sde]
)from maas.client import connect
from maas.client.enum import RaidLevel
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
machine = client.machines.get('abc123')
# Get block devices for RAID
sdb = machine.block_devices.get_by_name('sdb')
sdc = machine.block_devices.get_by_name('sdc')
sdd = machine.block_devices.get_by_name('sdd')
sde = machine.block_devices.get_by_name('sde') # spare
# Create RAID 5 array with spare
raid5 = await machine.raids.create(
machine,
RaidLevel.RAID_5,
devices=[sdb, sdc, sdd],
spare_devices=[sde],
name='storage-raid'
)
# Format and mount the RAID array
virtual_device = raid5.virtual_device
await virtual_device.format('xfs')
await virtual_device.mount('/storage')
print(f"Created {raid5.name} with {raid5.level}")
print(f"Total capacity: {raid5.size} bytes")
print(f"Mounted at: {virtual_device.filesystem.mount_point}")RAID arrays have the following properties:
id (int, readonly): Unique RAID identifiernode (Node, readonly): Parent machinename (str): RAID array name (e.g., 'md0')level (RaidLevel, readonly): RAID levelsize (int, readonly): Total RAID capacity in bytesuuid (str): RAID UUIDdevices (list): Active devices in the arrayspare_devices (list): Spare devicesvirtual_device (BlockDevice, readonly): Virtual block device representing the arrayfrom maas.client.enum import RaidLevel
class RaidLevel:
"""RAID level enumeration."""
RAID_0 = "raid-0" # Striping
RAID_1 = "raid-1" # Mirroring
RAID_5 = "raid-5" # Striping with parity
RAID_6 = "raid-6" # Striping with double parity
RAID_10 = "raid-10" # Mirrored stripes