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.

partitions.mddocs/reference/

Partition Management

Manage disk partitions on MAAS block devices, including creation, formatting, mounting, and deletion operations.

Capabilities

Listing Partitions

Retrieve all partitions on a block device.

# Via BlockDevice object
block_device.partitions
from 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")

Getting Specific Partition

Retrieve a single partition by ID.

Partition.read(node, block_device, id)
# Get partition by ID
partition = await Partition.read(machine, sda, 1)

Creating Partitions

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)

Deleting Partitions

Remove a partition from a block device.

partition.delete()
# Delete a partition
partition = sda.partitions[0]
await partition.delete()

Formatting Partitions

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
# - vfat

Unformatting Partitions

Remove filesystem from a partition.

partition.unformat()
# Remove filesystem
partition = sda.partitions[0]
await partition.unformat()

Mounting Partitions

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
# - /opt

Unmounting Partitions

Unmount a mounted partition.

partition.umount()
# Unmount partition
partition = sda.partitions[0]
await partition.umount()

Complete Partitioning Example

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

Partition Properties

Partitions have the following properties:

  • id (int, readonly): Unique partition identifier
  • block_device (BlockDevice, readonly): Parent block device
  • uuid (str, readonly): Partition UUID
  • path (str, readonly): Device path (e.g., '/dev/sda1')
  • size (int, readonly): Partition size in bytes
  • used_for (str, readonly): Description of current usage
  • filesystem (Filesystem, readonly): Filesystem if formatted

Related Documentation

  • Block Device Management - Manage storage devices
  • Filesystem Management - Working with filesystems
  • RAID Configuration - Create software RAID arrays
  • LVM Volume Groups - Logical Volume Management