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 wrapping 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

#command_builder, #configure, #configure_interface, #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.

Examples:

{
  key: <string>,
  key_format: <fixnum>,
  timeout: <fixnum>,
  retransmit: <fixnum>,
  servers: <array>
}

Returns:

  • (Array<Hash>)

    Single element Array of resource hashes.



74
75
76
77
78
79
80
81
82
# 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)
  global.merge!(parse_global_source)
  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.

Parameters:

  • opts (Hash) (defaults to: {})

    The configuration options.

Options Hash (opts):

  • hostname (String)

    The host value.

  • vrf (String)

    The vrf value.

  • auth_port (String)

    The auth-port value.

  • acct_port (String)

    The acct-port value.

Returns:

  • (Boolean)

    Returns true if there are no errors.



355
356
357
358
359
360
361
# File 'lib/rbeapi/api/radius.rb', line 355

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 enable option is false, 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.

Commands

radius-server key <format> <value>
no radius-server key
default radius-server key

Parameters:

  • value (Hash)

    a customizable set of options

  • key_format (Hash)

    a customizable set of options

  • opts (Hash) (defaults to: {})

    a customizable set of options

  • default (Hash)

    a customizable set of options

Options Hash (opts):

  • enable (Boolean)

    If false then the command is negated. Default is true.

Returns:

  • (Boolean)

    Returns true if the commands complete successfully.

Since:

  • eos_version 4.13.7M



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/rbeapi/api/radius.rb', line 218

def set_global_key(opts = {})
  value = opts[:value]
  enable = opts.fetch(:enable, true)
  key_format = opts[:key_format] || 0
  default = opts[:default] || false

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

#set_global_retransmit(opts = {}) ⇒ Boolean

set_global_retransmit configures the global radius-server retransmit value. If the enable option is false, then the radius-server retransmit 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 takes precedence.

Commands

radius-server retransmit <value>
no radius-server retransmit
default radius-server retransmit

Parameters:

  • value (Hash)

    a customizable set of options

  • opts (Hash) (defaults to: {})

    a customizable set of options

  • default (Hash)

    a customizable set of options

Options Hash (opts):

  • enable (Boolean)

    If false then the command is negated. Default is true.

Returns:

  • (Boolean)

    Returns true if the commands complete successfully.

Since:

  • eos_version 4.13.7M



293
294
295
296
# File 'lib/rbeapi/api/radius.rb', line 293

def set_global_retransmit(opts = {})
  cmd = command_builder('radius-server retransmit', opts)
  configure cmd
end

#set_global_timeout(opts = {}) ⇒ Boolean

set_global_timeout configures the radius-server timeout value. If the enable option is false, then 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.

Commands

radius-server timeout <value>
no radius-server timeout
default radius-server timeout

Parameters:

  • value (Hash)

    a customizable set of options

  • opts (Hash) (defaults to: {})

    a customizable set of options

  • default (Hash)

    a customizable set of options

Options Hash (opts):

  • enable (Boolean)

    If false then the command is negated. Default is true.

Returns:

  • (Boolean)

    Returns true if the commands complete successfully.

Since:

  • eos_version 4.13.7M



262
263
264
265
# File 'lib/rbeapi/api/radius.rb', line 262

def set_global_timeout(opts = {})
  cmd = command_builder('radius-server timeout', opts)
  configure cmd
end

#set_source_interface(sources) ⇒ Boolean

set_source_interface takes a dictionary mapping the VRF to the desired source interface. Any radius source-interface lines in the running-config that are not defined in the hash will be removed, then lines generated from the hash will be applied. This is NOT idempotent, however, it is explicit.

Parameters:

  • sources (Hash)

    A hash mapping the vrf name to the source interface.

Returns:

  • (Boolean)

    Returns true if there are no errors.



376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/rbeapi/api/radius.rb', line 376

def set_source_interface(sources)
  existing = config.scan(/ip radius.* source-interface.*/)
  desired = []
  sources.each do |vrf, intf|
    vrf_str = vrf == 'default' ? '' : " vrf #{vrf}"
    desired << "ip radius#{vrf_str} source-interface #{intf}"
  end
  remove = existing - desired
  cmds = remove.map { |line| "no #{line}" }
  cmds.concat(desired)
  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`.

Parameters:

  • opts (Hash) (defaults to: {})

    The configuration options.

Options Hash (opts):

  • key_format (Integer)

    The key format value.

  • hostname (String)

    The host value.

  • vrf (String)

    The vrf value.

  • auth_port (String)

    The auth-port value.

  • acct_port (String)

    The acct-port value.

  • timeout (String)

    The timeout value.

  • retransmit (String)

    The retransmit value.

  • key (String)

    The key value.

Returns:

  • (Boolean)

    Returns true if there are no errors.



325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/rbeapi/api/radius.rb', line 325

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