Class: Cisco::TacacsGlobal
- Defined in:
- lib/cisco_node_utils/tacacs_global.rb
Overview
TacacsGlobal - node utility class for
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.default_key ⇒ Object
Get default encryption password.
- .tacacs_global ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#default_source_interface ⇒ Object
Get default source interface.
- #default_timeout ⇒ Object
- #encryption_key_set(key_format, key) ⇒ Object
-
#initialize(name) ⇒ TacacsGlobal
constructor
A new instance of TacacsGlobal.
- #key ⇒ Object
- #key_format ⇒ Object
-
#source_interface ⇒ Object
Get source interface.
-
#source_interface=(name) ⇒ Object
Set source interface.
- #timeout ⇒ Object
- #timeout=(val) ⇒ Object
Methods inherited from NodeUtil
client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?
Constructor Details
#initialize(name) ⇒ TacacsGlobal
Returns a new instance of TacacsGlobal.
27 28 29 30 31 32 33 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 27 def initialize(name) fail TypeError unless name.is_a?(String) fail ArgumentError, "This provider only accepts an id of 'default'" \ unless name.eql?('default') @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 25 def name @name end |
Class Method Details
.default_key ⇒ Object
Get default encryption password
86 87 88 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 86 def self.default_key config_get_default('tacacs_global', 'key') end |
.tacacs_global ⇒ Object
35 36 37 38 39 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 35 def self.tacacs_global hash = {} hash['default'] = TacacsGlobal.new('default') hash end |
Instance Method Details
#==(other) ⇒ Object
41 42 43 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 41 def ==(other) name == other.name end |
#default_source_interface ⇒ Object
Get default source interface
112 113 114 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 112 def default_source_interface config_get_default('tacacs_global', 'source_interface') end |
#default_timeout ⇒ Object
50 51 52 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 50 def default_timeout config_get_default('tacacs_global', 'timeout') end |
#encryption_key_set(key_format, key) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 90 def encryption_key_set(key_format, key) # If we get an empty key - remove default if configured if key.nil? || key.to_s.empty? key = self.key return if key.empty? key_format = self.key_format config_set('tacacs_server', 'encryption', state: 'no', option: key_format, key: key) else Feature.tacacs_enable key = Utils.add_quotes(key) if key_format.nil? || key_format.to_s.empty? config_set('tacacs_server', 'encryption', state: '', option: '', key: key) else config_set('tacacs_server', 'encryption', state: '', option: key_format, key: key) end end end |
#key ⇒ Object
78 79 80 81 82 83 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 78 def key return nil unless Feature.tacacs_enabled? str = config_get('tacacs_global', 'key') return TacacsGlobal.default_key if str.empty? str[1].strip.gsub(/\"/, '') end |
#key_format ⇒ Object
73 74 75 76 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 73 def key_format match = config_get('tacacs_global', 'key_format') match.nil? ? TACACS_GLOBAL_ENC_UNKNOWN : match[0].to_i end |
#source_interface ⇒ Object
Get source interface
131 132 133 134 135 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 131 def source_interface return nil unless Feature.tacacs_enabled? i = config_get('tacacs_global', 'source_interface') i.nil? ? default_source_interface : i.downcase end |
#source_interface=(name) ⇒ Object
Set source interface
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 117 def source_interface=(name) if name Feature.tacacs_enable config_set( 'tacacs_global', 'source_interface', state: '', source_interface: name) else config_set( 'tacacs_global', 'source_interface', state: 'no', source_interface: '') end end |
#timeout ⇒ Object
45 46 47 48 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 45 def timeout return nil unless Feature.tacacs_enabled? config_get('tacacs_global', 'timeout') end |
#timeout=(val) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cisco_node_utils/tacacs_global.rb', line 54 def timeout=(val) unless val.nil? fail ArgumentError, 'timeout must be an Integer' \ unless val.is_a?(Integer) end if val.nil? fail ArgumentError, 'timeout cannot be unset if TACACS enabled - ' \ "use default value #{default_timeout}" \ if Feature.tacacs_enabled? else Feature.tacacs_enable config_set('tacacs_global', 'timeout', state: '', timeout: val) end end |