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

#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) ⇒ 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


34
35
36
# File 'lib/cisco_node_utils/portchannel_global.rb', line 34

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

Instance Method Details

#_parse_asymmetric_params(hash, params, line) ⇒ Object


306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/cisco_node_utils/portchannel_global.rb', line 306

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

N5k/N6k: The bundle hash and bundle select are merged into one output; also note that the field names are source & destination instead of src & dst as in other devices.


272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/cisco_node_utils/portchannel_global.rb', line 272

def _parse_ethernet_params(hash, params)
  hash_poly = params[2]

  # Depending on the chipset, hash_poly may have have a different
  # default value within the same platform family (this is done to
  # avoid polarization) but there is currently no command available
  # to dynamically determine the default state. As a result the
  # getter simply hard-codes a default value which means it may
  # encounter occasional idempotence issues.
  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_no_hash_params(hash, params) ⇒ Object


320
321
322
323
324
325
326
327
328
329
# File 'lib/cisco_node_utils/portchannel_global.rb', line 320

def _parse_no_hash_params(hash, params)
  bselect = params[0]
  bhash = params[1]
  ri = params.index('rotate')
  rotate = params[ri + 1].to_i
  hash[:bundle_select] = bselect
  hash[:bundle_hash] = bhash
  hash[:rotate] = rotate
  hash
end

#_parse_no_rotate_params(hash, params, line) ⇒ Object

N3k: The bundle hash and bundle select are merged into one output; also note that the field names are source & destination instead of src & dst as in other devices.


236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/cisco_node_utils/portchannel_global.rb', line 236

def _parse_no_rotate_params(hash, params, line)
  sym = (line.include? 'symmetric') ? true : false

  select_hash = params[1]
  lparams = select_hash.split('-')
  if lparams[0].downcase == 'destination'
    bselect = 'dst'
    bhash = lparams[1]
    # there are bundles hashes like ip-gre which
    # need extra processing
    bhash += '-gre' if select_hash.include? 'gre'
  else
    if select_hash.include? '-dest-'
      bselect = 'src-dst'
      bhash = lparams[2]
      bhash += '-gre' if select_hash.include? 'gre'
      # 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]
      # there are bundles hashes like ip-gre which
      # need extra processing
      bhash += '-gre' if select_hash.include? 'gre'
    end
  end
  hash[:bundle_select] = bselect
  hash[:bundle_hash] = bhash
  hash[:symmetry] = sym
  hash
end

#_parse_symmetry_params(hash, params, line) ⇒ Object


331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/cisco_node_utils/portchannel_global.rb', line 331

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


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

def asymmetric
  port_channel_load_balance[:asymmetric]
end

#bundle_hashObject


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

def bundle_hash
  port_channel_load_balance[:bundle_hash]
end

#bundle_selectObject


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

def bundle_select
  port_channel_load_balance[:bundle_select]
end

#concatenationObject


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

def concatenation
  port_channel_load_balance[:concatenation]
end

#default_asymmetricObject


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

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

#default_bundle_hashObject


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

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

#default_bundle_selectObject


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

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

#default_concatenationObject


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

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

#default_hash_distributionObject


55
56
57
# File 'lib/cisco_node_utils/portchannel_global.rb', line 55

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

#default_load_deferObject


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

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

#default_resilientObject


81
82
83
# File 'lib/cisco_node_utils/portchannel_global.rb', line 81

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

#default_rotateObject


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

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

#default_symmetryObject


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

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

#hash_distributionObject


46
47
48
# File 'lib/cisco_node_utils/portchannel_global.rb', line 46

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

#hash_distribution=(val) ⇒ Object


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

def hash_distribution=(val)
  config_set('portchannel_global',
             'hash_distribution', val)
end

#hash_polyObject


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

def hash_poly
  port_channel_load_balance[:hash_poly]
end

#load_balance_typeObject

PROPERTIES #


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

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

#load_deferObject


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

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

#load_defer=(val) ⇒ Object


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

def load_defer=(val)
  config_set('portchannel_global', 'load_defer', val)
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


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cisco_node_utils/portchannel_global.rb', line 101

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 :no_rotate # n3k
      _parse_no_rotate_params(hash, params, line)
    when :ethernet # n6k
      _parse_ethernet_params(hash, params)
    when :asymmetric # n7k
      _parse_asymmetric_params(hash, params, line)
    when :no_hash # n9k-f or n3k-f
      _parse_no_hash_params(hash, params)
    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


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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/cisco_node_utils/portchannel_global.rb', line 183

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 :no_rotate # n3k
    sym = sy ? 'symmetric' : ''
    if bselect == 'src'
      sel = 'source'
    elsif bselect == 'dst'
      sel = 'destination'
    else
      sel = 'source-dest'
    end
    sel_hash = sel + '-' + bhash
    # port-channel load-balance ethernet source-dest-ip symmetric
    config_set('portchannel_global', 'port_channel_load_balance',
               'ethernet', sel_hash, 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 :no_hash # n9k-f or n3k-f
    # port-channel load-balance dst ip-l4port rotate 4
    rot_str = rot.zero? ? '' : 'rotate'
    rot_val = rot.zero? ? '' : rot.to_s
    config_set('portchannel_global', 'port_channel_load_balance',
               bselect, bhash, rot_str, rot_val, '', '')
  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
end

#resilientObject


71
72
73
# File 'lib/cisco_node_utils/portchannel_global.rb', line 71

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

#resilient=(state) ⇒ Object


75
76
77
78
79
# File 'lib/cisco_node_utils/portchannel_global.rb', line 75

def resilient=(state)
  fail TypeError unless state == true || state == false
  no_cmd = (state ? '' : 'no')
  config_set('portchannel_global', 'resilient', no_cmd)
end

#rotateObject


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

def rotate
  port_channel_load_balance[:rotate]
end

#symmetryObject


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

def symmetry
  port_channel_load_balance[:symmetry]
end

#to_sObject


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

def to_s
  "portchannel_global #{name}"
end