interface

Methods to work with FABRIC network interfaces.

class fabrictestbed_extensions.fablib.interface.Interface(component=None, fim_interface=None, node=None, model=None, parent=None)[source]

Note

Objects of this class are not created directly.

Parameters:
  • component (Component) – the component to set on this interface

  • fim_interface (FimInterface) – the FABRIC information model interface to set on this fablib interface

  • node (FacilityPort) – the facility Port to which interface is assoicated with

add_mirror(port_name, name='mirror', vlan=None)[source]

Add Port Mirror Service

Parameters:
  • port_name (String) – Mirror Port Name

  • vlan (String) – Mirror Port vlan

  • name (String) – Name of the Port Mirror service

add_sub_interface(name, vlan, bw=10)[source]

Add a sub-interface to a dedicated NIC.

This method adds a sub-interface to a NIC (Network Interface Card) with the specified name, VLAN (Virtual Local Area Network) ID, and bandwidth. It supports only specific NIC models.

Parameters:
  • name (str) – The name of the sub-interface.

  • vlan (str) – The VLAN ID for the sub-interface.

  • bw (int) – The bandwidth allocated to the sub-interface, in Gbps. Default is 10 Gbps.

Raises:

Exception – If the NIC model does not support sub-interfaces.

config()[source]

Configure the interface based on its mode and network settings. Called when a .Node is configured.

This method configures the interface by setting its IP address and bringing it up. It checks the configuration mode and acts accordingly: - If the mode is ‘AUTO’ and no address is set, it automatically allocates an IP address. - If the mode is ‘CONFIG’ or ‘AUTO’, it configures the interface with the assigned IP address and subnet. - If the mode is ‘MANUAL’, it does not perform any automatic configuration.

When nmcli backend is available, uses a consolidated nmcli flow for persistent, reboot-safe configuration. For FabNetv4Ext/FabNetv6Ext networks, also configures Policy-Based Routing.

Returns:

None

config_vlan_iface()[source]

Configure vlan interface

NOTE: Not intended for API use

delete()[source]

Delete the interface by removing it from the corresponding network service

get_bandwidth()[source]

Gets the bandwidth of the interface in Gbps.

Basic NICs claim 0 bandwidth but are 100 Gbps shared by all Basic NICs on the host.

Results are cached for performance.

Returns:

the bandwidth in Gbps

Return type:

int

get_component()[source]

Gets the component attached to this interface.

Returns:

the component on this interface

Return type:

Component

get_device_name()[source]

Gets a name of the device name on the node

If the interface requires a FABRIC VLAN tag, the interface name returned will be the VLAN tagged interface name.

Returns:

OS interface name

Return type:

String

get_error_message()[source]

Gets the error messages

Returns:

error

Return type:

String

get_fim()[source]

Gets the node’s FABRIC Information Model (fim) object. This method is used to access data at a lower level than FABlib.

Returns:

the FABRIC model node

Return type:

fim interface

get_interfaces(refresh=False, output='list')[source]

Gets the interfaces attached to this fablib component’s FABRIC component.

Parameters:
  • refresh (bool) – Refresh the interface object with latest Fim info

  • output (str) – Specify how the return type is expected; Possible values: list or dict

Returns:

a list or dict of the interfaces on this component.

Return type:

Union[dict[str, Interface], list[Interface]]

get_ip_addr()[source]

Retrieve the IP address assigned to the interface.

This method returns the IP address assigned to the interface, either from the ‘fablib_data’ or by fetching it via SSH if not available in the stored data. If the MAC address is not available, it returns None.

Returns:

The IP address assigned to the interface.

Return type:

ipaddress.IPv4Address or ipaddress.IPv6Address or str or None

get_ip_addr_show(dev=None)[source]

Retrieve the IP address information for a specified network device.

This method executes the ip -j addr show command on the node to get the IP address information in JSON format for the specified device. If no device is specified, it defaults to the device name associated with the current instance.

Parameters:

dev (str, optional) – The name of the network device (optional).

Returns:

The JSON output of the ip -j addr show command.

Return type:

str

Raises:

Logs an error message if the command execution fails.

