Class: Rbeapi::Api::Tacacs
Overview
Tacacs provides instance methods to retrieve and set tacacs configuration values.
Constant Summary collapse
- DEFAULT_KEY_FORMAT =
0
- DEFAULT_KEY =
nil
- SERVER_REGEXP =
Regular expression to extract a tacacs server’s attributes from the running-configuration text. The explicit [ ] spaces enable line wrapping and indentation with the /x flag.
/tacacs-server[ ]host[ ]([^\s]+) (?:[ ](single-connection))? (?:[ ]vrf[ ]([^\s]+))? (?:[ ]port[ ](\d+))? (?:[ ]timeout[ ](\d+))? (?:[ ]key[ ](\d+)[ ](\w+))?\s/x
- DEFAULT_PORT =
Default Tacacs TCP port
49
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#get ⇒ Array<Hash>
getall Returns an Array with a single resource Hash describing the current state of the global tacacs configuration on the target device.
-
#remove_server(opts = {}) ⇒ Boolean
remove_server removes the tacacs server identified by the hostname, and port attributes.
-
#servers ⇒ Array<Hash<Symbol,Object>>
servers returns an Array of tacacs server resource hashes.
-
#set_global_key(opts = {}) ⇒ Boolean
set_global_key configures the tacacs default key.
-
#set_global_timeout(opts = {}) ⇒ Boolean
set_timeout configures the tacacs default timeout.
-
#update_server(opts = {}) ⇒ Boolean
update_server configures a tacacs server resource on the target device.
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
#get ⇒ Array<Hash>
getall Returns an Array with a single resource Hash describing the current state of the global tacacs configuration on the target device. This method is intended to be used by a provider’s instances class method.
76 77 78 79 80 81 82 |
# File 'lib/rbeapi/api/tacacs.rb', line 76 def get global = {} global.merge!(parse_global_timeout) global.merge!(parse_global_key) resource = { global: global, servers: servers } resource end |
#remove_server(opts = {}) ⇒ Boolean
remove_server removes the tacacs server identified by the hostname, and port attributes.
241 242 243 244 245 |
# File 'lib/rbeapi/api/tacacs.rb', line 241 def remove_server(opts = {}) cmd = "no tacacs-server host #{opts[:hostname]}" cmd << " port #{opts[:port]}" if opts[:port] configure cmd end |
#servers ⇒ Array<Hash<Symbol,Object>>
servers returns an Array of tacacs server resource hashes. Each hash describes the current state of the tacacs server and is suitable for use in initializing a tacacs_server provider.
The resource hash returned contains the following information:
* hostname: hostname or ip address, part of the identifier.
* port: (Fixnum) TCP port of the server, part of the identifier.
* key: (String) the key either in plain text or hashed format.
* key_format: (Fixnum) e.g. 0 or 7.
* timeout: (Fixnum) seconds before the timeout period ends.
* multiplex: (Boolean) true when configured to make requests through a
single connection.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/rbeapi/api/tacacs.rb', line 137 def servers tuples = config.scan(SERVER_REGEXP) tuples.map do |(host, mplex, vrf, port, tout, keyfm, key)| hsh = {} hsh[:hostname] = host hsh[:vrf] = vrf hsh[:port] = port.to_i hsh[:timeout] = tout.to_i hsh[:key_format] = keyfm.to_i hsh[:key] = key hsh[:multiplex] = mplex ? true : false hsh end end |
#set_global_key(opts = {}) ⇒ Boolean
set_global_key configures the tacacs default key. This method maps to the ‘tacacs-server key` EOS configuration command, e.g. `tacacs-server key 7 070E234F1F5B4A`.
166 167 168 169 170 171 172 |
# File 'lib/rbeapi/api/tacacs.rb', line 166 def set_global_key(opts = {}) format = opts[:key_format] key = opts[:key] raise ArgumentError, 'key option is required' unless key result = api.config("tacacs-server key #{format} #{key}") result == [{}] end |
#set_global_timeout(opts = {}) ⇒ Boolean
set_timeout configures the tacacs default timeout. This method maps to the ‘tacacs-server timeout` setting.
190 191 192 193 |
# File 'lib/rbeapi/api/tacacs.rb', line 190 def set_global_timeout(opts = {}) cmd = command_builder('tacacs-server timeout', opts) configure cmd end |
#update_server(opts = {}) ⇒ Boolean
update_server configures a tacacs server resource on the target device. This API method maps to the ‘tacacs server host` command, e.g. `tacacs-server host 1.2.3.4 single-connection port 4949 timeout 6 key 7 06070D221D1C5A`.
218 219 220 221 222 223 224 225 226 |
# File 'lib/rbeapi/api/tacacs.rb', line 218 def update_server(opts = {}) key_format = opts[:key_format] || 7 cmd = "tacacs-server host #{opts[:hostname]}" cmd << ' single-connection' if opts[:multiplex] cmd << " port #{opts[:port]}" if opts[:port] cmd << " timeout #{opts[:timeout]}" if opts[:timeout] cmd << " key #{key_format} #{opts[:key]}" if opts[:key] configure cmd end |