class Rbeapi::Api::PortchannelInterface
The PortchannelInterface
class manages all port channel interfaces on an EOS node.
Constants
- DEFAULT_LACP_FALLBACK
- DEFAULT_LACP_MODE
- DEFAULT_MIN_LINKS
Public Instance Methods
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.
@since eos_version 4.13.7M
@param name [String] The name of the port-channel interface to apply
the configuration to.
@param member [String] The name of the physical Ethernet interface to
add to the logical port-channel interface.
@return [Boolean] Returns true if the command completed successfully.
# 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 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
@example
{ 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] }
@see BaseInterface
Interface get example
@param 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.
@return [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.
Rbeapi::Api::BaseInterface#get
# 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
removes the interface specified in member from the port-channel interface specified by name in the nodes running-configuration.
@since eos_version 4.13.7M
@param name [String] The name of the port-channel interface to apply
the configuration to.
@param member [String] The name of the physical Ethernet interface to
remove from the logical port-channel interface.
@return [Boolean] Returns true if the command completed successfully.
# 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
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.
@since eos_version 4.13.7M
@param name [String] The interface name to apply the configuration
values to. The name must be the full interface identifier.
@param opts [Hash] Optional keyword arguments.
@option opts value [String] Specifies the value to configure for
the port-channel lacp fallback. Valid values are individual and static.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configures the lacp fallback value on
the interface using the default keyword.
@return [Boolean] Returns true if the command completed successfully.
# 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
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.
@since eos_version 4.13.7M
@param name [String] The interface name to apply the configuration
values to. The name must be the full interface identifier.
@param mode [String] The lacp mode to configure on the member
interfaces for the port-channel. Valid values include active, passive or on.
@return [Boolean] Returns true if the command completed successfully.
# 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
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.
@since eos_version 4.13.7M
@param name [String] The interface name to apply the configuration
values to. The name must be the full interface identifier.
@param opts [Hash] Optional keyword arguments.
@option opts value [String] Specifies the value to configure for
the port-channel lacp fallback timeout.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configures the lacp fallback timeout
value on the interface using the default keyword.
@return [Boolean] Returns true if the command completed successfully.
# 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
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.
@see add_member
Adds member links to the port-channel interface.
@see remove_member
Removes member links from the port-channel interface.
@param 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.
@param members [Array] The array of physical interface members to add
to the port-channel logical interface.
@param mode [str] 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.
@return [Boolean] Returns true if the command completed successfully.
# 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.
@since eos_version 4.13.7M
@param name [String] The interface name to apply the configuration
values to. The name must be the full interface identifier.
@param opts [Hash] Optional keyword arguments.
@option 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.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configures the minimum links value on
the interface using the default keyword.
@return [Boolean] Returns true if the command completed successfully.
# 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
Private Instance Methods
parse_lacp_fallback
scans the interface config block and returns the configured value of the lacp fallback attribute. If the value is not configured, then the method will return the value of DEFAULT_LACP_FALLBACK
. The hash returned is intended to be merged into the interface resource hash.
@api private
@param config [String] The interface configuration block to extract
the lacp fallback value from.
@return [Hash<Symbol, Object>] Returns the resource hash attribute.
# File lib/rbeapi/api/interfaces.rb, line 923 def parse_lacp_fallback(config) mdata = /lacp fallback (static|individual)/.match(config) { lacp_fallback: mdata ? mdata[1] : DEFAULT_LACP_FALLBACK } end
parse_lacp_mode
scans the member interfaces and returns the configured lacp mode. The lacp mode value must be common across every member in the port channel interface. If no members are configured, the value for lacp_mode will be set using DEFAULT_LACP_MODE
. The hash returned is intended to be merged into the interface resource hash
@api private
@param name [String] The name of the portchannel interface to extract
the members from in order to get the configured lacp_mode.
@return [Hash<Symbol, Object>] Returns the resource hash attribute.
# File lib/rbeapi/api/interfaces.rb, line 882 def parse_lacp_mode(name) members = parse_members(name)[:members] return { lacp_mode: DEFAULT_LACP_MODE } unless members config = get_block("interface #{members.first}") mdata = /channel-group \d+ mode (\w+)/.match(config) { lacp_mode: mdata ? mdata[1] : DEFAULT_LACP_MODE } end
parse_lacp_timeout
scans the interface config block and returns the value of the lacp fallback timeout value. The value is expected to be found in the interface configuration block. The hash returned is intended to be merged into the interface resource hash.
@api private
@param config [String] The interface configuration block to extract
the lacp timeout value from.
@return [Hash<Symbol, Object>] Returns the resource hash attribute.
# File lib/rbeapi/api/interfaces.rb, line 941 def parse_lacp_timeout(config) mdata = /lacp fallback timeout (\d+)$/.match(config) return { lacp_timeout: [] } unless defined? mdata[1] { lacp_timeout: mdata[1] } end
parse_members
scans the nodes running config and returns all of the Ethernet members for the port-channel interface specified. If the port-channel interface has no members configured, then this method will assign an empty array as the value for members. The hash returned is intended to be merged into the interface resource hash.
@api private
@param name [String] The name of the portchannel interface to extract
the members for.
@return [Hash<Symbol, Object>] Returns the resource hash attribute.
# File lib/rbeapi/api/interfaces.rb, line 860 def parse_members(name) grpid = name.scan(/(?<=Port-Channel)\d+/)[0] command = "show port-channel #{grpid} all-ports" config = node.enable(command, encoding: 'text') values = config.first[:result]['output'].scan(/\bEthernet[^\s]+/).sort { members: values } end
parse_minimum_links
scans the port-channel configuration and returns the value for port-channel minimum-links. If the value is not found in the interface configuration, then DEFAULT_MIN_LINKS
value is used. The hash returned is intended to be merged into the interface resource hash.
@api private
@param config [String] The interface configuration block to extract
the minimum links value from.
@return [Hash<Symbol, Object>] Returns the resource hash attribute.
# File lib/rbeapi/api/interfaces.rb, line 904 def parse_minimum_links(config) mdata = /port-channel min-links (\d+)$/.match(config) { minimum_links: mdata ? mdata[1] : DEFAULT_MIN_LINKS } end