rbeapi 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/Gemfile +1 -1
  3. data/README.md +17 -12
  4. data/guide/.gitignore +2 -0
  5. data/guide/api.rst +5894 -0
  6. data/guide/conf.py +5 -5
  7. data/guide/contributing.rst +6 -0
  8. data/guide/getting-started.rst +134 -0
  9. data/guide/index.rst +3 -5
  10. data/guide/installation.rst +56 -1
  11. data/guide/license.rst +13 -2
  12. data/guide/overview.rst +2 -5
  13. data/guide/testing.rst +5 -1
  14. data/guide/upgrading.rst +10 -0
  15. data/lib/rbeapi/api.rb +37 -36
  16. data/lib/rbeapi/api/aaa.rb +90 -90
  17. data/lib/rbeapi/api/acl.rb +70 -53
  18. data/lib/rbeapi/api/bgp.rb +186 -163
  19. data/lib/rbeapi/api/dns.rb +51 -45
  20. data/lib/rbeapi/api/interfaces.rb +344 -328
  21. data/lib/rbeapi/api/ipinterfaces.rb +92 -92
  22. data/lib/rbeapi/api/logging.rb +32 -32
  23. data/lib/rbeapi/api/mlag.rb +97 -97
  24. data/lib/rbeapi/api/ntp.rb +39 -39
  25. data/lib/rbeapi/api/ospf.rb +58 -58
  26. data/lib/rbeapi/api/prefixlists.rb +22 -22
  27. data/lib/rbeapi/api/radius.rb +77 -49
  28. data/lib/rbeapi/api/routemaps.rb +110 -64
  29. data/lib/rbeapi/api/snmp.rb +104 -100
  30. data/lib/rbeapi/api/staticroutes.rb +27 -20
  31. data/lib/rbeapi/api/stp.rb +100 -84
  32. data/lib/rbeapi/api/switchports.rb +98 -77
  33. data/lib/rbeapi/api/system.rb +93 -25
  34. data/lib/rbeapi/api/tacacs.rb +54 -35
  35. data/lib/rbeapi/api/users.rb +68 -68
  36. data/lib/rbeapi/api/varp.rb +56 -47
  37. data/lib/rbeapi/api/vlans.rb +86 -86
  38. data/lib/rbeapi/api/vrrp.rb +210 -173
  39. data/lib/rbeapi/client.rb +142 -108
  40. data/lib/rbeapi/eapilib.rb +73 -62
  41. data/lib/rbeapi/utils.rb +8 -8
  42. data/lib/rbeapi/version.rb +2 -2
  43. data/spec/fixtures/test.conf +3 -3
  44. data/spec/system/rbeapi/api/system_spec.rb +46 -2
  45. data/spec/system/rbeapi/api/vlans_spec.rb +5 -2
  46. data/spec/system/rbeapi/client_spec.rb +4 -4
  47. data/spec/unit/rbeapi/api/system/default_spec.rb +40 -4
  48. data/spec/unit/rbeapi/api/system/fixture_system.text +14 -0
  49. data/spec/unit/rbeapi/api/vlans/default_spec.rb +1 -1
  50. data/spec/unit/rbeapi/api/vlans/fixture_vlans.text +2 -0
  51. data/spec/unit/rbeapi/client_spec.rb +1 -0
  52. metadata +9 -9
  53. data/guide/cookbook.rst +0 -4
  54. data/guide/developing.rst +0 -4
  55. data/guide/faq.rst +0 -4
  56. data/guide/quickstart.rst +0 -4
  57. data/guide/troubleshooting.rst +0 -1
@@ -50,12 +50,12 @@ module Rbeapi
50
50
  'socket' => 'Rbeapi::Eapilib::SocketEapiConnection' }
51
51
 
52
52
  ##
53
- # Returns the currently loaded config object. This function will
53
+ # Returns the currently loaded config object. This function will
54
54
  # create a new instance of the config object if one doesn't already
55
- # exist
55
+ # exist.
56
56
  #
57
57
  # @return [Config] Returns an instance of Config used for working
58
- # with the eapi.conf file
58
+ # with the eapi.conf file.
59
59
  def config
60
60
  return @config if @config
61
61
  @config = Config.new
