Class: Cisco::InterfaceDeprecated

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

Overview

Interface - node utility class for general interface config management

Direct Known Subclasses

Interface

Constant Summary collapse

PVLAN_PROPERTY =
{
  host_promisc:  'switchport_mode_private_vlan_host_promiscous',
  allow_vlan:    'switchport_private_vlan_trunk_allowed_vlan',
  trunk_assoc:   'switchport_private_vlan_association_trunk',
  mapping_trunk: 'switchport_private_vlan_mapping_trunk',
  vlan_mapping:  'private_vlan_mapping',
}

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?

Instance Method Details

#configure_private_vlan_host_property(property, should_list_new, is_list_new, pr_vlan) ⇒ Object


169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 169

def configure_private_vlan_host_property(property, should_list_new,
                                         is_list_new, pr_vlan)
  delta_hash = Utils.delta_add_remove(should_list_new, is_list_new)
  [:add, :remove].each do |action|
    delta_hash[action].each do |vlans|
      state = (action == :add) ? '' : 'no'
      oper = (action == :add) ? 'add' : 'remove'
      if property[/(host_promisc|mapping_trunk)/]

        result = config_set('DEPRECATED', PVLAN_PROPERTY[property],
                            name: @name, state: state,
                            vlan_pr: pr_vlan, vlans: vlans)
        @match_found = true
      end
      if property[/allow_vlan/]
        result = config_set('DEPRECATED',
                            PVLAN_PROPERTY[property],
                            name: @name, state: '',
                            oper: oper, vlans: vlans)
      end
      if property[/vlan_mapping/]
        result = config_set('DEPRECATED',
                            PVLAN_PROPERTY[property],
                            name: @name, state: state,
                            vlans: vlans)
      end
      cli_error_check(result)
    end
  end
end

#configure_private_vlan_trunk_property(property, should_list_new, is_list, pr_vlan) ⇒ Object


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
232
233
234
235
236
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 200

def configure_private_vlan_trunk_property(property, should_list_new,
                                          is_list, pr_vlan)
  case property
  when :trunk_assoc
    is_list.each do |vlans|
      vlans = vlans.split(' ')
      if vlans[0].eql? should_list_new[0]
        config_set('DEPRECATED',
                   'switchport_private_vlan_association_trunk',
                   name: @name, state: 'no',
                   vlan_pr: pr_vlan, vlan: vlans[1])
        break
      else
        next
      end
    end
    result = config_set('DEPRECATED', PVLAN_PROPERTY[property], name: @name,
                        state: '', vlan_pr: should_list_new[0],
                        vlan: should_list_new[1])
  when :mapping_trunk
    @match_found = false
    is_list.each do |vlans|
      vlans = vlans.split(' ')
      interf_vlan_list_delta(:mapping_trunk, vlans,
                             should_list_new)
      if @match_found
        break
      else
        next
      end
    end
    result = config_set('DEPRECATED', PVLAN_PROPERTY[property], name: @name,
                        state: '', vlan_pr: should_list_new[0],
                        vlans: should_list_new[1])
  end
  cli_error_check(result)
end

#default_private_vlan_mappingObject


513
514
515
516
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 513

def default_private_vlan_mapping
  config_get_default('DEPRECATED',
                     'private_vlan_mapping')
end

#default_switchport_mode_private_vlan_hostObject


92
93
94
95
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 92

def default_switchport_mode_private_vlan_host
  config_get_default('DEPRECATED',
                     'switchport_mode_private_vlan_host')
end

#default_switchport_mode_private_vlan_host_associationObject


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

def default_switchport_mode_private_vlan_host_association
  config_get_default('DEPRECATED',
                     'switchport_mode_private_vlan_host_association')
end

#default_switchport_mode_private_vlan_host_promiscObject


297
298
299
300
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 297

def default_switchport_mode_private_vlan_host_promisc
  config_get_default('DEPRECATED',
                     'switchport_mode_private_vlan_host_promiscous')
end

#default_switchport_mode_private_vlan_trunk_promiscuousObject


330
331
332
333
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 330

