rbeapi 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +4 -0
  4. data/README.md +9 -9
  5. data/Rakefile +20 -0
  6. data/lib/rbeapi/api/bgp.rb +770 -0
  7. data/lib/rbeapi/api/dns.rb +32 -31
  8. data/lib/rbeapi/api/interfaces.rb +106 -87
  9. data/lib/rbeapi/api/ipinterfaces.rb +27 -42
  10. data/lib/rbeapi/api/logging.rb +9 -19
  11. data/lib/rbeapi/api/mlag.rb +60 -90
  12. data/lib/rbeapi/api/ntp.rb +12 -17
  13. data/lib/rbeapi/api/ospf.rb +9 -26
  14. data/lib/rbeapi/api/radius.rb +29 -43
  15. data/lib/rbeapi/api/snmp.rb +54 -83
  16. data/lib/rbeapi/api/staticroutes.rb +68 -21
  17. data/lib/rbeapi/api/stp.rb +41 -49
  18. data/lib/rbeapi/api/switchports.rb +41 -68
  19. data/lib/rbeapi/api/system.rb +6 -12
  20. data/lib/rbeapi/api/tacacs.rb +12 -21
  21. data/lib/rbeapi/api/varp.rb +25 -26
  22. data/lib/rbeapi/api/vlans.rb +19 -28
  23. data/lib/rbeapi/api.rb +30 -21
  24. data/lib/rbeapi/client.rb +3 -1
  25. data/lib/rbeapi/version.rb +1 -1
  26. data/rbeapi.spec.tmpl +4 -0
  27. data/spec/spec_helper.rb +8 -0
  28. data/spec/system/api_ospf_interfaces_spec.rb +16 -0
  29. data/spec/system/api_ospf_spec.rb +14 -0
  30. data/spec/system/api_varp_interfaces_spec.rb +16 -0
  31. data/spec/system/rbeapi/api/dns_spec.rb +66 -0
  32. data/spec/system/rbeapi/api/interfaces_base_spec.rb +4 -4
  33. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +6 -6
  34. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +6 -6
  35. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +4 -4
  36. data/spec/system/rbeapi/api/ipinterfaces_spec.rb +44 -0
  37. data/spec/system/rbeapi/api/logging_spec.rb +18 -2
  38. data/spec/system/rbeapi/api/mlag_spec.rb +94 -2
  39. data/spec/system/rbeapi/api/ntp_spec.rb +14 -0
  40. data/spec/system/rbeapi/api/snmp_spec.rb +105 -0
  41. data/spec/system/rbeapi/api/stp_interfaces_spec.rb +43 -6
  42. data/spec/system/rbeapi/api/stp_spec.rb +18 -6
  43. data/spec/system/rbeapi/api/switchports_spec.rb +75 -3
  44. data/spec/system/rbeapi/api/system_spec.rb +16 -0
  45. data/spec/system/rbeapi/api/vlans_spec.rb +28 -0
  46. data/spec/unit/rbeapi/api/bgp/bgp_neighbors_spec.rb +289 -0
  47. data/spec/unit/rbeapi/api/bgp/bgp_spec.rb +192 -0
  48. data/spec/unit/rbeapi/api/bgp/fixture_bgp.text +101 -0
  49. data/spec/unit/rbeapi/api/interfaces/base_spec.rb +7 -13
  50. data/spec/unit/rbeapi/api/interfaces/ethernet_spec.rb +3 -3
  51. data/spec/unit/rbeapi/api/interfaces/portchannel_spec.rb +11 -16
  52. data/spec/unit/rbeapi/api/interfaces/vxlan_spec.rb +15 -21
  53. data/spec/unit/rbeapi/api/mlag/default_spec.rb +13 -19
  54. data/spec/unit/rbeapi/api/staticroutes/default_spec.rb +138 -0
  55. data/spec/unit/rbeapi/api/staticroutes/fixture_staticroutes.text +5 -0
  56. data/spec/unit/rbeapi/api/vlans/default_spec.rb +4 -4
  57. metadata +15 -4
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014, Arista Networks, Inc.
2
+ # Copyright (c) 2014,2015, Arista Networks, Inc.
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -46,7 +46,7 @@ module Rbeapi
46
46
 