@@ -64,11 +64,11 @@ module Rbeapi
64
64
 
65
65
  ##
66
66
  # load_config overrides the default conf file loaded in the config
67
- # instances using the supplied conf argument as the conf file. This
67
+ # instances using the supplied conf argument as the conf file. This
68
68
  # method will clear out an previously loaded configuration and replace
69
69
  # all entries with the contents of the supplied file.
70
70
  #
71
- # @param [String] :conf The full path to the conf file to load into
71
+ # @param conf [String] The full path to the conf file to load into
72
72
  # the config instance.
73
73
  def load_config(conf)
74
74
  config.read(conf)
@@ -76,15 +76,15 @@ module Rbeapi
76
76
 
77
77
  ##
78
78
  # Returns the configuration options for the named connection from
79
- # the loaded configuration. The configuration name is specified as
79
+ # the loaded configuration. The configuration name is specified as
80
80
  # the string right of the colon in the section name.
81
81
  #
82
- # @param [String] :name The connection name to return from the loaded
83
- # configuration
82
+ # @param name [String] The connection name to return from the loaded
83
+ # configuration.
84
84
  #
85
85
  # @return [Hash, nil] This method will return the configuration hash for
86
- # the named configuration if found. If the name is not found, then
87
- # nil is returned
86
+ # the named configuration if found. If the name is not found, then
87
+ # nil is returned.
88
88
  def config_for(name)
89
89
  config.get_connection(name)
90
90
  end
@@ -93,11 +93,11 @@ module Rbeapi
93
93
  # Retrieves the node config from the loaded configuration file and
94
94
  # returns a Rbeapi::Node instance for working with the remote node.
95
95
  #
96
- # @param [String] :name The named configuration to use for creating the
97
- # connection to the remote node
96
+ # @param name [String] The named configuration to use for creating the
97
+ # connection to the remote node.
98
98
  #
99
- # @return [Rbeapi::Node, nil] Returns an instance of Rbeapi::Node. If
100
- # the named configuration is not found then nil is returned
99
+ # @return [Rbeapi::Node, nil] Returns an instance of Rbeapi::Node. If
100
+ # the named configuration is not found then nil is returned.
101
101
  def connect_to(name)
102
102
  config_entry = config_for(name)
103
103
  return nil unless config_entry
@@ -114,26 +114,32 @@ module Rbeapi
114
114
 
115
115
  ##
116
116
  # Builds a connection object to a remote node using the specified
117
- # options and return an instance of Rbeapi::Connection. All
117
+ # options and return an instance of Rbeapi::Connection. All
118
118
  # configuration options can be passed via the :opts param.
119
119
  #
120
- # @param [Hash] :opts the options to create a message with
121
- # @option :opts [String] :host The IP address or hostname of the remote
122
- # eAPI endpoint
123
- # @option :opts [String] :username The username to use to authenticate
124
- # the eAPI connection with
125
- # @option :opts [String] :password The password to use to authenticate
126
- # the eAPI connection with
127
- # @option :opts [String] :enablepwd The enable password (if defined) to
128
- # pass to the remote node to enter privilege mode
129
- # @option :opts [String] :use_ssl Specifies whether or not to use the
130
- # HTTP or HTTPS protocol
131
- # @option :opts [String] :port The port to connect to. If not specified
120
+ # @param opts [Hash] the options to create a message with.
121
+ #
122
+ # @option opts host [String] The IP address or hostname of the remote
123
+ # eAPI endpoint.
124
+ #
125
+ # @option opts username [String] The username to use to authenticate
126
+ # the eAPI connection with.
127
+ #
128
+ # @option opts password [String] The password to use to authenticate
129
+ # the eAPI connection with.
130
+ #
131
+ # @option opts enablepwd [String] The enable password (if defined) to
132
+ # pass to the remote node to enter privilege mode.
133
+ #
134
+ # @option opts use_ssl [String] Specifies whether or not to use the
135
+ # HTTP or HTTPS protocol.
136
+ #
137
+ # @option opts port [String] The port to connect to. If not specified
132
138
  # The port is automatically determined based on the protocol used
133
- # (443 for https, 80 for http)
139
+ # (443 for https, 80 for http).
134
140
  #
