switch

FABRIC P4 programmable switch abstraction.

This module provides the Switch class for working with P4-programmable network switches in FABRIC. Switches extend the Node class with specialized functionality for programmable data planes.

class fabrictestbed_extensions.fablib.switch.Switch(slice, node, validate=False, raise_exception=False)[source]

Switch constructor, usually invoked by Slice.add_switch().

Parameters:
  • slice (Slice) – the fablib slice to have this switch on

  • node (FimNode) – the FIM node that this Switch represents

  • validate (bool) – Validate node can be allocated w.r.t available resources

  • raise_exception (bool) – Raise exception in case validation fails

delete()[source]

Remove the switch from the slice. All components and interfaces associated with the Node are removed from the Slice.

generate_template_context(skip=None)[source]

Generate the base template context for this switch.

Creates a dictionary context suitable for Jinja2 template rendering, excluding the SSH command and setting an empty components list.

Parameters:

skip (list) – list of keys to exclude

Returns:

Template context dictionary with switch attributes

Return type:

dict

get_fim()[source]

Not recommended for most users.

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:

FIMNode

get_interface(name=None, refresh=False, raise_exception=None)[source]

Gets a specific interface by name.

Parameters:
  • name (str) – the interface name

  • refresh (bool) – force refresh from FIM

  • raise_exception (bool) – if True, raise ResourceNotFoundError when the interface is not found; if False, return None. When None (default), falls back to the global FablibManager.raise_on_not_found setting.

Returns:

the interface or None

Return type:

Optional[Interface]

Raises:

ResourceNotFoundError – if the interface is not found and raising is enabled

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

Gets a list of the interfaces associated with the FABRIC node.

Results are cached. Use refresh=True to force reload.

Parameters:
  • include_subs (bool) – Flag indicating if sub interfaces should be included

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

  • output (str) – return type - ‘list’ or ‘dict’

Returns:

interfaces on the node

Return type:

Union[Dict[str, Interface], List[Interface]]

static get_node(slice=None, node=None)[source]

Returns a new fablib node using existing FABRIC resources.

Note:

Not intended for API call.

Parameters:
  • slice (Slice) – the fablib slice storing the existing node

  • node (Node) – the FIM node stored in this fablib node

Returns:

a new fablib node storing resources

Return type:

Node

static get_pretty_name_dict()[source]

Get a mapping of field names to human-readable labels for display.

Returns a dictionary that maps internal field names to user-friendly display names used when rendering tables and formatted output.

Returns:

Dictionary mapping field names to pretty names

Return type:

dict

static get_switch(slice, node)[source]

Factory method to create a Switch from a FIM node.

Parameters:
  • slice (Slice) – the slice this switch belongs to

  • node (FimNode) – the FIM node

Returns:

a Switch instance

Return type:

Switch

static new_switch(slice=None, name=None, site=None, avoid=None, validate=False, raise_exception=False)[source]

Creates a new FABRIC switch on the slice.

Not intended for API use. Use slice.add_switch() instead.

Parameters:
  • slice (Slice) – the fablib slice to build the new switch on

  • name (str) – the name of the new switch

  • site (str) – the name of the site to build the switch on

  • avoid (List[str]) – a list of site names to avoid

  • validate (bool) – Validate switch can be allocated w.r.t available resources

  • raise_exception (bool) – Raise exception if validation fails

Returns:

a new Switch

Return type:

Switch

toDict(skip=None)[source]

Returns the node attributes as a dictionary.

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

Parameters:

skip (list) – list of keys to exclude

Returns:

switch attributes as dictionary

Return type:

dict

update(fim_node=None)[source]

Update the switch with new FIM data.

Parameters:

fim_node (FimNode) – The new FIM node data

class fabrictestbed_extensions.fablib.switch.Switch(slice, node, validate=False, raise_exception=False)[source]

Switch constructor, usually invoked by Slice.add_switch().

Parameters:
  • slice (Slice) – the fablib slice to have this switch on

  • node (FimNode) – the FIM node that this Switch represents

  • validate (bool) – Validate node can be allocated w.r.t available resources

  • raise_exception (bool) – Raise exception in case validation fails

__str__()[source]

Creates a tabulated string describing the properties of the node.

Intended for printing node information.

Returns:

Tabulated string of node information

Return type:

String

delete()[source]

Remove the switch from the slice. All components and interfaces associated with the Node are removed from the Slice.

generate_template_context(skip=None)[source]

Generate the base template context for this switch.

Creates a dictionary context suitable for Jinja2 template rendering, excluding the SSH command and setting an empty components list.

Parameters:

skip (list) – list of keys to exclude

Returns:

Template context dictionary with switch attributes

Return type:

dict

get_fim()[source]

Not recommended for most users.

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:

FIMNode

get_interface(name=None, refresh=False, raise_exception=None)[source]

Gets a specific interface by name.

Parameters:
  • name (str) – the interface name

  • refresh (bool) – force refresh from FIM

  • raise_exception (bool) – if True, raise ResourceNotFoundError when the interface is not found; if False, return None. When None (default), falls back to the global FablibManager.raise_on_not_found setting.

Returns:

the interface or None

Return type:

Optional[Interface]

Raises:

ResourceNotFoundError – if the interface is not found and raising is enabled

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

Gets a list of the interfaces associated with the FABRIC node.

Results are cached. Use refresh=True to force reload.

Parameters:
  • include_subs (bool) – Flag indicating if sub interfaces should be included

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

  • output (str) – return type - ‘list’ or ‘dict’

Returns:

interfaces on the node

Return type:

Union[Dict[str, Interface], List[Interface]]

static get_node(slice=None, node=None)[source]

Returns a new fablib node using existing FABRIC resources.

Note:

Not intended for API call.

Parameters:
  • slice (Slice) – the fablib slice storing the existing node

  • node (Node) – the FIM node stored in this fablib node

Returns:

a new fablib node storing resources

Return type:

Node

static get_pretty_name_dict()[source]

Get a mapping of field names to human-readable labels for display.

Returns a dictionary that maps internal field names to user-friendly display names used when rendering tables and formatted output.

Returns:

Dictionary mapping field names to pretty names

Return type:

dict

static get_switch(slice, node)[source]

Factory method to create a Switch from a FIM node.

Parameters:
  • slice (Slice) – the slice this switch belongs to

  • node (FimNode) – the FIM node

Returns:

a Switch instance

Return type:

Switch

static new_switch(slice=None, name=None, site=None, avoid=None, validate=False, raise_exception=False)[source]

Creates a new FABRIC switch on the slice.

Not intended for API use. Use slice.add_switch() instead.

Parameters:
  • slice (Slice) – the fablib slice to build the new switch on

  • name (str) – the name of the new switch

  • site (str) – the name of the site to build the switch on

  • avoid (List[str]) – a list of site names to avoid

  • validate (bool) – Validate switch can be allocated w.r.t available resources

  • raise_exception (bool) – Raise exception if validation fails

Returns:

a new Switch

Return type:

Switch

toDict(skip=None)[source]

Returns the node attributes as a dictionary.

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

Parameters:

skip (list) – list of keys to exclude

Returns:

switch attributes as dictionary

Return type:

dict

update(fim_node=None)[source]

Update the switch with new FIM data.

Parameters:

fim_node (FimNode) – The new FIM node data