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
@@ -32,10 +32,10 @@
32
32
  require 'rbeapi/api'
33
33
 
34
34
  ##
35
- # Rbeapi toplevel namespace
35
+ # Rbeapi toplevel namespace.
36
36
  module Rbeapi
37
37
  ##
38
- # Api is module namespace for working with the EOS command API
38
+ # Api is module namespace for working with the EOS command API.
39
39
  module Api
40
40
  ##
41
41
  # Tacacs provides instance methods to retrieve and set tacacs configuration
@@ -45,7 +45,7 @@ module Rbeapi
45
45
  DEFAULT_KEY = nil
46
46
 
47
47
  # Regular expression to extract a tacacs server's attributes from the
48
- # running-configuration text. The explicit [ ] spaces enable line
48
+ # running-configuration text. The explicit [ ] spaces enable line
49
49
  # wrapping and indentation with the /x flag.
50
50
  SERVER_REGEXP = /tacacs-server[ ]host[ ]([^\s]+)
51
51
  (?:[ ](single-connection))?
@@ -72,7 +72,7 @@ module Rbeapi
72
72
  # timeout: <integer>
73
73
  # }
74
74
  #
75
- # @return [Array<Hash>] Single element Array of resource hashes
75
+ # @return [Array<Hash>] Single element Array of resource hashes.
76
76
  def get
77
77
  global = {}
78
78
  global.merge!(parse_global_timeout)
@@ -84,15 +84,13 @@ module Rbeapi
84
84
  ##
85
85
  # parse_global_key takes a running configuration as a string and
86
86
  # parses out the radius global key and global key format if it exists in
87
- # the configuration. An empty Hash is returned if there is no global key
88
- # configured. The intent of the Hash is to be merged into a property
87
+ # the configuration. An empty Hash is returned if there is no global key
88
+ # configured. The intent of the Hash is to be merged into a property
89
89
  # hash.
90
90
  #
91
- # @param [String] config The running configuration as a single string.
92
- #
93
91
  # @api private
94
92
  #
95
- # @return [Hash<Symbol,Object>] resource hash attributes
93
+ # @return [Hash<Symbol,Object>] Returns the resource hash attributes.
96
94
  def parse_global_key
97
95
  rsrc_hsh = {}
98
96
  (key_format, key) = config.scan(/tacacs-server key (\d+) (\w+)/).first
@@ -105,15 +103,13 @@ module Rbeapi
105
103
  ##
106
104
  # parse_global_timeout takes a running configuration as a string
107
105
  # and parses out the tacacs global timeout if it exists in the
108
- # configuration. An empty Hash is returned if there is no global timeout
109
- # value configured. The intent of the Hash is to be merged into a
106
+ # configuration. An empty Hash is returned if there is no global timeout
107
+ # value configured. The intent of the Hash is to be merged into a
110
108
  # property hash.
111
109
  #
112
- # @param [String] config The running configuration as a single string.
113
- #
114
110
  # @api private
115
111
  #
116
- # @return [Hash<Symbol,Object>] resource hash attributes
112
+ # @return [Hash<Symbol,Object>] Returns the resource hash attributes.
117
113
  def parse_global_timeout
118
114
  timeout = config.scan(/tacacs-server timeout (\d+)/).first
119
115
  { timeout: timeout.first.to_i }
@@ -127,17 +123,17 @@ module Rbeapi
127
123
  #
128
124
  # The resource hash returned contains the following information:
129
125
  #
130
- # * hostname: hostname or ip address, part of the identifier
131
- # * port: (Fixnum) TCP port of the server, part of the identifier
132
- # * key: (String) the key either in plain text or hashed format
133
- # * key_format: (Fixnum) e.g. 0 or 7
134
- # * timeout: (Fixnum) seconds before the timeout period ends
126
+ # * hostname: hostname or ip address, part of the identifier.
127
+ # * port: (Fixnum) TCP port of the server, part of the identifier.
128
+ # * key: (String) the key either in plain text or hashed format.
129
+ # * key_format: (Fixnum) e.g. 0 or 7.
130
+ # * timeout: (Fixnum) seconds before the timeout period ends.
135
131
  # * multiplex: (Boolean) true when configured to make requests through a
136
- # single connection
132
+ # single connection.
137
133
  #