135
141
  # @return [Rbeapi::Connection] Returns an instance of Rbeapi::Connection
136
- # using the specified configuration options
142
+ # using the specified configuration options.
137
143
  def connect(opts = {})
138
144
  transport = opts.fetch(:transport, DEFAULT_TRANSPORT)
139
145
  make_connection(transport, opts)
@@ -143,10 +149,11 @@ module Rbeapi
143
149
  # Creates a connection instance that can either be used directly or
144
150
  # passed to a Node instance.
145
151
  #
146
- # @params [String] :transport The name of the transport to create.
147
- # @params [Hash] :opts The options used to create the transport
152
+ # @param transport [String] The name of the transport to create.
148
153
  #
149
- # @return [Rbeapi::EapiConnection] A instance of a connection object
154
+ # @param opts [Hash] The options used to create the transport.
155
+ #
156
+ # @return [Rbeapi::EapiConnection] A instance of a connection object.
150
157
  def make_connection(transport, opts = {})
151
158
  klass = TRANSPORTS.fetch(transport)
152
159
  cls = Rbeapi::Utils.class_from_string(klass)
@@ -155,7 +162,7 @@ module Rbeapi
155
162
  end
156
163
 
157
164
  ##
158
- # The Config class holds the loaded configuration file data. It is a
165
+ # The Config class holds the loaded configuration file data. It is a
159
166
  # subclass of IniFile.
160
167
  class Config < IniFile
161
168
  CONFIG_SEARCH_PATH = ['/mnt/flash/eapi.conf']
@@ -164,7 +171,9 @@ module Rbeapi
164
171
  # The Config class will automatically search for a filename to load
165
172
  # (if none provided) and load the data when the object is instantiated.
166
173
  #
167
- # @param [String] :filename The full path to the filename to load. If
174
+ # @param opts [Hash] The initialization parameters.
175
+ #
176
+ # @option opts filename [String] The full path to the filename to load. If
168
177
  # the filename is not provided, then this class will attempt to find
169
178
  # a valid conf file using the CONFIG_SEARCH_PATH.
170
179
  def initialize(opts = {})
@@ -175,13 +184,14 @@ module Rbeapi
175
184
 
176
185
  ##
177
186
  # This private method automatically finds and loads the conf file
178
- # into the instance using the class variable CONFIG_SEARCH_PATH. The
179
- # connections should be retrieved using the get_connection method
187
+ # into the instance using the class variable CONFIG_SEARCH_PATH. The
188
+ # connections should be retrieved using the get_connection method.
180
189
  #
181
- # @param [Hash] :opts The options for specifying the message
182
- # @option :opts [String] :filename The full path to the filename
183
- # to load. Using this option eliminates the use of the
184
- # search path
190
+ # @param opts [Hash] The options for specifying the message.
191
+ #
192
+ # @option opts filename [String] The full path to the filename
193
+ # to load. Using this option eliminates the use of the
194
+ # search path.
185
195
  def autoload(opts = {})
186
196
  search_path = CONFIG_SEARCH_PATH.dup
187
197
  # Add the home directory path if the HOME environement var is defined.
@@ -202,10 +212,10 @@ module Rbeapi
202
212
 
203
213
  ##
204
214
  # This method will read the specified filename and load its contents
205
- # into the instance. It will also add the default localhost entry
206
- # if it doesn't exist in the conf file
215
+ # into the instance. It will also add the default localhost entry
216
+ # if it doesn't exist in the conf file.
207
217
  #
208
- # @param [String] :filename The full path to the filename to load
218
+ # @param filename [String] The full path to the filename to load.
209
219
  def read(filename)
210
220
  begin
211
221
  super(filename: filename)
@@ -215,12 +225,15 @@ module Rbeapi
215
225
  end
216
226
 
217
227
  # For each section, if the host parameter is omitted then the
218
- # connection name is used
228
+ # connection name is used.
229
+ has_default = self.has_section?('DEFAULT')
219
230
  sections.each do |name|
220
- if name.start_with?('connection:')
221
- conn = self["#{name}"]
222
- conn['host'] = name.split(':')[1] unless conn['host']
223
- end
231
+ next unless name.start_with?('connection:')
232
+ conn = self["#{name}"]
233
+ conn['host'] = name.split(':')[1] unless conn['host']
234
+
235
+ # Merge in the default values into the connections
236
+ conn.merge!(self['DEFAULT']) { |_key, v1, _v2| v1 } if has_default
224
237
  end
