Class: Cisco::InterfacePortChannel

Inherits:
NodeUtil
  • Object
show all
Defined in:
lib/cisco_node_utils/interface_portchannel.rb

Overview

InterfacePortChannel - node utility class for port channel config management

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

#client, client, #config_get, config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, node, #node, platform, #platform, supports?, #supports?

Constructor Details

#initialize(name, instantiate = true) ⇒ InterfacePortChannel


26
27
28
29
30
31
32
33
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 26

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


24
25
26
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 24

def name
  @name
end

Class Method Details

.interfacesObject


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 39

def self.interfaces
  hash = {}
  intf_list = config_get('interface_portchannel', '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

Instance Method Details

PROPERTIES #


64
65
66
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 64

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

#bfd_per_link=(state) ⇒ Object


68
69
70
71
72
73
74
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 68

def bfd_per_link=(state)
  return if state == bfd_per_link
  no_cmd = (state ? '' : 'no')
  Feature.bfd_enable
  config_set('interface_portchannel',
             'bfd_per_link', @name, no_cmd)
end

#createObject


52
53
54
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 52

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

76
77
78
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 76

def default_bfd_per_link
  config_get_default('interface_portchannel', 'bfd_per_link')
end

#default_lacp_graceful_convergenceObject


90
91
92
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 90

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

#default_lacp_max_bundleObject


102
103
104
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 102

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

114
115
116
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 114

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

#default_lacp_suspend_individualObject


143
144
145
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 143

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

#default_port_hash_distributionObject


162
163
164
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 162

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

#default_port_load_deferObject


176
177
178
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 176

def default_port_load_defer
  config_get_default('interface_portchannel', 'port_load_defer')
end

#destroyObject


56
57
58
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 56

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

#lacp_graceful_convergenceObject


80
81
82
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 80

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

#lacp_graceful_convergence=(state) ⇒ Object


84
85
86
87
88
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 84

def lacp_graceful_convergence=(state)
  no_cmd = (state ? '' : 'no')
  config_set('interface_portchannel',
             'lacp_graceful_convergence', @name, no_cmd)
end

#lacp_max_bundleObject


94
95
96
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 94

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

#lacp_max_bundle=(val) ⇒ Object


98
99
100
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 98

def lacp_max_bundle=(val)
  config_set('interface_portchannel', 'lacp_max_bundle', @name, val)
end

106
107
108
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 106

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

#lacp_min_links=(val) ⇒ Object


110
111
112
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 110

def lacp_min_links=(val)
  config_set('interface_portchannel', 'lacp_min_links', @name, val)
end

#lacp_suspend_individualObject


122
123
124
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 122

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

#lacp_suspend_individual=(state) ⇒ Object


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 126

def lacp_suspend_individual=(state)
  no_cmd = (state ? '' : 'no')
  # This property can only be set if the port-channel is shutdown on
  # some platforms.
  # This setter will:
  # 1) Query the current state of the port-channel interface.
  # 2) Shutdown the port-channel interface if needed.
  # 3) Set the lacp_suspend_individual property.
  # 4) Restore the original state of the port-channel interface if needed.
  int = Interface.new(@name, false)
  current_state = int.shutdown
  int.shutdown = true if lacp_suspend_shut_needed? && !current_state
  config_set('interface_portchannel',
             'lacp_suspend_individual', @name, no_cmd)
  int.shutdown = current_state unless current_state == int.shutdown
end

#lacp_suspend_shut_needed?Boolean


118
119
120
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 118

def lacp_suspend_shut_needed?
  config_get('interface_portchannel', 'lacp_suspend_shut_needed')
end

#port_hash_distributionObject


147
148
149
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 147

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

#port_hash_distribution=(val) ⇒ Object


151
152
153
154
155
156
157
158
159
160
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 151

def port_hash_distribution=(val)
  if val
    state = ''
  else
    state = 'no'
    val = ''
  end
  config_set('interface_portchannel',
             'port_hash_distribution', @name, state, val)
end

#port_load_deferObject


166
167
168
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 166

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

#port_load_defer=(state) ⇒ Object


170
171
172
173
174
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 170

def port_load_defer=(state)
  no_cmd = (state ? '' : 'no')
  config_set('interface_portchannel',
             'port_load_defer', @name, no_cmd)
end

#to_sObject


35
36
37
# File 'lib/cisco_node_utils/interface_portchannel.rb', line 35

def to_s
  "interface_port_channel #{name}"
end