138
134
  # @api public
139
135
  #
140
- # @return [Array<Hash<Symbol,Object>>] Array of resource hashes
136
+ # @return [Array<Hash<Symbol,Object>>] Array of resource hashes.
141
137
  def servers
142
138
  tuples = config.scan(SERVER_REGEXP)
143
139
  tuples.map do |(host, mplex, vrf, port, tout, keyfm, key)|
@@ -154,19 +150,19 @@ module Rbeapi
154
150
  end
155
151
 
156
152
  ##
157
- # set_global_key configures the tacacs default key. This method maps to
153
+ # set_global_key configures the tacacs default key. This method maps to
158
154
  # the `tacacs-server key` EOS configuration command, e.g. `tacacs-server
159
155
  # key 7 070E234F1F5B4A`.
160
156
  #
161
- # @option opts [String] :key ('070E234F1F5B4A') The key value
157
+ # @option opts key [String] ('070E234F1F5B4A') The key value.
162
158
  #
163
- # @option opts [Fixnum] :key_format (7) The key format, 0 for plain text
164
- # and 7 for a hashed value. 7 will be assumed if this option is not
159
+ # @option opts key_format [Fixnum] (7) The key format, 0 for plain text
160
+ # and 7 for a hashed value. 7 will be assumed if this option is not
165
161
  # provided.
166
162
  #
167
163
  # @api public
168
164
  #
169
- # @return [Boolean] true if no errors
165
+ # @return [Boolean] Returns true if no errors.
170
166
  def set_global_key(opts = {})
171
167
  format = opts[:key_format]
172
168
  key = opts[:key]
@@ -176,18 +172,21 @@ module Rbeapi
176
172
  end
177
173
 
178
174
  ##
179
- # set_timeout configures the tacacs default timeout. This method maps to
175
+ # set_timeout configures the tacacs default timeout. This method maps to
180
176
  # the `tacacs-server timeout` setting.
181
177
  #
182
- # @param [Hash] opts The configuration parameters
183
- # @option opts [string] :value The value to set the timeout to
184
- # @option :opts [Boolean] :enable If false then the command is
178
+ # @param opts [Hash] The configuration parameters.
179
+ #
180
+ # @option opts value [string] The value to set the timeout to.
181
+ #
182
+ # @option opts enable [Boolean] If false then the command is
185
183
  # negated. Default is true.
186
- # @option opts [Boolean] :default The value should be set to default
184
+ #
185
+ # @option opts default [Boolean] The value should be set to default.
187
186
  #
188
187
  # @api public
189
188
  #
190
- # @return [Boolean] true if no errors
189
+ # @return [Boolean] Returns true if no errors.
191
190
  def set_global_timeout(opts = {})
192
191
  cmd = command_builder('tacacs-server timeout', opts)
193
192
  configure cmd
@@ -197,11 +196,25 @@ module Rbeapi
197
196
  # update_server configures a tacacs server resource on the target device.
198
197
  # This API method maps to the `tacacs server host` command, e.g.
199
198
  # `tacacs-server host 1.2.3.4 single-connection port 4949 timeout 6 key 7
200
- # 06070D221D1C5A`
199
+ # 06070D221D1C5A`.
201
200
  #
202
201
  # @api public
203
202
  #
204
- # @return [Boolean] true if there are no errors
203
+ # @param opts [Hash] The configuration parameters.
204
+ #
205
+ # @option opts key_format [Integer] The format for the key.
206
+ #
207
+ # @option opts hostname [String] The host value.
208
+ #
209
+ # @option opts multiplex [String] Defines single-connection.
210
+ #
211
+ # @option opts port [String] The port value.
212
+ #
213
+ # @option opts timeout [String] The timeout value.
214
+ #
215
+ # @option opts key [String] The key value.
216
+ #
217
+ # @return [Boolean] Returns true if there are no errors.
205
218
  def update_server(opts = {})
206
219
  key_format = opts[:key_format] || 7
207
220
  cmd = "tacacs-server host #{opts[:hostname]}"
@@ -218,7 +231,13 @@ module Rbeapi
218
231
  #
219
232
  # @api public
220
233
  #
