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 network interfaces on MAAS machines, including physical interfaces, bonds, bridges, VLANs, and interface links with various IP configuration modes.
Retrieve all network interfaces for a machine.
# Via Machine object
machine.interfacesfrom maas.client import connect
client = connect('http://maas.example.com:5240/MAAS/', apikey='key')
# Get a machine
machine = client.machines.get('abc123')
# List all interfaces
interfaces = machine.interfaces
for interface in interfaces:
print(f"{interface.name}: {interface.type} - {interface.mac_address}")
# Access by name
eth0 = machine.interfaces.by_name['eth0']Retrieve a single interface by ID or name.
Interface.read(node, id)
machine.interfaces.get_by_name(name)# Get interface by ID
interface = await Interface.read(machine, 5)
# Get interface by name
interface = machine.interfaces.get_by_name('eth0')Create a new physical network interface.
Interfaces.create(
node,
InterfaceType.PHYSICAL,
mac_address=str,
name=None,
tags=None,
vlan=None,
mtu=None,
accept_ra=None,
autoconf=None
)from maas.client.enum import InterfaceType
# Create physical interface
interface = await machine.interfaces.create(
machine,
InterfaceType.PHYSICAL,
mac_address='52:54:00:12:34:56',
name='eth1',
tags=['production', 'external']
)Create a bonded network interface from multiple physical interfaces.
Interfaces.create(
node,
InterfaceType.BOND,
parents=list,
name=str,
mac_address=None,
tags=None,
vlan=None,
mtu=None,
accept_ra=None,
autoconf=None,
bond_mode=None,
bond_miimon=None,
bond_downdelay=None,
bond_updelay=None,
bond_lacp_rate=None,
bond_xmit_hash_policy=None
)from maas.client.enum import InterfaceType
# Get parent interfaces
eth0 = machine.interfaces.get_by_name('eth0')
eth1 = machine.interfaces.get_by_name('eth1')
# Create bond
bond0 = await machine.interfaces.create(
machine,
InterfaceType.BOND,
parents=[eth0, eth1],
name='bond0',
bond_mode='802.3ad',
bond_miimon=100,
bond_lacp_rate='fast',
bond_xmit_hash_policy='layer3+4'
)Create a VLAN interface on top of a parent interface.
Interfaces.create(
node,
InterfaceType.VLAN,
parent=Interface,
vlan=Vlan,
name=None,
tags=None,
mtu=None,
accept_ra=None,
autoconf=None
)from maas.client.enum import InterfaceType
# Get parent interface and VLAN
eth0 = machine.interfaces.get_by_name('eth0')
vlan = client.vlans.get(vid=100)
# Create VLAN interface
vlan_if = await machine.interfaces.create(
machine,
InterfaceType.VLAN,
parent=eth0,
vlan=vlan,
name='eth0.100'
)Create a bridge interface for virtualization or network isolation.
Interfaces.create(
node,
InterfaceType.BRIDGE,
parent=Interface,
name=str,
mac_address=None,
tags=None,
vlan=None,
mtu=None,
accept_ra=None,
autoconf=None,
bridge_stp=None,
bridge_fd=None
)from maas.client.enum import InterfaceType
# Get parent interface
eth0 = machine.interfaces.get_by_name('eth0')
# Create bridge
br0 = await machine.interfaces.create(
machine,
InterfaceType.BRIDGE,
parent=eth0,
name='br0',
bridge_stp=True,
bridge_fd=15
)Modify interface attributes and save changes.
interface.save()# Update interface properties
interface = machine.interfaces.get_by_name('eth0')
interface.name = 'external'
interface.enabled = True
interface.tags = ['production', 'external']
interface.params = {'mtu': 9000}
# Change VLAN
new_vlan = client.vlans.get(vid=200)
interface.vlan = new_vlan
# Save changes
await interface.save()Remove an interface from a machine.
interface.delete()# Delete interface
interface = machine.interfaces.get_by_name('eth1')
await interface.delete()Disconnect an interface from all subnets.
interface.disconnect()# Disconnect interface from all subnets
interface = machine.interfaces.get_by_name('eth0')
await interface.disconnect()Manage IP address configuration on interfaces through links.
Configure IP addresses on interfaces using different modes.
InterfaceLinks.create(
interface,
mode,
subnet=None,
ip_address=None,
force=False,
default_gateway=False
)from maas.client.enum import LinkMode
interface = machine.interfaces.get_by_name('eth0')
subnet = client.subnets.get(cidr='10.0.0.0/24')
# Auto-assign IP from subnet
link = await interface.links.create(
interface,
LinkMode.AUTO,
subnet=subnet
)
# Static IP assignment
link = await interface.links.create(
interface,
LinkMode.STATIC,
subnet=subnet,
ip_address='10.0.0.100',
default_gateway=True
)
# DHCP configuration
link = await interface.links.create(
interface,
LinkMode.DHCP
)
# Link up without IP
link = await interface.links.create(
interface,
LinkMode.LINK_UP,
subnet=subnet
)Remove IP configuration from an interface.
link.delete()# Remove a link
link = interface.links[0]
await link.delete()Set an interface link as the default gateway for the node.
link.set_as_default_gateway()# Set as default gateway
link = interface.links[0]
await link.set_as_default_gateway()Interfaces have the following properties:
id (int, readonly): Unique interface identifiernode (Node, readonly): Parent machinetype (InterfaceType, readonly): Interface type (physical, bond, bridge, vlan)name (str): Interface namemac_address (str): MAC addressenabled (bool): Whether interface is enabledeffective_mtu (int, readonly): Current MTU settingtags (list): List of tagsparams (dict): Custom interface parametersparents (Interfaces): Parent interfaces (for bonds/bridges)children (Interfaces): Child interfacesvlan (Vlan): Connected VLANlinks (InterfaceLinks): IP configurationsdiscovered (InterfaceDiscoveredLinks, readonly): Discovered link informationInterface links have the following properties:
id (int, readonly): Unique link identifiermode (LinkMode, readonly): Link mode (AUTO, DHCP, STATIC, LINK_UP)subnet (Subnet, readonly): Connected subnetip_address (str, readonly): Assigned IP addressfrom maas.client.enum import InterfaceType, LinkMode
class InterfaceType:
"""Interface type enumeration."""
PHYSICAL = "physical" # Physical network interface
BOND = "bond" # Bonded interface
BRIDGE = "bridge" # Bridge interface
VLAN = "vlan" # VLAN interface
UNKNOWN = "unknown" # Interface not linked to a node
class LinkMode:
"""Interface link mode enumeration."""
AUTO = "auto" # IP auto-assigned by MAAS
DHCP = "dhcp" # IP assigned by DHCP server
STATIC = "static" # Static IP assignment
LINK_UP = "link_up" # Connected to subnet with no IP address