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.
Comprehensive network configuration including fabrics, VLANs, subnets, spaces, IP ranges, static routes, and interface management.
Network fabrics represent physical network groupings.
client.fabrics.list()
client.fabrics.get(id)
client.fabrics.get_default()
client.fabrics.create(name=None, description=None, class_type=None)
fabric.save()
fabric.delete()from maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
# List fabrics
fabrics = client.fabrics.list()
# Get specific fabric
fabric = client.fabrics.get(0)
# Get default fabric
default_fabric = client.fabrics.get_default()
# Create fabric
new_fabric = client.fabrics.create(
name='fabric-1',
description='Production network fabric',
class_type='10g'
)
# Update fabric
fabric.name = 'updated-fabric'
await fabric.save()
# Delete fabric
await fabric.delete()Fabric properties:
id (int, readonly): Unique fabric identifiername (str): Fabric nameclass_type (str): Network class type (e.g., '10g', '1g')vlans (Vlans): Collection of VLANs in this fabricVLANs segment network traffic within fabrics.
# VLANs are accessed via fabric objects
fabric.vlans.list()
fabric.vlans.get(vid)
fabric.vlans.create(vid, name=None, description=None, mtu=1500, dhcp_on=False, primary_rack=None, secondary_rack=None, relay_vlan=None, space=None)
Vlan.read(fabric, vid)
vlan.save()
vlan.delete()# Access VLANs through fabric
fabric = client.fabrics.get(0)
vlans = fabric.vlans.list()
# Get specific VLAN by VID
vlan = fabric.vlans.get(100)
# Or use Vlan.read()
from maas.client.viscera import Vlan
vlan = await Vlan.read(fabric, 100)
# Create VLAN
vlan = await fabric.vlans.create(
vid=100,
name='Production',
description='Production VLAN',
mtu=1500,
dhcp_on=True,
space='dmz'
)
# Update VLAN
vlan.name = 'Production-Updated'
vlan.mtu = 9000
await vlan.save()
# Delete VLAN
await vlan.delete()VLAN properties:
id (int, readonly): Unique VLAN identifierfabric (Fabric): Parent fabricvid (int): VLAN ID (0-4094)name (str): VLAN namemtu (int): Maximum transmission unitspace (Space): Associated spacerelay_vlan (Vlan): DHCP relay VLANdhcp_on (bool): DHCP enabledprimary_rack (RackController): Primary rack controller for DHCPsecondary_rack (RackController): Secondary rack controller for DHCPexternal_dhcp (str, readonly): External DHCP server IPSubnets define IP address ranges and network configuration.
client.subnets.list()
client.subnets.get(id)
Subnet.read(id)
client.subnets.create(cidr, name=None, description=None, vlan=None, fabric=None, gateway_ip=None, dns_servers=None, rdns_mode=None, allow_proxy=None, active_discovery=None, managed=True)
subnet.save()
subnet.delete()from maas.client.enum import RDNSMode
# List subnets
subnets = client.subnets.list()
# Get specific subnet
subnet = client.subnets.get(1)
# Create subnet
subnet = await client.subnets.create(
cidr='192.168.100.0/24',
name='Production Subnet',
description='Main production network',
vlan=100,
fabric=0,
gateway_ip='192.168.100.1',
dns_servers=['8.8.8.8', '8.8.4.4'],
rdns_mode=RDNSMode.ENABLED,
allow_proxy=True,
active_discovery=True,
managed=True
)
# Update subnet
subnet.name = 'Production-Primary'
subnet.gateway_ip = '192.168.100.254'
await subnet.save()
# Delete subnet
await subnet.delete()Subnet properties:
id (int, readonly): Subnet IDcidr (str, readonly): CIDR notationname (str): Subnet namegateway_ip (str): Gateway IP addressdns_servers (list): List of DNS server IPsvlan (Vlan): Associated VLANspace (str): Space namerdns_mode (RDNSMode): Reverse DNS modeactive_discovery (bool): Enable active subnet discoveryallow_proxy (bool): Allow proxy accessmanaged (bool): Whether MAAS manages this subnetSpaces provide logical network grouping for access control.
client.spaces.list()
client.spaces.get(id)
client.spaces.get_default()
Space.read(id)
client.spaces.create(name=None, description=None)
space.delete()# List spaces
spaces = client.spaces.list()
# Get specific space
space = client.spaces.get(1)
# Get default space
default_space = client.spaces.get_default()
# Create space
space = await client.spaces.create(
name='dmz',
description='DMZ network space'
)
# Delete space
await space.delete()Space properties:
id (int, readonly): Unique space identifiername (str, readonly): Space namedescription (str, readonly): Space descriptionvlans (Vlans, readonly): VLANs associated with this spaceManage dynamic and reserved IP address ranges.
client.ip_ranges.list()
client.ip_ranges.get(id)
IPRange.read(id)
client.ip_ranges.create(start_ip, end_ip, type=IPRangeType.RESERVED, comment=None, subnet=None)
ip_range.save()
ip_range.delete()from maas.client.enum import IPRangeType
# List IP ranges
ip_ranges = client.ip_ranges.list()
# Get specific IP range
ip_range = client.ip_ranges.get(1)
# Create dynamic range for DHCP
ip_range = await client.ip_ranges.create(
start_ip='192.168.1.100',
end_ip='192.168.1.200',
type=IPRangeType.DYNAMIC,
subnet=1,
comment='DHCP pool'
)
# Create reserved range
reserved = await client.ip_ranges.create(
start_ip='192.168.1.10',
end_ip='192.168.1.50',
type=IPRangeType.RESERVED,
subnet=1,
comment='Infrastructure IPs'
)
# Update IP range
ip_range.start_ip = '192.168.1.105'
ip_range.end_ip = '192.168.1.205'
ip_range.comment = 'Updated DHCP pool'
await ip_range.save()
# Delete IP range
await ip_range.delete()IP Range properties:
id (int, readonly): Unique IP range identifierstart_ip (str): Starting IP addressend_ip (str): Ending IP addresstype (IPRangeType, readonly): Range type (DYNAMIC or RESERVED)comment (str): Range comment/descriptionsubnet (Subnet, readonly): Associated subnetConfigure static network routes.
client.static_routes.list()
client.static_routes.get(id)
client.static_routes.create(**params)Parameters:
source (int): Source subnet IDdestination (int): Destination subnet IDgateway_ip (str): Gateway IP addressmetric (int, optional): Route metric# Create static route
route = client.static_routes.create(
source=1,
destination=2,
gateway_ip='192.168.1.254',
metric=10
)
# List routes
routes = client.static_routes.list()
# Delete route
route.delete()Machine and device network interfaces are now documented separately. See Network Interface Management for complete documentation on:
from maas.client.enum import IPRangeType, InterfaceType, LinkMode, RDNSMode
class IPRangeType:
"""IP range type enumeration."""
DYNAMIC = ... # Dynamic DHCP range
RESERVED = ... # Reserved range
class InterfaceType:
"""Network interface type enumeration."""
PHYSICAL = ...
BOND = ...
BRIDGE = ...
VLAN = ...
UNKNOWN = ...
class LinkMode:
"""Interface link mode enumeration."""
AUTO = ... # Automatic configuration
DHCP = ... # DHCP configuration
STATIC = ... # Static IP configuration
LINK_UP = ... # Link up only
class RDNSMode:
"""Reverse DNS mode enumeration."""
DISABLED = ...
ENABLED = ...
RFC2317 = ...