221
- # @return [Boolean] true if no errors
234
+ # @param opts [Hash] The configuration parameters.
235
+ #
236
+ # @option hostname [String] The host value.
237
+ #
238
+ # @option port [String] The port value.
239
+ #
240
+ # @return [Boolean] Returns true if there are no errors.
222
241
  def remove_server(opts = {})
223
242
  cmd = "no tacacs-server host #{opts[:hostname]}"
224
243
  cmd << " port #{opts[:port]}" if opts[:port]
@@ -32,10 +32,10 @@
32
32
  require 'rbeapi/api'
33
33
 
34
34
  ##
35
- # Rbeapi toplevel namespace
35
+ # Rbeapi toplevel namespace.
36
36
  module Rbeapi
37
37
  ##
38
- # Api is module namespace for working with the EOS command API
38
+ # Api is module namespace for working with the EOS command API.
39
39
  module Api
40
40
  ##
41
41
  # The Users class provides configuration of local user resources for
@@ -63,7 +63,7 @@ module Rbeapi
63
63
  end
64
64
 
65
65
  ##
66
- # get returns the local user configuration
66
+ # get returns the local user configuration.
67
67
  #
68
68
  # @example
69
69
  # {
@@ -76,12 +76,12 @@ module Rbeapi
76
76
  # sshkey: <string>
77
77
  # }
78
78
  #
79
- # @param [String] :name The user name to return a resource for from the
79
+ # @param name [String] The user name to return a resource for from the
80
80
  # nodes configuration
81
81
  #
82
82
  # @return [nil, Hash<Symbol, Object>] Returns the user resource as a
83
83
  # Hash. If the specified user name is not found in the nodes current
84
- # configuration a nil object is returned
84
+ # configuration a nil object is returned.
85
85
  def get(name)
86
86
  # The regex used here parses the running configuration to find one
87
87
  # username entry.
@@ -100,7 +100,7 @@ module Rbeapi
100
100
 
101
101
  ##
102
102
  # getall returns a collection of user resource hashes from the nodes
103
- # running configuration. The user resource collection hash is keyed
103
+ # running configuration. The user resource collection hash is keyed
104
104
  # by the unique user name.
105
105
  #
106
106
  # @example
@@ -126,7 +126,7 @@ module Rbeapi
126
126
  # ...
127
127
  # ]
128
128
  #
129
- # @return [Hash<Symbol, Object>] returns a hash that represents the
129
+ # @return [Hash<Symbol, Object>] Returns a hash that represents the
130
130
  # entire user collection from the nodes running configuration. If
131
131
  # there are no user names configured, this method will return an empty
132
132
  # hash.
@@ -144,10 +144,10 @@ module Rbeapi
144
144
  #
145
145
  # @api private
146
146
  #
147
- # @param [Array] :user An array of values returned from the regular
147
+ # @param user [Array] An array of values returned from the regular
148
148
  # expression scan of the nodes configuration.
149
149
  #
150
- # @return [Hash<Symbol, Object>] resource hash attribute
150
+ # @return [Hash<Symbol, Object>] Returns the resource hash attribute.
151
151
  def parse_user_entry(user)
152
152
  hsh = {}
153
153
  hsh[:name] = user[0]
@@ -178,34 +178,34 @@ module Rbeapi
178
178
  # Optional parameters can be passed in to initialize user name specific
179
179
  # settings.
180
180
  #
181
- # @eos_version 4.13.7M
181
+ # @since eos_version 4.13.7M
182
182
  #
183
- # @commands
183
+ # ===Commands
184
184
  # username <name> nopassword privilege <value> role <value>
185
185
  # username <name> secret [0,5,sha512] <secret> ...
186
186
  #
187
- # @param [String] :name The name of the user to create
187
+ # @param name [String] The name of the user to create.
188
188
  #
189
- # @param [hash] :opts Optional keyword arguments
189
+ # @param opts [hash] Optional keyword arguments.
190
190
  #
191
- # @option :opts [Boolean] :nopassword Configures the user to be able to
192
- # authenticate without a password challenge
191
+ # @option opts nopassword [Boolean] Configures the user to be able to
192
+ # authenticate without a password challenge.
193
193
  #
194
- # @option :opts [String] :secret The secret (password) to assign to this
195
- # user
194
+ # @option opts secret [String] The secret (password) to assign to this
195
+ # user.
196
196
  #
