Class: Cisco::ItdDeviceGroup
- Inherits:
-
NodeUtil
show all
- Defined in:
- lib/cisco_node_utils/itd_device_group.rb
Overview
node_utils class for itd_device_group
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, instantiate = true) ⇒ ItdDeviceGroup
Returns a new instance of ItdDeviceGroup.
24
25
26
27
28
29
30
31
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 24
def initialize(name, instantiate=true)
fail TypeError unless name.is_a?(String)
fail ArgumentError unless name.length > 0
@name = name
set_args_keys_default
create if instantiate
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
22
23
24
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 22
def name
@name
end
|
Class Method Details
.itds ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 33
def self.itds
hash = {}
groups = config_get('itd_device_group',
'all_itd_device_groups')
return hash if groups.nil?
groups.each do |id|
hash[id] = ItdDeviceGroup.new(id, false)
end
hash
end
|
Instance Method Details
#create ⇒ Object
49
50
51
52
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 49
def create
Feature.itd_enable
config_set('itd_device_group', 'create', name: @name)
end
|
#default_probe_control ⇒ Object
105
106
107
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 105
def default_probe_control
config_get_default('itd_device_group', 'probe_control')
end
|
#default_probe_frequency ⇒ Object
127
128
129
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 127
def default_probe_frequency
config_get_default('itd_device_group', 'probe_frequency')
end
|
#default_probe_retry_down ⇒ Object
152
153
154
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 152
def default_probe_retry_down
config_get_default('itd_device_group', 'probe_retry_down')
end
|
#default_probe_retry_up ⇒ Object
168
169
170
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 168
def default_probe_retry_up
config_get_default('itd_device_group', 'probe_retry_up')
end
|
#default_probe_timeout ⇒ Object
182
183
184
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 182
def default_probe_timeout
config_get_default('itd_device_group', 'probe_timeout')
end
|
#default_probe_type ⇒ Object
196
197
198
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 196
def default_probe_type
config_get_default('itd_device_group', 'probe_type')
end
|
#destroy ⇒ Object
54
55
56
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 54
def destroy
config_set('itd_device_group', 'destroy', name: @name)
end
|
#probe_control ⇒ Object
91
92
93
94
95
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 91
def probe_control
val = Utils.(probe_get, 'control')
return default_probe_control if val.nil?
val == 'enable' ? true : default_probe_control
end
|
#probe_control=(control) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 97
def probe_control=(control)
if control
@set_args[:control] = 'control enable'
else
@set_args[:control] = ''
end
end
|
#probe_dns_host ⇒ Object
109
110
111
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 109
def probe_dns_host
Utils.(probe_get, 'dns_host', 'host')
end
|
#probe_dns_host=(dns_host) ⇒ Object
113
114
115
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 113
def probe_dns_host=(dns_host)
@set_args[:dns_host] = Utils.attach_prefix(dns_host, :dns_host, 'host')
end
|
#probe_frequency ⇒ Object
117
118
119
120
121
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 117
def probe_frequency
val = Utils.(probe_get, 'frequency')
return default_probe_frequency if val.nil?
val.to_i
end
|
#probe_frequency=(frequency) ⇒ Object
123
124
125
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 123
def probe_frequency=(frequency)
@set_args[:frequency] = Utils.attach_prefix(frequency, :frequency)
end
|
#probe_get ⇒ Object
probe configuration is all done in a single line (like below) probe tcp port 32 frequency 10 timeout 5 retry-down-count 3 … probe udp port 23 frequency 10 timeout 5 retry-down-count 3 … probe icmp frequency 10 timeout 5 retry-down-count 3 retry-up-count 3 probe dns host 8.8.8.8 frequency 10 timeout 5 retry-down-count 3 … also the ‘control enable’ can be set if the type is tcp or udp only probe udp port 23 control enable frequency 10 timeout 5 …
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 77
def probe_get
str = config_get('itd_device_group', 'probe', @get_args)
return nil if str.nil?
regexp = Regexp.new('(?<type>\S+)'\
' *(?<dns_host>host \S+)?'\
' *(?<port>port \d+)?'\
' *(?<control>control \S+)?'\
' *(?<frequency>frequency \d+)?'\
' *(?<timeout>timeout \d+)'\
' *(?<retry_down>retry-down-count \d+)'\
' *(?<retry_up>retry-up-count \d+)')
regexp.match(str)
end
|
#probe_port ⇒ Object
131
132
133
134
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 131
def probe_port
val = Utils.(probe_get, 'port')
val.to_i unless val.nil?
end
|
#probe_port=(port) ⇒ Object
136
137
138
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 136
def probe_port=(port)
@set_args[:port] = Utils.attach_prefix(port, :port)
end
|
#probe_retry_down ⇒ Object
140
141
142
143
144
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 140
def probe_retry_down
val = Utils.(probe_get, 'retry_down', 'retry-down-count')
return default_probe_retry_down if val.nil?
val.to_i
end
|
#probe_retry_down=(rdc) ⇒ Object
146
147
148
149
150
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 146
def probe_retry_down=(rdc)
@set_args[:retry_down_count] = Utils.attach_prefix(rdc,
:retry_down_count,
'retry-down-count')
end
|
#probe_retry_up ⇒ Object
156
157
158
159
160
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 156
def probe_retry_up
val = Utils.(probe_get, 'retry_up', 'retry-up-count')
return default_probe_retry_up if val.nil?
val.to_i
end
|
#probe_retry_up=(ruc) ⇒ Object
162
163
164
165
166
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 162
def probe_retry_up=(ruc)
@set_args[:retry_up_count] = Utils.attach_prefix(ruc,
:retry_up_count,
'retry-up-count')
end
|
#probe_set(attrs) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 200
def probe_set(attrs)
if attrs[:probe_type] == false
cmd = 'probe_type'
@set_args[:state] = 'no'
else
cmd = 'probe'
set_args_keys_default
set_args_keys(attrs)
[:probe_type,
:probe_dns_host,
:probe_port,
:probe_control,
:probe_frequency,
:probe_timeout,
:probe_retry_down,
:probe_retry_up,
].each do |p|
attrs[p] = '' if attrs[p].nil?
send(p.to_s + '=', attrs[p])
end
send('probe_control=', false) if attrs[:probe_control] == ''
@get_args = @set_args
end
config_set('itd_device_group', cmd, @set_args)
set_args_keys_default
end
|
#probe_timeout ⇒ Object
172
173
174
175
176
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 172
def probe_timeout
val = Utils.(probe_get, 'timeout')
return default_probe_timeout if val.nil?
val.to_i
end
|
#probe_timeout=(timeout) ⇒ Object
178
179
180
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 178
def probe_timeout=(timeout)
@set_args[:timeout] = Utils.attach_prefix(timeout, :timeout)
end
|
#probe_type ⇒ Object
186
187
188
189
190
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 186
def probe_type
match = probe_get
return default_probe_type if match.nil?
match.names.include?('type') ? match[:type] : default_probe_type
end
|
#probe_type=(type) ⇒ Object
192
193
194
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 192
def probe_type=(type)
@set_args[:type] = type
end
|
#set_args_keys(hash = {}) ⇒ Object
rubocop:disable Style/AccessorMethodName
65
66
67
68
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 65
def set_args_keys(hash={})
set_args_keys_default
@set_args = @get_args.merge!(hash) unless hash.empty?
end
|
#set_args_keys_default ⇒ Object
Helper method to delete @set_args hash keys
59
60
61
62
|
# File 'lib/cisco_node_utils/itd_device_group.rb', line 59
def set_args_keys_default
keys = { name: @name }
@get_args = @set_args = keys
end
|