Class: Cisco::RadiusServer
Overview
RadiusServer - node utility class for Raidus Server configuration management
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from NodeUtil
client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?
Constructor Details
#initialize(name, instantiate = true, auth_p = nil, acct_p = nil) ⇒ RadiusServer
Returns a new instance of RadiusServer.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/cisco_node_utils/radius_server.rb', line 28
def initialize(name, instantiate=true, auth_p=nil, acct_p=nil)
unless name =~ /^[a-zA-Z0-9\.\:]*$/
fail ArgumentError,
'Invalid value (IPv4/IPv6 address contains invalid characters)'
end
begin
IPAddr.new(name)
rescue
raise ArgumentError,
'Invalid value (Name is not a valid single IPv4/IPv6 address)'
end
@name = name
if platform == :ios_xr
if auth_p.nil?
@auth_port = config_get_default('radius_server', 'auth-port')
else
fail ArgumentError, 'auth_p must be an Integer' \
unless auth_p.is_a?(Integer)
@auth_port = auth_p
end
if acct_p.nil?
@acct_port = config_get_default('radius_server', 'acct-port')
else
fail ArgumentError, 'acct_p must be an Integer' \
unless acct_p.is_a?(Integer)
@acct_port = acct_p
end
end
create if instantiate
return if platform == :ios_xr
unless auth_p.nil?
fail ArgumentError, 'auth_p must be an Integer' \
unless auth_p.is_a?(Integer)
self.auth_port = auth_p
end
return if acct_p.nil?
fail ArgumentError, 'acct_p must be an Integer' \
unless acct_p.is_a?(Integer)
self.acct_port = acct_p
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
26
27
28
|
# File 'lib/cisco_node_utils/radius_server.rb', line 26
def name
@name
end
|
Class Method Details
.radiusservers ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/cisco_node_utils/radius_server.rb', line 75
def self.radiusservers
hash = {}
radiusservers_list = config_get('radius_server', 'hosts')
return hash if radiusservers_list.empty?
radiusservers_list.each do |id|
if platform == :ios_xr
authp = config_get('radius_server', 'auth-port', ip: id)
authp = authp[0] if authp.is_a?(Array)
authp = authp.to_i
acctp = config_get('radius_server', 'acct-port', ip: id)
acctp = acctp[0] if acctp.is_a?(Array)
acctp = acctp.to_i
hash[id] = RadiusServer.new(id, false, authp, acctp)
else
hash[id] = RadiusServer.new(id, false)
end
end
hash
end
|
Instance Method Details
#==(other) ⇒ Object
142
143
144
|
# File 'lib/cisco_node_utils/radius_server.rb', line 142
def ==(other)
name == other.name
end
|
#accounting ⇒ Object
297
298
299
300
301
302
303
304
305
|
# File 'lib/cisco_node_utils/radius_server.rb', line 297
def accounting
return nil if platform == :ios_xr
val = config_get('radius_server', 'accounting', ip: @name)
if val.nil?
false
else
val
end
end
|
#accounting=(val) ⇒ Object
311
312
313
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/cisco_node_utils/radius_server.rb', line 311
def accounting=(val)
if !val
config_set('radius_server',
'accounting',
state: 'no',
ip: @name)
else
config_set('radius_server',
'accounting',
state: '',
ip: @name)
end
end
|
#acct_port ⇒ Object
180
181
182
183
|
# File 'lib/cisco_node_utils/radius_server.rb', line 180
def acct_port
platform == :ios_xr ? @acct_port : config_get('radius_server',
'acct-port', ip: @name)
end
|
#acct_port=(val) ⇒ Object
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/cisco_node_utils/radius_server.rb', line 189
def acct_port=(val)
fail("'acct_port' setter method not applicable for this platform." \
'acct_port must be passed in to the constructor.') \
if platform == :ios_xr
unless val.nil?
fail ArgumentError, 'acct_port must be an Integer' \
unless val.is_a?(Integer)
end
if val.nil?
config_set('radius_server',
'acct-port',
state: 'no',
ip: @name,
port: acct_port)
else
config_set('radius_server',
'acct-port',
state: '',
ip: @name,
port: val)
end
end
|
#auth_port ⇒ Object
146
147
148
149
|
# File 'lib/cisco_node_utils/radius_server.rb', line 146
def auth_port
platform == :ios_xr ? @auth_port : config_get('radius_server',
'auth-port', ip: @name)
end
|
#auth_port=(val) ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/cisco_node_utils/radius_server.rb', line 155
def auth_port=(val)
fail("'auth_port' setter method not applicable for this platform." \
'auth_port must be passed in to the constructor.') \
if platform == :ios_xr
unless val.nil?
fail ArgumentError, 'auth_port must be an Integer' \
unless val.is_a?(Integer)
end
if val.nil?
config_set('radius_server',
'auth-port',
state: 'no',
ip: @name,
port: auth_port)
else
config_set('radius_server',
'auth-port',
state: '',
ip: @name,
port: val)
end
end
|
#authentication ⇒ Object
325
326
327
328
329
330
331
332
333
|
# File 'lib/cisco_node_utils/radius_server.rb', line 325
def authentication
return nil if platform == :ios_xr
val = config_get('radius_server', 'authentication', ip: @name)
if val.nil?
false
else
val
end
end
|
#authentication=(val) ⇒ Object
339
340
341
342
343
344
345
346
347
348
349
350
351
|
# File 'lib/cisco_node_utils/radius_server.rb', line 339
def authentication=(val)
if !val
config_set('radius_server',
'authentication',
state: 'no',
ip: @name)
else
config_set('radius_server',
'authentication',
state: '',
ip: @name)
end
end
|
#create ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/cisco_node_utils/radius_server.rb', line 99
def create
destroy if platform == :ios_xr
config_set('radius_server',
'hosts',
state: '',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port)
end
|
#default_accounting ⇒ Object
307
308
309
|
# File 'lib/cisco_node_utils/radius_server.rb', line 307
def default_accounting
config_get_default('radius_server', 'accounting')
end
|
#default_acct_port ⇒ Object
185
186
187
|
# File 'lib/cisco_node_utils/radius_server.rb', line 185
def default_acct_port
config_get_default('radius_server', 'acct-port')
end
|
#default_auth_port ⇒ Object
151
152
153
|
# File 'lib/cisco_node_utils/radius_server.rb', line 151
def default_auth_port
config_get_default('radius_server', 'auth-port')
end
|
#default_authentication ⇒ Object
335
336
337
|
# File 'lib/cisco_node_utils/radius_server.rb', line 335
def default_authentication
config_get_default('radius_server', 'authentication')
end
|
#default_retransmit_count ⇒ Object
267
268
269
|
# File 'lib/cisco_node_utils/radius_server.rb', line 267
def default_retransmit_count
config_get_default('radius_server', 'retransmit')
end
|
#default_timeout ⇒ Object
226
227
228
|
# File 'lib/cisco_node_utils/radius_server.rb', line 226
def default_timeout
config_get_default('radius_server', 'timeout')
end
|
#destroy ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/cisco_node_utils/radius_server.rb', line 109
def destroy
if platform == :ios_xr
all_hosts = config_get('radius_server', 'host_port_pairs', ip: @name)
return unless all_hosts.is_a?(Array)
warn("#{name} is configured multiple times on the device" \
' (possibly using different ports). This is unsupported by this' \
' API and the duplicate entries are being deleted.') \
if all_hosts.count > 1
all_hosts.each do |host|
auth = host[0]
acct = host[1]
config_set('radius_server',
'hosts',
state: 'no',
ip: @name,
auth_port: auth,
acct_port: acct)
end
else
config_set('radius_server',
'hosts',
state: 'no',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port)
end
end
|
#key ⇒ Object
364
365
366
367
368
369
370
371
372
373
374
375
376
|
# File 'lib/cisco_node_utils/radius_server.rb', line 364
def key
val = config_get('radius_server',
'key',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port)
val = val[0] if val.is_a?(Array)
return if val.nil? || val.empty?
index = val.index('auth-port')
val = val[0..index - 2] unless index.nil?
val.strip
end
|
353
354
355
356
357
358
359
360
361
362
|
# File 'lib/cisco_node_utils/radius_server.rb', line 353
def key_format
val = config_get('radius_server',
'key_format',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port)
val = val[0] if val.is_a?(Array)
val
end
|
#key_set(value, format) ⇒ Object
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
# File 'lib/cisco_node_utils/radius_server.rb', line 378
def key_set(value, format)
unless value.nil?
fail ArgumentError, 'value must be a String' \
unless value.is_a?(String)
end
unless format.nil?
fail ArgumentError, 'format must be an Integer' \
unless format.is_a?(Integer)
end
return if value.nil? && key.nil?
if value.nil? && !key.nil?
config_set('radius_server',
'key',
state: 'no',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port,
key: "#{key_format} #{key}")
elsif !format.nil?
value = Utils.add_quotes(value)
config_set('radius_server',
'key',
state: '',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port,
key: "#{format} #{value}")
else
value = Utils.add_quotes(value)
config_set('radius_server',
'key',
state: '',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port,
key: "#{value}")
end
end
|
#retransmit_count ⇒ Object
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/cisco_node_utils/radius_server.rb', line 256
def retransmit_count
val = config_get('radius_server',
'retransmit',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port)
val = val[0] if val.is_a?(Array)
val = val.to_i unless val.nil?
val
end
|
#retransmit_count=(val) ⇒ Object
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
# File 'lib/cisco_node_utils/radius_server.rb', line 271
def retransmit_count=(val)
unless val.nil?
fail ArgumentError, 'retransmit_count must be an Integer' \
unless val.is_a?(Integer)
end
if val.nil?
return if retransmit_count.nil?
config_set('radius_server',
'retransmit',
state: 'no',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port,
count: retransmit_count)
else
config_set('radius_server',
'retransmit',
state: '',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port,
count: val)
end
end
|
#timeout ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/cisco_node_utils/radius_server.rb', line 214
def timeout
val = config_get('radius_server',
'timeout',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port)
val = val[0] if val.is_a?(Array)
val = val.to_i unless val.nil?
val
end
|
#timeout=(val) ⇒ Object
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/cisco_node_utils/radius_server.rb', line 230
def timeout=(val)
unless val.nil?
fail ArgumentError, 'timeout must be an Integer' \
unless val.is_a?(Integer)
end
if val.nil?
return if timeout.nil?
config_set('radius_server',
'timeout',
state: 'no',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port,
timeout: timeout)
else
config_set('radius_server',
'timeout',
state: '',
ip: @name,
auth_port: @auth_port,
acct_port: @acct_port,
timeout: val)
end
end
|