197
- # @option :opts [String] :encryption Specifies how the secret is encoded.
197
+ # @option opts encryption [String] Specifies how the secret is encoded.
198
198
  # Valid values are "cleartext", "md5", "sha512". The default is
199
- # "cleartext"
199
+ # "cleartext".
200
200
  #
201
- # @option :opts [String] :privilege The privilege value to assign to
202
- # the user
201
+ # @option opts privilege [String] The privilege value to assign to
202
+ # the user.
203
203
  #
204
- # @option :opts [String] :role The role value to assign to the user
204
+ # @option opts role [String] The role value to assign to the user.
205
205
  #
206
- # @option :opts [String] :sshkey The sshkey value to assign to the user
206
+ # @option opts sshkey [String] The sshkey value to assign to the user.
207
207
  #
208
- # @return [Boolean] returns true if the command completed successfully
208
+ # @return [Boolean] Returns true if the command completed successfully.
209
209
  def create(name, opts = {})
210
210
  cmd = "username #{name}"
211
211
  cmd << " privilege #{opts[:privilege]}" if opts[:privilege]
@@ -234,134 +234,134 @@ module Rbeapi
234
234
 
235
235
  ##
236
236
  # delete will delete an existing user name from the nodes current
237
- # running configuration. If the delete method is called and the user
237
+ # running configuration. If the delete method is called and the user
238
238
  # name does not exist, this method will succeed.
239
239
  #
240
- # @eos_version 4.13.7M
240
+ # @since eos_version 4.13.7M
241
241
  #
242
- # @commands
242
+ # ===Commands
243
243
  # no username <name>
244
244
  #
245
- # @param [String] :name The user name to delete from the node.
245
+ # @param name [String] The user name to delete from the node.
246
246
  #
247
- # @return [Boolean] returns true if the command completed successfully
247
+ # @return [Boolean] Returns true if the command completed successfully.
248
248
  def delete(name)
249
249
  configure("no username #{name}")
250
250
  end
251
251
 
252
252
  ##
253
- # default will configure the user name using the default keyword. This
253
+ # default will configure the user name using the default keyword. This
254
254
  # command has the same effect as deleting the user name from the nodes
255
255
  # running configuration.
256
256
  #
257
- # @eos_version 4.13.7M
257
+ # @since eos_version 4.13.7M
258
258
  #
259
- # @commands
259
+ # ===Commands
260
260
  # default username <name>
261
261
  #
262
- # @param [String] :name The user name to default in the nodes
262
+ # @param name [String] The user name to default in the nodes
263
263
  # configuration.
264
264
  #
265
- # @return [Boolean] returns true if the command complete successfully
265
+ # @return [Boolean] Returns true if the command complete successfully.
266
266
  def default(name)
267
267
  configure("default username #{name}")
268
268
  end
269
269
 
270
270
  ##
271
271
  # set_privilege configures the user privilege value for the specified user
272
- # name in the nodes running configuration. If enable is false in the
272
+ # name in the nodes running configuration. If enable is false in the
273
273
  # opts keyword Hash then the name value is negated using the no
274
274
  # keyword. If the default keyword is set to true, then the privilege value
275
- # is defaulted using the default keyword. The default keyword takes
275
+ # is defaulted using the default keyword. The default keyword takes
276
276
  # precedence over the enable keyword
277
277
  #
278
- # @eos_version 4.13.7M
278
+ # @since eos_version 4.13.7M
279
279
  #
280
- # @commands
280
+ # ===Commands
281
281
  # username <name> privilege <value>
282
282
  # no username <name> privilege <value>
283
283
  # default username <name> privilege <value>
284
284
  #
285
- # @param [String] :name The user name to default in the nodes
285
+ # @param name [String] The user name to default in the nodes
286
286
  # configuration.
287
287
  #
288
- # @param [Hash] :opts Optional keyword arguments
288
+ # @param opts [Hash] Optional keyword arguments.
289
289
  #
290
- # @option :opts [String] :value The privilege value to assign to the user
290
+ # @option opts value [String] The privilege value to assign to the user.
291
291
  #
292
- # @option :opts [Boolean] :enable If false then the command is
292
+ # @option opts enable [Boolean] If false then the command is
293
293
  # negated. Default is true.
294
294
  #
