rbeapi 0.1.0 → 0.2.0

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 (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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbeapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-25 00:00:00.000000000 Z
12
+ date: 2015-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: inifile
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
14
46
  - !ruby/object:Gem::Dependency
15
47
  name: net_http_unix
16
48
  requirement: !ruby/object:Gem::Requirement
@@ -28,7 +60,7 @@ dependencies:
28
60
  - !ruby/object:Gem::Version
29
61
  version: '0'
30
62
  - !ruby/object:Gem::Dependency
31
- name: inifile
63
+ name: netaddr
32
64
  requirement: !ruby/object:Gem::Requirement
33
65
  none: false
34
66
  requirements:
@@ -163,14 +195,26 @@ extensions: []
163
195
  extra_rdoc_files: []
164
196
  files:
165
197
  - .gitignore
198
+ - .rubocop.yml
199
+ - CHANGELOG.md
166
200
  - Gemfile
167
201
  - Guardfile
168
202
  - LICENSE
169
203
  - README.md
170
204
  - Rakefile
205
+ - gems/README.rst
206
+ - gems/inifile/.gitignore
207
+ - gems/inifile/README.rst
208
+ - gems/inifile/inifile.spec.tmpl
209
+ - gems/net_http_unix/.gitignore
210
+ - gems/net_http_unix/README.rst
211
+ - gems/net_http_unix/net_http_unix.spec.tmpl
212
+ - gems/netaddr/README.rst
213
+ - gems/netaddr/netaddr.spec.tmpl
171
214
  - lib/rbeapi.rb
172
215
  - lib/rbeapi/api.rb
173
216
  - lib/rbeapi/api/aaa.rb
217
+ - lib/rbeapi/api/acl.rb
174
218
  - lib/rbeapi/api/dns.rb
175
219
  - lib/rbeapi/api/interfaces.rb
176
220
  - lib/rbeapi/api/ipinterfaces.rb
@@ -180,7 +224,6 @@ files:
180
224
  - lib/rbeapi/api/ospf.rb
181
225
  - lib/rbeapi/api/prefixlists.rb
182
226
  - lib/rbeapi/api/radius.rb
183
- - lib/rbeapi/api/radius.rb.old
184
227
  - lib/rbeapi/api/routemaps.rb
185
228
  - lib/rbeapi/api/snmp.rb
186
229
  - lib/rbeapi/api/staticroutes.rb
@@ -196,10 +239,12 @@ files:
196
239
  - lib/rbeapi/utils.rb
197
240
  - lib/rbeapi/version.rb
198
241
  - rbeapi.gemspec
242
+ - rbeapi.spec.tmpl
199
243
  - spec/fixtures/dut.conf
200
244
  - spec/spec_helper.rb
201
245
  - spec/support/fixtures.rb
202
246
  - spec/support/shared_examples_for_api_modules.rb
247
+ - spec/system/api_acl_spec.rb
203
248
  - spec/system/api_ospf_interfaces_spec.rb
204
249
  - spec/system/api_ospf_spec.rb
205
250
  - spec/system/api_varp_interfaces_spec.rb
@@ -221,6 +266,17 @@ files:
221
266
  - spec/system/rbeapi/api/switchports_spec.rb
222
267
  - spec/system/rbeapi/api/system_spec.rb
223
268
  - spec/system/rbeapi/api/vlans_spec.rb
269
+ - spec/unit/rbeapi/api/acl/default_spec.rb
270
+ - spec/unit/rbeapi/api/acl/fixture_acl_standard.text
271
+ - spec/unit/rbeapi/api/interfaces/base_spec.rb
272
+ - spec/unit/rbeapi/api/interfaces/ethernet_spec.rb
273
+ - spec/unit/rbeapi/api/interfaces/fixture_interfaces.text
274
+ - spec/unit/rbeapi/api/interfaces/portchannel_spec.rb
275
+ - spec/unit/rbeapi/api/interfaces/vxlan_spec.rb
276
+ - spec/unit/rbeapi/api/mlag/default_spec.rb
277
+ - spec/unit/rbeapi/api/mlag/fixture_mlag.text
278
+ - spec/unit/rbeapi/api/vlans/default_spec.rb
279
+ - spec/unit/rbeapi/api/vlans/fixture_vlans.text
224
280
  homepage: https://github.com/arista-eosplus/rbeapi
225
281
  licenses:
226
282
  - New BSD
@@ -234,12 +290,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
290
  - - ! '>='
235
291
  - !ruby/object:Gem::Version
236
292
  version: '0'
293
+ segments:
294
+ - 0
295
+ hash: 1144077190260473885
237
296
  required_rubygems_version: !ruby/object:Gem::Requirement
238
297
  none: false
239
298
  requirements:
240
299
  - - ! '>='
241
300
  - !ruby/object:Gem::Version
242
301
  version: '0'
302
+ segments:
303
+ - 0
304
+ hash: 1144077190260473885
243
305
  requirements: []
244
306
  rubyforge_project:
245
307
  rubygems_version: 1.8.23
@@ -251,6 +313,7 @@ test_files:
251
313
  - spec/spec_helper.rb
252
314
  - spec/support/fixtures.rb
253
315
  - spec/support/shared_examples_for_api_modules.rb
316
+ - spec/system/api_acl_spec.rb
254
317
  - spec/system/api_ospf_interfaces_spec.rb
255
318
  - spec/system/api_ospf_spec.rb
256
319
  - spec/system/api_varp_interfaces_spec.rb
@@ -272,3 +335,15 @@ test_files:
272
335
  - spec/system/rbeapi/api/switchports_spec.rb
273
336
  - spec/system/rbeapi/api/system_spec.rb
274
337
  - spec/system/rbeapi/api/vlans_spec.rb
338
+ - spec/unit/rbeapi/api/acl/default_spec.rb
339
+ - spec/unit/rbeapi/api/acl/fixture_acl_standard.text
340
+ - spec/unit/rbeapi/api/interfaces/base_spec.rb
341
+ - spec/unit/rbeapi/api/interfaces/ethernet_spec.rb
342
+ - spec/unit/rbeapi/api/interfaces/fixture_interfaces.text
343
+ - spec/unit/rbeapi/api/interfaces/portchannel_spec.rb
344
+ - spec/unit/rbeapi/api/interfaces/vxlan_spec.rb
345
+ - spec/unit/rbeapi/api/mlag/default_spec.rb
346
+ - spec/unit/rbeapi/api/mlag/fixture_mlag.text
347
+ - spec/unit/rbeapi/api/vlans/default_spec.rb
348
+ - spec/unit/rbeapi/api/vlans/fixture_vlans.text
349
+ has_rdoc:
@@ -1,399 +0,0 @@
1
- #
2
- # Copyright (c) 2014, Arista Networks, Inc.
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are
7
- # met:
8
- #
9
- # Redistributions of source code must retain the above copyright notice,
10
- # this list of conditions and the following disclaimer.
11
- #
12
- # Redistributions in binary form must reproduce the above copyright
13
- # notice, this list of conditions and the following disclaimer in the
14
- # documentation and/or other materials provided with the distribution.
15
- #
16
- # Neither the name of Arista Networks nor the names of its
17
- # contributors may be used to endorse or promote products derived from
18
- # this software without specific prior written permission.
19
- #
20
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
24
- # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
- # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
- # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
- # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30
- # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- #
32
- require 'rbeapi/api'
33
-
34
-
35
- module Rbeapi
36
- ##
37
- # Eos is module namesapce for working with the EOS command API
38
- module Api
39
- ##
40
- # Radius provides instance methods to retrieve and set radius configuration
41
- # values.
42
- class Radius < Entity
43
-
44
- DEFAULT_AUTH_PORT = 1812
45
- DEFAULT_ACCT_PORT = 1813
46
-
47
- # Regular expression to extract a radius server's attributes from the
48
- # running-configuration text. The explicit [ ] spaces enable line
49
- # wrappping and indentation with the /x flag.
50
- SERVER_REGEXP = /radius-server[ ]host[ ](.*?)
51
- (?:[ ]auth-port[ ](\d+))?
52
- (?:[ ]acct-port[ ](\d+))?
53
- (?:[ ]timeout[ ](\d+))?
54
- (?:[ ]deadtime[ ](\d+))?
55
- (?:[ ]retransmit[ ](\d+))?
56
- (?:[ ]key[ ](\d+)[ ](\w+))?\s/x
57
-
58
- GROUP_MEMBER_REGEXP = /server[ ](.*?)
59
- (?:[ ]auth-port[ ](\d+))?
60
- (?:[ ]acct-port[ ](\d+))?\s/x
61
-
62
- # Regular expression to extract a radius server's attributes from the
63
- # running-configuration text. The explicit [ ] spaces enable line
64
- # wrappping and indentation with the /x flag.
65
- SERVER_GROUP_REGEXP = /aaa group server radius (.*)/
66
-
67
- ##
68
- # getall Returns an Array with a single resource Hash describing the
69
- # current state of the global radius configuration on the target device.
70
- # This method is intended to be used by a provider's instances class
71
- # method.
72
- #
73
- # The resource hash returned contains the following information:
74
- # * name: ('settings')
75
- # * enable: (true | false) if radius functionality is enabled. This is
76
- # always true for EOS.
77
- # * key: (String) the key either in plaintext or hashed format
78
- # * key_format: (Integer) e.g. 0 or 7
79
- # * timeout: (Integer) seconds before the timeout period ends
80
- # * retransmit_count: (Integer), e.g. 3, attempts after first timeout
81
- # expiry.
82
- #
83
- # @api public
84
- #
85
- # @return [Array<Hash>] Single element Array of resource hashes
86
- def getall
87
- rsrc_hsh = radius_global_defaults
88
- rsrc_hsh.merge!(parse_global_key(config))
89
- rsrc_hsh.merge!(parse_global_timeout(config))
90
- rsrc_hsh.merge!(parse_global_retransmit(config))
91
- [rsrc_hsh]
92
- end
93
-
94
- ##
95
- # servers returns an Array of radius server resource hashes. Each hash
96
- # describes the current state of the radius server and is suitable for
97
- # use in initializing a radius_server provider.
98
- #
99
- # The resource hash returned contains the following information:
100
- # * hostname: hostname or ip address
101
- # * key: (String) the key either in plaintext or hashed format
102
- # * key_format: (Fixnum) e.g. 0 or 7
103
- # * timeout: (Fixnum) seconds before the timeout period ends
104
- # * retransmit_count: (Integer), e.g. 3, attempts after first timeout
105
- # expiry.
106
- # * group: (String) Server group associated with this server.
107
- # * deadtime: (Fixnum) number of minutes to ignore an unresponsive
108
- # server.
109
- # * acct_port: (Fixnum) Port number to use for accounting.
110
- # * accounting_only: (Boolean) Enable this server for accounting only.
111
- # * auth_port: (Fixnum) Port number to use for authentication
112
- #
113
- # @api public
114
- #
115
- # @return [Array<Hash<Symbol,Object>>] Array of resource hashes
116
- def servers
117
- config = running_configuration
118
- tuples = config.scan(SERVER_REGEXP)
119
- tuples.map do |(host, authp, acctp, tout, dead, tries, keyfm, key)|
120
- hsh = { auth_port: DEFAULT_AUTH_PORT, acct_port: DEFAULT_ACCT_PORT }
121
- hsh[:hostname] = host if host
122
- hsh[:auth_port] = authp.to_i if authp
123
- hsh[:acct_port] = acctp.to_i if acctp
124
- hsh[:timeout] = tout.to_i if tout
125
- hsh[:retransmit_count] = tries.to_i if tries
126
- hsh[:deadtime] = dead.to_i if dead
127
- hsh[:key_format] = keyfm.to_i if keyfm
128
- hsh[:key] = key if key
129
- hsh
130
- end
131
- end
132
-
133
- ##
134
- # server_groups retrieves a list of radius server groups from the target
135
- # device.
136
- #
137
- # @api public
138
- #
139
- # @return [Array<Hash<Symbol,Object>>] Array of resource hashes
140
- def server_groups
141
- config = running_configuration
142
- tuples = config.scan(SERVER_GROUP_REGEXP)
143
- tuples.map do |(name)|
144
- { name: name, servers: parse_group_servers(config, name) }
145
- end
146
- end
147
-
148
- ##
149
- # parse_group_servers parses the list of servers associated with a radius
150
- # server group given a group name and a running configuration text.
151
- #
152
- # @param [String] config The running configuration text.
153
- #
154
- # @param [String] name The name of the server group to parse.
155
- #
156
- # @api private
157
- #
158
- # @return [Array<Hash<Symbol,Object>] Array of server attributes
159
- def parse_group_servers(config, name)
160
- regexp = /aaa group server radius #{name}(.*?)!/m
161
- mdata = regexp.match(config)
162
- if mdata
163
- tuples = mdata[1].scan(GROUP_MEMBER_REGEXP)
164
- tuples.collect do |(hostname, auth_port, acct_port)|
165
- {
166
- hostname: hostname,
167
- auth_port: auth_port ? auth_port.to_i : DEFAULT_AUTH_PORT,
168
- acct_port: acct_port ? acct_port.to_i : DEFAULT_ACCT_PORT
169
- }
170
- end
171
- else
172
- Array.new
173
- end
174
- end
175
-
176
- ##
177
- # update_server_group updates a radius server group given an Array of
178
- # server attributes and the name of the server group. The update happens
179
- # by first deleting the existing group if it exists then creating it
180
- # again with all of the specified servers.
181
- #
182
- # @param [String] name The name of the server group to update
183
- #
184
- # @param [Array<Hash<Symbol,Object>>] servers The array of servers to
185
- # associate with the server group. This hash should have at least the
186
- # :hostname key.
187
- #
188
- # @api public
189
- #
190
- # @return [Boolean] true if no errors
191
- def update_server_group(opts = {})
192
- cmd = "aaa group server radius #{opts[:name]}"
193
- api.config("no #{cmd}")
194
- cmds = [cmd]
195
- opts[:servers].each do |hsh|
196
- server = "server #{hsh[:hostname]}"
197
- server << " auth-port #{hsh[:auth_port] || DEFAULT_AUTH_PORT}"
198
- server << " acct-port #{hsh[:acct_port] || DEFAULT_ACCT_PORT}"
199
- cmds << server
200
- end
201
- result = api.config(cmds)
202
- !result.find { |r| r != {} }
203
- end
204
-
205
- ##
206
- # remove_server_group removes a radius server group by name. This API
207
- # call maps to the `no aaa group server radius <name>` command.
208
- #
209
- # @option opts [String] :name ('RAD-SV2') The name of the radius server
210
- # group to remove.
211
- #
212
- # @api public
213
- #
214
- # @return [Boolean] true if no errors
215
- def remove_server_group(opts = {})
216
- result = api.config("no aaa group server radius #{opts[:name]}")
217
- result == [{}]
218
- end
219
-
220
- ##
221
- # update_server configures a radius server resource on the target device.
222
- # This API method maps to the `radius server host` command, e.g.
223
- # `radius-server host 10.11.12.13 auth-port 1024 acct-port 2048 timeout
224
- # 30 retransmit 5 key 7 011204070A5955`
225
- #
226
- # @api public
227
- #
228
- # @return [Boolean] true if there are no errors
229
- def update_server(opts = {})
230
- retransmit = opts[:retransmit_count]
231
- key_format = opts[:key_format] || 7
232
- cmd = "radius-server host #{opts[:hostname]}"
233
- cmd << " auth-port #{opts[:auth_port]}" if opts[:auth_port]
234
- cmd << " acct-port #{opts[:acct_port]}" if opts[:acct_port]
235
- cmd << " timeout #{opts[:timeout]}" if opts[:timeout]
236
- cmd << " deadtime #{opts[:deadtime]}" if opts[:deadtime]
237
- cmd << " retransmit #{retransmit}" if retransmit
238
- cmd << " key #{key_format} #{opts[:key]}" if opts[:key]
239
- result = api.config(cmd)
240
- result == [{}]
241
- end
242
-
243
- ##
244
- # remove_server removes the SNMP server identified by the hostname,
245
- # auth_port, and acct_port attributes.
246
- #
247
- # @api public
248
- #
249
- # @return [Boolean] true if no errors
250
- def remove_server(opts = {})
251
- cmd = "no radius-server host #{opts[:hostname]}"
252
- cmd << " auth-port #{opts[:auth_port]}" if opts[:auth_port]
253
- cmd << " acct-port #{opts[:acct_port]}" if opts[:acct_port]
254
- result = api.config(cmd)
255
- result == [{}]
256
- end
257
-
258
- ##
259
- # radius_global_defaults returns the default values for the radius_global
260
- # resource. This is in a single method to keep the information in one
261
- # place. If a value is explicitly configured to be the same as a default
262
- # value it will not show up in the running configuration and as a result
263
- # will not be parsed out by the parse instance methods. This method
264
- # exposes the default values.
265
- #
266
- # @return [Array<Hash>] Single element Array of resource hashes
267
- def radius_global_defaults
268
- {
269
- name: 'settings',
270
- enable: true,
271
- timeout: 5,
272
- retransmit_count: 3
273
- }
274
- end
275
- private :radius_global_defaults
276
-
277
- ##
278
- # parse_global_key takes a running configuration as a string and
279
- # parses out the radius global key and global key format if it exists in
280
- # the configuration. An empty Hash is returned if there is no global key
281
- # configured. The intent of the Hash is to be merged into a property
282
- # hash.
283
- #
284
- # @param [String] config The running configuration as a single string.
285
- #
286
- # @api private
287
- #
288
- # @return [Hash<Symbol,Object>] resource hash attributes
289
- def parse_global_key(config)
290
- rsrc_hsh = {}
291
- (key_format, key) = config.scan(/radius-server key (\d+) (\w+)/).first
292
- rsrc_hsh[:key_format] = key_format.to_i if key_format
293
- rsrc_hsh[:key] = key if key
294
- rsrc_hsh
295
- end
296
- private :parse_global_key
297
-
298
- ##
299
- # parse_global_timeout takes a running configuration as a string
300
- # and parses out the radius global timeout if it exists in the
301
- # configuration. An empty Hash is returned if there is no global timeout
302
- # value configured. The intent of the Hash is to be merged into a
303
- # property hash.
304
- #
305
- # @param [String] config The running configuration as a single string.
306
- #
307
- # @api private
308
- #
309
- # @return [Hash<Symbol,Object>] resource hash attributes
310
- def parse_global_timeout(config)
311
- rsrc_hsh = {}
312
- timeout = config.scan(/radius-server timeout (\d+)/).first
313
- # EOS default is 5 (does not show up in the running config)
314
- rsrc_hsh[:timeout] = timeout.first.to_i if timeout
315
- rsrc_hsh
316
- end
317
- private :parse_global_timeout
318
-
319
- ##
320
- # parse_global_retransmit takes a running configuration as a string and
321
- # parses out the radius global retransmit count value if it exists in the
322
- # configuration. An empty Hash is returned if there is no global timeout
323
- # value configured. The intent of the Hash is to be merged into a
324
- # property hash.
325
- #
326
- # @param [String] config The running configuration as a single string.
327
- #
328
- # @api private
329
- #
330
- # @return [Hash<Symbol,Object>] resource hash attributes
331
- def parse_global_retransmit(config)
332
- rsrc_hsh = {}
333
- count = config.scan(/radius-server retransmit (\d+)/).first
334
- # EOS default is 3 (does not show up in the running config)
335
- rsrc_hsh[:retransmit_count] = count.first.to_i if count
336
- rsrc_hsh
337
- end
338
- private :parse_global_retransmit
339
-
340
- ##
341
- # set_global_key configures the radius default key. This method maps to
342
- # the `radius-server key` EOS configuration command, e.g. `radius-server
343
- # key 7 070E234F1F5B4A`.
344
- #
345
- # @option opts [String] :key ('070E234F1F5B4A') The key value
346
- #
347
- # @option opts [Fixnum] :key_format (7) The key format, 0 for plaintext
348
- # and 7 for a hashed value. 7 will be assumed if this option is not
349
- # provided.
350
- #
351
- # @api public
352
- #
353
- # @return [Boolean] true if no errors
354
- def set_global_key(opts = {})
355
- format = opts[:key_format] || 7
356
- key = opts[:key]
357
- fail ArgumentError, 'key option is required' unless key
358
- result = api.config("radius-server key #{format} #{key}")
359
- result == [{}]
360
- end
361
-
362
- ##
363
- # set_timeout configures the radius default timeout. This method maps to
364
- # the `radius-server timeout` setting.
365
- #
366
- # @option opts [Fixnum] :timeout (50) The timeout in seconds to
367
- # configure.
368
- #
369
- # @api public
370
- #
371
- # @return [Boolean] true if no errors
372
- def set_timeout(opts = {})
373
- timeout = opts[:timeout]
374
- fail ArgumentError, 'timeout option is required' unless timeout
375
- result = api.config("radius-server timeout #{timeout}")
376
- result == [{}]
377
- end
378
-
379
- ##
380
- # set_retransmit_count configures the radius default retransmit count.
381
- # This method maps to the `radius-server retransmit` configuration
382
- # command.
383
- #
384
- # @option opts [Fixnum] :retransmit_count (4) The number of times to
385
- # retry an unresponsive server after the first timeout period.
386
- #
387
- # @api public
388
- #
389
- # @return [Boolean] true if no errors
390
- def set_retransmit_count(opts = {})
391
- retransmit_count = opts[:retransmit_count]
392
- fail ArgumentError,
393
- 'retransmit_count option is required' unless retransmit_count
394
- result = api.config("radius-server retransmit #{retransmit_count}")
395
- result == [{}]
396
- end
397
- end
398
- end
399
- end