Class: Cisco::PortChannelGlobal

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

Overview

node_utils class for portchannel_global

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show

Constructor Details

#initialize(name) ⇒ PortChannelGlobal

Returns a new instance of PortChannelGlobal.



24
25
26
27
28
# File 'lib/cisco_node_utils/portchannel_global.rb', line 24

def initialize(name)
  fail TypeError unless name.is_a?(String)
  fail ArgumentError unless name == 'default'
  @name = name.downcase
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/cisco_node_utils/portchannel_global.rb', line 22

def name
  @name
end

Class Method Details

.globalsObject



30
31
32
# File 'lib/cisco_node_utils/portchannel_global.rb', line 30

def self.globals
  { 'default' => PortChannelGlobal.new('default') }
end

Instance Method Details

#_parse_asymmetric_params(hash, params, line) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/cisco_node_utils/portchannel_global.rb', line 247

def _parse_asymmetric_params(hash, params, line)
  bselect = params[0]
  bhash = params[1]
  # asymmetric keyword does not show up if it is false
  asym = (line.include? 'asymmetric') ? true : false
  ri = params.index('rotate')
  rotate = params[ri + 1].to_i
  hash[:bundle_select] = bselect
  hash[:bundle_hash] = bhash
  hash[:asymmetric] = asym
  hash[:rotate] = rotate
  hash
end

#_parse_ethernet_params(hash, params) ⇒ Object

on n6k, the bundle hash and bundle select are merged into one and so we need to break them apart, also they are called source and destination instead of src and dst as in other devices, so we convert them



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/cisco_node_utils/portchannel_global.rb', line 219

def _parse_ethernet_params(hash, params)
  hash_poly = params[2]
  # hash_poly is not shown on the running config
  # if it is default under some circumstatnces
  hash_poly = hash_poly.nil? ? 'CRC10b' : hash_poly
  select_hash = params[1]
  lparams = select_hash.split('-')
  if lparams[0].downcase == 'destination'
    bselect = 'dst'
    bhash = lparams[1]
  else
    if select_hash.include? '-dest-'
      bselect = 'src-dst'
      bhash = lparams[2]
      # there are bundles hashes like ip-only and
      # port-only specific to src-dst
      bhash += '-only' if select_hash.include? 'only'
    else
      bselect = 'src'
      bhash = lparams[1]
    end
  end
  hash[:bundle_select] = bselect
  hash[:bundle_hash] = bhash
  hash[:hash_poly] = hash_poly
  hash
end

#_parse_symmetry_params(hash, params, line) ⇒ Object



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/cisco_node_utils/portchannel_global.rb', line 261

def _parse_symmetry_params(hash, params, line)
  bselect = params[0]
  bhash = params[1]
  ri = params.index('rotate')
  rotate = params[ri + 1].to_i
  # concatenation and symmetry keywords do not show up if false
  concat = (line.include? 'concatenation') ? true : false
  sym = (line.include? 'symmetric') ? true : false
  hash[:bundle_select] = bselect
  hash[:bundle_hash] = bhash
  hash[:symmetry] = sym
  hash[:rotate] = rotate
  hash[:concatenation] = concat
  hash
end

#asymmetricObject



119
120
121
# File 'lib/cisco_node_utils/portchannel_global.rb', line 119

def asymmetric
  port_channel_load_balance[:asymmetric]
end

#bundle_hashObject



128
129
130
# File 'lib/cisco_node_utils/portchannel_global.rb', line 128

def bundle_hash
  port_channel_load_balance[:bundle_hash]
end

#bundle_selectObject



137
138
139
# File 'lib/cisco_node_utils/portchannel_global.rb', line 137

def bundle_select
  port_channel_load_balance[:bundle_select]
end

#concatenationObject



146
147
148
# File 'lib/cisco_node_utils/portchannel_global.rb', line 146

def concatenation
  port_channel_load_balance[:concatenation]
end

#default_asymmetricObject



123
124
125
126
# File 'lib/cisco_node_utils/portchannel_global.rb', line 123

def default_asymmetric
  config_get_default('portchannel_global',
                     'asymmetric')
end

#default_bundle_hashObject



132
133
134
135
# File 'lib/cisco_node_utils/portchannel_global.rb', line 132

def default_bundle_hash
  config_get_default('portchannel_global',
                     'bundle_hash')
end

#default_bundle_selectObject



141
142
143
144
# File 'lib/cisco_node_utils/portchannel_global.rb', line 141

def default_bundle_select
  config_get_default('portchannel_global',
                     'bundle_select')
end

#default_concatenationObject



150
151
152
153
# File 'lib/cisco_node_utils/portchannel_global.rb', line 150

def default_concatenation
  config_get_default('portchannel_global',
                     'concatenation')
end

#default_hash_distributionObject



49
50
51
# File 'lib/cisco_node_utils/portchannel_global.rb', line 49

def default_hash_distribution
  config_get_default('portchannel_global', 'hash_distribution')
end

#default_hash_polyObject



159
160
161
162
# File 'lib/cisco_node_utils/portchannel_global.rb', line 159

def default_hash_poly
  config_get_default('portchannel_global',
                     'hash_poly')
end

#default_load_deferObject



63
64
65
# File 'lib/cisco_node_utils/portchannel_global.rb', line 63