295
- # @option :opts [Boolean] :default Configure the user privilege value
296
- # using the default keyword
295
+ # @option opts default [Boolean] Configure the user privilege value
296
+ # using the default keyword.
297
297
  #
298
- # @return [Boolean] returns true if the command completed successfully
298
+ # @return [Boolean] Returns true if the command completed successfully.
299
299
  def set_privilege(name, opts = {})
300
300
  configure(command_builder("username #{name} privilege", opts))
301
301
  end
302
302
 
303
303
  ##
304
304
  # set_role configures the user role value for the specified user
305
- # name in the nodes running configuration. If enable is false in the
305
+ # name in the nodes running configuration. If enable is false in the
306
306
  # opts keyword Hash then the name value is negated using the no
307
307
  # keyword. If the default keyword is set to true, then the role value
308
- # is defaulted using the default keyword. The default keyword takes
308
+ # is defaulted using the default keyword. The default keyword takes
309
309
  # precedence over the enable keyword
310
310
  #
311
- # @eos_version 4.13.7M
311
+ # @since eos_version 4.13.7M
312
312
  #
313
- # @commands
313
+ # ===Commands
314
314
  # username <name> role <value>
315
315
  # no username <name> role <value>
316
316
  # default username <name> role <value>
317
317
  #
318
- # @param [String] :name The user name to default in the nodes
318
+ # @param name [String] The user name to default in the nodes
319
319
  # configuration.
320
320
  #
321
- # @param [Hash] :opts Optional keyword arguments
321
+ # @param opts [Hash] Optional keyword arguments.
322
322
  #
323
- # @option :opts [String] :value The role value to assign to the user
323
+ # @option opts value [String] The role value to assign to the user.
324
324
  #
325
- # @option :opts [Boolean] :enable If false then the command is
325
+ # @option opts enable [Boolean] If false then the command is
326
326
  # negated. Default is true.
327
327
  #
328
- # @option :opts [Boolean] :default Configure the user role value
329
- # using the default keyword
328
+ # @option opts default [Boolean] Configure the user role value
329
+ # using the default keyword.
330
330
  #
331
- # @return [Boolean] returns true if the command completed successfully
331
+ # @return [Boolean] Returns true if the command completed successfully.
332
332
  def set_role(name, opts = {})
333
333
  configure(command_builder("username #{name} role", opts))
334
334
  end
335
335
 
336
336
  ##
337
337
  # set_sshkey configures the user sshkey value for the specified user
338
- # name in the nodes running configuration. If enable is false in the
338
+ # name in the nodes running configuration. If enable is false in the
339
339
  # opts keyword Hash then the name value is negated using the no
340
340
  # keyword. If the default keyword is set to true, then the sshkey value
341
- # is defaulted using the default keyword. The default keyword takes
342
- # precedence over the enable keyword
341
+ # is defaulted using the default keyword. The default keyword takes
342
+ # precedence over the enable keyword.
343
343
  #
344
- # @eos_version 4.13.7M
344
+ # @since eos_version 4.13.7M
345
345
  #
346
- # @commands
346
+ # ===Commands
347
347
  # username <name> sshkey <value>
348
348
  # no username <name> sshkey <value>
349
349
  # default username <name> sshkey <value>
350
350
  #
351
- # @param [String] :name The user name to default in the nodes
351
+ # @param name [String] The user name to default in the nodes
352
352
  # configuration.
353
353
  #
354
- # @param [Hash] :opts Optional keyword arguments
354
+ # @param opts [Hash] Optional keyword arguments
355
355
  #
356
- # @option :opts [String] :value The sshkey value to assign to the user
356
+ # @option opts value [String] The sshkey value to assign to the user
357
357
  #
358
- # @option :opts [Boolean] :enable If false then the command is
358
+ # @option opts enable [Boolean] If false then the command is
359
359
  # negated. Default is true.
360
360
  #
361
- # @option :opts [Boolean] :default Configure the user sshkey value
362
- # using the default keyword
361
+ # @option opts default [Boolean] Configure the user sshkey value
362
+ # using the default keyword.
363
363
  #
364
- # @return [Boolean] returns true if the command completed successfully
364
+ # @return [Boolean] Returns true if the command completed successfully.
365
365
  def set_sshkey(name, opts = {})
366
366
  configure(command_builder("username #{name} sshkey", opts))
367
367
  end