rbeapi 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +25 -2
  4. data/Gemfile +13 -7
  5. data/Rakefile +8 -7
  6. data/lib/rbeapi/api/alias.rb +160 -0
  7. data/lib/rbeapi/api/bgp.rb +9 -9
  8. data/lib/rbeapi/api/dns.rb +3 -1
  9. data/lib/rbeapi/api/interfaces.rb +194 -32
  10. data/lib/rbeapi/api/ipinterfaces.rb +5 -3
  11. data/lib/rbeapi/api/managementdefaults.rb +119 -0
  12. data/lib/rbeapi/api/mlag.rb +6 -6
  13. data/lib/rbeapi/api/ntp.rb +1 -1
  14. data/lib/rbeapi/api/ospf.rb +171 -12
  15. data/lib/rbeapi/api/prefixlists.rb +19 -9
  16. data/lib/rbeapi/api/radius.rb +5 -5
  17. data/lib/rbeapi/api/routemaps.rb +12 -12
  18. data/lib/rbeapi/api/snmp.rb +6 -4
  19. data/lib/rbeapi/api/stp.rb +24 -24
  20. data/lib/rbeapi/api/switchports.rb +15 -9
  21. data/lib/rbeapi/api/tacacs.rb +1 -1
  22. data/lib/rbeapi/api/users.rb +4 -4
  23. data/lib/rbeapi/api/varp.rb +7 -3
  24. data/lib/rbeapi/api/vlans.rb +2 -2
  25. data/lib/rbeapi/api/vrrp.rb +61 -61
  26. data/lib/rbeapi/client.rb +9 -6
  27. data/lib/rbeapi/eapilib.rb +3 -3
  28. data/lib/rbeapi/netdev/snmp.rb +8 -6
  29. data/lib/rbeapi/switchconfig.rb +9 -10
  30. data/lib/rbeapi/version.rb +1 -1
  31. data/spec/support/fixtures.rb +4 -4
  32. data/spec/support/matchers/switch_config_sections.rb +2 -2
  33. data/spec/system/rbeapi/api/acl_spec.rb +2 -4
  34. data/spec/system/rbeapi/api/alias_spec.rb +168 -0
  35. data/spec/system/rbeapi/api/bgp_spec.rb +1 -2
  36. data/spec/system/rbeapi/api/interfaces_base_spec.rb +7 -8
  37. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +36 -3
  38. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +35 -3
  39. data/spec/system/rbeapi/api/interfaces_vlan_spec.rb +90 -0
  40. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +3 -4
  41. data/spec/system/rbeapi/api/managementdefaults_spec.rb +31 -0
  42. data/spec/system/rbeapi/api/ospf_interfaces_spec.rb +36 -11
  43. data/spec/system/rbeapi/api/ospf_spec.rb +240 -17
  44. data/spec/system/rbeapi/api/prefixlists_spec.rb +105 -89
  45. data/spec/system/rbeapi/api/routemaps_spec.rb +15 -10
  46. data/spec/system/rbeapi/api/users_spec.rb +4 -5
  47. data/spec/system/rbeapi/api/vrrp_spec.rb +2 -5
  48. data/spec/system/rbeapi/client_spec.rb +1 -2
  49. data/spec/unit/rbeapi/api/acl/default_spec.rb +1 -2
  50. data/spec/unit/rbeapi/api/alias/default_spec.rb +119 -0
  51. data/spec/unit/rbeapi/api/alias/fixture_alias.text +3 -0
  52. data/spec/unit/rbeapi/api/bgp/bgp_neighbors_spec.rb +1 -2
  53. data/spec/unit/rbeapi/api/bgp/bgp_spec.rb +1 -2
  54. data/spec/unit/rbeapi/api/interfaces/base_spec.rb +1 -1
  55. data/spec/unit/rbeapi/api/interfaces/ethernet_spec.rb +35 -1
  56. data/spec/unit/rbeapi/api/interfaces/fixture_interfaces.text +68 -0
  57. data/spec/unit/rbeapi/api/interfaces/portchannel_spec.rb +41 -4
  58. data/spec/unit/rbeapi/api/interfaces/vlan_spec.rb +72 -0
  59. data/spec/unit/rbeapi/api/interfaces/vxlan_spec.rb +2 -2
  60. data/spec/unit/rbeapi/api/managementdefaults/default_spec.rb +50 -0
  61. data/spec/unit/rbeapi/api/managementdefaults/fixture_managementdefaults.yaml +1 -0
  62. data/spec/unit/rbeapi/api/prefixlists/default_spec.rb +98 -80
  63. data/spec/unit/rbeapi/api/prefixlists/fixture_prefixlists.text +9 -4
  64. data/spec/unit/rbeapi/api/users/default_spec.rb +2 -4
  65. data/spec/unit/rbeapi/api/vrrp/default_spec.rb +2 -5
  66. data/spec/unit/rbeapi/client_spec.rb +21 -14
  67. data/spec/unit/rbeapi/switchconfig_spec.rb +10 -3
  68. metadata +49 -59
