rbeapi 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.gitignore +5 -0
  2. data/.rubocop.yml +21 -0
  3. data/CHANGELOG.md +24 -0
  4. data/Gemfile +3 -1
  5. data/Guardfile +3 -3
  6. data/README.md +92 -17
  7. data/Rakefile +99 -4
  8. data/gems/README.rst +4 -0
  9. data/gems/inifile/.gitignore +2 -0
  10. data/gems/inifile/README.rst +5 -0
  11. data/gems/inifile/inifile.spec.tmpl +84 -0
  12. data/gems/net_http_unix/.gitignore +2 -0
  13. data/gems/net_http_unix/README.rst +5 -0
  14. data/gems/net_http_unix/net_http_unix.spec.tmpl +54 -0
  15. data/gems/netaddr/README.rst +5 -0
  16. data/gems/netaddr/netaddr.spec.tmpl +50 -0
  17. data/lib/rbeapi/api/aaa.rb +14 -17
  18. data/lib/rbeapi/api/acl.rb +276 -0
  19. data/lib/rbeapi/api/dns.rb +7 -4
  20. data/lib/rbeapi/api/interfaces.rb +239 -239
  21. data/lib/rbeapi/api/ipinterfaces.rb +5 -3
  22. data/lib/rbeapi/api/logging.rb +8 -5
  23. data/lib/rbeapi/api/mlag.rb +45 -127
  24. data/lib/rbeapi/api/ntp.rb +1 -4
  25. data/lib/rbeapi/api/ospf.rb +16 -13
  26. data/lib/rbeapi/api/prefixlists.rb +4 -4
  27. data/lib/rbeapi/api/radius.rb +34 -25
  28. data/lib/rbeapi/api/routemaps.rb +16 -10
  29. data/lib/rbeapi/api/snmp.rb +26 -13
  30. data/lib/rbeapi/api/staticroutes.rb +6 -5
  31. data/lib/rbeapi/api/stp.rb +77 -18
  32. data/lib/rbeapi/api/switchports.rb +20 -12
  33. data/lib/rbeapi/api/system.rb +6 -6
  34. data/lib/rbeapi/api/tacacs.rb +9 -6
  35. data/lib/rbeapi/api/varp.rb +15 -10
  36. data/lib/rbeapi/api/vlans.rb +5 -6
  37. data/lib/rbeapi/api.rb +56 -16
  38. data/lib/rbeapi/client.rb +85 -50
  39. data/lib/rbeapi/eapilib.rb +95 -56
  40. data/lib/rbeapi/netdev/snmp.rb +7 -16
  41. data/lib/rbeapi/utils.rb +3 -5
  42. data/lib/rbeapi/version.rb +1 -1
  43. data/rbeapi.gemspec +4 -2
  44. data/rbeapi.spec.tmpl +72 -0
  45. data/spec/support/fixtures.rb +6 -4
  46. data/spec/support/shared_examples_for_api_modules.rb +3 -18
  47. data/spec/system/api_acl_spec.rb +128 -0
  48. data/spec/system/api_ospf_interfaces_spec.rb +17 -14
  49. data/spec/system/api_ospf_spec.rb +8 -8
  50. data/spec/system/api_varp_interfaces_spec.rb +22 -13
  51. data/spec/system/api_varp_spec.rb +1 -4
  52. data/spec/system/rbeapi/api/interfaces_base_spec.rb +3 -4
  53. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +13 -9
  54. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +43 -26
  55. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +7 -6
  56. data/spec/system/rbeapi/api/ipinterfaces_spec.rb +34 -21
  57. data/spec/system/rbeapi/api/mlag_interfaces_spec.rb +15 -38
  58. data/spec/system/rbeapi/api/mlag_spec.rb +26 -30
  59. data/spec/system/rbeapi/api/snmp_spec.rb +0 -3
  60. data/spec/system/rbeapi/api/stp_instances_spec.rb +20 -12
  61. data/spec/system/rbeapi/api/stp_interfaces_spec.rb +1 -3
  62. data/spec/system/rbeapi/api/switchports_spec.rb +14 -12
  63. data/spec/system/rbeapi/api/system_spec.rb +0 -3
  64. data/spec/system/rbeapi/api/vlans_spec.rb +19 -9
  65. data/spec/unit/rbeapi/api/acl/default_spec.rb +158 -0
  66. data/spec/unit/rbeapi/api/acl/fixture_acl_standard.text +22 -0
  67. data/spec/unit/rbeapi/api/interfaces/base_spec.rb +123 -0
  68. data/spec/unit/rbeapi/api/interfaces/ethernet_spec.rb +89 -0
  69. data/spec/unit/rbeapi/api/interfaces/fixture_interfaces.text +219 -0
  70. data/spec/unit/rbeapi/api/interfaces/portchannel_spec.rb +149 -0
  71. data/spec/unit/rbeapi/api/interfaces/vxlan_spec.rb +243 -0
  72. data/spec/unit/rbeapi/api/mlag/default_spec.rb +218 -0
  73. data/spec/unit/rbeapi/api/mlag/fixture_mlag.text +238 -0
  74. data/spec/unit/rbeapi/api/vlans/default_spec.rb +135 -0
  75. data/spec/unit/rbeapi/api/vlans/fixture_vlans.text +5 -0
  76. metadata +79 -4
  77. data/lib/rbeapi/api/radius.rb.old +0 -399