def default_switchport_mode_private_vlan_trunk_promiscuous
  config_get_default('DEPRECATED',
                     'switchport_mode_private_vlan_trunk_promiscuous')
end

#default_switchport_mode_private_vlan_trunk_secondaryObject


361
362
363
364
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 361

def default_switchport_mode_private_vlan_trunk_secondary
  config_get_default('DEPRECATED',
                     'switchport_mode_private_vlan_trunk_secondary')
end

#default_switchport_private_vlan_association_trunkObject


456
457
458
459
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 456

def default_switchport_private_vlan_association_trunk
  config_get_default('DEPRECATED',
                     'switchport_private_vlan_association_trunk')
end

#default_switchport_private_vlan_mapping_trunkObject


483
484
485
486
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 483

def default_switchport_private_vlan_mapping_trunk
  config_get_default('DEPRECATED',
                     'switchport_private_vlan_mapping_trunk')
end

#default_switchport_private_vlan_trunk_allowed_vlanObject


401
402
403
404
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 401

def default_switchport_private_vlan_trunk_allowed_vlan
  config_get_default('DEPRECATED',
                     'switchport_private_vlan_trunk_allowed_vlan')
end

#default_switchport_private_vlan_trunk_native_vlanObject


429
430
431
432
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 429

def default_switchport_private_vlan_trunk_native_vlan
  config_get_default('DEPRECATED',
                     'switchport_private_vlan_trunk_native_vlan')
end

#deprecation_warning(method, new_prop = nil) ⇒ Object


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

def deprecation_warning(method, new_prop=nil)
  if new_prop.nil?
    new_prop = ''
  else
    new_prop = "The new property name is '#{new_prop}'"
  end

  warn "
  #########################################################################
   WARNING: Method '#{method.to_s.delete('=')}'
   is deprecated and should not be used.
   #{new_prop}
  #########################################################################
  "
end

#interf_vlan_list_delta(property, is_list, should_list) ⇒ Object


interf_vlan_list_delta is a helper function for the private_vlan_mapping property. It walks the delta hash and adds/removes each target private vlan.


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
268
269
270
271
272
273
274
275
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 243

def interf_vlan_list_delta(property, is_list, should_list)
  pr_vlan = should_list[0]
  if is_list[0].eql? should_list[0]
    should_list = should_list[1].split(',')
    is_list = is_list[1].split(',')

    should_list_new = prepare_array(should_list)
    is_list_new = prepare_array(is_list)
    configure_private_vlan_host_property(property, should_list_new,
                                         is_list_new, pr_vlan)
  else
    case property
    when :mapping_trunk
      return
    end
    # If primary vlan are different we can simply replacing the all
    # config
    if should_list == default_switchport_mode_private_vlan_host_promisc
      result = config_set('DEPRECATED',
                          'switchport_mode_private_vlan_host_promiscous',
                          name: @name, state: 'no',
                          vlan_pr: '', vlans: '')

    else
      result = config_set('DEPRECATED',
                          'switchport_mode_private_vlan_host_promiscous',
                          name: @name, state: '',
                          vlan_pr: pr_vlan, vlans: should_list[1])

    end
    cli_error_check(result)
  end
end

#prepare_array(is_list) ⇒ Object

This api is used by private vlan to prepare the input to the setter method. The input can be in the following formats for vlans: 10-12,14. Prepare_array api is transforming this input into a flat array. In the example above the returned array will be 10, 11, 12, 13. Prepare array is first splitting the input on ',' and the than expanding the vlan range element like 10-12 into a flat array. The final result will be a flat array. This way we can later used the lib utility to check the delta from the input vlan value and the vlan configured to apply the right config.


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 141

def prepare_array(is_list)
  new_list = []
  is_list.each do |item|
    if item.include?(',')
      new_list.push(item.split(','))
    else
      new_list.push(item)
    end
  end
  new_list.flatten!
  new_list.sort!
  new_list.each { |item| item.gsub!('-', '..') }
  is_list_new = []
  new_list.each do |elem|
    if elem.include?('..')
      elema = elem.split('..').map { |d| Integer(d) }
      elema.sort!
      tr = elema[0]..elema[1]
      tr.to_a.each do |item|
        is_list_new.push(item.to_s)
      end
    else
      is_list_new.push(elem)
    end
  end
  is_list_new
