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.

interfaces.mddocs/reference/

Network Interface Management

Manage network interfaces on MAAS machines, including physical interfaces, bonds, bridges, VLANs, and interface links with various IP configuration modes.

Capabilities

Listing Interfaces

Retrieve all network interfaces for a machine.

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

Getting Specific Interface

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

Creating Physical Interfaces

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

Creating Bond Interfaces

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

Creating VLAN Interfaces

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

Creating Bridge Interfaces

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
)

Updating Interface Properties

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

Deleting Interfaces

Remove an interface from a machine.

interface.delete()
# Delete interface
interface = machine.interfaces.get_by_name('eth1')
await interface.delete()

Disconnecting Interfaces

Disconnect an interface from all subnets.

interface.disconnect()
# Disconnect interface from all subnets
interface = machine.interfaces.get_by_name('eth0')
await interface.disconnect()

Interface Links

Manage IP address configuration on interfaces through links.

Creating Interface 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
)

Deleting Interface Links

Remove IP configuration from an interface.

link.delete()
# Remove a link
link = interface.links[0]
await link.delete()

Setting Default Gateway

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

Interface Properties

Interfaces have the following properties:

  • id (int, readonly): Unique interface identifier
  • node (Node, readonly): Parent machine
  • type (InterfaceType, readonly): Interface type (physical, bond, bridge, vlan)
  • name (str): Interface name
  • mac_address (str): MAC address
  • enabled (bool): Whether interface is enabled
  • effective_mtu (int, readonly): Current MTU setting
  • tags (list): List of tags
  • params (dict): Custom interface parameters
  • parents (Interfaces): Parent interfaces (for bonds/bridges)
  • children (Interfaces): Child interfaces
  • vlan (Vlan): Connected VLAN
  • links (InterfaceLinks): IP configurations
  • discovered (InterfaceDiscoveredLinks, readonly): Discovered link information

Interface Link Properties

Interface links have the following properties:

  • id (int, readonly): Unique link identifier
  • mode (LinkMode, readonly): Link mode (AUTO, DHCP, STATIC, LINK_UP)
  • subnet (Subnet, readonly): Connected subnet
  • ip_address (str, readonly): Assigned IP address

Types

from 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