Stp

Module for working with spanning-tree in EOS

This module provides an API for working with spanning-tree configuration in EOS. This includes both global spanning-tree configuration as well as interface config.

Global Parameters:
mode (string): The spanning-tree operational mode. Accepted values

for this version are ‘mstp’ or ‘none’. This configuration parameter is not defaultable

interfaces (StpInterfaces): The collection of STP enabled interfaces.

Interface Parameters:
name (string): The name of the interface the STP configuration is in

reference to. The interface name is the full interface identifier

portfast (string): The portfast configuration value for the interface.

Accepted values are ‘edge’, ‘network’, or ‘disabled’

bpduguard (boolean): True if the BPDU Guard feature is enabled on the

interface or False if it is disabled

class pyeapi.api.stp.Stp(*args, **kwargs)[source]

Bases: pyeapi.api.abstract.Entity

The Stp class implements global configuration for spanning-tree

The spanning-tree protocol provides both global and interface configuration options. This class is the top-level class that provides access to all spanning-tree configuration options supported.

Example

The below example demonstrates how to use the STP class to work with both global configuration and interface configuration.

>>> import pyeapi.resources.stp
>>> stp = pyeapi.resources.stp.instance(node)
>>> stp.set_mode('mstp')
True
>>> stp.interfaces.set_bpduguard('Ethernet1', True)
True
interfaces

An instance for configuration spanning-tree configuration interfaces

Type

StpInterfaces

instances

An instance object for working with spanning-tree global instances

Type

StpInstances

get()[source]

Returns the spanning-tree configuration as a dict object

The dictionary object represents the entire spanning-tree configuration derived from the nodes running config. This includes both globally configuration attributes as well as interfaces and instances. See the StpInterfaces and StpInstances classes for the key/value pair definitions.

Note

See the individual classes for detailed message structures

Returns

A Python dictionary object of key/value pairs the represent the entire supported spanning-tree configuration:

{
    "mode": [mstp, none],
    "interfaces": {...},
    "instances": {...}
}

property instances
property interfaces
set_mode(value=None, default=False, disable=False)[source]

Configures the global spanning-tree mode

Note

This configuration parameter is not defaultable

Parameters
  • value (string) – The value to configure the global spanning-tree mode of operation. Valid values include ‘mstp’, ‘none’

  • default (bool) – Set the global spanning-tree mode to default.

  • disable (bool) – Negate the global spanning-tree mode.

Returns

True if the configuration operation succeeds otherwise False

Raises

ValueError if the value is not in the accepted range

class pyeapi.api.stp.StpInstances(node)[source]

Bases: pyeapi.api.abstract.EntityCollection

Provides a configuration resource for spanning-tree instances

This class provides an API for working with spanning-tree instances from the global configuration. Spanning tree instances work with MST configuration

getall()[source]
class pyeapi.api.stp.StpInterfaces(node)[source]

Bases: pyeapi.api.abstract.EntityCollection

Provides a configuration resource for spanning-tree interfaces

This class provides an API for working with spanning-tree interface configurations. It provides access to managing specific interface spanning-tree configuration options. Note that spanning-tree interfaces cannot be created or deleted.

configure_interface(name, cmds)[source]

Configures the specified interface with the commands

Parameters
  • name (str) – The interface name to configure

  • commands – The commands to configure in the interface

Returns

True if the commands completed successfully

get(name)[source]

Returns the specified interfaces STP configuration resource

The STP interface resource contains the following

  • name (str): The interface name

  • portfast (bool): The spanning-tree portfast admin state

  • bpduguard (bool): The spanning-tree bpduguard admin state

  • portfast_type (str): The spanning-tree portfast <type> value.

    Valid values include “edge”, “network”, “normal”

Parameters

name (string) – The interface identifier to retrieve the config for. Note: Spanning-tree interfaces are only supported on Ethernet and Port-Channel interfaces

Returns

A resource dict object that represents the interface

configuration.

None: If the specified interace is not a STP port

Return type

dict

getall()[source]

Returns the collection of STP interfaces

This method will return all of the configured spanning-tree interfaces from the current nodes configuration.

Returns

A Python dictionary object that represents all configured

spanning-tree interfaces indexed by interface name.

set_bpduguard(name, value=False, default=False, disable=False)[source]

Configures the bpduguard value for the specified interface

Parameters
  • name (string) – The interface identifier to configure. The name must be the full interface name (eg Ethernet1, not Et1)

  • value (bool) – True if bpduguard is enabled otherwise False

  • default (bool) – Configures the bpduguard parameter to its default value using the EOS CLI default config command

  • disable (bool) – Negates the bpduguard parameter using the EOS CLI no config command

Returns

True if the command succeeds, otherwise False

Raises
  • ValueError – Rasied if an invalid interface name is specified

  • TypeError – Raised if the value keyword argument does not evaluate to a valid boolean

set_portfast(name, value=None, default=False, disable=False)[source]

Configures the portfast value for the specified interface

Parameters
  • name (string) – The interface identifier to configure. The name must be the full interface name (eg Ethernet1, not Et1)

  • value (bool) – True if portfast is enabled otherwise False

  • default (bool) – Configures the portfast parameter to its default value using the EOS CLI default config command

  • disable (bool) – Negates the portfast parameter using the EOS CLI no config command

Returns

True if the command succeeds, otherwise False

Raises
  • ValueError – Rasied if an invalid interface name is specified

  • TypeError – Raised if the value keyword argument does not evaluate to a valid boolean

set_portfast_type(name, value='normal')[source]

Configures the portfast value for the specified interface

Parameters
  • name (string) – The interface identifier to configure. The name must be the full interface name (eg Ethernet1, not Et1).

  • value (string) – The value to configure the portfast setting to. Valid values include “edge”, “network”, “normal”. The default value is “normal”

Returns

True if the command succeeds, otherwise False

Raises

ValueError – Raised if an invalid interface name or value is specified

pyeapi.api.stp.instance(api)[source]
pyeapi.api.stp.isvalidinterface(value)[source]

Checks value to see if it could be a spanning-tree interface

This function will check the value and return a boolean whether or not the interface could be a spanning-tree interface

Note

This function only checks if the interface could be a spanning-tree

interface but does not check if it is configured as a spanning-tree interface

Parameters

value (string) – The interface name to validate

Returns

True if it could be a spanning-tree interface, otherwise False