get_ip_addr_ssh(dev=None)[source]

Gets the ip addr info for this interface.

When the device name can be resolved, returns the first IP address as a string. When the device name is None, returns the full ip -j addr list output as a list of dicts. Returns None when no output is available or the device is not found.

Returns:

IP address string, list of addr dicts, or None

Return type:

Optional[Union[str, list]]

Gets the ip link info for this interface.

Returns:

ip link info

Return type:

str

get_ips(family=None)[source]

Gets a list of ips assigned to this interface.

Returns:

list of ips

Return type:

list[str]

get_mac()[source]

Gets the MAC address of the interface.

Results are cached for performance.

Returns:

the MAC address

Return type:

str

get_mode()[source]

Retrieve the mode of the interface.

This method returns the current mode of the interface from the ‘fablib_data’ dictionary. If the mode is not set, it defaults to “config” and updates the ‘fablib_data’ accordingly.

Returns:

The mode of the interface.

Return type:

str

get_model()[source]

Gets the component model type on this interface’s component.

Returns:

the model of this interface’s component

Return type:

str

get_network()[source]

Gets the network this interface is on.

Returns:

the network service this interface is on

Return type:

NetworkService

get_node()[source]

Gets the node this interface’s component is on.

Returns:

the node this interface is attached to

Return type:

Node

get_numa_node()[source]

Retrieve the NUMA node of the component linked to the interface.

Returns:

NUMA node of the linked component.

Return type:

str

get_os_dev()[source]

Gets json output of ‘ip addr list’ for the interface.

Returns:

device description

Return type:

Dict

get_os_interface()[source]

Gets a name of the interface the operating system uses for this FABLib interface.

If the interface requires a FABRIC VLAN tag, the interface name returned will be the VLAN tagged.

Returns:

OS interface name

Return type:

String

Deprecated since version 1.6.5: Use get_device_name() instead.

get_peer_account_id()[source]

Get Peer Account Id associated with the interface

Returns:

peer account id associated with the interface (Used when interface is peered to AWS via AL2S)

Return type:

String

get_peer_asn()[source]

Get Peer ASN; Set only for Peered Interface using L3Peering via AL2S

Returns:

peer asn

Return type:

String

get_peer_bgp_key()[source]

Get Peer BGP Key; Set only for Peered Interface using L3Peering via AL2S

Returns:

peer BGP Key

Return type:

String

get_peer_port_name()[source]

If available provide the name of the attached port on the dataplane switch. Only possible once the slice has been instantiated.

Return type:

Optional[str]

get_peer_port_vlan()[source]

Returns the VLAN associated with the interface. For shared NICs extracts it from label_allocations.

Returns:

VLAN to be used for Port Mirroring

Return type:

String

get_peer_subnet()[source]

Get Peer Subnet associated with the interface

Returns:

peer ipv4/ipv6 subnet associated with the interface

Return type:

String

get_physical_os_interface_name()[source]

Gets a name of the physical interface the operating system uses for this FABLib interface.

If the interface requires a FABRIC VLAN tag, the base interface name will be returned (i.e. not the VLAN tagged interface)

Results are cached for performance.

Returns:

physical OS interface name

Return type:

str

static get_pretty_name_dict()[source]

Return a mapping used when rendering table headers.

Return type:

dict[str, str]

get_reservation_id()[source]

Gets the reservation id

Returns:

reservation id

Return type:

String

get_reservation_state()[source]

Gets the reservation state

Returns:

reservation state

Return type:

String

get_short_name()[source]

Retrieve the shortened name of the interface.

This method strips off the extra parts of the name added by the FIM. Specifically, it removes the prefix formed by concatenating the node name and the component’s short name followed by a hyphen.

Returns:

Shortened name of the interface.

Return type:

str

get_site()[source]

Gets the site where the interface is located.

Results are cached for performance.

Returns:

the site name

Return type:

str

get_slice()[source]

Gets the FABLIB slice this interface’s node is attached to.

Returns:

the slice this interface is attached to

Return type:

Slice

get_subnet()[source]

Get Subnet associated with the interface

Returns:

ipv4/ipv6 subnet associated with the interface

