Class: Rbeapi::Api::PortchannelInterface

Inherits:
BaseInterface show all
Defined in:
lib/rbeapi/api/interfaces.rb

Overview

The PortchannelInterface class manages all port channel interfaces on an EOS node.

Constant Summary collapse

DEFAULT_LACP_FALLBACK =
'disabled'.freeze
DEFAULT_LACP_MODE =
'on'.freeze
'0'.freeze

Constants inherited from BaseInterface

BaseInterface::DEFAULT_INTF_DESCRIPTION, BaseInterface::DEFAULT_INTF_ENCAPSULATION, BaseInterface::DEFAULT_LOAD_INTERVAL

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from BaseInterface

#create, #default, #delete, #set_description, #set_encapsulation, #set_load_interval, #set_shutdown

Methods inherited from Entity

#command_builder, #configure, #configure_interface, #get_block, #initialize, instance

Constructor Details

This class inherits a constructor from Rbeapi::Api::Entity

Instance Method Details

#add_member(name, member) ⇒ Boolean

add_member adds the interface specified in member to the port-channel interface specified by name in the nodes running-configuration. If the port-channel interface does not already exist, it will be created.

Parameters:

  • name (String)

    The name of the port-channel interface to apply the configuration to.

  • member (String)

    The name of the physical Ethernet interface to add to the logical port-channel interface.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



1052
1053
1054
1055
1056
# File 'lib/rbeapi/api/interfaces.rb', line 1052

def add_member(name, member)
  lacp = parse_lacp_mode(name)[:lacp_mode]
  grpid = /(\d+)/.match(name)[0]
  configure_interface(member, "channel-group #{grpid} mode #{lacp}")
end

#get(name) ⇒ nil, Hash<Symbol, Object>

get returns the specified port-channel interface configuration from the nodes running configuration as a resource hash. The resource hash returned extends the BaseInterface resource hash, sets the type value to portchannel and adds the portchannel specific attributes

Examples:

{
  type: 'portchannel'
  description: <string>
  encapsulation: <integer>
  shutdown: [true, false]
  load_interval: <string>
  members: array[<strings>]
  lacp_mode: [active, passive, on]
  minimum_links: <string>
  lacp_timeout: <string>
  lacp_fallback: [static, individual, disabled]
}

Parameters:

  • name (String)

    The name of the portchannel interface to return a resource hash for. The name must be the full interface name of the desired interface.

Returns:

  • (nil, Hash<Symbol, Object>)

    Returns the interface resource as a hash object. If the specified interface does not exist in the running configuration, a nil object is returned.

See Also:



834
835
836
837
838
839
840
841
842
843
844
845
# File 'lib/rbeapi/api/interfaces.rb', line 834

def get(name)
  config = get_block("^interface #{name}")
  return nil unless config
  response = super(name)
  response[:type] = 'portchannel'
  response.merge!(parse_members(name))
  response.merge!(parse_lacp_mode(name))
  response.merge!(parse_minimum_links(config))
  response.merge!(parse_lacp_fallback(config))
  response.merge!(parse_lacp_timeout(config))
  response
end

#remove_member(name, member) ⇒ Boolean

remove_member removes the interface specified in member from the port-channel interface specified by name in the nodes running-configuration.

Parameters:

  • name (String)

    The name of the port-channel interface to apply the configuration to.

  • member (String)

    The name of the physical Ethernet interface to remove from the logical port-channel interface.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



1072
1073
1074
1075
# File 'lib/rbeapi/api/interfaces.rb', line 1072

def remove_member(name, member)
  grpid = /(\d+)/.match(name)[0]
  configure_interface(member, "no channel-group #{grpid}")
end

#set_lacp_fallback(name, opts = {}) ⇒ Boolean

set_lacp_fallback configures the lacp fallback mode for the port-channel interface. If the enable keyword is false, lacp fallback is configured using the no keyword argument. If the default option is specified and set to true, the lacp fallback value is configured using the default keyword. The default keyword takes precedence over the enable keyword if both options are provided.

