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 Logical Volume Manager (LVM) volume groups and logical volumes on MAAS machines for flexible storage management.
Retrieve all LVM volume groups configured on a machine.
# Via Machine object
machine.volume_groupsfrom maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
# Get a machine
machine = client.machines.get('abc123')
# List all volume groups
volume_groups = machine.volume_groups
for vg in volume_groups:
print(f"{vg.name}: {vg.size} bytes ({vg.available_size} available)")
# Access by name
vg_data = machine.volume_groups.by_name['vg-data']Retrieve a single volume group by ID or name.
VolumeGroup.read(node, id)
machine.volume_groups.get_by_name(name)# Get volume group by ID
vg = await VolumeGroup.read(machine, 3)
# Get volume group by name
vg_data = machine.volume_groups.get_by_name('vg-data')Create a new LVM volume group from block devices or partitions.
VolumeGroups.create(
node,
name,
devices,
uuid=None
)# Create volume group from block devices
sdb = machine.block_devices.get_by_name('sdb')
sdc = machine.block_devices.get_by_name('sdc')
vg = await machine.volume_groups.create(
machine,
name='vg-data',
devices=[sdb, sdc]
)
# Create volume group from partitions
sdd = machine.block_devices.get_by_name('sdd')
partition1 = await sdd.partitions.create(sdd, size=sdd.available_size)
vg_partition = await machine.volume_groups.create(
machine,
name='vg-apps',
devices=[partition1]
)
# Create volume group with specific UUID
vg_custom = await machine.volume_groups.create(
machine,
name='vg-storage',
devices=[sdb],
uuid='12345678-1234-1234-1234-123456789abc'
)Modify volume group attributes and save changes.
vg.save()# Update volume group properties
vg = machine.volume_groups.get_by_name('vg-data')
vg.name = 'vg-production'
vg.uuid = 'new-uuid-value'
# Save changes
await vg.save()Remove a volume group from a machine.
vg.delete()# Delete volume group
vg = machine.volume_groups.get_by_name('vg-data')
await vg.delete()Logical volumes are created within volume groups and act as virtual block devices.
Access logical volumes through their parent volume group.
# Via VolumeGroup object
volume_group.logical_volumes# List logical volumes in a volume group
vg = machine.volume_groups.get_by_name('vg-data')
for lv in vg.logical_volumes:
print(f"{lv.name}: {lv.size} bytes")
# Access by name
lv_root = vg.logical_volumes.by_name['lv-root']Create a new logical volume within a volume group.
LogicalVolumes.create(
volume_group,
name,
size,
uuid=None,
tags=None
)# Create logical volume (100 GB)
vg = machine.volume_groups.get_by_name('vg-data')
lv = await vg.logical_volumes.create(
vg,
name='lv-data',
size=107374182400 # 100 GB in bytes
)
# Create logical volume with tags
lv_apps = await vg.logical_volumes.create(
vg,
name='lv-apps',
size=53687091200, # 50 GB
tags=['applications', 'production']
)
# Create logical volume with custom UUID
lv_custom = await vg.logical_volumes.create(
vg,
name='lv-custom',
size=21474836480, # 20 GB
uuid='87654321-4321-4321-4321-210987654321'
)Logical volumes can be formatted and mounted like regular block devices.
# Create and format logical volume
vg = machine.volume_groups.get_by_name('vg-data')
lv = await vg.logical_volumes.create(
vg,
name='lv-www',
size=107374182400 # 100 GB
)
# Format and mount
await lv.format('ext4')
await lv.mount('/var/www')Logical volumes inherit all block device methods, including delete.
# Delete logical volume
lv = vg.logical_volumes.get_by_name('lv-old')
await lv.delete()from maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
machine = client.machines.get('abc123')
# Get block devices for volume group
sdb = machine.block_devices.get_by_name('sdb')
sdc = machine.block_devices.get_by_name('sdc')
# Create volume group
vg = await machine.volume_groups.create(
machine,
name='vg-storage',
devices=[sdb, sdc]
)
print(f"Created {vg.name}")
print(f"Total size: {vg.size} bytes")
print(f"Available: {vg.available_size} bytes")
# Create logical volumes
lv_data = await vg.logical_volumes.create(
vg,
name='lv-data',
size=107374182400 # 100 GB
)
await lv_data.format('xfs')
await lv_data.mount('/data')
lv_logs = await vg.logical_volumes.create(
vg,
name='lv-logs',
size=53687091200 # 50 GB
)
await lv_logs.format('ext4')
await lv_logs.mount('/var/log')
lv_backup = await vg.logical_volumes.create(
vg,
name='lv-backup',
size=vg.available_size # Use remaining space
)
await lv_backup.format('ext4')
await lv_backup.mount('/backup')
print(f"\nLogical volumes created:")
for lv in vg.logical_volumes:
print(f" {lv.name}: {lv.filesystem.mount_point}")Volume groups have the following properties:
id (int, readonly): Unique volume group identifiernode (Node, readonly): Parent machinename (str): Volume group namesize (int, readonly): Total volume group capacity in bytesavailable_size (int, readonly): Available space in bytesused_size (int, readonly): Used space in bytesuuid (str): Volume group UUIDdevices (list): Block devices or partitions in the grouplogical_volumes (LogicalVolumes): Collection of logical volumesLogical volumes inherit all properties from BlockDevice and include:
id (int, readonly): Unique logical volume identifiernode (Node, readonly): Parent machinename (str): Logical volume namesize (int): Logical volume size in bytesuuid (str): Logical volume UUIDtags (list): List of tagsLVM provides several advantages over traditional partitioning:
Note on Snapshots: While LVM supports snapshots, snapshot creation and management must be performed at the operating system level after machine deployment. The MAAS API focuses on initial storage configuration and does not provide direct snapshot management capabilities.