47
47
  # Regular expression to extract a radius server's attributes from the
48
48
  # running-configuration text. The explicit [ ] spaces enable line
49
- # wrappping and indentation with the /x flag.
49
+ # wrapping and indentation with the /x flag.
50
50
  SERVER_REGEXP = /radius-server[ ]host[ ](.*?)
51
51
  (?:[ ]vrf[ ]([^\s]+))?
52
52
  (?:[ ]auth-port[ ](\d+))?
@@ -62,7 +62,7 @@ module Rbeapi
62
62
  # method.
63
63
  #
64
64
  # The resource hash returned contains the following information:
65
- # * key: (String) the key either in plaintext or hashed format
65
+ # * key: (String) the key either in plain text or hashed format
66
66
  # * key_format: (Fixnum) e.g. 0 or 7
67
67
  # * timeout: (Fixnum) seconds before the timeout period ends
68
68
  # * retransmit: (Fixnum), e.g. 3, attempts after first timeout expiry.
@@ -81,7 +81,7 @@ module Rbeapi
81
81
  end
82
82
 
83
83
  ##
84
- # parse_time scans the nodes current configuraiton and parse the
84
+ # parse_time scans the nodes current configuration and parse the
85
85
  # radius-server timeout value. The timeout value is expected to always
86
86
  # be present in the config
87
87
  #
@@ -96,7 +96,7 @@ module Rbeapi
96
96
 
97
97
  ##
98
98
  # parse_retransmit scans the cnodes current configuration and parses the
99
- # radius-server retransmit value. the retransmist value is expected to
99
+ # radius-server retransmit value. the retransmit value is expected to
100
100
  # always be present in the config
101
101
  #
102
102
  # @api private
@@ -134,7 +134,7 @@ module Rbeapi
134
134
  # The resource hash returned contains the following information:
135
135
  # * hostname: hostname or ip address
136
136
  # * vrf: (String) vrf name
137
- # * key: (String) the key either in plaintext or hashed format
137
+ # * key: (String) the key either in plain text or hashed format
138
138
  # * key_format: (Fixnum) e.g. 0 or 7
139
139
  # * timeout: (Fixnum) seconds before the timeout period ends
140
140
  # * retransmit: (Integer), e.g. 3, attempts after first timeout expiry.
@@ -164,8 +164,8 @@ module Rbeapi
164
164
  private :parse_servers
165
165
 
166
166
  ##
167
- # set_global_key configures the global radius-server key. If the value
168
- # option is not specified, radius-server key is configured using the no
167
+ # set_global_key configures the global radius-server key. If the enable
168
+ # option is false, radius-server key is configured using the no
169
169
  # keyword. If the default option is specified, radius-server key is
170
170
  # configured using the default keyword. If both options are specified,
171
171
  # the default keyword option takes precedence.
@@ -181,15 +181,19 @@ module Rbeapi
181
181
  # in the nodes running configuration
182
182
  #
183
183
  # @option [Fixnum] :key_format The format of the key to be passed to the
184
- # nodes running configuration. Valid values are 0 (cleartext) or 7
184
+ # nodes running configuration. Valid values are 0 (clear text) or 7
185
185
  # (encrypted). The default value is 0 if format is not provided.
186
186
  #
187
+ # @option :opts [Boolean] :enable If false then the command is
188
+ # negated. Default is true.
189
+ #
187
190
  # @option [Boolean] :default Configures the radius-server key using the
188
191
  # default keyword argument
189
192
  #
190
193
  # @return [Boolean] returns true if the commands complete successfully
191
194
  def set_global_key(opts = {})
192
195
  value = opts[:value]