Return type:

String

get_switch_port()[source]

Get the name of the port on the switch corresponding to this interface

Returns:

name of the port on switch

Return type:

String

get_type()[source]

Get Interface type

Returns:

get interface type

Return type:

String

get_vlan()[source]

Gets the VLAN of the interface.

Results are cached for performance.

Returns:

the VLAN

Return type:

str

ip_addr_add(addr, subnet)[source]

Add an IP address to the interface in the node.

Parameters:
  • addr (IPv4Address or IPv6Address) – IP address

  • subnet (IPv4Network or IPv6Network) – subnet

ip_addr_del(addr, subnet)[source]

Delete an IP address to the interface in the node.

Parameters:
  • addr (IPv4Address or IPv6Address) – IP address

  • subnet (IPv4Network or IPv4Network) – subnet

Bring down the link on the interface.

Toggle the dev down then up.

Bring up the link on the interface.

is_configured()[source]

Check if the interface is configured.

This method checks the ‘fablib_data’ dictionary to determine if the interface is marked as configured.

Returns:

True if the interface is configured, False otherwise.

Return type:

bool

set_auto_config()[source]

Enable autoconfiguration for the interface.

This method sets the auto_config flag to True for the interface associated with the current instance. The auto_config flag enables automatic configuration of the interface by Control Framework.

Returns:

None

set_bandwidth(bw)[source]

Set the Bandwidths on the FABRIC request.

Parameters:

bw (int) – bw

set_ip_addr(addr=None, mode=None)[source]

Set the IP address for the interface.

This method assigns an IP address to the interface based on the provided address or allocation mode. If an address is provided, it will be allocated to the interface. If the mode is set to ‘AUTO’ and no address is provided, an IP address will be automatically allocated by the network.

Parameters:
  • addr (ipaddress.IPv4Address or ipaddress.IPv6Address, optional) – The IP address to assign to the interface (optional).

  • mode (str, optional) – The mode for IP address allocation, e.g., “auto”, “manual”, or “config”.

Returns:

The current instance with the updated IP address.

Return type:

self

set_mode(mode='config')[source]

Set the mode for the interface.

This method sets the mode for the interface in the ‘fablib_data’ dictionary. The mode determines the configuration behavior of the interface.

Parameters:

mode (str) – The mode to set for the interface (default is “config”). Allowed values: “auto”, “manual”, or “config”..

Returns:

The current instance with the updated mode.

Return type:

self

set_network(network)[source]

Set the network for the interface.

This method assigns the interface to the specified network. If the interface is already part of another network, it will be removed from the current network before being added to the new one.

Parameters:

network (NetworkService) – The network service to assign the interface to.

Returns:

The current instance with the updated network.

Return type:

self

set_subnet(ipv4_subnet=None, ipv6_subnet=None)[source]

Set subnet for the interface. Used only for interfaces connected to L3VPN service where each interface could be connected to multiple subnets

Parameters:
  • ipv4_subnet (str) – ipv4 subnet

  • ipv6_subnet (str) – ipv6 subnet

:raises Exception in case invalid subnet string is specified.

set_vlan(vlan=None)[source]

Set the VLAN on the FABRIC request.

Parameters:

vlan (String or int) – vlan

toDict(skip=None)[source]

Returns the interface attributes as a dictionary.

Results are cached. Cache is invalidated when _invalidate_cache() is called.

Parameters:

skip (List[str]) – list of keys to exclude

Returns:

interface attributes as dictionary

Return type:

dict

un_manage_interface()[source]

Mark an interface unmanaged by Network Manager; This is needed to be run on rocky* images to avoid the network configuration from being overwritten by NetworkManager

unset_auto_config()[source]

Disable autoconfiguration for the interface.

This method sets the auto_config flag to False for the interface associated with the current instance. The auto_config flag disables automatic configuration of the interface by Control Framework.

Returns:

None

update(fim_interface=None)[source]

Update the interface with new FIM data.

Parameters:

fim_interface (FimInterface) – The new FIM interface data

class fabrictestbed_extensions.fablib.interface.Interface(component=None, fim_interface=None, node=None, model=None, parent=None)[source]

