Switchports

Module for working with logical layer 2 switchports in EOS

This module provides an API for working with logical layer 2 interfaces (switchports) in EOS. Switchports are interfaces built on top of physical Ethernet and bundled Port-Channel interfaces.

class pyeapi.api.switchports.Switchports(node)[source]

Bases: pyeapi.api.abstract.EntityCollection

The Switchports class provides a configuration resource for swichports

Logical layer 2 interfaces built on top of physical Ethernet and bundled Port-Channel interfaces can be configured and managed with an instance of Switchports. The Switchports class is a resource collection and supports get and getall methods. The Switchports class is derived from the BaseResource class

add_trunk_group(intf, value)[source]

Adds the specified trunk group to the interface

Parameters
  • intf (str) – The interface name to apply the trunk group to

  • value (str) – The trunk group value to apply to the interface

Returns

True if the operation as successfully applied otherwise false

create(name)[source]

Creates a new logical layer 2 interface

This method will create a new switchport for the interface specified in the arguments (name). If the logical switchport already exists then this command will have no effect

Parameters

name (string) – The interface identifier to create the logical layer 2 switchport for. The name must be the full interface name and not an abbreviated interface name (eg Ethernet1, not Et1)

Returns

True if the create operation succeeds otherwise False. If the

interface specified in args is already a switchport then this method will have no effect but will still return True

default(name)[source]

Defaults the configuration of the switchport interface

This method will default the configuration state of the logical layer 2 interface.

Parameters

name (string) – The interface identifier to create the logical layer 2 switchport for. The name must be the full interface name and not an abbreviated interface name (eg Ethernet1, not Et1)

Returns

True if the create operation succeeds otherwise False. If the

interface specified in args is already a switchport then this method will have no effect but will still return True

delete(name)[source]

Deletes the logical layer 2 interface

This method will delete the logical switchport for the interface specified in the arguments. If the interface doe not have a logical layer 2 interface defined, then this method will have no effect.

Parameters

name (string) – The interface identifier to create the logical layer 2 switchport for. The name must be the full interface name and not an abbreviated interface name (eg Ethernet1, not Et1)

Returns

True if the create operation succeeds otherwise False. If the

interface specified in args is already a switchport then this method will have no effect but will still return True

get(name)[source]

Returns a dictionary object that represents a switchport

The Switchport resource returns the following:

  • name (str): The name of the interface

  • mode (str): The switchport mode value

  • access_vlan (str): The switchport access vlan value

  • trunk_native_vlan (str): The switchport trunk native vlan vlaue

  • trunk_allowed_vlans (str): The trunk allowed vlans value

  • trunk_groups (list): The list of trunk groups configured

Parameters

name (string) – The interface identifier to get. Note: Switchports are only supported on Ethernet and Port-Channel interfaces

Returns

A Python dictionary object of key/value pairs that represent

the switchport configuration for the interface specified If the specified argument is not a switchport then None is returned

Return type

dict

getall()[source]

Returns a dict object to all Switchports

This method will return all of the configured switchports as a dictionary object keyed by the interface identifier.

Returns

A Python dictionary object that represents all configured

switchports in the current running configuration

remove_trunk_group(intf, value)[source]

Removes a specified trunk group to the interface

Parameters
  • intf (str) – The interface name to remove the trunk group from

  • value (str) – The trunk group value

Returns

True if the operation as successfully applied otherwise false

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

Configures the switchport access vlan

Parameters
  • name (string) – The interface identifier to create the logical layer 2 switchport for. The name must be the full interface name and not an abbreviated interface name (eg Ethernet1, not Et1)

  • value (string) – The value to set the access vlan to. The value must be a valid VLAN ID in the range of 1 to 4094.

  • default (bool) – Configures the access vlan parameter to its default value using the EOS CLI

  • disable (bool) – Negate the access vlan parameter using the EOS CLI

Returns

True if the create operation succeeds otherwise False.

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

Configures the switchport mode

Parameters
  • name (string) – The interface identifier to create the logical layer 2 switchport for. The name must be the full interface name and not an abbreviated interface name (eg Ethernet1, not Et1)

  • value (string) – The value to set the mode to. Accepted values for this argument are access or trunk

  • default (bool) – Configures the mode parameter to its default value using the EOS CLI

  • disable (bool) – Negate the mode parameter using the EOS CLI

Returns

True if the create operation succeeds otherwise False.

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

Configures the switchport trunk allowed vlans value

Parameters
  • name (string) – The interface identifier to create the logical layer 2 switchport for. The name must be the full interface name and not an abbreviated interface name (eg Ethernet1, not Et1)

  • value (string) – The value to set the trunk allowed vlans to. The value must be a valid VLAN ID in the range of 1 to 4094.

  • default (bool) – Configures the access vlan parameter to its default value using the EOS CLI

  • disable (bool) – Negate the access vlan parameter using the EOS CLI

Returns

True if the create operation succeeds otherwise False.

set_trunk_groups(intf, value=None, default=False, disable=False)[source]

Configures the switchport trunk group value

Parameters
  • intf (str) – The interface identifier to configure.

  • value (str) – The set of values to configure the trunk group

  • default (bool) – Configures the trunk group default value

  • disable (bool) – Negates all trunk group settings

Returns

True if the config operation succeeds otherwise False

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

Configures the switchport trunk native vlan value

Parameters
  • name (string) – The interface identifier to create the logical layer 2 switchport for. The name must be the full interface name and not an abbreviated interface name (eg Ethernet1, not Et1)

  • value (string) – The value to set the trunk nativevlan to. The value must be a valid VLAN ID in the range of 1 to 4094.

  • default (bool) – Configures the access vlan parameter to its default value using the EOS CLI

  • disable (bool) – Negate the access vlan parameter using the EOS CLI

Returns

True if the create operation succeeds otherwise False.

pyeapi.api.switchports.instance(node)[source]

Returns an instance of Switchports

This method will create and return an instance of the Switchports object passing the value of node to the instance. The module method is required for the resource to be autoloaded by the Node object

Parameters

node (Node) – The node argument provides an instance of Node to the resource