end

#private_vlan_mappingObject


488
489
490
491
492
493
494
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 488

def private_vlan_mapping
  match = config_get('DEPRECATED',
                     'private_vlan_mapping',
                     name: @name)
  match[0].delete!(' ') unless match == default_private_vlan_mapping
  match
end

#private_vlan_mapping=(vlans) ⇒ Object


496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 496

def private_vlan_mapping=(vlans)
  deprecation_warning(__method__, 'pvlan_mapping')
  fail TypeError unless vlans.is_a?(Array) || vlans.empty?
  Feature.private_vlan_enable
  feature_vlan_set(true)
  if vlans == default_private_vlan_mapping
    config_set('DEPRECATED', 'private_vlan_mapping',
               name: @name, state: 'no', vlans: '')
  else
    is_list = private_vlan_mapping
    new_is_list = prepare_array(is_list)
    new_vlans = prepare_array(vlans)
    configure_private_vlan_host_property(:vlan_mapping, new_vlans,
                                         new_is_list, '')
  end
end

#switchport_enable_and_mode_private_vlan_host(mode_set) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 55

def switchport_enable_and_mode_private_vlan_host(mode_set)
  deprecation_warning(__method__)
  switchport_enable unless switchport
  if mode_set[/(host|promiscuous)/]
    config_set('DEPRECATED', 'switchport_mode_private_vlan_host',
               name: @name, state: '', mode: IF_SWITCHPORT_MODE[mode_set])
  else
    config_set('DEPRECATED', 'switchport_mode_private_vlan_host',
               name: @name, state: 'no', mode: IF_SWITCHPORT_MODE[mode_set])
  end
end

#switchport_mode_private_vlan_hostObject


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 67

def switchport_mode_private_vlan_host
  return nil if switchport_mode == :disabled
  mode = config_get('DEPRECATED',
                    'switchport_mode_private_vlan_host',
                    name: @name)
  unless mode == default_switchport_mode_private_vlan_host
    mode = IF_SWITCHPORT_MODE.key(mode)
  end
  mode
rescue IndexError
  # Assume this is an interface that doesn't support switchport.
  # Do not raise exception since the providers will prefetch this property
  # regardless of interface type.
  # TODO: this should probably be nil instead
  return default_switchport_mode_private_vlan_host
end

#switchport_mode_private_vlan_host=(mode_set) ⇒ Object


84
85
86
87
88
89
90
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 84

def switchport_mode_private_vlan_host=(mode_set)
  deprecation_warning(__method__, 'switchport_pvlan_host')

  fail ArgumentError unless IF_SWITCHPORT_MODE.keys.include? mode_set
  Feature.private_vlan_enable
  switchport_enable_and_mode_private_vlan_host(mode_set)
end

#switchport_mode_private_vlan_host_associationObject


97
98
99
100
101
102
103
104
105
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 97

def switchport_mode_private_vlan_host_association
  result = config_get('DEPRECATED',
                      'switchport_mode_private_vlan_host_association',
                      name: @name)
  unless result == default_switchport_mode_private_vlan_host_association
    result = result[0].split(' ')
  end
  result
end

#switchport_mode_private_vlan_host_association=(vlans) ⇒ Object


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 107

def switchport_mode_private_vlan_host_association=(vlans)
  deprecation_warning(__method__, 'switchport_pvlan_host_association')
  fail TypeError unless vlans.is_a?(Array) || vlans.empty?
  switchport_enable unless switchport
  Feature.private_vlan_enable
  if vlans == default_switchport_mode_private_vlan_host_association
    result = config_set('DEPRECATED',
                        'switchport_mode_private_vlan_host_association',
                        name: @name, state: 'no', vlan_pr: '', vlan_sec: '')

  else
    result = config_set('DEPRECATED',
                        'switchport_mode_private_vlan_host_association',
                        name: @name, state: '',
                        vlan_pr: vlans[0], vlan_sec: vlans[1])

  end
  cli_error_check(result)