Note

Objects of this class are not created directly.

Parameters:
  • component (Component) – the component to set on this interface

  • fim_interface (FimInterface) – the FABRIC information model interface to set on this fablib interface

  • node (FacilityPort) – the facility Port to which interface is assoicated with

__str__()[source]

Creates a tabulated string describing the properties of the interface.

Intended for printing interface information.

Returns:

Tabulated string of interface information

Return type:

String

add_mirror(port_name, name='mirror', vlan=None)[source]

Add Port Mirror Service

Parameters:
  • port_name (String) – Mirror Port Name

  • vlan (String) – Mirror Port vlan

  • name (String) – Name of the Port Mirror service

add_sub_interface(name, vlan, bw=10)[source]

Add a sub-interface to a dedicated NIC.

This method adds a sub-interface to a NIC (Network Interface Card) with the specified name, VLAN (Virtual Local Area Network) ID, and bandwidth. It supports only specific NIC models.

Parameters:
  • name (str) – The name of the sub-interface.

  • vlan (str) – The VLAN ID for the sub-interface.

  • bw (int) – The bandwidth allocated to the sub-interface, in Gbps. Default is 10 Gbps.

Raises:

Exception – If the NIC model does not support sub-interfaces.

config()[source]

Configure the interface based on its mode and network settings. Called when a .Node is configured.

This method configures the interface by setting its IP address and bringing it up. It checks the configuration mode and acts accordingly: - If the mode is ‘AUTO’ and no address is set, it automatically allocates an IP address. - If the mode is ‘CONFIG’ or ‘AUTO’, it configures the interface with the assigned IP address and subnet. - If the mode is ‘MANUAL’, it does not perform any automatic configuration.

When nmcli backend is available, uses a consolidated nmcli flow for persistent, reboot-safe configuration. For FabNetv4Ext/FabNetv6Ext networks, also configures Policy-Based Routing.

Returns:

None

config_vlan_iface()[source]

Configure vlan interface

NOTE: Not intended for API use

delete()[source]

Delete the interface by removing it from the corresponding network service

get_bandwidth()[source]

Gets the bandwidth of the interface in Gbps.

Basic NICs claim 0 bandwidth but are 100 Gbps shared by all Basic NICs on the host.

Results are cached for performance.

Returns:

the bandwidth in Gbps

Return type:

int

get_component()[source]

Gets the component attached to this interface.

Returns:

the component on this interface

Return type:

Component

get_device_name()[source]

Gets a name of the device name on the node

If the interface requires a FABRIC VLAN tag, the interface name returned will be the VLAN tagged interface name.

Returns:

OS interface name

Return type:

String

get_error_message()[source]

Gets the error messages

Returns:

error

Return type:

String

get_fim()[source]

Gets the node’s FABRIC Information Model (fim) object. This method is used to access data at a lower level than FABlib.

Returns:

the FABRIC model node

Return type:

fim interface

get_interfaces(refresh=False, output='list')[source]

Gets the interfaces attached to this fablib component’s FABRIC component.

Parameters:
  • refresh (bool) – Refresh the interface object with latest Fim info

  • output (str) – Specify how the return type is expected; Possible values: list or dict

Returns:

a list or dict of the interfaces on this component.

Return type:

Union[dict[str, Interface], list[Interface]]

get_ip_addr()[source]

Retrieve the IP address assigned to the interface.

This method returns the IP address assigned to the interface, either from the ‘fablib_data’ or by fetching it via SSH if not available in the stored data. If the MAC address is not available, it returns None.

Returns:

The IP address assigned to the interface.

Return type:

ipaddress.IPv4Address or ipaddress.IPv6Address or str or None

get_ip_addr_show(dev=None)[source]

Retrieve the IP address information for a specified network device.

This method executes the ip -j addr show command on the node to get the IP address information in JSON format for the specified device. If no device is specified, it defaults to the device name associated with the current instance.

Parameters:

dev (str, optional) – The name of the network device (optional).

Returns:

The JSON output of the ip -j addr show command.

Return type:

str

Raises:

Logs an error message if the command execution fails.