@@ -201,11 +201,11 @@ module Rbeapi
201
201
  when true
202
202
  cmds = 'default radius-server key'
203
203
  when false
204
- if enable
205
- cmds = "radius-server key #{key_format} #{value}"
206
- else
207
- cmds = 'no radius-server key'
208
- end
204
+ cmds = if enable
205
+ "radius-server key #{key_format} #{value}"
206
+ else
207
+ 'no radius-server key'
208
+ end
209
209
  end
210
210
  configure cmds
211
211
  end
@@ -253,13 +253,13 @@ module Rbeapi
253
253
  #
254
254
  # @return [Array] Returns the prepared eos command.
255
255
  def name_commands(name, action, seqno, opts = {})
256
- if opts[:default] == true
257
- cmd = "default route-map #{name}"
258
- elsif opts[:enable] == false
259
- cmd = "no route-map #{name}"
260
- else
261
- cmd = "route-map #{name}"
262
- end
256
+ cmd = if opts[:default] == true
257
+ "default route-map #{name}"
258
+ elsif opts[:enable] == false
259
+ "no route-map #{name}"
260
+ else
261
+ "route-map #{name}"
262
+ end
263
263
  cmd << " #{action}"
264
264
  cmd << " #{seqno}"
265
265
  [cmd]
@@ -305,7 +305,7 @@ module Rbeapi
305
305
  cmds = name_commands(name, action, seqno)
306
306
  else
307
307
  if opts[:match] && !opts[:match].is_a?(Array)
308
- fail ArgumentError, 'opts match must be an Array'
308
+ raise ArgumentError, 'opts match must be an Array'
309
309
  end
310
310
  cmds = name_commands(name, action, seqno, opts)
311
311
  if opts[:description]
@@ -346,7 +346,7 @@ module Rbeapi
346
346
  #
347
347
  # @return [Boolean] Returns true if the command completed successfully.
348
348
  def remove_match_statements(name, action, seqno, cmds)
349
- fail ArgumentError, 'cmds must be an Array' unless cmds.is_a?(Array)
349
+ raise ArgumentError, 'cmds must be an Array' unless cmds.is_a?(Array)
350
350
 
351
351
  entries = parse_entries(name)
352
352
  return nil unless entries
@@ -374,7 +374,7 @@ module Rbeapi
374
374
  #
375
375
  # @return [Boolean] Returns true if the command completed successfully.
376
376
  def remove_set_statements(name, action, seqno, cmds)
377
- fail ArgumentError, 'cmds must be an Array' unless cmds.is_a?(Array)
377
+ raise ArgumentError, 'cmds must be an Array' unless cmds.is_a?(Array)
378
378
 
379
379
  entries = parse_entries(name)
380
380
  return nil unless entries
@@ -446,7 +446,7 @@ module Rbeapi
446
446
  #
447
447
  # @return [Boolean] Returns true if the command completed successfully.
448
448
  def set_match_statements(name, action, seqno, value)
449
- fail ArgumentError, 'value must be an Array' unless value.is_a?(Array)
449
+ raise ArgumentError, 'value must be an Array' unless value.is_a?(Array)
450
450
 
