Class: Cisco::TacacsServerHost

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

Constant Summary collapse

@@node =
Cisco::Node.instance
@@hosts =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, create = true) ⇒ TacacsServerHost

Returns a new instance of TacacsServerHost.

Raises:

  • (TypeError)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 28

def initialize(name, create=true)
  raise TypeError unless name.is_a? String
  raise ArgumentError if name.empty?
  @name = name

  if create
    # feature Tacacs+ must be enabled to create a host
    TacacsServer.new.enable unless TacacsServer.enabled
    @@node.config_set("tacacs_server_host", "host", "", name)
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 24

def name
  @name
end

Class Method Details

.default_encryption_passwordObject



88
89
90
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 88

def TacacsServerHost.default_encryption_password
  @@node.config_get_default("tacacs_server_host", "encryption_password")
end

.default_encryption_typeObject



79
80
81
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 79

def TacacsServerHost.default_encryption_type
  TacacsServer.default_encryption_type
end

.default_portObject



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

def TacacsServerHost.default_port
  @@node.config_get_default("tacacs_server_host", "port")
end

.default_timeoutObject



124
125
126
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 124

def TacacsServerHost.default_timeout
  @@node.config_get_default("tacacs_server_host", "timeout")
end

.hostsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 40

def TacacsServerHost.hosts
  @@hosts = {}

  return @@hosts unless TacacsServer.enabled

  hosts = @@node.config_get("tacacs_server_host", "hosts")
  unless hosts.nil?
    hosts = [hosts] if hosts.is_a?(Hash)
    hosts.each { |name|
      @@hosts[name] = TacacsServerHost.new(name, false) if @@hosts[name].nil?
    }
  end
  @@hosts
end

Instance Method Details

#destroyObject



55
56
57
58
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 55

def destroy
  @@node.config_set("tacacs_server_host", "host", "no", @name)
  @@hosts.delete(@name) unless @@hosts.nil?
end

#encryption_key_set(enctype, password) ⇒ Object

Raises:

  • (TypeError)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 92

def encryption_key_set(enctype, password)
  raise TypeError unless enctype.is_a? Fixnum
  raise ArgumentError if password and not [TACACS_SERVER_ENC_NONE,
                                           TACACS_SERVER_ENC_CISCO_TYPE_7,
                                           TACACS_SERVER_ENC_UNKNOWN].include? enctype
  # if enctype is TACACS_SERVER_ENC_UNKNOWN, we'll unset the key
  if enctype == TACACS_SERVER_ENC_UNKNOWN
    # if current encryption type is not TACACS_SERVER_ENC_UNKNOWN, we need
    # to unset the key value. Otherwise, the box is not configured with key,
    # thus we don't need to do anything
    if encryption_type != TACACS_SERVER_ENC_UNKNOWN
       @@node.config_set("tacacs_server_host", "encryption", "no", @name,
                      encryption_type,
                      encryption_password)
    end
  else
    @@node.config_set("tacacs_server_host", "encryption", "", @name, enctype, password)
  end
end

#encryption_passwordObject



83
84
85
86
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 83

def encryption_password
  pass = @@node.config_get("tacacs_server_host", "encryption_password", @name)
  pass.nil? ? TacacsServerHost.default_encryption_password : pass.first
end

#encryption_typeObject



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

def encryption_type
  type = @@node.config_get("tacacs_server_host", "encryption_type", @name)
  type.nil? ? TACACS_SERVER_ENC_UNKNOWN : type.first.to_i
end

#portObject



60
61
62
63
64
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 60

def port
  p = @@node.config_get("tacacs_server_host", "port", @name)
  raise "unable to retrieve port information for #{@name}" if p.nil?
  p.first.to_i
end

#port=(n) ⇒ Object



66
67
68
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 66

def port=(n)
  @@node.config_set("tacacs_server_host", "port", @name, n.to_i)
end

#timeoutObject



112
113
114
115
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 112

def timeout
  t = @@node.config_get("tacacs_server_host", "timeout", @name)
  t.nil? ? TacacsServerHost.default_timeout : t.first.to_i
end

#timeout=(t) ⇒ Object

Raises:

  • (TypeError)


117
118
119
120
121
122
# File 'lib/cisco_node_utils/tacacs_server_host.rb', line 117

def timeout=(t)
  raise TypeError unless t.is_a? Fixnum
  return if t == timeout

  @@node.config_set("tacacs_server_host", "timeout", "", @name, t)
end