Parameters:

  • name (String)

    The interface name to apply the configuration values to. The name must be the full interface identifier.

  • opts (Hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    Specifies the value to configure for the port-channel lacp fallback. Valid values are individual and static.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configures the lacp fallback value on the interface using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



1135
1136
1137
1138
# File 'lib/rbeapi/api/interfaces.rb', line 1135

def set_lacp_fallback(name, opts = {})
  commands = command_builder('port-channel lacp fallback', opts)
  configure_interface(name, commands)
end

#set_lacp_mode(name, mode) ⇒ Boolean

set_lacp_mode configures the lacp mode on the port-channel interface by configuring the lacp mode value for each member interface. This method will find all member interfaces for a port-channel and reconfigure them using the mode argument.

Parameters:

  • name (String)

    The interface name to apply the configuration values to. The name must be the full interface identifier.

  • mode (String)

    The lacp mode to configure on the member interfaces for the port-channel. Valid values include active, passive or on.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
# File 'lib/rbeapi/api/interfaces.rb', line 1093

def set_lacp_mode(name, mode)
  return false unless %w(on passive active).include?(mode)
  grpid = /(\d+)/.match(name)[0]

  remove_commands = []
  add_commands = []

  parse_members(name)[:members].each do |member|
    remove_commands << "interface #{member}"
    remove_commands << "no channel-group #{grpid}"
    add_commands << "interface #{member}"
    add_commands << "channel-group #{grpid} mode #{mode}"
  end
  configure remove_commands + add_commands
end

#set_lacp_timeout(name, opts = {}) ⇒ Boolean

set_lacp_timeout configures the lacp fallback timeout for the port-channel interface. If the enable keyword is false, lacp fallback timeout is configured using the no keyword argument. If the default option is specified and set to true, the lacp fallback timeout value is configured using the default keyword. The default keyword takes precedence over the enable keyword if both options are provided.

Parameters:

  • name (String)

    The interface name to apply the configuration values to. The name must be the full interface identifier.

  • opts (Hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    Specifies the value to configure for the port-channel lacp fallback timeout.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configures the lacp fallback timeout value on the interface using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



1165
1166
1167
1168
# File 'lib/rbeapi/api/interfaces.rb', line 1165

def set_lacp_timeout(name, opts = {})
  commands = command_builder('port-channel lacp fallback timeout', opts)
  configure_interface(name, commands)
end

#set_members(name, members, mode = nil) ⇒ Boolean

set_members configures the set of physical interfaces that comprise the logical port-channel interface. The members value passed should be an array of physical interface names that comprise the port-channel interface. This method will add and remove individual members as required to sync the provided members array.

Parameters:

  • name (String)

    The name of the port-channel interface to apply the members to. If the port-channel interface does not already exist it will be created.

  • members (Array)

    The array of physical interface members to add to the port-channel logical interface.

  • mode (str) (defaults to: nil)

    The LACP mode to configure the member interfaces to. Valid values are ‘on, ’passive’, ‘active’. When there are existing channel-group members and their lacp mode differs from this attribute, all of those members will be removed and then re-added using the specified lacp mode. If this attribute is omitted, the existing lacp mode will be used for new member additions.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Raises:

  • (ArgumentError)

See Also:



1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
# File 'lib/rbeapi/api/interfaces.rb', line 1007

def set_members(name, members, mode = nil)
  raise ArgumentError, 'members must be an Array' unless
  members.is_a?(Array)

  current_members = Set.new parse_members(name)[:members]
  members = Set.new members

  lacp_mode = parse_lacp_mode(name)[:lacp_mode]
  if mode && mode != lacp_mode
    lacp_mode = mode
    set_lacp_mode(name, lacp_mode)
  end

  cmds = []
  grpid = /(\d+)/.match(name)[0]

  # remove members from the current port-channel interface.
  current_members.difference(members).each do |intf|
    cmds << "interface #{intf}"
    cmds << "no channel-group #{grpid}"
  end

  # add new member interfaces to the port-channel.
  members.difference(current_members).each do |intf|
    cmds << "interface #{intf}"
    cmds << "channel-group #{grpid} mode #{lacp_mode}"
  end

  configure(cmds)
end

set_minimum_links configures the minimum physical links up required to consider the logical portchannel interface operationally up. If the enable keyword is false then the minimum-links is configured using the no keyword argument. If the default keyword argument is provided and set to true, the minimum-links value is defaulted using the default keyword. The default keyword takes precedence over the enable keyword argument if both are provided.

Parameters:

  • name (String)

    The interface name to apply the configuration values to. The name must be the full interface identifier.

  • opts (Hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String, Integer)

    Specifies the value to configure the minimum-links to in the configuration. Valid values are in the range of 1 to 16.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configures the minimum links value on the interface using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



975
976
977
978
# File 'lib/rbeapi/api/interfaces.rb', line 975

def set_minimum_links(name, opts = {})
  commands = command_builder('port-channel min-links', opts)
  configure_interface(name, commands)
end