225
238
 
226
239
  return if get_connection 'localhost'
@@ -228,13 +241,14 @@ module Rbeapi
228
241
  end
229
242
 
230
243
  ##
231
- # This method will cause the config to be loaded. The process of
244
+ # This method will cause the config to be loaded. The process of
232
245
  # finding the configuration will be repeated so it is possible a
233
246
  # different conf file could be chosen if the original file was
234
- # removed or a new file added higher on the search priority list
247
+ # removed or a new file added higher on the search priority list.
248
+ #
249
+ # @param opts [Hash] The options for specifying the message.
235
250
  #
236
- # @param [Hash] :opts The options for specifying the message
237
- # @opton :opts [String] :filename The full path to the file to load
251
+ # @option opts filename [String] The full path to the file to load.
238
252
  def reload(opts = {})
239
253
  autoload opts
240
254
  end
@@ -244,12 +258,12 @@ module Rbeapi
244
258
  # connection is not found matching the name and if a default
245
259
  # connection has been specified then return the default connection.
246
260
  #
247
- # @param [String] :name The name of the connection to return from
248
- # the configuration. This should be the string right of the :
249
- # in the config section header
261
+ # @param name [String] The name of the connection to return from
262
+ # the configuration. This should be the string right of the :
263
+ # in the config section header.
250
264
  #
251
265
  # @return [nil, Hash<String, String> Returns a hash of the connection
252
- # properties from the loaded config. This method will return nil
266
+ # properties from the loaded config. This method will return nil
253
267
  # if the connection name is not found.
254
268
  def get_connection(name)
255
269
  return self["connection:#{name}"] \
@@ -259,11 +273,12 @@ module Rbeapi
259
273
  end
260
274
 
261
275
  ##
262
- # Adds a new connection section to the current configuration
276
+ # Adds a new connection section to the current configuration.
263
277
  #
264
- # @param [String] :name The name of the connection to add to the
278
+ # @param name [String] The name of the connection to add to the
265
279
  # configuration.
266
- # @param [Hash] :values The properties for the connection
280
+ #
281
+ # @param values [Hash] The properties for the connection.
267
282
  def add_connection(name, values)
268
283
  self["connection:#{name}"] = values
269
284
  nil
@@ -273,7 +288,7 @@ module Rbeapi
273
288
  ##
274
289
  # The Node object provides an instance for sending and receiving messages
275
290
  # with a specific EOS device. The methods provided in this class allow
276
- # for handling both enable mode and config mode commands
291
+ # for handling both enable mode and config mode commands.
277
292
  class Node
278
293
  attr_reader :connection
279
294
  attr_accessor :dry_run
@@ -281,7 +296,7 @@ module Rbeapi
281
296
  ##
282
297
  # Save the connection and set autorefresh to true.
283
298
  #
284
- # @param [Rbeapi::Eapilib::EapiConnection] :connection An instance of
299
+ # @param connection [Rbeapi::Eapilib::EapiConnection] An instance of
285
300
  # EapiConnection used to send and receive eAPI formatted messages
286
301
  def initialize(connection)
287
302
  @connection = connection
@@ -291,52 +306,58 @@ module Rbeapi
291
306
 
292
307
  ##
293
308
  # Provides access the nodes running-configuration. This is a lazily
294
- # loaded memoized property for working with the node configuration
309
+ # loaded memoized property for working with the node configuration.
295
310
  #
296
- # @return [String] The node's running-config as a string
311
+ # @return [String] The node's running-config as a string.
297
312
  def running_config
298
313
  return @running_config if @running_config
299
314
  @running_config = get_config(params: 'all', as_string: true)
300
315
  end
301
316
 
302
317
  ##
303
- # Provides access to the nodes startup-configuration. This is a lazily
304
- # loaded memoized property for working with the nodes startup config
318
+ # Provides access to the nodes startup-configuration. This is a lazily
319
+ # loaded memoized property for working with the nodes startup config.
305
320
  #