end

#switchport_mode_private_vlan_host_promiscObject


277
278
279
280
281
282
283
284
285
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 277

def switchport_mode_private_vlan_host_promisc
  result = config_get('DEPRECATED',
                      'switchport_mode_private_vlan_host_promiscous',
                      name: @name)
  unless result == default_switchport_mode_private_vlan_host_promisc
    result = result[0].split(' ')
  end
  result
end

#switchport_mode_private_vlan_host_promisc=(vlans) ⇒ Object


287
288
289
290
291
292
293
294
295
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 287

def switchport_mode_private_vlan_host_promisc=(vlans)
  deprecation_warning(__method__, 'switchport_pvlan_promiscuous')
  fail TypeError unless vlans.is_a?(Array)
  fail TypeError unless vlans.empty? || vlans.length == 2
  switchport_enable unless switchport
  Feature.private_vlan_enable
  is_list = switchport_mode_private_vlan_host_promisc
  interf_vlan_list_delta(:host_promisc, is_list, vlans)
end

#switchport_mode_private_vlan_trunk_promiscuousObject


302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 302

def switchport_mode_private_vlan_trunk_promiscuous
  return nil if switchport_mode == :disabled
  config_get('DEPRECATED',
             'switchport_mode_private_vlan_trunk_promiscuous',
             name: @name)
rescue IndexError
  # Assume this is an interface that doesn't support switchport.
  # Do not raise exception since the providers will prefetch this property
  # regardless of interface type.
  # TODO: this should probably be nil instead
  return default_switchport_mode_private_vlan_trunk_promiscuous
end

#switchport_mode_private_vlan_trunk_promiscuous=(state) ⇒ Object


315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 315

def switchport_mode_private_vlan_trunk_promiscuous=(state)
  deprecation_warning(__method__, 'switchport_pvlan_trunk_promiscuous')
  Feature.private_vlan_enable
  switchport_enable unless switchport
  if state == default_switchport_mode_private_vlan_trunk_promiscuous
    config_set('DEPRECATED',
               'switchport_mode_private_vlan_trunk_promiscuous',
               name: @name, state: 'no')
  else
    config_set('DEPRECATED',
               'switchport_mode_private_vlan_trunk_promiscuous',
               name: @name, state: '')
  end
end

#switchport_mode_private_vlan_trunk_secondaryObject


335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 335

def switchport_mode_private_vlan_trunk_secondary
  return nil if switchport_mode == :disabled
  config_get('DEPRECATED',
             'switchport_mode_private_vlan_trunk_secondary',
             name: @name)
rescue IndexError
  # Assume this is an interface that doesn't support switchport.
  # Do not raise exception since the providers will prefetch this property
  # regardless of interface type.
  # TODO: this should probably be nil instead
  return default_switchport_mode_private_vlan_trunk_secondary
end

#switchport_mode_private_vlan_trunk_secondary=(state) ⇒ Object


348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 348

def switchport_mode_private_vlan_trunk_secondary=(state)
  deprecation_warning(__method__, 'switchport_pvlan_trunk_secondary')
  Feature.private_vlan_enable
  switchport_enable unless switchport
  if state == default_switchport_mode_private_vlan_trunk_secondary
    config_set('DEPRECATED', 'switchport_mode_private_vlan_trunk_secondary',
               name: @name, state: 'no')
  else
    config_set('DEPRECATED', 'switchport_mode_private_vlan_trunk_secondary',
               name: @name, state: '')
  end
end

#switchport_private_vlan_association_trunkObject


434
435
436
437
438
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 434

def switchport_private_vlan_association_trunk
  config_get('DEPRECATED',
             'switchport_private_vlan_association_trunk',
             name: @name)
end

#switchport_private_vlan_association_trunk=(vlans) ⇒ Object


440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 440