451
451
  cmds = ["route-map #{name} #{action} #{seqno}"]
452
452
  remove_match_statements(name, action, seqno, cmds)
@@ -473,7 +473,7 @@ module Rbeapi
473
473
  #
474
474
  # @return [Boolean] Returns true if the command completed successfully.
475
475
  def set_set_statements(name, action, seqno, value)
476
- fail ArgumentError, 'value must be an Array' unless value.is_a?(Array)
476
+ raise ArgumentError, 'value must be an Array' unless value.is_a?(Array)
477
477
 
478
478
  cmds = ["route-map #{name} #{action} #{seqno}"]
479
479
  remove_set_statements(name, action, seqno, cmds)
@@ -44,12 +44,14 @@ module Rbeapi
44
44
  #
45
45
  # @since eos_version 4.13.7M
46
46
  class Snmp < Entity
47
- DEFAULT_SNMP_LOCATION = ''
48
- DEFAULT_SNMP_CONTACT = ''
49
- DEFAULT_SNMP_CHASSIS_ID = ''
50
- DEFAULT_SNMP_SOURCE_INTERFACE = ''
47
+ DEFAULT_SNMP_LOCATION = ''.freeze
48
+ DEFAULT_SNMP_CONTACT = ''.freeze
49
+ DEFAULT_SNMP_CHASSIS_ID = ''.freeze
50
+ DEFAULT_SNMP_SOURCE_INTERFACE = ''.freeze
51
51
  CFG_TO_STATE = { 'default' => 'default', 'no' => 'off', nil => 'on' }
52
+ .freeze
52
53
  STATE_TO_CFG = { 'default' => 'default', 'on' => nil, 'off' => 'no' }
54
+ .freeze
53
55
 
54
56
  ##
55
57
  # get returns the snmp resource Hash that represents the nodes snmp
@@ -146,7 +146,7 @@ module Rbeapi
146
146
  # spanning-tree instances in EOS
147
147
  #
148
148
  class StpInstances < Entity
149
- DEFAULT_STP_PRIORITY = '32768'
149
+ DEFAULT_STP_PRIORITY = '32768'.freeze
150
150
 
151
151
  ##
152
152
  # get returns the specified stp instance config parsed from the nodes
@@ -263,11 +263,11 @@ module Rbeapi
263
263
  when true
264
264
  cmd = "default spanning-tree mst #{inst} priority"
265
265
  when false
266
- if enable
267
- cmd = "spanning-tree mst #{inst} priority #{value}"
268
- else
269
- cmd = "no spanning-tree mst #{inst} priority"
270
- end
266
+ cmd = if enable
267
+ "spanning-tree mst #{inst} priority #{value}"
268
+ else
269
+ "no spanning-tree mst #{inst} priority"
270
+ end
271
271
  end
272
272
  configure cmd
273
273
  end
@@ -360,13 +360,13 @@ module Rbeapi
360
360
  #
361
361
  # @return [Hash<Symbol, Object>] Resource hash attribute.
362
362
  def parse_portfast_type(config)
363
- if /spanning-tree portfast network/ =~ config
364
- value = 'network'
365
- elsif /no spanning-tree portfast/ =~ config
366
- value = 'normal'
367
- else
368
- value = 'edge'
369
- end
363
+ value = if /spanning-tree portfast network/ =~ config
364
+ 'network'
365
+ elsif /no spanning-tree portfast/ =~ config
366
+ 'normal'
367
+ else
368
+ 'edge'
369
+ end
370
370
  { portfast_type: value }
371
371
  end
372
372
  private :parse_portfast_type
@@ -423,7 +423,7 @@ module Rbeapi
423
423
  # @return [Boolean] True if the commands succeed otherwise False.
424
424
  def set_portfast_type(name, opts = {})
425
425
  value = opts[:value]
426
- fail ArgumentError, 'value must be set' unless value
426
+ raise ArgumentError, 'value must be set' unless value
427
427
  enable = opts.fetch(:enable, true)
