Class: Cisco::TacacsServer

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/tacacs_server.rb

Overview

TacacsServer - node utility class for TACACS+ server config management

Class Method Summary collapse

Instance Method Summary collapse

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(instantiate = true) ⇒ TacacsServer

Returns a new instance of TacacsServer.



27
28
29
# File 'lib/cisco_node_utils/tacacs_server.rb', line 27

def initialize(instantiate=true)
  enable if instantiate && !TacacsServer.enabled
end

Class Method Details

.default_deadtimeObject

Get default deadtime



80
81
82
# File 'lib/cisco_node_utils/tacacs_server.rb', line 80

def self.default_deadtime
  config_get_default('tacacs_server', 'deadtime')
end

.default_directed_requestObject

Get default directed_request



100
101
102
# File 'lib/cisco_node_utils/tacacs_server.rb', line 100

def self.default_directed_request
  config_get_default('tacacs_server', 'directed_request')
end

.default_encryption_passwordObject

Get default encryption password



150
151
152
# File 'lib/cisco_node_utils/tacacs_server.rb', line 150

def self.default_encryption_password
  config_get_default('tacacs_server', 'encryption_password')
end

.default_encryption_typeObject

Get default encryption type



138
139
140
# File 'lib/cisco_node_utils/tacacs_server.rb', line 138

def self.default_encryption_type
  config_get_default('tacacs_server', 'encryption_type')
end

.default_source_interfaceObject

Get default source interface



127
128
129
# File 'lib/cisco_node_utils/tacacs_server.rb', line 127

def self.default_source_interface
  config_get_default('tacacs_server', 'source_interface')
end

.default_timeoutObject

Get default timeout



63
64
65
# File 'lib/cisco_node_utils/tacacs_server.rb', line 63

def self.default_timeout
  config_get_default('tacacs_server', 'timeout')
end

.enabledObject

Check feature enablement



32
33
34
# File 'lib/cisco_node_utils/tacacs_server.rb', line 32

def self.enabled
  Feature.tacacs_enabled?
end

Instance Method Details

#deadtimeObject

Get deadtime



75
76
77
# File 'lib/cisco_node_utils/tacacs_server.rb', line 75

def deadtime
  config_get('tacacs_server', 'deadtime')
end

#deadtime=(deadtime) ⇒ Object

Set deadtime



68
69
70
71
72
# File 'lib/cisco_node_utils/tacacs_server.rb', line 68

def deadtime=(deadtime)
  # 'no tacacs deadtime' will fail.
  # Just set it to the requested timeout value.
  config_set('tacacs_server', 'deadtime', '', deadtime)
end

#destroyObject

Disable tacacs_server feature



42
43
44
# File 'lib/cisco_node_utils/tacacs_server.rb', line 42

def destroy
  config_set('tacacs_server', 'feature', 'no') unless platform == :ios_xr
end

#directed_request=(state) ⇒ Object

Set directed_request



85
86
87
88
89
90
91
92
# File 'lib/cisco_node_utils/tacacs_server.rb', line 85

def directed_request=(state)
  fail TypeError unless state == true || state == false
  if state == TacacsServer.default_directed_request
    config_set('tacacs_server', 'directed_request', 'no')
  else
    config_set('tacacs_server', 'directed_request', '')
  end
end

#directed_request?Boolean

Check if directed request is enabled

Returns:

  • (Boolean)


95
96
97
# File 'lib/cisco_node_utils/tacacs_server.rb', line 95

def directed_request?
  config_get('tacacs_server', 'directed_request')
end

#enableObject

Enable tacacs_server feature



37
38
39
# File 'lib/cisco_node_utils/tacacs_server.rb', line 37

def enable
  config_set('tacacs_server', 'feature', '') unless platform == :ios_xr
end

#encryption_key_set(enctype, password) ⇒ Object

Set encryption type and password



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/cisco_node_utils/tacacs_server.rb', line 155

def encryption_key_set(enctype, password)
  password = Utils.add_quotes(password)
  # if enctype is TACACS_SERVER_ENC_UNKNOWN, we will unset the key
  if enctype == TACACS_SERVER_ENC_UNKNOWN
    # if current encryption type is not TACACS_SERVER_ENC_UNKNOWN, we
    # need to unset it. Otherwise the box is not configured with key, we
    # don't need to do anything
    if encryption_type != TACACS_SERVER_ENC_UNKNOWN
      config_set('tacacs_server', 'encryption', state:  'no',
                                                option: encryption_type,
                                                key:    encryption_password)
    end
  else
    config_set('tacacs_server', 'encryption', state: '', option: enctype,
                key: password)
  end
end

#encryption_passwordObject

Get encryption password



143
144
145
146
147
# File 'lib/cisco_node_utils/tacacs_server.rb', line 143

def encryption_password
  str = config_get('tacacs_server', 'encryption_password')
  return TacacsServer.default_encryption_password if str.empty?
  str[1].strip
end

#encryption_typeObject

Get encryption type used for the key



132
133
134
135
# File 'lib/cisco_node_utils/tacacs_server.rb', line 132

def encryption_type
  match = config_get('tacacs_server', 'encryption_type')
  match.nil? ? TACACS_SERVER_ENC_UNKNOWN : match[0].to_i
end

#source_interfaceObject

Get source interface



115
116
117
118
119
120
121
122
123
124
# File 'lib/cisco_node_utils/tacacs_server.rb', line 115

def source_interface
  # Sample output
  # ip tacacs source-interface Ethernet1/1
  # no tacacs source-interface
  match = config_get('tacacs_server', 'source_interface')
  return TacacsServer.default_source_interface if match.empty?
  # match_data will contain one of the following
  # [nil, " Ethernet1/1"] or ["no", nil]
  match[0] == 'no' ? TacacsServer.default_source_interface : match[1]
end

#source_interface=(name) ⇒ Object

Set source interface



105
106
107
108
109
110
111
112
# File 'lib/cisco_node_utils/tacacs_server.rb', line 105

def source_interface=(name)
  fail TypeError unless name.is_a? String
  if name.empty?
    config_set('tacacs_server', 'source_interface', 'no', '')
  else
    config_set('tacacs_server', 'source_interface', '', name)
  end
end

#timeoutObject

Get timeout



58
59
60
# File 'lib/cisco_node_utils/tacacs_server.rb', line 58

def timeout
  config_get('tacacs_server', 'timeout')
end

#timeout=(timeout) ⇒ Object

Set timeout



51
52
53
54
55
# File 'lib/cisco_node_utils/tacacs_server.rb', line 51

def timeout=(timeout)
  # 'no tacacs timeout' will fail.
  # Just set it to the requested timeout value.
  config_set('tacacs_server', 'timeout', state: '', timeout: timeout)
end