Class: Cisco::TacacsServerGroup

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

Overview

NXAPI implementation of AAA Server Group class

Instance Attribute Summary collapse

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(name, create = true) ⇒ TacacsServerGroup

Returns a new instance of TacacsServerGroup


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

def initialize(name, create=true)
  fail TypeError unless name.is_a? String
  @name = name

  return unless create

  TacacsServer.new.enable if platform != :ios_xr && !TacacsServer.enabled
  config_set('tacacs_server_group', 'group', state: '', name: name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


26
27
28
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 26

def name
  @name
end

Class Method Details

.groupsObject


82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 82

def self.groups
  grps = {}
  if platform == :ios_xr
    tacgroups = config_get('tacacs_server_group', 'group')
  else
    tacgroups = config_get('tacacs_server_group', 'group') if
      TacacsServer.enabled
  end
  unless tacgroups.nil?
    tacgroups.each { |s| grps[s] = TacacsServerGroup.new(s, false) }
  end
  grps
end

.tacacs_server_groupsObject

for netdev compatibility


78
79
80
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 78

def self.tacacs_server_groups
  groups
end

Instance Method Details

#==(other) ⇒ Object


73
74
75
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 73

def ==(other)
  name == other.name
end

#deadtimeObject


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

def deadtime
  d = config_get('tacacs_server_group', 'deadtime', @name)
  d.nil? ? default_deadtime : d.to_i
end

#deadtime=(t) ⇒ Object


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

def deadtime=(t)
  no_cmd = t == default_deadtime ? 'no' : ''
  config_set('tacacs_server_group',
             'deadtime',
             name:     @name,
             state:    no_cmd,
             deadtime: t)
end

#default_deadtimeObject


126
127
128
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 126

def default_deadtime
  config_get_default('tacacs_server_group', 'deadtime')
end

#default_serversObject


69
70
71
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 69

def default_servers
  config_get_default('tacacs_server_group', 'servers')
end

#default_source_interfaceObject


145
146
147
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 145

def default_source_interface
  config_get_default('tacacs_server_group', 'source_interface')
end

#default_vrfObject


108
109
110
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 108

def default_vrf
  config_get_default('tacacs_server_group', 'vrf')
end

#destroyObject


38
39
40
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 38

def destroy
  config_set('tacacs_server_group', 'group', state: 'no', name: @name)
end

#serversObject


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

def servers
  config_get('tacacs_server_group', 'servers', @name)
end

#servers=(new_servs) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 46

def servers=(new_servs)
  fail TypeError unless new_servs.is_a? Array
  current_servs = servers
  new_servs.each do |s|
    # add any servers not yet configured
    next if current_servs.include? s
    config_set('tacacs_server_group',
               'servers',
               name:   @name,
               state:  '',
               server: s)
  end
  current_servs.each do |s|
    # remove any undesired existing servers
    next if new_servs.include? s
    config_set('tacacs_server_group',
               'servers',
               name:   @name,
               state:  'no',
               server: s)
  end
end

#source_interfaceObject


130
131
132
133
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 130

def source_interface
  i = config_get('tacacs_server_group', 'source_interface', @name)
  i.nil? ? default_source_interface : i.downcase
end

#source_interface=(s) ⇒ Object


135
136
137
138
139
140
141
142
143
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 135

def source_interface=(s)
  fail TypeError unless s.is_a? String
  no_cmd = s == default_source_interface ? 'no' : ''
  config_set('tacacs_server_group',
             'source_interface',
             name:      @name,
             state:     no_cmd,
             interface: s)
end

#vrfObject


96
97
98
99
100
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 96

def vrf
  # vrf is always present in running config
  v = config_get('tacacs_server_group', 'vrf', @name)
  v.nil? ? default_vrf : v
end

#vrf=(v) ⇒ Object


102
103
104
105
106
# File 'lib/cisco_node_utils/tacacs_server_group.rb', line 102

def vrf=(v)
  fail TypeError unless v.is_a? String
  # vrf = "default" is equivalent to unconfiguring vrf
  config_set('tacacs_server_group', 'vrf', name: @name, state: '', vrf: v)
end