196
+ enable = opts.fetch(:enable, true)
193
197
  key_format = opts[:key_format] || 0
194
198
  default = opts[:default] || false
195
199
 
@@ -197,7 +201,7 @@ module Rbeapi
197
201
  when true
198
202
  cmds = 'default radius-server key'
199
203
  when false
200
- if value
204
+ if enable
201
205
  cmds = "radius-server key #{key_format} #{value}"
202
206
  else
203
207
  cmds = 'no radius-server key'
@@ -208,7 +212,7 @@ module Rbeapi
208
212
 
209
213
  ##
210
214
  # set_global_timeout configures the radius-server timeout value. If the
211
- # value # options is not specified, radius-server timeout is configured
215
+ # enable option is false, then radius-server timeout is configured
212
216
  # using the no keyword. If the default option is specified, radius-server
213
217
  # timeout is configured using the default keyword. If both options are
214
218
  # specified then the default keyword takes precedence.
@@ -224,30 +228,21 @@ module Rbeapi
224
228
  # radius-server timeout value to. This value should be in the range of
225
229
  # 1 to 1000
226
230
  #
231
+ # @option :opts [Boolean] :enable If false then the command is
232
+ # negated. Default is true.
233
+ #
227
234
  # @option [Boolean] :default Configures the radius-server timeout value
228
235
  # using the default keyword.
229
236
  #
230
237
  # @return [Boolean] returns true if the commands complete successfully
231
238
  def set_global_timeout(opts = {})
232
- value = opts[:value]
233
- default = opts[:default] || false
234
-
235
- case default
236
- when true
237
- cmds = 'default radius-server timeout'
238
- when false
239
- if value
240
- cmds = "radius-server timeout #{value}"
241
- else
242
- cmds = 'no radius-server timeout'
243
- end
244
- end
245
- configure cmds
239
+ cmd = command_builder('radius-server timeout', opts)
240
+ configure cmd
246
241
  end
247
242
 
248
243
  ##
249
- # set_global_retransmit configures the global radius-server restransmit
250
- # value. If the value is not specified, the radius-server retransmist
244
+ # set_global_retransmit configures the global radius-server retransmit
245
+ # value. If the enable option is false, then the radius-server retransmit
251
246
  # value is configured using the no keyword. If the default option is
252
247
  # specified, the radius-server retransmit value is configured using the
253
248
  # default keyword. If both options are specified then the default keyword
@@ -258,31 +253,22 @@ module Rbeapi
258
253
  # @commands
259
254
  # radius-server retransmit <value>
260
255
  # no radius-server retransmit
261
- # default radius-server retrasmit
256
+ # default radius-server retransmit
262
257
  #
263
- # @option [String, Fixnum] :value The valu to set the global
258
+ # @option [String, Fixnum] :value The value to set the global
264
259
  # radius-server retransmit value to. This value should be in the range
265
260
  # of 1 to 100
266
261
  #
262
+ # @option :opts [Boolean] :enable If false then the command is
263
+ # negated. Default is true.
264
+ #
267
265
  # @option [Boolean] :default Configures the radius-server retransmit
268
266
  # value using the default keyword
269
267
  #
270
268
  # @return [Boolean] returns true if the commands complete successfully
271
269
  def set_global_retransmit(opts = {})
272
- value = opts[:value]
273
- default = opts[:default] || false
274
-
275
- case default
276
- when true
277
- cmds = 'default radius-server retransmit'
278
- when false
279
- if value
280
- cmds = "radius-server retransmit #{value}"
281
- else
282
- cmds = 'no radius-server retransmit'
283
- end
284
- end
285
- configure cmds
270
+ cmd = command_builder('radius-server retransmit', opts)
271
+ configure cmd
286
272
  end
287
273
 
288
274
  ##
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014, Arista Networks, Inc.
2
+ # Copyright (c) 2014,2015, Arista Networks, Inc.
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -39,11 +39,9 @@ module Rbeapi
39
39
  module Api