428
428
  default = opts[:default] || false
429
429
 
@@ -431,11 +431,11 @@ module Rbeapi
431
431
  when true
432
432
  cmds = "default spanning-tree portfast #{value}"
433
433
  when false
434
- if enable
435
- cmds = "spanning-tree portfast #{value}"
436
- else
437
- cmds = "no spanning-tree portfast #{value}"
438
- end
434
+ cmds = if enable
435
+ "spanning-tree portfast #{value}"
436
+ else
437
+ "no spanning-tree portfast #{value}"
438
+ end
439
439
  end
440
440
  configure_interface(name, cmds)
441
441
  end
@@ -463,11 +463,11 @@ module Rbeapi
463
463
  when true
464
464
  cmds = 'default spanning-tree bpduguard'
465
465
  when false
466
- if enable
467
- cmds = 'spanning-tree bpduguard enable'
468
- else
469
- cmds = 'spanning-tree bpduguard disable'
470
- end
466
+ cmds = if enable
467
+ 'spanning-tree bpduguard enable'
468
+ else
469
+ 'spanning-tree bpduguard disable'
470
+ end
471
471
  end
472
472
  configure_interface(name, cmds)
473
473
  end
@@ -85,6 +85,7 @@ module Rbeapi
85
85
  # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
86
86
  def parse_mode(config)
87
87
  mdata = /(?<=\s{3}switchport\smode\s)(.+)$/.match(config)
88
+ return { mode: [] } unless defined? mdata[1]
88
89
  { mode: mdata[1] }
89
90
  end
90
91
  private :parse_mode
@@ -101,6 +102,7 @@ module Rbeapi
101
102
  # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
102
103
  def parse_access_vlan(config)
103
104
  mdata = /(?<=access\svlan\s)(.+)$/.match(config)
105
+ return { access_vlan: [] } unless defined? mdata[1]
104
106
  { access_vlan: mdata[1] }
105
107
  end
106
108
  private :parse_access_vlan
@@ -117,6 +119,7 @@ module Rbeapi
117
119
  # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
118
120
  def parse_trunk_native_vlan(config)
119
121
  mdata = /(?<=trunk\snative\svlan\s)(.+)$/.match(config)
122
+ return { trunk_native_vlan: [] } unless defined? mdata[1]
120
123
  { trunk_native_vlan: mdata[1] }
121
124
  end
122
125
  private :parse_trunk_native_vlan
@@ -154,7 +157,8 @@ module Rbeapi
154
157
  # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
155
158
  def parse_trunk_groups(config)
156
159
  mdata = config.scan(/(?<=trunk\sgroup\s)(.+)$/)
157
- mdata = mdata.flatten if mdata.length > 0
160
+ return { trunk_group: [] } unless defined? mdata[1]
161
+ mdata = mdata.flatten unless mdata.empty?
158
162
  { trunk_groups: mdata }
159
163
  end
160
164
  private :parse_trunk_groups
@@ -277,7 +281,9 @@ module Rbeapi
277
281
  default = opts[:default] || false
278
282
 
279
283
  if value
280
- fail ArgumentError, 'value must be an Array' unless value.is_a?(Array)
284
+ unless value.is_a?(Array)
285
+ raise ArgumentError, 'value must be an Array'
286
+ end
281
287
  value = value.map(&:inspect).join(',').tr('"', '')
282
288
  end
283
289
 
@@ -285,11 +291,11 @@ module Rbeapi
285
291
  when true
286
292
  cmds = 'default switchport trunk allowed vlan'
287
293
  when false
288
- if !enable
289
- cmds = 'no switchport trunk allowed vlan'
290
- else
291
- cmds = ["switchport trunk allowed vlan #{value}"]
292
- end
294
+ cmds = if !enable
295
+ 'no switchport trunk allowed vlan'
296
+ else
297
+ ["switchport trunk allowed vlan #{value}"]
298
+ end
293
299
  end
294
300
  configure_interface(name, cmds)
295
301
  end
@@ -370,7 +376,7 @@ module Rbeapi
370
376
  end
