Class: Cisco::TacacsServer

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

Constant Summary collapse

@@node =
Cisco::Node.instance

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instantiate = true) ⇒ TacacsServer

Returns a new instance of TacacsServer.



29
30
31
# File 'lib/cisco_node_utils/tacacs_server.rb', line 29

def initialize(instantiate=true)
  enable if instantiate and not TacacsServer.enabled
end

Class Method Details

.default_deadtimeObject

Get default deadtime



87
88
89
# File 'lib/cisco_node_utils/tacacs_server.rb', line 87

def TacacsServer.default_deadtime
  @@node.config_get_default("tacacs_server", "deadtime")
end

.default_directed_requestObject

Get default directed_request



107
108
109
# File 'lib/cisco_node_utils/tacacs_server.rb', line 107

def TacacsServer.default_directed_request
  @@node.config_get_default("tacacs_server", "directed_request")
end

.default_encryption_passwordObject

Get default encryption password



154
155
156
# File 'lib/cisco_node_utils/tacacs_server.rb', line 154

def TacacsServer.default_encryption_password
  @@node.config_get_default("tacacs_server", "encryption_password")
end

.default_encryption_typeObject

Get default encryption type



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

def TacacsServer.default_encryption_type
  @@node.config_get_default("tacacs_server", "encryption_type")
end

.default_source_interfaceObject

Get default source interface



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

def TacacsServer.default_source_interface
  @@node.config_get_default("tacacs_server", "source_interface")
end

.default_timeoutObject

Get default timeout



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

def TacacsServer.default_timeout
  @@node.config_get_default("tacacs_server", "timeout")
end

.enabledObject

Check feature enablement



34
35
36
37
38
39
40
41
# File 'lib/cisco_node_utils/tacacs_server.rb', line 34

def TacacsServer.enabled
  feat = @@node.config_get("tacacs_server", "feature")
  return (!feat.nil? and !feat.empty?)
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled
  raise unless e.clierror =~ /Syntax error/
  return false
end

Instance Method Details

#deadtimeObject

Get deadtime



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

def deadtime
  match = @@node.config_get("tacacs_server", "deadtime")
  match.nil? ? TacacsServer.default_deadtime : match.first.to_i
end

#deadtime=(deadtime) ⇒ Object

Set deadtime



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

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

#destroyObject

Disable tacacs_server feature



49
50
51
# File 'lib/cisco_node_utils/tacacs_server.rb', line 49

def destroy
  @@node.config_set("tacacs_server", "feature", "no")
end

#directed_request=(state) ⇒ Object

Set directed_request

Raises:

  • (TypeError)


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

def directed_request=(state)
  raise TypeError unless state == true || state == false
  state == TacacsServer.default_directed_request ?
    @@node.config_set("tacacs_server", "directed_request", "no") :
    @@node.config_set("tacacs_server", "directed_request", "")
end

#directed_request?Boolean

Check if directed request is enabled

Returns:

  • (Boolean)


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

def directed_request?
  match = @@node.config_get("tacacs_server", "directed_request")
  return TacacsServer.default_directed_request if match.nil?
  match.first[/^no/] ? false : true
end

#enableObject

Enable tacacs_server feature



44
45
46
# File 'lib/cisco_node_utils/tacacs_server.rb', line 44

def enable
  @@node.config_set("tacacs_server", "feature", "")
end

#encryption_key_set(enctype, password) ⇒ Object

Set encryption type and password



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

def encryption_key_set(enctype, 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
        @@node.config_set("tacacs_server", "encryption", "no",
                    encryption_type,
                    encryption_password)
     end
  else
     @@node.config_set("tacacs_server", "encryption", "", enctype, password)
  end
end

#encryption_passwordObject

Get encryption password



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

def encryption_password
  match = @@node.config_get("tacacs_server", "encryption_password")
  match.nil? ? TacacsServer.default_encryption_password : match[0][1]
end

#encryption_typeObject

Get encryption type used for the key



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

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

#source_interfaceObject

Get source interface



120
121
122
123
124
125
126
127
128
129
# File 'lib/cisco_node_utils/tacacs_server.rb', line 120

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

#source_interface=(name) ⇒ Object

Set source interface

Raises:

  • (TypeError)


112
113
114
115
116
117
# File 'lib/cisco_node_utils/tacacs_server.rb', line 112

def source_interface=(name)
  raise TypeError unless name.is_a? String
  name.empty? ?
    @@node.config_set("tacacs_server", "source_interface", "no", "") :
    @@node.config_set("tacacs_server", "source_interface", "", name)
end

#timeoutObject

Get timeout



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

def timeout
  match = @@node.config_get("tacacs_server", "timeout")
  match.nil? ? TacacsServer.default_timeout : match.first.to_i
end

#timeout=(timeout) ⇒ Object

Set timeout



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

def timeout=(timeout)
  # 'no tacacs timeout' will fail, just set it to the requested timeout value.
  @@node.config_set("tacacs_server", "timeout", "", timeout)
end