40
40
  ##
41
41
  # The Snmp class provides a class implementation for working with the
42
- # nodes SNMP conifguration entity. This class presents an abstraction
42
+ # nodes SNMP configuration entity. This class presents an abstraction
43
43
  # of the node's snmp configuration from the running config.
44
44
  #
45
- # rubocop:disable Metrics/ClassLength
46
- #
47
45
  # @eos_version 4.13.7M
48
46
  class Snmp < Entity
49
47
  DEFAULT_SNMP_LOCATION = ''
@@ -145,7 +143,7 @@ module Rbeapi
145
143
  ##
146
144
  # parse_communities scans the running config from the node and parses all
147
145
  # of the configure snmp community strings. If there are no configured
148
- # snmp community strings, the communitys value is set to an empty array.
146
+ # snmp community strings, the community value is set to an empty array.
149
147
  # The returned hash is intended to be merged into the global snmp
150
148
  # resource hash
151
149
  #
@@ -164,8 +162,8 @@ module Rbeapi
164
162
 
165
163
  ##
166
164
  # parse_notifications scans the running configuration and parses all of
167
- # the snmp trap notificaitons configuration. It is expected the trap
168
- # configuration is in the running config. The returned hash is intendd
165
+ # the snmp trap notifications configuration. It is expected the trap
166
+ # configuration is in the running config. The returned hash is intended
169
167
  # to be merged into the resource hash
170
168
  def parse_notifications
171
169
  traps = config.scan(/(default|no)?[ ]?snmp-server enable traps (.+)$/)
@@ -181,7 +179,7 @@ module Rbeapi
181
179
  private :parse_notifications
182
180
 
183
181
  ##
184
- # set_notification configures the snmp trap notificaiton for the
182
+ # set_notification configures the snmp trap notification for the
185
183
  # specified trap. The name option accepts the snmp trap name to
186
184
  # configure or the keyword all to globally enable or disable
187
185
  # notifications. If the optional state argument is not provided then the
@@ -210,11 +208,10 @@ module Rbeapi
210
208
 
211
209
  ##
212
210
  # set_location updates the snmp location value in the nodes running
213
- # configuration. If the value is not provided in the opts Hash then
214
- # the snmp location value is negated using the no keyword. If the
215
- # default keyword is set to true, then the snmp location value is
216
- # defaulted using the default keyword. The default parameter takes
217
- # precedence over the value keyword.
211
+ # configuration. If enable is false, then the snmp location value is
212
+ # negated using the no keyword. If the default keyword is set to true,
213
+ # then the snmp location value is defaulted using the default keyword.
214
+ # The default parameter takes precedence over the enable keyword.
218
215
  #
219
216
  # @eos_version 4.13.7M
220
217
  #
@@ -227,34 +224,25 @@ module Rbeapi
227
224
  #
228
225
  # @option opts [string] :value The snmp location value to configure
229
226
  #
227
+ # @option :opts [Boolean] :enable If false then the command is
228
+ # negated. Default is true.
229
+ #
230
230
  # @option opts [Boolean] :default Configure the snmp location value
231
231
  # using the default keyword
232
232
  #
233
233
  # @return [Boolean] returns true if the command completed successfully
234
234
  def set_location(opts = {})
235
- value = opts[:value]
236
- default = opts[:default] || false
237
-
238
- case default
239
- when true
240
- cmds = ['default snmp-server location']
241
- when false
242
- if value.nil?
243
- cmds = 'no snmp-server location'
244
- else
245
- cmds = "snmp-server location #{value}"
246
- end
247
- end
248
- configure(cmds)
235
+ cmd = command_builder('snmp-server location', opts)
236
+ configure(cmd)
249
237
  end
250
238
 
251
239
  ##
252
240
  # set_contact updates the snmp contact value in the nodes running