371
377
 
372
378
  value = opts.fetch(:value, [])
373
- fail ArgumentError, 'value must be an Array' unless value.is_a?(Array)
379
+ raise ArgumentError, 'value must be an Array' unless value.is_a?(Array)
374
380
 
375
381
  value = Set.new value
376
382
  current_value = Set.new get(name)[:trunk_groups]
@@ -385,7 +391,7 @@ module Rbeapi
385
391
  current_value.difference(value).each do |group|
386
392
  cmds << "no switchport trunk group #{group}"
387
393
  end
388
- configure_interface(name, cmds) if cmds.length > 0
394
+ configure_interface(name, cmds) unless cmds.empty?
389
395
  end
390
396
  end
391
397
  end
@@ -166,7 +166,7 @@ module Rbeapi
166
166
  def set_global_key(opts = {})
167
167
  format = opts[:key_format]
168
168
  key = opts[:key]
169
- fail ArgumentError, 'key option is required' unless key
169
+ raise ArgumentError, 'key option is required' unless key
170
170
  result = api.config("tacacs-server key #{format} #{key}")
171
171
  result == [{}]
172
172
  end
@@ -149,7 +149,7 @@ module Rbeapi
149
149
  #
150
150
  # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
151
151
  def parse_user_entry(user)
152
- fail ArgumentError, 'user must be an Array' unless user.is_a?(Array)
152
+ raise ArgumentError, 'user must be an Array' unless user.is_a?(Array)
153
153
 
154
154
  hsh = {}
155
155
  hsh[:name] = user[0]
@@ -219,13 +219,13 @@ module Rbeapi
219
219
  # just return the value.
220
220
  enc = opts.fetch(:encryption, 'cleartext')
221
221
  unless @encryption_map[enc]
222
- fail ArgumentError, "invalid encryption value: #{enc}"
222
+ raise ArgumentError, "invalid encryption value: #{enc}"
223
223
  end
224
224
  enc = @encryption_map[enc]
225
225
 
226
226
  unless opts[:secret]
227
- fail ArgumentError,
228
- 'secret must be specified if nopassword is false'
227
+ raise ArgumentError,
228
+ 'secret must be specified if nopassword is false'
229
229
  end
230
230
  cmd << " secret #{enc} #{opts[:secret]}"
231
231
  end
@@ -207,7 +207,9 @@ module Rbeapi
207
207
  cmds = ["interface #{name}"]
208
208
 
209
209
  if value
210
- fail ArgumentError, 'value must be an Array' unless value.is_a?(Array)
210
+ unless value.is_a?(Array)
211
+ raise ArgumentError, 'value must be an Array'
212
+ end
211
213
  end
212
214
 
213
215
  case default
@@ -216,8 +218,10 @@ module Rbeapi
216
218
  when false
217
219
  cmds << 'no ip virtual-router address'
218
220
  if enable
219
- fail ArgumentError,
220
- 'no values for addresses provided' unless value
221
+ unless value
222
+ raise ArgumentError,
223
+ 'no values for addresses provided'
224
+ end
221
225
  value.each do |addr|
222
226
  cmds << "ip virtual-router address #{addr}"
223
227
  end
@@ -283,7 +283,7 @@ module Rbeapi
283
283
  def set_state(id, opts = {})
284
284
  value = opts[:value]
285
285
  unless ['active', 'suspend', nil].include?(value)
286
- fail ArgumentError, 'state must be active, suspend or nil'
286
+ raise ArgumentError, 'state must be active, suspend or nil'
287
287
  end
288
288
 
289
289
  cmd = command_builder('state', opts)
@@ -360,7 +360,7 @@ module Rbeapi
360
360
  return configure(["vlan #{name}", 'no trunk group']) unless enable
361
361
 
362
362
  value = opts.fetch(:value, [])
363
- fail ArgumentError, 'value must be an Array' unless value.is_a?(Array)
363
+ raise ArgumentError, 'value must be an Array' unless value.is_a?(Array)
364
364
 
365
365
  value = Set.new value