def switchport_private_vlan_association_trunk=(vlans)
  deprecation_warning(__method__, 'switchport_pvlan_trunk_association')
  fail TypeError unless vlans.is_a?(Array) || vlans.empty?
  Feature.private_vlan_enable
  switchport_enable unless switchport
  if vlans == default_switchport_private_vlan_association_trunk
    config_set('DEPRECATED', 'switchport_private_vlan_association_trunk',
               name: @name, state: 'no',
               vlan_pr: '', vlan: '')
  else
    is_list = switchport_private_vlan_association_trunk
    configure_private_vlan_trunk_property(:trunk_assoc, vlans,
                                          is_list, vlans[0])
  end
end

#switchport_private_vlan_mapping_trunkObject


461
462
463
464
465
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 461

def switchport_private_vlan_mapping_trunk
  config_get('DEPRECATED',
             'switchport_private_vlan_mapping_trunk',
             name: @name)
end

#switchport_private_vlan_mapping_trunk=(vlans) ⇒ Object


467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 467

def switchport_private_vlan_mapping_trunk=(vlans)
  deprecation_warning(__method__, 'switchport_pvlan_mapping_trunk')
  fail TypeError unless vlans.is_a?(Array) || vlans.empty?
  Feature.private_vlan_enable
  switchport_enable unless switchport
  if vlans == default_switchport_private_vlan_mapping_trunk
    config_set('DEPRECATED', 'switchport_private_vlan_mapping_trunk',
               name: @name, state: 'no',
               vlan_pr: '', vlans: '')
  else
    is_list = switchport_private_vlan_mapping_trunk
    configure_private_vlan_trunk_property(:mapping_trunk, vlans,
                                          is_list, vlans[0])
  end
end

#switchport_private_vlan_trunk_allowed_vlanObject


366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 366

def switchport_private_vlan_trunk_allowed_vlan
  return nil if switchport_mode == :disabled
  result = config_get('DEPRECATED',
                      'switchport_private_vlan_trunk_allowed_vlan',
                      name: @name)

  unless result == default_switchport_private_vlan_trunk_allowed_vlan
    if result[0].eql? 'none'
      result = default_switchport_private_vlan_trunk_allowed_vlan
    else
      result = result[0].split(',')
    end
  end
  result
end

#switchport_private_vlan_trunk_allowed_vlan=(vlans) ⇒ Object


382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 382

def switchport_private_vlan_trunk_allowed_vlan=(vlans)
  deprecation_warning(__method__, 'switchport_pvlan_trunk_allowed_vlan')
  fail TypeError unless vlans.is_a?(Array)
  Feature.private_vlan_enable
  switchport_enable unless switchport
  if vlans == default_switchport_private_vlan_trunk_allowed_vlan
    vlans = prepare_array(switchport_private_vlan_trunk_allowed_vlan)
    # If there are no vlan presently configured, we can simply return
    return if vlans == default_switchport_private_vlan_trunk_allowed_vlan
    configure_private_vlan_host_property(:allow_vlan, [],
                                         vlans, '')
  else
    vlans = prepare_array(vlans)
    is_list = prepare_array(switchport_private_vlan_trunk_allowed_vlan)
    configure_private_vlan_host_property(:allow_vlan, vlans,
                                         is_list, '')
  end
end

#switchport_private_vlan_trunk_native_vlanObject


406
407
408
409
410
411
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 406

def switchport_private_vlan_trunk_native_vlan
  return nil if switchport_mode == :disabled
  config_get('DEPRECATED',
             'switchport_private_vlan_trunk_native_vlan',
             name: @name)
end

#switchport_private_vlan_trunk_native_vlan=(vlan) ⇒ Object


413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/cisco_node_utils/interface_DEPRECATED.rb', line 413

def switchport_private_vlan_trunk_native_vlan=(vlan)
  deprecation_warning(__method__, 'switchport_pvlan_trunk_native_vlan')
  Feature.private_vlan_enable
  switchport_enable unless switchport
  if vlan == default_switchport_private_vlan_trunk_native_vlan
    config_set('DEPRECATED',
               'switchport_private_vlan_trunk_native_vlan',
               name: @name, state: 'no', vlan: '')

  else
    config_set('DEPRECATED',
               'switchport_private_vlan_trunk_native_vlan',
               name: @name, state: '', vlan: vlan)
  end
end