get_ip_addr_ssh(dev=None)[source]

Gets the ip addr info for this interface.

When the device name can be resolved, returns the first IP address as a string. When the device name is None, returns the full ip -j addr list output as a list of dicts. Returns None when no output is available or the device is not found.

Returns:

IP address string, list of addr dicts, or None

Return type:

Optional[Union[str, list]]

get_ip_link()[source]

Gets the ip link info for this interface.

Returns:

ip link info

Return type:

str

get_ips(family=None)[source]

Gets a list of ips assigned to this interface.

Returns:

list of ips

Return type:

list[str]

get_mac()[source]

Gets the MAC address of the interface.

Results are cached for performance.

Returns:

the MAC address

Return type:

str

get_mode()[source]

Retrieve the mode of the interface.

This method returns the current mode of the interface from the ‘fablib_data’ dictionary. If the mode is not set, it defaults to “config” and updates the ‘fablib_data’ accordingly.

Returns:

The mode of the interface.

Return type:

str

get_model()[source]

Gets the component model type on this interface’s component.

Returns:

the model of this interface’s component

Return type:

str

get_network()[source]

Gets the network this interface is on.

Returns:

the network service this interface is on

Return type:

NetworkService

get_node()[source]

Gets the node this interface’s component is on.

Returns:

the node this interface is attached to

Return type:

Node

get_numa_node()[source]

Retrieve the NUMA node of the component linked to the interface.

Returns:

NUMA node of the linked component.

Return type:

str

get_os_dev()[source]

Gets json output of ‘ip addr list’ for the interface.

Returns:

device description

Return type:

Dict

get_os_interface()[source]

Gets a name of the interface the operating system uses for this FABLib interface.

If the interface requires a FABRIC VLAN tag, the interface name returned will be the VLAN tagged.

Returns:

OS interface name

Return type:

String

Deprecated since version 1.6.5: Use get_device_name() instead.

get_peer_account_id()[source]

Get Peer Account Id associated with the interface

Returns:

peer account id associated with the interface (Used when interface is peered to AWS via AL2S)

Return type:

String

get_peer_asn()[source]

Get Peer ASN; Set only for Peered Interface using L3Peering via AL2S

Returns:

peer asn

Return type:

String

get_peer_bgp_key()[source]

Get Peer BGP Key; Set only for Peered Interface using L3Peering via AL2S

Returns:

peer BGP Key

Return type:

String

get_peer_port_name()[source]

If available provide the name of the attached port on the dataplane switch. Only possible once the slice has been instantiated.

Return type:

Optional[str]

get_peer_port_vlan()[source]

Returns the VLAN associated with the interface. For shared NICs extracts it from label_allocations.

Returns:

VLAN to be used for Port Mirroring

Return type:

String

get_peer_subnet()[source]

Get Peer Subnet associated with the interface

Returns:

peer ipv4/ipv6 subnet associated with the interface

Return type:

String

get_physical_os_interface_name()[source]

Gets a name of the physical interface the operating system uses for this FABLib interface.

If the interface requires a FABRIC VLAN tag, the base interface name will be returned (i.e. not the VLAN tagged interface)

Results are cached for performance.

Returns:

physical OS interface name

Return type:

str

static get_pretty_name_dict()[source]

Return a mapping used when rendering table headers.

Return type:

dict[str, str]

get_reservation_id()[source]

Gets the reservation id

Returns:

reservation id

Return type:

String

get_reservation_state()[source]

Gets the reservation state

Returns:

reservation state

Return type:

String

get_short_name()[source]

Retrieve the shortened name of the interface.

This method strips off the extra parts of the name added by the FIM. Specifically, it removes the prefix formed by concatenating the node name and the component’s short name followed by a hyphen.

Returns:

Shortened name of the interface.

Return type:

str

get_site()[source]

Gets the site where the interface is located.

Results are cached for performance.

Returns:

the site name

Return type:

str

get_slice()[source]

Gets the FABLIB slice this interface’s node is attached to.

Returns:

the slice this interface is attached to

Return type:

Slice

get_subnet()[source]

Get Subnet associated with the interface

Returns:

