class PuppetX::Eos::Portchannel
The Portchannel
class provides a base class instance for working with logical link aggregation interfaces.
Public Class Methods
Initialize innstance of Portchannel
@param [PuppetX::Eos::Eapi] api An instance of Eapi
@return [PuppetX::Eos::Interface]
# File lib/puppet_x/eos/modules/portchannel.rb, line 50 def initialize(api) @api = api end
Public Instance Methods
Adds a new member interface to the channel group
@param [String] name The name of the port channel to add the interface @param [String] member The name of the interface to add
@return [Boolean] True if the create succeeds otherwise False
# File lib/puppet_x/eos/modules/portchannel.rb, line 147 def add_member(name, member) id = name.match(/\d+/) @api.config(["interface #{member}", "channel-group #{id} mode on"]) == [{}, {}] end
Create a logical port-channel interface
@param [String] name The name of the interface to create
@return [Boolean] True if the create succeeds otherwise False
# File lib/puppet_x/eos/modules/portchannel.rb, line 116 def create(name) @api.config("interface #{name}") == [{}] end
Defaults a logical port-channel interface
@param [String] name The name of the interface to create
@return [Boolean] True if the create succeeds otherwise False
# File lib/puppet_x/eos/modules/portchannel.rb, line 136 def default(name) @api.config("default interface #{name}") == [{}] end
Deletes a logical port-channel interface
@param [String] name The name of the interface to create
@return [Boolean] True if the create succeeds otherwise False
# File lib/puppet_x/eos/modules/portchannel.rb, line 126 def delete(name) @api.config("no interface #{name}") == [{}] end
Retrievess a port channel interface from the running-configuration
Example
{ "name": <String>, "lacp_mode": [active, passive, off], "members": [Array], "lacp_fallback": [static, individual], "lacp_timeout": <0-900> }
@param [String] name The name of the port-channel interface
@return [Hash] A hash of the port channel attributes and properties
# File lib/puppet_x/eos/modules/portchannel.rb, line 69 def get(name) members = get_members name result = @api.enable("show interfaces #{name}") interface = result.first['interfaces'] attr_hash = { name: name } attr_hash[:members] = members attr_hash[:lacp_mode] = get_lacp_mode members attr_hash[:lacp_fallback] = get_lacp_fallback interface attr_hash[:lacp_timeout] = interface['fallbackTimeout'] attr_hash end
Retreives the member interfaces for the specified channel group
@param [String] name The name of the port-channel interface to return
members for
@return [Array] An array of interface names that are members of the
specified channel group id
# File lib/puppet_x/eos/modules/portchannel.rb, line 104 def get_members(name) result = @api.enable("show #{name} all-ports", format: 'text') result.first['output'].scan(/Ethernet\d+/) end
Retrieves all logical port-channel interfaces from the running config
@return [Array] an array of port-channel attribute hashes
# File lib/puppet_x/eos/modules/portchannel.rb, line 86 def getall result = @api.enable('show interfaces') interfaces = result.first['interfaces'] resp = [] interfaces.each do |key, value| resp << get(key) if value['hardware'] == 'portChannel' end resp end
Removes a member interface from the channel group
@param [String] name The name of the port-channel to add the interface @param [String] member The name of the interface to remove
@return [Boolean] True if the create succeeds otherwise False
# File lib/puppet_x/eos/modules/portchannel.rb, line 160 def remove_member(_name, member) @api.config(["interface #{member}", 'no channel-group']) == [{}, {}] end
Configures the lacp fallback value
@param [String] name The name of the interface to configure @param [Hash] opts The configuration parameters for the interface @option opts [string] :value The value to set the value to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# File lib/puppet_x/eos/modules/portchannel.rb, line 213 def set_lacp_fallback(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default port-channel lacp fallback' when false cmds << (value.nil? ? "no port-channel lacp fallback #{value}" : \ "port-channel lacp fallback #{value}") end @api.config(cmds) == [{}, {}] end
Configures the lacp mode for the interface
@param [String] name The name of the port-channel interface @param [String] mode The LACP mode to configure
@return [Boolean] True if the create succeeds otherwise False
# File lib/puppet_x/eos/modules/portchannel.rb, line 187 def set_lacp_mode(name, mode) id = name.match(/\d+/) members = get_members name commands = [] config = [] members.each do |member| commands << "interface #{member}" << 'no channel-group' config << "interface #{member}" << "channel-group #{id} mode #{mode}" end config.unshift(*commands) result = @api.config(config) config.size == result.size end
Configures the lacp fallback timeout value
@param [String] name The name of the interface to configure @param [Hash] opts The configuration parameters for the interface @option opts [string] :value The value to set the timeout to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# File lib/puppet_x/eos/modules/portchannel.rb, line 237 def set_lacp_timeout(name, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["interface #{name}"] case default when true cmds << 'default port-channel lacp fallback timeout' when false cmds << (value.nil? ? 'no port-channel lacp fallback timeout' : \ "port-channel lacp fallback timeout #{value}") end @api.config(cmds) == [{}, {}] end
Configures the member interfaces for the port-channel interface
@param [String] name The name of the port-channel to assign the
the members to
@param [Array] members The array of members to add to the port-channel
# File lib/puppet_x/eos/modules/portchannel.rb, line 170 def set_members(name, members) current = get_members(name) (current - members).each do |member| remove_member(name, member) end (members - current).each do |member| add_member(name, member) end end
Private Instance Methods
# File lib/puppet_x/eos/modules/portchannel.rb, line 264 def get_lacp_fallback(attr_hash) if attr_hash['fallbackEnabled'] case attr_hash['fallbackEnabledType'] when 'fallbackStatic' fallback = 'static' when 'fallbackIndividual' fallback = 'individual' end end fallback || '' end
# File lib/puppet_x/eos/modules/portchannel.rb, line 254 def get_lacp_mode(members) return '' if members.empty? name = members.first result = @api.enable("show running-config interfaces #{name}", format: 'text') m = /channel-group\s\d+\smode\s(?<lacp>.*)/ .match(result.first['output']) m['lacp'] end