@@ -31,16 +31,17 @@
31
31
  #
32
32
  require 'rbeapi/api'
33
33
 
34
+ ##
35
+ # Rbeapi toplevel namespace
34
36
  module Rbeapi
35
-
37
+ ##
38
+ # Rbeapi::Api
36
39
  module Api
37
-
38
40
  ##
39
41
  # The Staticroute class provides a configuration instance for working
40
42
  # with static routes in EOS.
41
43
  #
42
44
  class Staticroute < Entity
43
-
44
45
  ##
45
46
  # Returns the static routes configured on the node
46
47
  #
@@ -57,14 +58,14 @@ module Rbeapi
57
58
  # there are no static routes configured, this method will return
58
59
  # an empty hash
59
60
  def getall
60
- regex = %r{
61
+ regex = /
61
62
  (?<=^ip\sroute\s)
62
63
  ([^\s]+)\s # captures network
63
64
  ([^\s$]+) # captures next hop
64
65
  (?:\s\d+) # non-capture metric
65
66
  (?:\stag\s\d+) # non-catpure route tag
66
67
  [\s|$]{1}(?:name\s(.+))? # capture route name
67
- }x
68
+ /x
68
69
 
69
70
  routes = config.scan(regex)
70
71
 
@@ -31,17 +31,16 @@
31
31
  #
32
32
 
33
33
  ##
34
- # PuppetX is the toplevel namespace for working with Arista EOS nodes
34
+ # Rbeapi toplevel namespace
35
35
  module Rbeapi
36
36
  ##
37
- # Eos is module namesapce for working with the EOS command API
37
+ # Rbeapi::Api
38
38
  module Api
39
39
  ##
40
40
  # The Stp class provides a base class instance for working with
41
41
  # the EOS spanning-tree configuration
42
42
  #
43
43
  class Stp < Entity
44
-
45
44
  ##
46
45
  # get returns the current stp configuration parsed from the nodes
47
46
  # current running configuration.
@@ -65,7 +64,6 @@ module Rbeapi
65
64
  response
66
65
  end
67
66
 
68
-
69
67
  ##
70
68
  # parse_mode scans the nodes running configuration and extracts the
71
69
  # value of the spanning-tree mode. The spanning tree mode is
@@ -135,8 +133,11 @@ module Rbeapi
135
133
  when true
136
134
  cmd = 'default spanning-tree mode'
137
135
  when false
138
- cmd = (value ? "spanning-tree mode #{value}" : \
139
- 'no spanning-tree mode')
136
+ if value
137
+ cmd = "spanning-tree mode #{value}"
138
+ else
139
+ cmd = 'no spanning-tree mode'
140
+ end
140
141
  end