ipv4/ipv6 subnet associated with the interface

Return type:

String

get_switch_port()[source]

Get the name of the port on the switch corresponding to this interface

Returns:

name of the port on switch

Return type:

String

get_type()[source]

Get Interface type

Returns:

get interface type

Return type:

String

get_vlan()[source]

Gets the VLAN of the interface.

Results are cached for performance.

Returns:

the VLAN

Return type:

str

ip_addr_add(addr, subnet)[source]

Add an IP address to the interface in the node.

Parameters:
  • addr (IPv4Address or IPv6Address) – IP address

  • subnet (IPv4Network or IPv6Network) – subnet

ip_addr_del(addr, subnet)[source]

Delete an IP address to the interface in the node.

Parameters:
  • addr (IPv4Address or IPv6Address) – IP address

  • subnet (IPv4Network or IPv4Network) – subnet

ip_link_down()[source]

Bring down the link on the interface.

ip_link_toggle()[source]

Toggle the dev down then up.

ip_link_up()[source]

Bring up the link on the interface.

is_configured()[source]

Check if the interface is configured.

This method checks the ‘fablib_data’ dictionary to determine if the interface is marked as configured.

Returns:

True if the interface is configured, False otherwise.

Return type:

bool

set_auto_config()[source]

Enable autoconfiguration for the interface.

This method sets the auto_config flag to True for the interface associated with the current instance. The auto_config flag enables automatic configuration of the interface by Control Framework.

Returns:

None

set_bandwidth(bw)[source]

Set the Bandwidths on the FABRIC request.

Parameters:

bw (int) – bw

set_ip_addr(addr=None, mode=None)[source]

Set the IP address for the interface.

This method assigns an IP address to the interface based on the provided address or allocation mode. If an address is provided, it will be allocated to the interface. If the mode is set to ‘AUTO’ and no address is provided, an IP address will be automatically allocated by the network.

Parameters:
  • addr (ipaddress.IPv4Address or ipaddress.IPv6Address, optional) – The IP address to assign to the interface (optional).

  • mode (str, optional) – The mode for IP address allocation, e.g., “auto”, “manual”, or “config”.

Returns:

The current instance with the updated IP address.

Return type:

self

set_mode(mode='config')[source]

Set the mode for the interface.

This method sets the mode for the interface in the ‘fablib_data’ dictionary. The mode determines the configuration behavior of the interface.

Parameters:

mode (str) – The mode to set for the interface (default is “config”). Allowed values: “auto”, “manual”, or “config”..

Returns:

The current instance with the updated mode.

Return type:

self

set_network(network)[source]

Set the network for the interface.

This method assigns the interface to the specified network. If the interface is already part of another network, it will be removed from the current network before being added to the new one.

Parameters:

network (NetworkService) – The network service to assign the interface to.

Returns:

The current instance with the updated network.

Return type:

self

set_subnet(ipv4_subnet=None, ipv6_subnet=None)[source]

Set subnet for the interface. Used only for interfaces connected to L3VPN service where each interface could be connected to multiple subnets

Parameters:
  • ipv4_subnet (str) – ipv4 subnet

  • ipv6_subnet (str) – ipv6 subnet

:raises Exception in case invalid subnet string is specified.

set_vlan(vlan=None)[source]

Set the VLAN on the FABRIC request.

Parameters:

vlan (String or int) – vlan

toDict(skip=None)[source]

Returns the interface attributes as a dictionary.

Results are cached. Cache is invalidated when _invalidate_cache() is called.

Parameters:

skip (List[str]) – list of keys to exclude

Returns:

interface attributes as dictionary

Return type:

dict

un_manage_interface()[source]

Mark an interface unmanaged by Network Manager; This is needed to be run on rocky* images to avoid the network configuration from being overwritten by NetworkManager

unset_auto_config()[source]

Disable autoconfiguration for the interface.

This method sets the auto_config flag to False for the interface associated with the current instance. The auto_config flag disables automatic configuration of the interface by Control Framework.

Returns:

None

update(fim_interface=None)[source]

Update the interface with new FIM data.

Parameters:

fim_interface (FimInterface) – The new FIM interface data