366
366
  current_value = Set.new get(name)[:trunk_groups]
@@ -152,8 +152,8 @@ module Rbeapi
152
152
  # address or nil if the value is not set.
153
153
  def parse_primary_ip(config, vrid)
154
154
  match = config.scan(/^\s+vrrp #{vrid} ip (\d+\.\d+\.\d+\.\d+)$/)
155
- if match.empty?
156
- fail 'Did not get a default value for primary_ip'
155
+ if match.empty? # rubocop:disable Style/GuardClause
156
+ raise 'Did not get a default value for primary_ip'
157
157
  else
158
158
  value = match[0][0]
159
159
  end
@@ -175,8 +175,8 @@ module Rbeapi
175
175
  # <1-255> or nil if the value is not set.
176
176
  def parse_priority(config, vrid)
177
177
  match = config.scan(/^\s+vrrp #{vrid} priority (\d+)$/)
178
- if match.empty?
179
- fail 'Did not get a default value for priority'
178
+ if match.empty? # rubocop:disable Style/GuardClause
179
+ raise 'Did not get a default value for priority'
180
180
  else
181
181
  value = match[0][0].to_i
182
182
  end
@@ -198,8 +198,8 @@ module Rbeapi
198
198
  # is between <1-255> or nil if the value is not set.
199
199
  def parse_timers_advertise(config, vrid)
200
200
  match = config.scan(/^\s+vrrp #{vrid} timers advertise (\d+)$/)
201
- if match.empty?
202
- fail 'Did not get a default value for timers advertise'
201
+ if match.empty? # rubocop:disable Style/GuardClause
202
+ raise 'Did not get a default value for timers advertise'
203
203
  else
204
204
  value = match[0][0].to_i
205
205
  end
@@ -221,11 +221,11 @@ module Rbeapi
221
221
  # between <1-255> or nil if the value is not set.
222
222
  def parse_preempt(config, vrid)
223
223
  match = config.scan(/^\s+vrrp #{vrid} preempt$/)
224
- if match.empty?
225
- value = false
226
- else
227
- value = true
228
- end
224
+ value = if match.empty?
225
+ false
226
+ else
227
+ true
228
+ end
229
229
  { preempt: value }
230
230
  end
231
231
  private :parse_preempt
@@ -243,11 +243,11 @@ module Rbeapi
243
243
  # @return [Hash<'enable', Boolean>]
244
244
  def parse_enable(config, vrid)
245
245
  match = config.scan(/^\s+vrrp #{vrid} shutdown$/)
246
- if match.empty?
247
- value = true
248
- else
249
- value = false
250
- end
246
+ value = if match.empty?
247
+ true
248
+ else
249
+ false
250
+ end
251
251
  { enable: value }
252
252
  end
253
253
  private :parse_enable
@@ -289,11 +289,11 @@ module Rbeapi
289
289
  # value is not set.
290
290
  def parse_description(config, vrid)
291
291
  match = config.scan(/^\s+vrrp #{vrid} description\s+(.*)\s*$/)
292
- if match.empty?
293
- value = nil
294
- else
295
- value = match[0][0]
296
- end
292
+ value = if match.empty?
293
+ nil
294
+ else
295
+ match[0][0]
296
+ end
297
297
  { description: value }
298
298
  end
299
299
  private :parse_description
@@ -341,8 +341,8 @@ module Rbeapi
341
341
  # value is not set.
342
342
  def parse_ip_version(config, vrid)
343
343
  match = config.scan(/^\s+vrrp #{vrid} ip version (\d+)$/)
344
- if match.empty?
345
- fail 'Did not get a default value for ip version'
344
+ if match.empty? # rubocop:disable Style/GuardClause
345
+ raise 'Did not get a default value for ip version'
346
346
  else
347
347
  value = match[0][0].to_i
348
348
  end
@@ -367,7 +367,7 @@ module Rbeapi
367
367
  regex = "vrrp #{vrid} mac-address advertisement-interval"
368
368
  match = config.scan(/^\s+#{regex} (\d+)$/)
369
369
  if match.empty?
370
- fail 'Did not get a default value for mac address ' \
370
+ raise 'Did not get a default value for mac address ' \
371
371
  'advertisement interval'
372
372
  else
373
373
  value = match[0][0].to_i
@@ -390,8 +390,8 @@ module Rbeapi
390
390
  # value is not set.
391
391
  def parse_preempt_delay_min(config, vrid)
392
392
  match = config.scan(/^\s+vrrp #{vrid} preempt delay minimum (\d+)$/)
393
- if match.empty?
394
- fail 'Did not get a default value for preempt delay minimum'
393
+ if match.empty? # rubocop:disable Style/GuardClause
394
+ raise 'Did not get a default value for preempt delay minimum'
395
395
  else
396
396
  value = match[0][0].to_i
397
397
  end
@@ -413,8 +413,8 @@ module Rbeapi
413
413
  # value is not set.
414
414
  def parse_preempt_delay_reload(config, vrid)
415
415
  match = config.scan(/^\s+vrrp #{vrid} preempt delay reload (\d+)$/)
416
- if match.empty?
417
- fail 'Did not get a default value for preempt delay reload'
416
+ if match.empty? # rubocop:disable Style/GuardClause
417
+ raise 'Did not get a default value for preempt delay reload'
418
418
  else
419
419
  value = match[0][0].to_i
420
420
  end
@@ -436,8 +436,8 @@ module Rbeapi
436
436
  # value is not set.
437
437
  def parse_delay_reload(config, vrid)
438
438
  match = config.scan(/^\s+vrrp #{vrid} delay reload (\d+)$/)
439
- if match.empty?
440
- fail 'Did not get a default value for delay reload'
439
+ if match.empty? # rubocop:disable Style/GuardClause
440
+ raise 'Did not get a default value for delay reload'
441
441
  else
442
442
  value = match[0][0].to_i
443
443
  end
@@ -513,23 +513,23 @@ module Rbeapi
513
513
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize,
514
514
  # rubocop:disable Metrics/PerceivedComplexity
515
515
  def create(name, vrid, opts = {})
516
- fail ArgumentError, 'create has no options set' if opts.empty?
516
+ raise ArgumentError, 'create has no options set' if opts.empty?
517
517
 
518
518
  if opts[:secondary_ip] && !opts[:secondary_ip].is_a?(Array)
519
- fail ArgumentError, 'opts secondary_ip must be an Array'
519
+ raise ArgumentError, 'opts secondary_ip must be an Array'
520
520
  end
521
521
 
522
522
  if opts[:track] && !opts[:track].is_a?(Array)
523
- fail ArgumentError, 'opts track must be an Array'
523
+ raise ArgumentError, 'opts track must be an Array'
524
524
  end
525
525
 
526
526
  cmds = []
527
527
  if opts.key?(:enable)
528
- if opts[:enable]
529
- cmds << "no vrrp #{vrid} shutdown"
530
- else
531
- cmds << "vrrp #{vrid} shutdown"
532
- end
528
+ cmds << if opts[:enable]
529
+ "no vrrp #{vrid} shutdown"
530
+ else
531
+ "vrrp #{vrid} shutdown"
532
+ end
533
533
  end
534
534
  cmds << "vrrp #{vrid} ip #{opts[:primary_ip]}" if opts.key?(:primary_ip)
535
535
  if opts.key?(:priority)
@@ -552,11 +552,11 @@ module Rbeapi
552
552
  cmds << "vrrp #{vrid} mac-address advertisement-interval #{val}"
553
553
  end
554
554
  if opts.key?(:preempt)
555
- if opts[:preempt]
556
- cmds << "vrrp #{vrid} preempt"
557
- else
558
- cmds << "no vrrp #{vrid} preempt"
559
- end
555
+ cmds << if opts[:preempt]
556
+ "vrrp #{vrid} preempt"
557
+ else
558
+ "no vrrp #{vrid} preempt"
559
+ end
560
560
  end
561
561
  if opts.key?(:preempt_delay_min)
562
562
  val = opts[:preempt_delay_min]
@@ -642,10 +642,10 @@ module Rbeapi
642
642
  #
643
643
  # @return [Boolean] Returns true if the command complete successfully.
644
644
  def set_shutdown(name, vrid, opts = {})
645
- fail 'set_shutdown has the value option set' if opts[:value]
645
+ raise 'set_shutdown has the value option set' if opts[:value]
646
646
  # Shutdown semantics are opposite of enable semantics so invert enable.
647
647
  enable = opts.fetch(:enable, true)
648
- opts.merge!(enable: !enable)
648
+ opts[:enable] = !enable
649
649
  cmd = "vrrp #{vrid} shutdown"
650
650
  configure_interface(name, command_builder(cmd, opts))
651
651
  end
@@ -757,11 +757,11 @@ module Rbeapi
757
757
  vrrp = get(name)
758
758
  vrrp = [] if vrrp.nil?
759
759
 
760
- if vrrp.key?(vrid)
761
- current_addrs = Set.new vrrp[vrid][:secondary_ip]
762
- else
763
- current_addrs = Set.new []
764
- end
760
+ current_addrs = if vrrp.key?(vrid)
761
+ Set.new vrrp[vrid][:secondary_ip]
762
+ else
763
+ Set.new []
764
+ end
765
765
 
766
766
  cmds = []
767
767
  # Add commands to delete any secondary IP addresses that are
@@ -921,7 +921,7 @@ module Rbeapi
921
921
  #
922
922
  # @return [Boolean] Returns true if the command complete successfully.
923
923
  def set_preempt(name, vrid, opts = {})
924
- fail 'set_preempt has the value option set' if opts[:value]
924
+ raise 'set_preempt has the value option set' if opts[:value]
925
925
  cmd = "vrrp #{vrid} preempt"
926
926
  configure_interface(name, command_builder(cmd, opts))
927
927
  end
@@ -1038,22 +1038,22 @@ module Rbeapi
1038
1038
  tracks.each do |track|
1039
1039
  track.keys do |key|
1040
1040
  unless valid_keys.include?(key)
1041
- fail ArgumentError, 'Key: #{key} invalid in track hash'
1041
+ raise ArgumentError, 'Key: #{key} invalid in track hash'
1042
1042
  end
1043
1043
  end
1044
1044
  unless track.key?(:name) && track.key?(:action)
1045
- fail ArgumentError, 'Must specify :name and :action in track hash'
1045
+ raise ArgumentError, 'Must specify :name and :action in track hash'
1046
1046
  end
1047
1047
  unless track[:action] == 'decrement' || track[:action] == 'shutdown'
1048
- fail ArgumentError, "Action must be 'decrement' or 'shutdown'"
1048
+ raise ArgumentError, "Action must be 'decrement' or 'shutdown'"
1049
1049
  end
1050
1050
  if track.key?(:amount) && track[:action] != 'decrement'
1051
- fail ArgumentError, "Action must be 'decrement' to set amount"
1051
+ raise ArgumentError, "Action must be 'decrement' to set amount"
1052
1052
  end
1053
1053
  if track.key?(:amount)
1054
1054
  track[:amount] = track[:amount].to_i
1055
1055
  if track[:amount] < 0
1056
- fail ArgumentError, 'Amount must be greater than zero'
1056
+ raise ArgumentError, 'Amount must be greater than zero'
1057
1057
  end
1058
1058
  end
1059
1059
  end
@@ -1066,11 +1066,11 @@ module Rbeapi
1066
1066
  vrrp = get(name)
1067
1067
  vrrp = [] if vrrp.nil?
1068
1068
 
1069
- if vrrp.key?(vrid)
1070
- current_tracks = Set.new vrrp[vrid][:track]
1071
- else
1072
- current_tracks = Set.new []
1073
- end
1069
+ current_tracks = if vrrp.key?(vrid)
1070
+ Set.new vrrp[vrid][:track]
1071
+ else
1072
+ Set.new []
1073
+ end
1074
1074
 
1075
1075
  cmds = []
1076
1076
  # Add commands to delete any tracks that are