def default_load_defer
  config_get_default('portchannel_global', 'load_defer')
end

#default_resilientObject



79
80
81
# File 'lib/cisco_node_utils/portchannel_global.rb', line 79

def default_resilient
  config_get_default('portchannel_global', 'resilient')
end

#default_rotateObject



168
169
170
171
# File 'lib/cisco_node_utils/portchannel_global.rb', line 168

def default_rotate
  config_get_default('portchannel_global',
                     'rotate')
end

#default_symmetryObject



177
178
179
180
# File 'lib/cisco_node_utils/portchannel_global.rb', line 177

def default_symmetry
  config_get_default('portchannel_global',
                     'symmetry')
end

#hash_distributionObject

PROPERTIES #



38
39
40
# File 'lib/cisco_node_utils/portchannel_global.rb', line 38

def hash_distribution
  config_get('portchannel_global', 'hash_distribution')
end

#hash_distribution=(val) ⇒ Object



42
43
44
45
46
47
# File 'lib/cisco_node_utils/portchannel_global.rb', line 42

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

#hash_polyObject



155
156
157
# File 'lib/cisco_node_utils/portchannel_global.rb', line 155

def hash_poly
  port_channel_load_balance[:hash_poly]
end

#load_deferObject



53
54
55
# File 'lib/cisco_node_utils/portchannel_global.rb', line 53

def load_defer
  config_get('portchannel_global', 'load_defer')
end

#load_defer=(val) ⇒ Object



57
58
59
60
61
# File 'lib/cisco_node_utils/portchannel_global.rb', line 57

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

#port_channel_load_balanceObject

port-channel load-balance is a complicated command and this has so many forms in the same device and in different devices. For ex: port-channel load-balance src-dst ip rotate 4 concatenation symmetric port-channel load-balance resilient port-channel load-balance ethernet destination-mac CRC10c port-channel load-balance ethernet source-ip port-channel load-balance dst ip-l4port rotate 4 asymmetric port-channel load-balance dst ip-l4port-vlan module 9 port-channel load-balance hash-modulo we need to eliminate all the clutter and get the correct line of config first and after that get index of each property and get the property value because some properties may or may not be present always. This method returns a hash



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cisco_node_utils/portchannel_global.rb', line 99

def port_channel_load_balance
  lb = config_get('portchannel_global',
                  'port_channel_load_balance')
  hash = {}
  lb.each do |line|
    next if line[/(internal|resilient|module|fex|hash)/]
    params = line.split
    lb_type = config_get('portchannel_global', 'load_balance_type')
    case lb_type.to_sym
    when :ethernet # n6k
      _parse_ethernet_params(hash, params)
    when :asymmetric # n7k
      _parse_asymmetric_params(hash, params, line)
    when :symmetry # n9k
      _parse_symmetry_params(hash, params, line)
    end
  end
  hash
end

#port_channel_load_balance=(bselect, bhash, hpoly, asy, sy, conc, rot) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/cisco_node_utils/portchannel_global.rb', line 182

def port_channel_load_balance=(bselect, bhash, hpoly, asy, sy, conc, rot)
  lb_type = config_get('portchannel_global', 'load_balance_type')
  case lb_type.to_sym
  when :ethernet # n6k
    if bselect == 'src'
      sel = 'source'
    elsif bselect == 'dst'
      sel = 'destination'
    else
      sel = 'source-dest'
    end
    sel_hash = sel + '-' + bhash
    # port-channel load-balance ethernet destination-mac CRC10c
    config_set('portchannel_global', 'port_channel_load_balance',
               'ethernet', sel_hash, hpoly, '', '', '')
  when :asymmetric # n7k
    asym = (asy == true) ? 'asymmetric' : ''
    # port-channel load-balance dst ip-l4port rotate 4 asymmetric
    config_set('portchannel_global', 'port_channel_load_balance',
               bselect, bhash, 'rotate', rot.to_s, asym, '')
  when :symmetry # n9k
    sym = sy ? 'symmetric' : ''
    concat = conc ? 'concatenation' : ''
    rot_str = rot.zero? ? '' : 'rotate'
    rot_val = rot.zero? ? '' : rot.to_s
    # port-channel load-balance src-dst ip rotate 4 concatenation symmetric
    config_set('portchannel_global', 'port_channel_load_balance',
               bselect, bhash, rot_str, rot_val, concat, sym)
  end
rescue Cisco::CliError => e
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end

#resilientObject



67
68
69
# File 'lib/cisco_node_utils/portchannel_global.rb', line 67

def resilient
  config_get('portchannel_global', 'resilient')
end

#resilient=(state) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/cisco_node_utils/portchannel_global.rb', line 71

def resilient=(state)
  fail TypeError unless state == true || state == false
  no_cmd = (state ? '' : 'no')
  config_set('portchannel_global', 'resilient', no_cmd)
rescue Cisco::CliError => e
  raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end

#rotateObject



164
165
166
# File 'lib/cisco_node_utils/portchannel_global.rb', line 164

def rotate
  port_channel_load_balance[:rotate]
end

#symmetryObject



173
174
175
# File 'lib/cisco_node_utils/portchannel_global.rb', line 173

def symmetry
  port_channel_load_balance[:symmetry]
end