Class: Rbeapi::Api::AaaGroups
Overview
The AaaGroups class manages the server groups on an EOS node.
Constant Summary collapse
- DEFAULT_RADIUS_AUTH_PORT =
1812
- DEFAULT_RADIUS_ACCT_PORT =
1813
- RADIUS_GROUP_SERVER =
Regular expression that parses the radius servers from the aaa group server radius configuration block.
/\s{3}server [ ]([^\s]+) [ ]auth-port[ ](\d+) [ ]acct-port[ ](\d+)/x
- TACACS_GROUP_SERVER =
Regular expression that parses the tacacs servers from the aaa group server tacacs+ configuration block.
/\s{3}server [ ]([^\s]+) (?:[ ]vrf[ ](\w+))? (?:[ ]port[ ](\d+))?/x
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#add_radius_server(name, server, opts = {}) ⇒ Boolean
add_radius_server adds a new radius server to the nodes current configuration.
-
#add_server(name, server, opts = {}) ⇒ Boolean
add_server adds a new server to the specified aaa server group.
-
#add_tacacs_server(name, server, opts = {}) ⇒ Boolean
add_tacacs_server adds a new tacacs server to the nodes current configuration.
-
#create(name, type) ⇒ Boolean
create adds a new aaa group server to the nodes current configuration.
-
#delete(name) ⇒ Boolean
delete removes a current aaa server group from the nodes current configuration.
-
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns the aaa server group resource hash that describes the current configuration for the specified server group name.
-
#getall ⇒ Hash<Symbol, Object>
getall returns a aaa server groups hash.
-
#parse_tacacs_server(config) ⇒ Hash<Symbol, Object>
private
parse_tacacs_server scans the provided configuration block and returns the list of configured servers.
-
#remove_server(name, server, opts = {}) ⇒ Boolean
remove_server deletes an existing server from the specified aaa server group.
-
#set_servers(name, servers) ⇒ Boolean
set_servers configures the set of servers for a specified aaa server group.
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
#add_radius_server(name, server, opts = {}) ⇒ Boolean
add_radius_server adds a new radius server to the nodes current configuration. If the server already exists in the specified group name this method will still return successfully.
commmands
aaa group server radius <name>
server <server> [acct-port <acct_port>] [auth-port <auth_port>]
[vrf <vrf>]
378 379 380 381 382 383 384 385 |
# File 'lib/rbeapi/api/aaa.rb', line 378 def add_radius_server(name, server, opts = {}) # order of command options matter here! server = "server #{server} " server << "auth-port #{opts[:auth_port]} " if opts[:auth_port] server << "acct-port #{opts[:acct_port]} " if opts[:acct_port] server << "vrf #{opts[:vrf]}" if opts[:vrf] configure ["aaa group server radius #{name}", server, 'exit'] end |
#add_server(name, server, opts = {}) ⇒ Boolean
add_server adds a new server to the specified aaa server group. If the server is already configured in the list of servers, this method will still return successfully.
347 348 349 350 351 352 353 354 355 |
# File 'lib/rbeapi/api/aaa.rb', line 347 def add_server(name, server, opts = {}) type = find_type(name) return false unless type case type when 'radius' then add_radius_server(name, server, opts) when 'tacacs+' then add_tacacs_server(name, server, opts) else return false end end |
#add_tacacs_server(name, server, opts = {}) ⇒ Boolean
add_tacacs_server adds a new tacacs server to the nodes current configuration. If the server already exists in the specified group name this method will still return successfully.
commmands
aaa group server tacacs+ <name>
server <server> [acct-port <acct_port>] [auth-port <auth_port>]
[vrf <vrf>]
408 409 410 411 412 413 414 |
# File 'lib/rbeapi/api/aaa.rb', line 408 def add_tacacs_server(name, server, opts = {}) # order of command options matter here! server = "server #{server} " server << "vrf #{opts[:vrf]} " if opts[:vrf] server << "port #{opts[:port]} " if opts[:port] configure ["aaa group server tacacs+ #{name}", server, 'exit'] end |
#create(name, type) ⇒ Boolean
create adds a new aaa group server to the nodes current configuration. If the specified name and type are already created then this method will return successfully. If the name is configured but the type is different, this method will not return successfully (returns false).
Commands
aaa group server <type> <name>
277 278 279 |
# File 'lib/rbeapi/api/aaa.rb', line 277 def create(name, type) configure ["aaa group server #{type} #{name}", 'exit'] end |
#delete(name) ⇒ Boolean
delete removes a current aaa server group from the nodes current configuration. This method will automatically determine the server group type based on the name. If the name is not configured in the nodes current configuration, this method will return successfully.
Commands
no aaa group server [radius | tacacs+] <name>
296 297 298 299 300 |
# File 'lib/rbeapi/api/aaa.rb', line 296 def delete(name) type = find_type(name) return true unless type configure "no aaa group server #{type} #{name}" end |
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns the aaa server group resource hash that describes the current configuration for the specified server group name.
114 115 116 117 118 119 120 121 |
# File 'lib/rbeapi/api/aaa.rb', line 114 def get(name) block = get_block("aaa group server ([^\s]+) #{name}") return nil unless block response = {} response.merge!(parse_type(block)) response.merge!(parse_servers(block, response[:type])) response end |
#getall ⇒ Hash<Symbol, Object>
getall returns a aaa server groups hash.
140 141 142 143 144 145 146 |
# File 'lib/rbeapi/api/aaa.rb', line 140 def getall cfg = config.scan(/aaa group server (?:radius|tacacs\+) (.+)$/) cfg.each_with_object({}) do |name, hsh| values = get(name.first) hsh[name.first] = values if values end end |
#parse_tacacs_server(config) ⇒ Hash<Symbol, Object>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
parse_tacacs_server scans the provided configuration block and returns the list of configured servers. The configuration block is expected to be a tacacs configuration block. If there are no servers configured for the group the servers value will return an empty array.
226 227 228 229 230 231 232 233 234 235 |
# File 'lib/rbeapi/api/aaa.rb', line 226 def parse_tacacs_server(config) values = config.scan(TACACS_GROUP_SERVER).map do |(name, vrf, port)| { name: name, vrf: vrf, port: port } end { servers: values } end |
#remove_server(name, server, opts = {}) ⇒ Boolean
remove_server deletes an existing server from the specified aaa server group. If the specified server is not configured in the specified server group, this method will still return true.
eos_version 4.13.7M
Commands
aaa group server [radius | tacacs+] <name>
no server <server>
434 435 436 437 438 439 440 |
# File 'lib/rbeapi/api/aaa.rb', line 434 def remove_server(name, server, opts = {}) type = find_type(name) return false unless type server = "no server #{server} " server << "vrf #{opts[:vrf]}" if opts[:vrf] configure ["aaa group server #{type} #{name}", server, 'exit'] end |
#set_servers(name, servers) ⇒ Boolean
set_servers configures the set of servers for a specified aaa server group. This is an atomic operation that first removes all current servers and then adds the new servers back. If any of the servers failes to be removed or added, this method will return unsuccessfully.
318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/rbeapi/api/aaa.rb', line 318 def set_servers(name, servers) current = get(name) current[:servers].each do |srv| return false unless remove_server(name, srv) end servers.each do |srv| hostname = srv[:name] return false unless add_server(name, hostname, srv) end true end |