306
- # @return [String] The node's startup-config as a string
321
+ # @return [String] The node's startup-config as a string.
307
322
  def startup_config
308
323
  return @startup_config if @startup_config
309
324
  @startup_config = get_config(config: 'startup-config', as_string: true)
310
325
  end
311
326
 
312
327
  ##
313
- # Configures the node instance to use an enable password. EOS can be
328
+ # Configures the node instance to use an enable password. EOS can be
314
329
  # configured to require a second layer of authentication when putting
315
- # the session into enable mode. The password supplied will be used to
330
+ # the session into enable mode. The password supplied will be used to
316
331
  # authenticate the session to enable mode if necessary.
317
332
  #
318
- # @param [String] :password The value of the enable password
333
+ # @param password [String] The value of the enable password.
319
334
  def enable_authentication(password)
320
335
  @enablepwd = password
321
336
  end
322
337
 
323
338
  ##
324
339
  # The config method is a convenience method that will handling putting
325
- # the switch into config mode prior to executing commands. The method
340
+ # the switch into config mode prior to executing commands. The method
326
341
  # will insert 'config' at the top of the command stack and then pop
327
342
  # the empty hash from the response output before return the array
328
- # to the caller
343
+ # to the caller.
329
344
  #
330
- # @param [Array<String>] commands An ordered list of commands to execute
331
- # @option :opts [String] :encoding The encoding scheme to use for sending
332
- # and receive eAPI messages. Valid values are json and text. The
333
- # default value is json
334
- # @option :opts [Float] :open_timeout Number of seconds to wait for the
345
+ # @param commands [Array<String, Hash>] An ordered list of commands to
346
+ # execute. A string in the list is an eapi command. A Hash entry in the
347
+ # array consists of the following key value pairs:
348
+ # { cmd: 'eapi command', input: 'text passed into stdin for command' }
349
+ #
350
+ # @option opts encoding [String] The encoding scheme to use for sending
351
+ # and receive eAPI messages. Valid values are json and text. The
352
+ # default value is json.
353
+ #
354
+ # @option opts open_timeout [Float] Number of seconds to wait for the
335
355
  # eAPI connection to open.
336
- # @option :opts [Float] :read_timeout Number of seconds to wait for one
356
+ #
357
+ # @option opts read_timeout [Float] Number of seconds to wait for one
337
358
  # block of eAPI results to be read (via one read(2) call).
338
359
  #
339
- # @return [Array<Hash>] ordered list of output from commands
360
+ # @return [Array<Hash>] Ordered list of output from commands.
340
361
  def config(commands, opts = {})
341
362
  commands = [*commands] unless commands.respond_to?('each')
342
363
 
@@ -361,16 +382,22 @@ module Rbeapi
361
382
  #
362
383
  # rubocop:disable Metrics/MethodLength
363
384
  #
364
- # @param [Array<String>] commands An ordered list of commands to execute
365
- # @option :opts [String] :encoding The encoding scheme to use for sending
366
- # and receive eAPI messages. Valid values are json and text. The
367
- # default value is json
368
- # @option :opts [Float] :open_timeout Number of seconds to wait for the
385
+ # @param commands [Array<String, Hash>] An ordered list of commands to
386
+ # execute. A string in the list is an eapi command. A Hash entry in the
387
+ # array consists of the following key value pairs:
388
+ # { cmd: 'eapi command', input: 'text passed into stdin for command' }
389
+ #
390
+ # @option opts encoding [String] The encoding scheme to use for sending
391
+ # and receive eAPI messages. Valid values are json and text. The
392
+ # default value is json.
393
+ #
394
+ # @option opts open_timeout [Float] Number of seconds to wait for the
369
395
  # eAPI connection to open.
370
- # @option :opts [Float] :read_timeout Number of seconds to wait for one
396
+ #
397
+ # @option opts read_timeout [Float] Number of seconds to wait for one
371
398
  # block of eAPI results to be read (via one read(2) call).
372
399
  #
373
- # @return [Array<Hash>] ordered list of output from commands
400
+ # @return [Array<Hash>] Ordered list of output from commands.
374
401
  def enable(commands, opts = {})
375
402
  commands = [*commands] unless commands.respond_to?('each')
376
403
 
@@ -401,16 +428,18 @@ module Rbeapi
401
428
  end