141
142
  configure cmd
142
143
  end
@@ -147,7 +148,6 @@ module Rbeapi
147
148
  # spanning-tree instances in EOS
148
149
  #
149
150
  class StpInstances < Entity
150
-
151
151
  DEFAULT_STP_PRIORITY = '32768'
152
152
 
153
153
  ##
@@ -215,10 +215,7 @@ module Rbeapi
215
215
  #
216
216
  # @return [Hash<Symbol, Object>] resource hash attribute
217
217
  def parse_priority(inst)
218
- priority_re = %r{
219
- (?<=^spanning-tree\smst\s#{inst}\spriority\s)
220
- (.+$)
221
- }x
218
+ priority_re = /(?<=^spanning-tree\smst\s#{inst}\spriority\s)(.+$)/x
222
219
  mdata = priority_re.match(config)
223
220
  { priority: mdata.nil? ? DEFAULT_STP_PRIORITY : mdata[1] }
224
221
  end
@@ -252,8 +249,11 @@ module Rbeapi
252
249
  when true
253
250
  cmd = "default spanning-tree mst #{inst} priority"
254
251
  when false
255
- cmd = (value ? "spanning-tree mst #{inst} priority #{value}" : \
256
- "no spanning-tree mst #{inst} priority")
252
+ if value
253
+ cmd = "spanning-tree mst #{inst} priority #{value}"
254
+ else
255
+ cmd = "no spanning-tree mst #{inst} priority"
256
+ end
257
257
  end
258
258
  configure cmd
259
259
  end
@@ -264,7 +264,6 @@ module Rbeapi
264
264
  # spanning-tree insterfaces in EOS
265
265
  #
266
266
  class StpInterfaces < Entity
267
-
268
267
  ##
269
268
  # get returns the configured stp interfaces from the nodes running
270
269
  # configuration as a resource hash. If the specified interface is not
@@ -284,6 +283,7 @@ module Rbeapi
284
283
  return nil if /no switchport$/ =~ config
285
284
  response = {}
286
285
  response.merge!(parse_portfast(config))
286
+ response.merge!(parse_portfast_type(config))
287
287
  response.merge!(parse_bpduguard(config))
288
288
  response
289
289
  end
@@ -325,6 +325,26 @@ module Rbeapi
325
325
  end
326
326
  private :parse_portfast
327
327
 
328
+ ##
329
+ # parse_portfast_type scans the supplied interface configuration block
330
+ # and parses the value stp portfast type. The value of portfast type
331
+ # is either not set which implies normal (default), edge, or network.
332
+ #
333
+ # @api private
334
+ #
335
+ # @return [Hash<Symbol, Object>] resource hash attribute
336
+ def parse_portfast_type(config)
337
+ if /spanning-tree portfast network/ =~ config
338
+ value = 'network'
339
+ elsif /no spanning-tree portfast/ =~ config
340
+ value = 'normal'
341
+ else
342
+ value = 'edge'
343
+ end
344
+ { portfast_type: value }
345
+ end
346
+ private :parse_portfast_type
347
+
328
348
  ##
329
349
  # parse_bpduguard scans the supplied interface configuration block and
330
350
  # parses the value of stp bpduguard. The value of bpduguard is either
@@ -337,6 +357,7 @@ module Rbeapi
337
357
  val = /spanning-tree bpduguard enable/ =~ config
338
358
  { bpduguard: !val.nil? }
339
359
  end
360
+ private :parse_bpduguard
340
361
 
341
362
  ##
342
363
  # Configures the interface portfast value
@@ -356,12 +377,47 @@ module Rbeapi
356
377
  when true
357
378
  cmds << 'default spanning-tree portfast'
358
379
  when false
359
- cmds << (value ? 'spanning-tree portfast' :
360
- 'no spanning-tree portfast')
380
+ if value
381
+ cmds << 'spanning-tree portfast'
382
+ else
383
+ cmds << 'no spanning-tree portfast'
384
+ end
361
385
  end
362
386
  configure(cmds)
363
387
  end
364
388
 
389
+ ##
390
+ # Configures the interface portfast type value
391
+ #
392
+ # @param [String] name The name of the interface to configure
393
+ # @param [Hash] opts The configuration parameters for portfast type
394
+ # @option opts [String] :value The value to set portfast type to.
395
+ # @option opts [Boolean] :default The value should be set to default
396
+ #
397
+ # @return [Boolean] True if the commands succeed otherwise False
398
+ def set_portfast_type(name, opts = {})
399
+ value = opts[:value]
400
+ default = opts[:default] || false
401
+
402
+ cmds = ["interface #{name}"]
403
+ case default
404
+ when true
405
+ cmds << 'default spanning-tree portfast normal'
406
+ when false
407
+ cmds << "spanning-tree portfast #{value}"
408
+ end
409
+ configure(cmds)
410
+ end
411
+
412
+ ##
413
+ # Configures the interface bpdu guard value
414
+ #
415
+ # @param [String] name The name of the interface to configure
416
+ # @param [Hash] opts The configuration parameters for bpduguard
417
+ # @option opts [Boolean] :value The value to set bpduguard
418
+ # @option opts [Boolean] :default The value should be set to default
419
+ #
420
+ # @return [Boolean] True if the commands succeed otherwise False
365
421
  def set_bpduguard(name, opts = {})
366
422
  value = opts[:value]
367
423
  default = opts[:default] || false
@@ -371,8 +427,11 @@ module Rbeapi
371
427
  when true
372
428
  cmds << 'default spanning-tree bpduguard'
373
429
  when false
374
- cmds << (value ? 'spanning-tree bpduguard enable' :
375
- 'spanning-tree bpduguard disable')
430
+ if value
431
+ cmds << 'spanning-tree bpduguard enable'
432
+ else
433
+ cmds << 'spanning-tree bpduguard disable'
434
+ end
376
435
  end
377
436
  configure(cmds)
378
437
  end
@@ -31,16 +31,17 @@
31
31
  #
32
32
  require 'rbeapi/api'
33
33
 
34
+ ##
35
+ # Rbeapi toplevel namespace
34
36
  module Rbeapi
35
37
  ##
36
- # Eos is module namesapce for working with the EOS command API
38
+ # Api is module namesapce for working with the EOS command API
37
39
  module Api
38
40
  ##
39
41
  # The Switchport class provides a base class instance for working with
40
42
  # logical layer-2 interfaces.
41
43
  #
42
44
  class Switchports < Entity
43
-
44
45
  ##
45
46
  # Retrieves the properies for a logical switchport from the
46
47
  # running-config using eAPI
@@ -162,8 +163,11 @@ module Rbeapi
162
163
  when true
163
164
  cmds << 'default switchport mode'
164
165
  when false
165
- cmds << (value.nil? ? 'no switchport mode' : \
166
- "switchport mode #{value}")
166
+ if value.nil?
167
+ cmds << 'no switchport mode'
168
+ else
169
+ cmds << "switchport mode #{value}"
170
+ end
167
171
  end
168
172
  configure(cmds)
169
173
  end
@@ -195,9 +199,7 @@ module Rbeapi
195
199
  value = opts[:value]
196
200
  default = opts[:default] || false
197
201
 
198
- unless value.is_a?(Array)
199
- raise ArgumentError, 'value must be an Array'
200
- end
202
+ fail ArgumentError, 'value must be an Array' unless value.is_a?(Array)
201
203
 
202
204
  value = value.map(&:inspect).join(',') if value
203
205
 
@@ -210,7 +212,7 @@ module Rbeapi
210
212
  cmds << 'no switchport trunk allowed vlan'
211
213
  else
212
214
  cmds << 'switchport trunk allowed vlan none'
213
- cmds << "switchport trunk allowed vlan add #{value}"
215
+ cmds << "switchport trunk allowed vlan #{value}"
214
216
  end
215
217
  end
216
218
  configure(cmds)
@@ -236,8 +238,11 @@ module Rbeapi
236
238
  when true
237
239
  cmds << 'default switchport trunk native vlan'
238
240
  when false
239
- cmds << (value.nil? ? 'no switchport trunk native vlan' : \
240
- "switchport trunk native vlan #{value}")
241
+ if value.nil?
242
+ cmds << 'no switchport trunk native vlan'
243
+ else
244
+ cmds << "switchport trunk native vlan #{value}"
245
+ end
241
246
  end
242
247
  configure(cmds)
243
248
  end
@@ -262,8 +267,11 @@ module Rbeapi
262
267
  when true
263
268
  cmds << 'default switchport access vlan'
264
269
  when false
265
- cmds << (value.nil? ? 'no switchport access vlan' : \
266
- "switchport access vlan #{value}")
270
+ if value.nil?
271
+ cmds << 'no switchport access vlan'
272
+ else
273
+ cmds << "switchport access vlan #{value}"
274
+ end
267
275
  end
268
276
  configure(cmds)
269
277
  end
@@ -31,15 +31,16 @@
31
31
  #
32
32
  require 'rbeapi/api'
33
33
 
34
+ ##
35
+ # Rbeapi toplevel namespace
34
36
  module Rbeapi
35
-
37
+ ##
38
+ # Rbeapi::Api
36
39
  module Api
37
-
38
40
  ##
39
41
  # The System class configures the node system services such as
40
42
  # hostname and domain name
41
43
  class System < Entity
42
-
43
44
  ##
44
45
  # Returns the system settings
45
46
  #
@@ -50,7 +51,7 @@ module Rbeapi
50
51
  #
51
52
  # @return [Hash] A Ruby hash objec that provides the system settings as
52
53
  # key/value pairs.
53
- def get()
54
+ def get
54
55
  response = {}
55
56
  response.merge!(parse_hostname(config))
56
57
  response
@@ -77,8 +78,7 @@ module Rbeapi
77
78
  when true
78
79
  cmds = ['default hostname']
79
80
  when false
80
- cmds = (value.nil? ? 'no hostname' : \
81
- "hostname #{value}")
81
+ cmds = (value.nil? ? 'no hostname' : "hostname #{value}")
82
82
  end
83
83
  configure(cmds)
84
84
  end
@@ -31,16 +31,16 @@
31
31
  #
32
32
  require 'rbeapi/api'
33
33
 
34
+ ##
35
+ # Rbeapi toplevel namespace
34
36
  module Rbeapi
35
37
  ##
36
- # Eos is module namesapce for working with the EOS command API
38
+ # Api is module namesapce for working with the EOS command API
37
39
  module Api
38
-
39
40
  ##
40
41
  # Tacacs provides instance methods to retrieve and set tacacs configuration
41
42
  # values.
42
43
  class Tacacs < Entity
43
-
44
44
  DEFAULT_KEY_FORMAT = 0
45
45
  DEFAULT_KEY = nil
46
46
 
@@ -192,10 +192,13 @@ module Rbeapi
192
192
 
193
193
  case default
194
194
  when true
195
- cmds = 'default tacacs-server timeout'
195
+ cmds = 'default tacacs-server timeout'
196
196
  when false
197
- cmds = value ? "tacacs-server timeout #{value}" :
198
- 'no tacacs-server timeout'
197
+ if value
198
+ cmds = "tacacs-server timeout #{value}"
199
+ else
200
+ cmds = 'no tacacs-server timeout'
201
+ end
199
202
  end
200
203
  configure cmds
201
204
  end
@@ -31,15 +31,16 @@
31
31
  #
32
32
  require 'rbeapi/api'
33
33
 
34
+ ##
35
+ # Rbeapi toplevel namespace
34
36
  module Rbeapi
35
-
37
+ ##
38
+ # Rbeapi::Api
36
39
  module Api
37
-
38
40
  ##
39
41
  # The Varp class provides an instance for working with the global
40
42
  # VARP configuration of the node
41
43
  class Varp < Entity
42
-
43
44
  ##
44
45
  # Returns the global VARP configuration from the node
45
46
  #
@@ -54,10 +55,8 @@ module Rbeapi
54
55
  def get
55
56
  response = {}
56
57
 
57
- regex = %r{
58
- (?<=^ip\svirtual-router\smac-address\s)
59
- ((?:[a-f0-9]{2}:){5}[a-f0-9]{2})$
60
- }x
58
+ regex = /(?<=^ip\svirtual-router\smac-address\s)
59
+ ((?:[a-f0-9]{2}:){5}[a-f0-9]{2})$/x
61
60
 
62
61
  mdata = regex.match(config)
63
62
  response['mac_address'] = mdata.nil? ? '' : mdata[1]
@@ -87,13 +86,19 @@ module Rbeapi
87
86
  when true
88
87
  cmds = ['default ip virtual-router mac-address']
89
88
  when false
90
- cmds = (value ? "ip virtual-router mac-address #{value}" : \
91
- 'no ip virtual-router mac-address')
89
+ if value
90
+ cmds = "ip virtual-router mac-address #{value}"
91
+ else
92
+ cmds = 'no ip virtual-router mac-address'
93
+ end
92
94
  end
93
95
  configure(cmds)
94
96
  end
95
97
  end
96
98
 
99
+ ##
100
+ # The VarpInterfaces class provides an instance for working with the global
101
+ # VARP interface configuration of the node
97
102
  class VarpInterfaces < Entity
98
103
  ##
99
104
  # Returns a single VARP interface configuration
@@ -165,7 +170,7 @@ module Rbeapi
165
170
  return result unless result
166
171
  end
167
172
  end
168
- return true
173
+ true
169
174
  end
170
175
 
171
176
  def add_address(name, value)
@@ -31,12 +31,12 @@
31
31
  #
32
32
  require 'rbeapi/api'
33
33
 
34
+ ##
35
+ # Rbeapi toplevel namespace
34
36
  module Rbeapi
35
-
36
37
  ##
37
38
  # Api is module namesapce for working with the EOS command API
38
39
  module Api
39
-
40
40
  ##
41
41
  # The Vlan class provides a class implementation for working with the
42
42
  # collection of Vlans on the node. This class presents an abstraction
@@ -44,7 +44,6 @@ module Rbeapi
44
44
  #
45
45
  # @eos_version 4.13.7M
46
46
  class Vlans < Entity
47
-
48
47
  ##
49
48
  # get returns the specified vlan resource Hash that represents the
50
49
  # nodes current vlan configuration.
@@ -106,7 +105,7 @@ module Rbeapi
106
105
  #
107
106
  # @return [Hash<Symbol, Object>] resource hash attribute
108
107
  def parse_name(config)
109
- mdata = /name (\w+)$/.match(config)
108
+ mdata = /name ([^\s]+)$/.match(config)
110
109
  { name: mdata[1] }
111
110
  end
112
111
  private :parse_name
@@ -236,7 +235,7 @@ module Rbeapi
236
235
  when true
237
236
  cmds << 'default name'
238
237
  when false
239
- cmds << (value.nil? ? 'no name' : "name #{value}")
238
+ cmds << (value.nil? ? 'no name' : "name #{value}")
240
239
  end
241
240
  configure(cmds)
242
241
  end
@@ -278,7 +277,7 @@ module Rbeapi
278
277
  default = opts[:default] || false
279
278
 
280
279
  unless ['active', 'suspend', nil].include?(value)
281
- raise ArgumentError, 'state must be active, suspend or nil'
280
+ fail ArgumentError, 'state must be active, suspend or nil'
282
281
  end
283
282
 
284
283
  cmds = ["vlan #{id}"]
data/lib/rbeapi/api.rb CHANGED
@@ -31,20 +31,24 @@
31
31
  #
32
32
  require 'rbeapi/eapilib'
33
33
 
34
+ ##
35
+ # Rbeapi toplevel namespace
34
36
  module Rbeapi
35
-
37
+ ##
38
+ # Rbeapi::Api
36
39
  module Api
37
-
40
+ ##
41
+ # The Entity class provides a base class implementation for building
42
+ # API modules. The Entity class is typcially not instantiated directly
43
+ # but serves as a super class with convenience methods used to
44
+ # work with the node.
38
45
  class Entity
39
-
40
46
  attr_reader :error
41
47
  attr_reader :config
42
48
  attr_reader :node
43
49
 
44
50
  ##
45
- # The instance class method is used to create a new instance of the
46
- # object. It works in conjunction with the Node.api loader method
47
- # to make it easy to load classes derived from Entity
51
+ # Construct the node.
48
52
  #
49
53
  # @param [Node] :node An instance of Rbeapi::Client::Node used to
50
54
  # send and receive eAPI messages
@@ -61,7 +65,7 @@ module Rbeapi
61
65
  # @param [Node] :node This should be an instance of Rbeapi::Client::Node
62
66
  # that is used to send and receive eAPI messages
63
67
  #
64
- def initialize(node, opts = {})
68
+ def initialize(node)
65
69
  @node = node
66
70
  end
67
71
 
@@ -72,7 +76,7 @@ module Rbeapi
72
76
  #
73
77
  # @return [String] The current running-config from the node
74
78
  def config
75
- return @node.running_config
79
+ @node.running_config
76
80
  end
77
81
 
78
82
  ##
@@ -82,7 +86,7 @@ module Rbeapi
82
86
  # @return [Rbeapi::Eapilib::CommandError] An instance of CommandError
83
87
  # that can be used to futher evaluate the root cause of an error
84
88
  def error
85
- return @node.connection.error
89
+ @node.connection.error
86
90
  end
87
91
 
88
92
  ##
@@ -105,7 +109,7 @@ module Rbeapi
105
109
  return nil unless mdata
106
110
 
107
111
  _, block_end = mdata.offset(0)
108
- block_end = block_end - block_start
112
+ block_end -= block_start
109
113
 
110
114
  config[block_start, block_end]
111
115
  end
@@ -122,14 +126,50 @@ module Rbeapi
122
126
  # returns False if there was an error issuing the commands on the
123
127
  # node. Use error to further investigate the cause of any errors
124
128
  def configure(commands)
125
- begin
126
- @node.config(commands)
127
- return true
128
- rescue Rbeapi::Eapilib::CommandError, Rbeapi::Eapilib::ConnectionError
129
- return false
129
+ @node.config(commands)
130
+ return true
131
+ rescue Rbeapi::Eapilib::CommandError, Rbeapi::Eapilib::ConnectionError
132
+ return false
133
+ end
134
+
135
+ ##
136
+ # command_builder builds the correct version of a command based on the
137
+ # configuration options. If the value option is not provided then the
138
+ # no keyword is used to build the command. If the default value is
139
+ # provided and set to true, then the default keyword is used. If both
140
+ # options are provided, then the default option will take precedence.
141
+ #
142
+ # @return [String]
143
+ def command_builder(cmd, opts = {})
144
+ value = opts[:value]
145
+ default = opts.fetch(:default, false)
146
+ case default
147
+ when true then "default #{cmd}"
148
+ when false
149
+ case value
150
+ when nil, false then "no #{cmd}"
151
+ when true then cmd
152
+ else "#{cmd} #{value}"
153
+ end
130
154
  end
131
155
  end
156
+
157
+ ##
158
+ # configure_interface sends the commands over eAPI to the desitnation
159
+ # node to configure a specific interface.
160
+ #
161
+ # @param [String] :name The interface name to apply the configuration
162
+ # to. The name value must be the full interface identifier
163
+ #
164
+ # @param [Array] :commands The list of commands to configure the
165
+ # interface
166
+ #
167
+ # @return [Boolean] Returns true if the commands complete successfully
168
+ def configure_interface(name, commands)
169
+ commands = [*commands]
170
+ commands.insert(0, "interface #{name}")
171
+ configure commands
172
+ end
132
173
  end
133
174
  end
134
175
  end
135
-