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.
-
#set_source_interface(sources) ⇒ Boolean
set_source_interface takes a dictionary mapping the VRF to the desired source interface.
-
#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 83 |
# File 'lib/rbeapi/api/tacacs.rb', line 76 def get global = {} global.merge!(parse_global_timeout) global.merge!(parse_global_key) global.merge!(parse_global_source) resource = { global: global, servers: servers } resource end |
#remove_server(opts = {}) ⇒ Boolean
remove_server removes the tacacs server identified by the hostname, and port attributes.
263 264 265 266 267 |
# File 'lib/rbeapi/api/tacacs.rb', line 263 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.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/rbeapi/api/tacacs.rb', line 159 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`.
188 189 190 191 192 193 194 |
# File 'lib/rbeapi/api/tacacs.rb', line 188 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.
212 213 214 215 |
# File 'lib/rbeapi/api/tacacs.rb', line 212 def set_global_timeout(opts = {}) cmd = command_builder('tacacs-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 tacacs 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.
282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/rbeapi/api/tacacs.rb', line 282 def set_source_interface(sources) existing = config.scan(/ip tacacs.* source-interface.*/) desired = [] sources.each do |vrf, intf| vrf_str = vrf == 'default' ? '' : " vrf #{vrf}" desired << "ip tacacs#{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 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`.
240 241 242 243 244 245 246 247 248 |
# File 'lib/rbeapi/api/tacacs.rb', line 240 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 |