402
429
 
403
430
  ##
404
- # Returns a response object from a call to the enable method. This
431
+ # Returns a response object from a call to the enable method. This
405
432
  # private method is an internal method to ensure consistency in the
406
- # return message format
433
+ # return message format.
434
+ #
435
+ # @param command [String] The command send to the node.
407
436
  #
408
- # @param [String] :command The command send to the node
409
- # @param [Hash] :response The response returned from the eAPI call
410
- # @param [String] :encoding The encoding scheme used in the response
411
- # which should be either json or text
437
+ # @param result [Hash] The response returned from the eAPI call.
412
438
  #
413
- # @return [Hash] A Ruby hash object
439
+ # @param encoding [String] The encoding scheme used in the response
440
+ # which should be either json or text.
441
+ #
442
+ # @return [Hash] A Ruby hash object.
414
443
  def make_response(command, result, encoding)
415
444
  { command: command, result: result, encoding: encoding }
416
445
  end
@@ -418,17 +447,20 @@ module Rbeapi
418
447
 
419
448
  ##
420
449
  # This method will send the ordered list of commands to the destination
421
- # node using the transport. It is also response for inserting enable
422
- # onto the command stack and popping the enable result on the response
450
+ # node using the transport. It is also response for inserting enable
451
+ # onto the command stack and popping the enable result on the response.
423
452
  #
424
- # @param [Array] :commands The ordered list of commands to send to the
453
+ # @param commands [Array] The ordered list of commands to send to the
425
454
  # destination node.
426
- # @option :opts [String] :encoding The encoding scheme to use for
427
- # sending and receive eAPI requests. This argument is optional.
428
- # Valid values include json or text. The default is json
429
- # @option :opts [Float] :open_timeout Number of seconds to wait for the
455
+ #
456
+ # @option opts encoding [String] The encoding scheme to use for
457
+ # sending and receive eAPI requests. This argument is optional.
458
+ # Valid values include json or text. The default is json.
459
+ #
460
+ # @option opts open_timeout [Float] Number of seconds to wait for the
430
461
  # eAPI connection to open.
431
- # @option :opts [Float] :read_timeout Number of seconds to wait for one
462
+ #
463
+ # @option opts read_timeout [Float] Number of seconds to wait for one
432
464
  # block of eAPI results to be read (via one read(2) call).
433
465
  def run_commands(commands, opts = {})
434
466
  encoding = opts.fetch(:encoding, 'json')
@@ -452,12 +484,14 @@ module Rbeapi
452
484
  # and return it in full text.
453
485
  #
454
486
  # @param [Hash] opts the options to create a message with
455
- # @option :opts [String] :config The configuration instance to return from
456
- # the node. Valid values are 'running-config' and 'startup-config'. If
457
- # no value is specified, then 'running-config' is used
458
- # @ :opts [String] :param Additional parameters to append to the
459
- # retrieving the configuration. Valid values depend on the config
460
- # file requested
487
+ #
488
+ # @option opts config [String] The configuration instance to return from
489
+ # the node. Valid values are 'running-config' and 'startup-config'. If
490
+ # no value is specified, then 'running-config' is used.
491
+ #
492
+ # @option opts param [String] Additional parameters to append to the
493
+ # retrieving the configuration. Valid values depend on the config
494
+ # file requested.
461
495
  #
462
496
  # running-config params
463
497
  # all Configuration with defaults
@@ -472,7 +506,7 @@ module Rbeapi
472
506
  # interfaces Filter config to include only the given interfaces
473
507
  # section Display sections containing matching commands
474
508
  #
475
- # @return [String] the specified configuration as text
509
+ # @return [String] The specified configuration as text.
476
510
  def get_config(opts = {})
477
511
  config = opts.fetch(:config, 'running-config')
478
512
  params = opts.fetch(:params, '')
@@ -484,7 +518,7 @@ module Rbeapi
484
518
 
485
519
  ##
486
520
  # Returns an API module for working with the active configuration
487
- # of the node
521
+ # of the node.
488
522
  def api(name, opts = {})
489
523
  path = opts.fetch(:path, 'rbeapi/api')
490
524
  namespace = opts.fetch(:namespace, 'Rbeapi::Api')