Class: Cisco::VrfAF
Overview
VrfAF - node utility class for VRF Address-Family configuration
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(vrf, af, instantiate = true) ⇒ VrfAF
Returns a new instance of VrfAF.
26
27
28
29
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 26
def initialize(vrf, af, instantiate=true)
validate_args(vrf, af)
create if instantiate
end
|
Class Method Details
.afs ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 35
def self.afs
hash = {}
vrfs = config_get('vrf', 'all_vrfs')
vrfs.each do |vrf|
hash[vrf] = {}
afs = config_get('vrf_af', 'all_afs', vrf: vrf)
next if afs.nil?
afs.each do |af|
hash[vrf][af] = VrfAF.new(vrf, af, false)
end
end
hash
end
|
Instance Method Details
#create ⇒ Object
50
51
52
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 50
def create
config_set('vrf', 'address_family', set_args_keys(state: ''))
end
|
#default_route_policy_export ⇒ Object
115
116
117
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 115
def default_route_policy_export
config_get_default('vrf_af', 'route_policy_export')
end
|
#default_route_policy_import ⇒ Object
136
137
138
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 136
def default_route_policy_import
config_get_default('vrf_af', 'route_policy_import')
end
|
#default_route_target_both_auto ⇒ Object
151
152
153
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 151
def default_route_target_both_auto
config_get_default('vrf_af', 'route_target_both_auto')
end
|
#default_route_target_both_auto_evpn ⇒ Object
166
167
168
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 166
def default_route_target_both_auto_evpn
config_get_default('vrf_af', 'route_target_both_auto_evpn')
end
|
#default_route_target_both_auto_mvpn ⇒ Object
181
182
183
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 181
def default_route_target_both_auto_mvpn
config_get_default('vrf_af', 'route_target_both_auto_mvpn')
end
|
#default_route_target_export ⇒ Object
196
197
198
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 196
def default_route_target_export
config_get_default('vrf_af', 'route_target_export')
end
|
#default_route_target_export_evpn ⇒ Object
212
213
214
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 212
def default_route_target_export_evpn
config_get_default('vrf_af', 'route_target_export_evpn')
end
|
#default_route_target_export_mvpn ⇒ Object
228
229
230
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 228
def default_route_target_export_mvpn
config_get_default('vrf_af', 'route_target_export_mvpn')
end
|
#default_route_target_export_stitching ⇒ Object
243
244
245
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 243
def default_route_target_export_stitching
config_get_default('vrf_af', 'route_target_export_stitching')
end
|
#default_route_target_import ⇒ Object
258
259
260
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 258
def default_route_target_import
config_get_default('vrf_af', 'route_target_import')
end
|
#default_route_target_import_evpn ⇒ Object
274
275
276
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 274
def default_route_target_import_evpn
config_get_default('vrf_af', 'route_target_import_evpn')
end
|
#default_route_target_import_mvpn ⇒ Object
290
291
292
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 290
def default_route_target_import_mvpn
config_get_default('vrf_af', 'route_target_import_mvpn')
end
|
#default_route_target_import_stitching ⇒ Object
305
306
307
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 305
def default_route_target_import_stitching
config_get_default('vrf_af', 'route_target_import_stitching')
end
|
#destroy ⇒ Object
54
55
56
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 54
def destroy
config_set('vrf', 'address_family', set_args_keys(state: 'no'))
end
|
#route_policy_export ⇒ Object
98
99
100
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 98
def route_policy_export
config_get('vrf_af', 'route_policy_export', @get_args)
end
|
#route_policy_export=(name) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 102
def route_policy_export=(name)
Feature.bgp_enable if platform == :nexus
if name
set_args_keys(state: '', policy_name: name)
else
remove_name = config_get('vrf_af', 'route_policy_export', @get_args)
return nil if remove_name.nil?
set_args_keys(state: 'no', policy_name: remove_name)
end
config_set('vrf_af', 'route_policy_export', @set_args)
end
|
#route_policy_import ⇒ Object
119
120
121
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 119
def route_policy_import
config_get('vrf_af', 'route_policy_import', @get_args)
end
|
#route_policy_import=(name) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 123
def route_policy_import=(name)
Feature.bgp_enable if platform == :nexus
if name
set_args_keys(state: '', policy_name: name)
else
remove_name = config_get('vrf_af', 'route_policy_import', @get_args)
return nil if remove_name.nil?
set_args_keys(state: 'no', policy_name: remove_name)
end
config_set('vrf_af', 'route_policy_import', @set_args)
end
|
#route_target_both_auto ⇒ Object
141
142
143
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 141
def route_target_both_auto
config_get('vrf_af', 'route_target_both_auto', @get_args)
end
|
#route_target_both_auto=(state) ⇒ Object
145
146
147
148
149
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 145
def route_target_both_auto=(state)
route_target_feature_enable(:require_nv_overlay)
set_args_keys(state: (state ? '' : 'no'))
config_set('vrf_af', 'route_target_both_auto', @set_args)
end
|
#route_target_both_auto_evpn ⇒ Object
156
157
158
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 156
def route_target_both_auto_evpn
config_get('vrf_af', 'route_target_both_auto_evpn', @get_args)
end
|
#route_target_both_auto_evpn=(state) ⇒ Object
160
161
162
163
164
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 160
def route_target_both_auto_evpn=(state)
route_target_feature_enable(:require_nv_overlay)
set_args_keys(state: (state ? '' : 'no'))
config_set('vrf_af', 'route_target_both_auto_evpn', @set_args)
end
|
#route_target_both_auto_mvpn ⇒ Object
171
172
173
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 171
def route_target_both_auto_mvpn
config_get('vrf_af', 'route_target_both_auto_mvpn', @get_args)
end
|
#route_target_both_auto_mvpn=(state) ⇒ Object
175
176
177
178
179
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 175
def route_target_both_auto_mvpn=(state)
route_target_feature_enable(nil, :require_ngmvpn)
set_args_keys(state: (state ? '' : 'no'))
config_set('vrf_af', 'route_target_both_auto_mvpn', @set_args)
end
|
#route_target_delta(should, is, prop) ⇒ Object
route_target_delta is a common helper function for the route_target properties. It walks the delta hash and adds/removes each target cli.
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 312
def route_target_delta(should, is, prop)
fail Cisco::UnsupportedError.new('vrf_af', prop) if is.nil?
delta_hash = Utils.delta_add_remove(should, is)
return if delta_hash.values.flatten.empty?
[:add, :remove].each do |action|
Cisco::Logger.debug("#{prop}" \
"#{@get_args}\n #{action}: #{delta_hash[action]}")
delta_hash[action].each do ||
state = (action == :add) ? '' : 'no'
set_args_keys(state: state, community: )
config_set('vrf_af', prop, @set_args)
end
end
end
|
#route_target_export ⇒ Object
186
187
188
189
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 186
def route_target_export
cmds = config_get('vrf_af', 'route_target_export', @get_args)
cmds.nil? ? nil : cmds.sort
end
|
#route_target_export=(should) ⇒ Object
191
192
193
194
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 191
def route_target_export=(should)
route_target_feature_enable
route_target_delta(should, route_target_export, 'route_target_export')
end
|
#route_target_export_evpn ⇒ Object
201
202
203
204
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 201
def route_target_export_evpn
cmds = config_get('vrf_af', 'route_target_export_evpn', @get_args)
cmds.nil? ? nil : cmds.sort
end
|
#route_target_export_evpn=(should) ⇒ Object
206
207
208
209
210
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 206
def route_target_export_evpn=(should)
route_target_feature_enable(:require_nv_overlay)
route_target_delta(should, route_target_export_evpn,
'route_target_export_evpn')
end
|
#route_target_export_mvpn ⇒ Object
217
218
219
220
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 217
def route_target_export_mvpn
cmds = config_get('vrf_af', 'route_target_export_mvpn', @get_args)
cmds.nil? ? nil : cmds.sort
end
|
#route_target_export_mvpn=(should) ⇒ Object
222
223
224
225
226
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 222
def route_target_export_mvpn=(should)
route_target_feature_enable(nil, :require_ngmvpn)
route_target_delta(should, route_target_export_mvpn,
'route_target_export_mvpn')
end
|
#route_target_export_stitching ⇒ Object
233
234
235
236
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 233
def route_target_export_stitching
cmds = config_get('vrf_af', 'route_target_export_stitching', @get_args)
cmds.nil? ? nil : cmds.sort
end
|
#route_target_export_stitching=(should) ⇒ Object
238
239
240
241
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 238
def route_target_export_stitching=(should)
route_target_delta(should, route_target_export_stitching,
'route_target_export_stitching')
end
|
#route_target_feature_enable(require_nv_overlay = nil, require_ngmvpn = nil) ⇒ Object
#route_target_import ⇒ Object
248
249
250
251
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 248
def route_target_import
cmds = config_get('vrf_af', 'route_target_import', @get_args)
cmds.nil? ? nil : cmds.sort
end
|
#route_target_import=(should) ⇒ Object
253
254
255
256
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 253
def route_target_import=(should)
route_target_feature_enable
route_target_delta(should, route_target_import, 'route_target_import')
end
|
#route_target_import_evpn ⇒ Object
263
264
265
266
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 263
def route_target_import_evpn
cmds = config_get('vrf_af', 'route_target_import_evpn', @get_args)
cmds.nil? ? nil : cmds.sort
end
|
#route_target_import_evpn=(should) ⇒ Object
268
269
270
271
272
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 268
def route_target_import_evpn=(should)
route_target_feature_enable(:require_nv_overlay)
route_target_delta(should, route_target_import_evpn,
'route_target_import_evpn')
end
|
#route_target_import_mvpn ⇒ Object
279
280
281
282
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 279
def route_target_import_mvpn
cmds = config_get('vrf_af', 'route_target_import_mvpn', @get_args)
cmds.nil? ? nil : cmds.sort
end
|
#route_target_import_mvpn=(should) ⇒ Object
284
285
286
287
288
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 284
def route_target_import_mvpn=(should)
route_target_feature_enable(nil, :require_ngmvpn)
route_target_delta(should, route_target_import_mvpn,
'route_target_import_mvpn')
end
|
#route_target_import_stitching ⇒ Object
295
296
297
298
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 295
def route_target_import_stitching
cmds = config_get('vrf_af', 'route_target_import_stitching', @get_args)
cmds.nil? ? nil : cmds.sort
end
|
#route_target_import_stitching=(should) ⇒ Object
300
301
302
303
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 300
def route_target_import_stitching=(should)
route_target_delta(should, route_target_import_stitching,
'route_target_import_stitching')
end
|
#set_args_keys(hash = {}) ⇒ Object
rubocop:disable Style/AccessorMethodName
73
74
75
76
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 73
def set_args_keys(hash={}) set_args_keys_default
@set_args = @get_args.merge!(hash) unless hash.empty?
end
|
#set_args_keys_default ⇒ Object
67
68
69
70
71
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 67
def set_args_keys_default
keys = { afi: @afi, safi: @safi }
keys[:vrf] = @vrf unless @vrf == 'default'
@get_args = @set_args = keys
end
|
#to_s ⇒ Object
31
32
33
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 31
def to_s
"VRF #{@vrf} afi #{@afi} safi #{@safi}"
end
|
#validate_args(vrf, af) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/cisco_node_utils/vrf_af.rb', line 58
def validate_args(vrf, af)
fail ArgumentError unless vrf.is_a?(String) && (vrf.length > 0)
fail ArgumentError, "'af' must be an array specifying afi and safi" unless
af.is_a?(Array) || af.length == 2
@vrf = vrf.downcase
@afi, @safi = af
set_args_keys_default
end
|