253
- # configuration. If the value is not provided in the opts Hash then
241
+ # configuration. If enable is false in the opts Hash then
254
242
  # the snmp contact value is negated using the no keyword. If the
255
243
  # default keyword is set to true, then the snmp contact value is
256
244
  # defaulted using the default keyword. The default parameter takes
257
- # precedence over the value keyword.
245
+ # precedence over the enable keyword.
258
246
  #
259
247
  # @eos_version 4.13.7M
260
248
  #
@@ -267,34 +255,25 @@ module Rbeapi
267
255
  #
268
256
  # @option opts [string] :value The snmp contact value to configure
269
257
  #
258
+ # @option :opts [Boolean] :enable If false then the command is
259
+ # negated. Default is true.
260
+ #
270
261
  # @option opts [Boolean] :default Configures the snmp contact value
271
262
  # using the default keyword
272
263
  #
273
264
  # @return [Boolean] returns true if the command completed successfully
274
265
  def set_contact(opts = {})
275
- value = opts[:value]
276
- default = opts[:default] || false
277
-
278
- case default
279
- when true
280
- cmds = ['default snmp-server contact']
281
- when false
282
- if value.nil?
283
- cmds = 'no snmp-server contact'
284
- else
285
- cmds = "snmp-server contact #{value}"
286
- end
287
- end
288
- configure(cmds)
266
+ cmd = command_builder('snmp-server contact', opts)
267
+ configure(cmd)
289
268
  end
290
269
 
291
270
  ##
292
271
  # set_chassis_id updates the snmp chassis id value in the nodes
293
- # running configuration. If the value is not provided in the opts
272
+ # running configuration. If enable is false in the opts
294
273
  # Hash then the snmp chassis id value is negated using the no
295
274
  # keyword. If the default keyword is set to true, then the snmp
296
275
  # chassis id value is defaulted using the default keyword. The default
297
- # keyword takes precedence over the value keyword.
276
+ # keyword takes precedence over the enable keyword.
298
277
  #
299
278
  # @eos_version 4.13.7M
300
279
  #
@@ -307,34 +286,25 @@ module Rbeapi
307
286
  #
308
287
  # @option opts [string] :value The snmp chassis id value to configure
309
288
  #
289
+ # @option :opts [Boolean] :enable If false then the command is
290
+ # negated. Default is true.
291
+ #
310
292
  # @option opts [Boolean] :default Configures the snmp chassis id value
311
293
  # using the default keyword
312
294
  #
313
295
  # @return [Boolean] returns true if the command completed successfully
314
296
  def set_chassis_id(opts = {})
315
- value = opts[:value]
316
- default = opts[:default] || false
317
-
318
- case default
319
- when true
320
- cmds = 'default snmp-server chassis-id'
321
- when false
322
- if value.nil?
323
- cmds = 'no snmp-server chassis-id'
324
- else
325
- cmds = "snmp-server chassis-id #{value}"
326
- end
327
- end
328
- configure(cmds)
297
+ cmd = command_builder('snmp-server chassis-id', opts)
298
+ configure(cmd)
329
299
  end
330
300
 
331
301
  ##
332
302
  # set_source_interface updates the snmp source interface value in the
333
- # nodes running configuration. If the value is not provided in the opts
303
+ # nodes running configuration. If enable is false in the opts
334
304
  # Hash then the snmp source interface is negated using the no keyword.
335
- # If the deafult keyword is set to true, then the snmp source interface
336
- # value is defaulted using the default keyword. The deafult keyword
337
- # takes precedence over the value keyword.
305
+ # If the default keyword is set to true, then the snmp source interface
306
+ # value is defaulted using the default keyword. The default keyword
307
+ # takes precedence over the enable keyword.
338
308
  #
339
309
  # @eos_version 4.13.7M
340
310
  #
@@ -348,25 +318,15 @@ module Rbeapi
348
318
  # @option opts [string] :value The snmp source interface value to
349
319
  # configure. This method will not ensure the interface is present
