Class: Rbeapi::Api::Radius

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/radius.rb

Overview

Radius provides instance methods to retrieve and set radius configuration values.

Constant Summary collapse

DEFAULT_KEY_FORMAT =
0
DEFAULT_KEY =
nil
SERVER_REGEXP =

Regular expression to extract a radius server's attributes from the running-configuration text. The explicit [ ] spaces enable line wrappping and indentation with the /x flag.

/radius-server[ ]host[ ](.*?)
(?:[ ]vrf[ ]([^\s]+))?
(?:[ ]auth-port[ ](\d+))?
(?:[ ]acct-port[ ](\d+))?
(?:[ ]timeout[ ](\d+))?
(?:[ ]retransmit[ ](\d+))?
(?:[ ]key[ ](\d+)[ ](\w+))?\s/x

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from Entity

#configure, #get_block, #initialize, instance

Constructor Details

This class inherits a constructor from Rbeapi::Api::Entity

Instance Method Details

#getArray<Hash>

get Returns an Array with a single resource Hash describing the current state of the global radius configuration on the target device. This method is intended to be used by a provider's instances class method.

The resource hash returned contains the following information:

* key: (String) the key either in plaintext or hashed format
* key_format: (Fixnum) e.g. 0 or 7
* timeout: (Fixnum) seconds before the timeout period ends
* retransmit: (Fixnum), e.g. 3, attempts after first timeout expiry.
* servers: (Array),

Returns:

  • (Array<Hash>)

    Single element Array of resource hashes


74
75
76
77
78
79
80
81
# File 'lib/rbeapi/api/radius.rb', line 74

def get
  global = {}
  global.merge!(parse_global_timeout)
  global.merge!(parse_global_retransmit)
  global.merge!(parse_global_key)
  resource = { global: global, servers: parse_servers }
  resource
end

#remove_server(opts = {}) ⇒ Boolean

remove_server removes the SNMP server identified by the hostname, auth_port, and acct_port attributes.

Returns:

  • (Boolean)

    true if no errors


308
309
310
311
312
313
314
# File 'lib/rbeapi/api/radius.rb', line 308

def remove_server(opts = {})
  cmd = "no radius-server host #{opts[:hostname]}"
  cmd << " vrf #{opts[:vrf]}"             if opts[:vrf]
  cmd << " auth-port #{opts[:auth_port]}" if opts[:auth_port]
  cmd << " acct-port #{opts[:acct_port]}" if opts[:acct_port]
  configure cmd
end

#set_global_key(opts = {}) ⇒ Boolean

set_global_key configures the global radius-server key. If the value option is not specified, radius-server key is configured using the no keyword. If the default option is specified, radius-server key is configured using the default keyword. If both options are specified, the default keyword option takes precedence.

Parameters:

  • [String] (Hash)

    a customizable set of options

  • [Fixnum] (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Returns:

  • (Boolean)

    returns true if the commands complete successfully


191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/rbeapi/api/radius.rb', line 191

def set_global_key(opts = {})
  value = opts[:value]
  key_format = opts[:key_format] || 0
  default = opts[:default] || false

  case default
  when true
    cmds = 'default radius-server key'
  when false
    cmds = value ? "radius-server key #{key_format} #{value}" :
                   'no radius-server key'
  end
  configure cmds
end

#set_global_retransmit(opts = {}) ⇒ Boolean

set_global_retransmit configures the global radius-server restransmit value. If the value is not specified, the radius-server retransmist value is configured using the no keyword. If the default option is specified, the radius-server retransmit value is configured using the default keyword. If both options are specified then the default keyword taks precedence

Parameters:

  • [String, (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Returns:

  • (Boolean)

    returns true if the commands complete successfully


265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/rbeapi/api/radius.rb', line 265

def set_global_retransmit(opts = {})
  value = opts[:value]
  default = opts[:default] || false

  case default
  when true
    cmds = 'default radius-server retransmit'
  when false
    cmds = value ?  "radius-server retransmit #{value}" :
                    'no radius-server retransmit'
  end
  configure cmds
end

#set_global_timeout(opts = {}) ⇒ Boolean

set_global_timeout configures the radius-server timeout value. If the value options is not specified, radius-server timeout is configured using the no keyword. If the default option is specified, radius-server timeout is configured using the default keyword. If both options are specified then the default keyword takes precedence.

Parameters:

  • [String, (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Returns:

  • (Boolean)

    returns true if the commands complete successfully


228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/rbeapi/api/radius.rb', line 228

def set_global_timeout(opts = {})
  value = opts[:value]
  default = opts[:default] || false

  case default
  when true
    cmds = 'default radius-server timeout'
  when false
    cmds = value ? "radius-server timeout #{value}" :
                   'no radius-server timeout'
  end
  configure cmds
end

#update_server(opts = {}) ⇒ Boolean

update_server configures a radius server resource on the target device. This API method maps to the `radius server host` command, e.g. `radius-server host 10.11.12.13 auth-port 1024 acct-port 2048 timeout 30 retransmit 5 key 7 011204070A5955`

Returns:

  • (Boolean)

    true if there are no errors


288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/rbeapi/api/radius.rb', line 288

def update_server(opts = {})
  # beware: order of cli keyword options counts
  key_format = opts[:key_format] || 7
  cmd = "radius-server host #{opts[:hostname]}"
  cmd << " vrf #{opts[:vrf]}"               if opts[:vrf]
  cmd << " auth-port #{opts[:auth_port]}"   if opts[:auth_port]
  cmd << " acct-port #{opts[:acct_port]}"   if opts[:acct_port]
  cmd << " timeout #{opts[:timeout]}"       if opts[:timeout]
  cmd << " retransmit #{opts[:retransmit]}" if opts[:retransmit]
  cmd << " key #{key_format} #{opts[:key]}" if opts[:key]
  configure cmd
end