Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Changelog
* pim (@smigopal)
* pim_group_list (@smigopal)
* pim_rp_address (@smigopal)
* Port Channel
* interface_portchannel (@saichint)
* portchannel_global (@saichint)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be consistent on these names - please choose port_channel or portchannel.

* SNMP
* snmpnotification (@tphoney)
* VDC
Expand Down
54 changes: 54 additions & 0 deletions lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# interface_portchannel
---
_template:
config_set: ["interface %s"]
config_get_token: '/^interface %s$/i'
config_get: "show running interface all"

create:
config_set: "interface %s"

destroy:
config_set: "no interface %s"

lacp_graceful_convergence:
kind: boolean
auto_default: false
config_get_token_append: ['/^lacp graceful.convergence$/']
config_set_append: ["%s lacp graceful-convergence"]
default_value: true

lacp_max_bundle:
kind: int
config_get_token_append: ['/^lacp max.bundle (\d+)$/']
config_set_append: ["lacp max-bundle %s"]
/N(3|9)/:
default_value: 32
else:
default_value: 16

lacp_min_links:
kind: int
config_get_token_append: ['/^lacp min.links (\d+)$/']
config_set_append: ["lacp min-links %s"]
default_value: 1

lacp_suspend_individual:
kind: boolean
auto_default: false
config_get_token_append: ['/^lacp suspend.individual$/']
config_set_append: ["%s lacp suspend-individual"]
default_value: true

port_hash_distribution:
_exclude: [/N6/, /N5/]
config_get_token_append: ['/^port-channel port hash.distribution (.*)$/']
config_set: ["terminal dont-ask", "interface %s", "%s port-channel port hash-distribution %s", "end"]
default_value: false

port_load_defer:
_exclude: [/N6/, /N5/]
kind: boolean
config_get_token_append: ['/^port-channel port load.defer$/']
config_set_append: ["%s port-channel port load-defer"]
default_value: false
69 changes: 69 additions & 0 deletions lib/cisco_node_utils/cmd_ref/portchannel_global.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# portchannel_global
---
_template:
config_get: "show running all"

asymmetric:
_exclude: [/N6/, /N5/, /N3/, /N9/]
default_value: false

bundle_hash:
/N(5|6|7)/:
default_value: 'ip'
/N(3|9)/:
default_value: 'ip-l4port'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, remove the K's and combine the common stuff:

bundle_hash:
  /N(5|6|7)/:
    default_value: 'ip'
  /N(3|9)/:
    default_value: 'ip-l4port'

ditto for the rest of this file


bundle_select:
default_value: 'src-dst'

concatenation:
_exclude: [/N7/, /N5/, /N6/]
default_value: false

hash_distribution:
_exclude: [/N6/, /N5/, /N3/, /N9/]
config_get_token: ['/^port.channel hash.distribution (.*)$/']
config_set: ["terminal dont-ask", "port-channel hash-distribution %s", "end"]
default_value: 'adaptive'

hash_poly:
_exclude: [/N7/, /N3/, /N9/]
default_value: 'CRC10b'

load_balance_type:
kind: string
/N(5|6)/:
default_only: "ethernet"
/N7/:
default_only: "asymmetric"
/N(3|9)/:
default_only: "symmetry"

load_defer:
_exclude: [/N6/, /N5/, /N3/, /N9/]
kind: int
config_get_token: ['/^port.channel load.defer (\d+)$/']
config_set: ["port-channel load-defer %s"]
default_value: 120

port_channel_load_balance:
multiple:
config_get_token: '/^port-channel load-balance (.*)$/'
config_set: "port-channel load-balance %s %s %s %s %s %s"

resilient:
_exclude: [/N6/, /N5/, /N7/]
kind: boolean
config_get: "show running-config all"
config_get_token: '/^port-channel load-balance resilient$/'
config_set: "%s port-channel load-balance resilient"
default_value: false

rotate:
_exclude: [/N5/, /N6/]
kind: int
default_value: 0

symmetry:
_exclude: [/N7/, /N3/, /N5/, /N6/]
default_value: false
157 changes: 157 additions & 0 deletions lib/cisco_node_utils/interface_portchannel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# December 2015, Sai Chintalapudi
#
# Copyright (c) 2015 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative 'node_util'
require_relative 'interface'

# Add some interface-specific constants to the Cisco namespace
module Cisco
# InterfacePortChannel - node utility class for port channel config management
class InterfacePortChannel < NodeUtil
attr_reader :name

def initialize(name, instantiate=true)
fail TypeError unless name.is_a?(String)
fail ArgumentError unless name.length > 0
@name = name.downcase
fail ArgumentError unless @name.start_with?('port-channel')

create if instantiate
end

def self.interfaces
hash = {}
intf_list = config_get('interface', 'all_interfaces')
return hash if intf_list.nil?

intf_list.each do |id|
id = id.downcase
next unless id.start_with?('port-channel')
hash[id] = InterfacePortChannel.new(id, false)
end
hash
end

def create
config_set('interface_portchannel', 'create', @name)
end

def destroy
config_set('interface_portchannel', 'destroy', @name)
end

########################################################
# PROPERTIES #
########################################################

def lacp_graceful_convergence
config_get('interface_portchannel', 'lacp_graceful_convergence', @name)
end

def lacp_graceful_convergence=(state)
no_cmd = (state ? '' : 'no')
config_set('interface_portchannel',
'lacp_graceful_convergence', @name, no_cmd)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end

def default_lacp_graceful_convergence
config_get_default('interface_portchannel', 'lacp_graceful_convergence')
end

def lacp_max_bundle
config_get('interface_portchannel', 'lacp_max_bundle', @name)
end

def lacp_max_bundle=(val)
config_set('interface_portchannel', 'lacp_max_bundle', @name, val)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end

def default_lacp_max_bundle
config_get_default('interface_portchannel', 'lacp_max_bundle')
end

def lacp_min_links
config_get('interface_portchannel', 'lacp_min_links', @name)
end

def lacp_min_links=(val)
config_set('interface_portchannel', 'lacp_min_links', @name, val)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end

def default_lacp_min_links
config_get_default('interface_portchannel', 'lacp_min_links')
end

def lacp_suspend_individual
config_get('interface_portchannel', 'lacp_suspend_individual', @name)
end

def lacp_suspend_individual=(state)
no_cmd = (state ? '' : 'no')
config_set('interface_portchannel',
'lacp_suspend_individual', @name, no_cmd)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end

def default_lacp_suspend_individual
config_get_default('interface_portchannel', 'lacp_suspend_individual')
end

def port_hash_distribution
config_get('interface_portchannel', 'port_hash_distribution', @name)
end

def port_hash_distribution=(val)
if val
state = ''
else
state = 'no'
val = ''
end
config_set('interface_portchannel',
'port_hash_distribution', @name, state, val)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end

def default_port_hash_distribution
config_get_default('interface_portchannel', 'port_hash_distribution')
end

def port_load_defer
config_get('interface_portchannel', 'port_load_defer', @name)
end

def port_load_defer=(state)
no_cmd = (state ? '' : 'no')
config_set('interface_portchannel',
'port_load_defer', @name, no_cmd)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end

def default_port_load_defer
config_get_default('interface_portchannel', 'port_load_defer')
end
end # Class
end # Module
Loading