350
320
  # in the configuration
321
+ # @option :opts [Boolean] :enable If false then the command is
322
+ # negated. Default is true.
351
323
  # @option opts [Boolean] :default Configures the snmp source interface
352
324
  # value using the default keyword
353
325
  #
354
326
  # @return [Boolean] returns true if the command completed successfully
355
327
  def set_source_interface(opts = {})
356
- value = opts[:value]
357
- default = opts[:default] || false
358
-
359
- case default
360
- when true
361
- cmds = ['default snmp-server source-interface']
362
- when false
363
- if value.nil?
364
- cmds = 'no snmp-server source-interface'
365
- else
366
- cmds = "snmp-server source-interface #{value}"
367
- end
368
- end
369
- configure(cmds)
328
+ cmd = command_builder('snmp-server source-interface', opts)
329
+ configure(cmd)
370
330
  end
371
331
 
372
332
  ##
@@ -407,8 +367,8 @@ module Rbeapi
407
367
 
408
368
  ##
409
369
  # set_community_acl configures the acl to apply to the specified
410
- # community name. If the value option is not specified, the acl is
411
- # removed from the community name
370
+ # community name. When enable is true, it will remove the
371
+ # the named community and then add the new acl entry.
412
372
  #
413
373
  # @eos_version 4.13.7M
414
374
  #
@@ -419,16 +379,27 @@ module Rbeapi
419
379
  # @param [String] :name The name of the snmp community to add to the
420
380
  # nodes running configuration.
421
381
  #
422
- # @option [String] :value The name of the acl to apply to the snmp
423
- # community in the nodes config
382
+ # @param [Hash] opts The configuration parameters
383
+ #
384
+ # @option opts [String] :value The name of the acl to apply to the snmp
385
+ # community in the nodes config. If nil, then the community name
386
+ # allows access to all objects.
387
+ # @option opts [Boolean] :enable If false then the command is
388
+ # negated. Default is true.
389
+ # @option opts [Boolean] :default Configure the snmp community name
390
+ # using the default keyword. Default takes precedence over enable.
424
391
  #
425
392
  # @return [Boolean] returns true if the command completed successfully
426
393
  def set_community_acl(name, opts = {})
427
394
  value = opts[:value]
395
+ enable = opts.fetch(:enable, true)
396
+ default = opts.fetch(:default, false)
397
+ # Default is same as negate for this command
398
+ enable = default ? false : enable
428
399
  communities = parse_communities[:communities]
429
400
  access = communities[name][:access] if communities.include?(name)
430
- cmds = ["no snmp-server community #{name}",
431
- "snmp-server community #{name} #{access} #{value}"]
401
+ cmds = ["no snmp-server community #{name}"]
402
+ cmds << "snmp-server community #{name} #{access} #{value}" if enable
432
403
  configure cmds
433
404
  end
434
405
 
@@ -38,51 +38,98 @@ module Rbeapi
38
38
  # Rbeapi::Api
39
39
  module Api
40
40
  ##
41
- # The Staticroute class provides a configuration instance for working
41
+ # The Staticroutes class provides a configuration instance for working
42
42
  # with static routes in EOS.
43
43
  #
44
- class Staticroute < Entity
44
+ class Staticroutes < Entity
45
45
  ##
46
46
  # Returns the static routes configured on the node
47
47
  #
48
48
  # @example
49
49
  # {
50
- # <route>: {
51
- # "next_hop": <string>,
52
- # "name": <string, nil>
53
- # }
50
+ # [
51
+ # {
52
+ # destination: <route_dest/masklen>,
53
+ # nexthop: next_hop>,
54
+ # distance: <integer>,
55
+ # tag: <integer, nil>,
56
+ # name: <string, nil>
57
+ # },
58
+ # ...
59
+ # ]
54
60
  # }
55
61
  #
