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.

volume-groups.mddocs/reference/

LVM Volume Groups

Manage Logical Volume Manager (LVM) volume groups and logical volumes on MAAS machines for flexible storage management.

Capabilities

Listing Volume Groups

Retrieve all LVM volume groups configured on a machine.

# Via Machine object
machine.volume_groups
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 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']

Getting Specific Volume Group

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')

Creating Volume Groups

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'
)

Updating Volume Group Properties

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()

Deleting Volume Groups

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

Logical volumes are created within volume groups and act as virtual block devices.

Listing Logical Volumes

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']

Creating Logical Volumes

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'
)

Formatting and Mounting Logical Volumes

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')

Deleting Logical Volumes

Logical volumes inherit all block device methods, including delete.

# Delete logical volume
lv = vg.logical_volumes.get_by_name('lv-old')
await lv.delete()

Complete LVM Example

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 Group Properties

Volume groups have the following properties:

  • id (int, readonly): Unique volume group identifier
  • node (Node, readonly): Parent machine
  • name (str): Volume group name
  • size (int, readonly): Total volume group capacity in bytes
  • available_size (int, readonly): Available space in bytes
  • used_size (int, readonly): Used space in bytes
  • uuid (str): Volume group UUID
  • devices (list): Block devices or partitions in the group
  • logical_volumes (LogicalVolumes): Collection of logical volumes

Logical Volume Properties

Logical volumes inherit all properties from BlockDevice and include:

  • id (int, readonly): Unique logical volume identifier
  • node (Node, readonly): Parent machine
  • name (str): Logical volume name
  • size (int): Logical volume size in bytes
  • uuid (str): Logical volume UUID
  • tags (list): List of tags
  • All other block device properties and methods

Benefits of LVM

LVM provides several advantages over traditional partitioning:

  1. Flexibility: Resize volumes without unmounting (resize via OS tools after deployment)
  2. Pooling: Combine multiple disks into one volume group
  3. Snapshots: Create point-in-time snapshots for backups (managed at OS level after deployment, not via MAAS API)
  4. Dynamic Allocation: Create volumes as needed from available space
  5. Easy Management: Add or remove storage devices dynamically

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.

Related Documentation

  • Block Device Management - Manage storage devices
  • Partition Management - Create partitions for LVM
  • RAID Configuration - Combine LVM with RAID
  • Filesystem Management - Format logical volumes