56
- # @returns [Hash<String, String> The method will return all of the
57
- # configured static routes on the node as a Ruby hash object. If
62
+ # @returns [Array<Hash, Hash>] The method will return all of the
63
+ # configured static routes on the node as a Ruby array object
64
+ # containing a list of hashes with each hash describing a route. If
58
65
  # there are no static routes configured, this method will return
59
- # an empty hash
66
+ # an empty array.
60
67
  def getall
61
68
  regex = /
62
69
  (?<=^ip\sroute\s)
63
- ([^\s]+)\s # captures network
64
- ([^\s$]+) # captures next hop
65
- (?:\s\d+) # non-capture metric
66
- (?:\stag\s\d+) # non-catpure route tag
70
+ ([^\s]+)\s # capture destination
71
+ ([^\s$]+) # capture next hop IP or egress interface
72
+ [\s|$](\d+) # capture metric (distance)
73
+ [\s|$]{1}(?:tag\s(\d+))? # catpure route tag
67
74
  [\s|$]{1}(?:name\s(.+))? # capture route name
68
75
  /x
69
76
 
70
77
  routes = config.scan(regex)
71
78
 
72
- routes.each_with_object({}) do |route, hsh|
73
- hsh[route[0]] = { 'next_hop' => route[1],
74
- 'name' => route[2] }
79
+ routes.each_with_object([]) do |route, arry|
80
+ arry << { destination: route[0],
81
+ nexthop: route[1],
82
+ distance: route[2],
83
+ tag: route[3],
84
+ name: route[4] }
75
85
  end
76
86
  end
77
87
 
78
- def create(route, nexthop, opts = {})
79
- cmd = "ip route #{route} #{nexthop}"
80
- opts.each { |param, value| cmds << "#{param} #{value}" }
88
+ ##
89
+ # Creates a static route in EOS. May add or overwrite an existing route.
90
+ #
91
+ # @commands
92
+ # ip route <destination> <nexthop> [router_ip] [distance] [tag <tag>]
93
+ # [name <name>]
94
+ #
95
+ # @param [String] :destination The destination and prefix matching the
96
+ # route(s). Ex '192.168.0.2/24'.
97
+ # @param [String] :nexthop The nexthop for this entry, which may an IP
98
+ # address or interface name.
99
+ # @param [Hash] :opts Additional options for the route entry.
100
+ # @option :opts [String] :router_ip If nexthop is an egress interface,
101
+ # router_ip specifies the router to which traffic will be forwarded
102
+ # @option :opts [String] :distance The administrative distance (metric)
103
+ # @option :opts [String] :tag The route tag
104
+ # @option :opts [String] :name A route name
105
+ #
106
+ # @return [Boolean] returns true on success
107
+ def create(destination, nexthop, opts = {})
108
+ cmd = "ip route #{destination} #{nexthop}"
109
+ cmd << " #{opts[:router_ip]}" if opts[:router_ip]
110
+ cmd << " #{opts[:distance]}" if opts[:distance]
111
+ cmd << " tag #{opts[:tag]}" if opts[:tag]
112
+ cmd << " name #{opts[:name]}" if opts[:name]
81
113
  configure cmd
82
114
  end
83
115
 
84
- def delete(route)
85
- configure "no ip route #{route}"
116
+ ##
117
+ # Removes a given route from EOS. May remove multiple routes if nexthop
118
+ # is not specified.
119
+ #
120
+ # @commands
121
+ # no ip route <destination> [nexthop]
122
+ #
123
+ # @param [String] :destination The destination and prefix matching the
124
+ # route(s). Ex '192.168.0.2/24'.
125
+ # @param [String] :nexthop The nexthop for this entry, which may an IP
126
+ # address or interface name.
127
+ #
128
+ # @return [Boolean] returns true on success
129
+ def delete(destination, nexthop = nil)
130
+ cmd = "no ip route #{destination}"
131
+ cmd << " #{nexthop}" if nexthop
132
+ configure cmd
86
133
  end
87
134
  end
88
135
  end