Class: Cisco::VrfAF

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/vrf_af.rb

Overview

VrfAF - node utility class for VRF Address-Family configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show

Constructor Details

#initialize(vrf, af, instantiate = true) ⇒ VrfAF

Returns a new instance of VrfAF.



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

def initialize(vrf, af, instantiate=true)
  validate_args(vrf, af)
  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.afsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cisco_node_utils/vrf_af.rb', line 33

def self.afs
  hash = {}
  vrfs = config_get('vrf', 'all_vrfs')
  vrfs.each do |vrf|
    hash[vrf] = {}
    afs = config_get('vrf', 'all_vrf_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

#createObject



48
49
50
# File 'lib/cisco_node_utils/vrf_af.rb', line 48

def create
  config_set('vrf', 'address_family', set_args_keys(state: ''))
end

#default_route_target_both_autoObject



96
97
98
# File 'lib/cisco_node_utils/vrf_af.rb', line 96

def default_route_target_both_auto
  config_get_default('vrf', 'route_target_both_auto')
end

#default_route_target_both_auto_evpnObject



111
112
113
# File 'lib/cisco_node_utils/vrf_af.rb', line 111

def default_route_target_both_auto_evpn
  config_get_default('vrf', 'route_target_both_auto_evpn')
end

#default_route_target_exportObject



125
126
127
# File 'lib/cisco_node_utils/vrf_af.rb', line 125

def default_route_target_export
  config_get_default('vrf', 'route_target_export')
end

#default_route_target_export_evpnObject



140
141
142
# File 'lib/cisco_node_utils/vrf_af.rb', line 140

def default_route_target_export_evpn
  config_get_default('vrf', 'route_target_export_evpn')
end

#default_route_target_importObject



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

def default_route_target_import
  config_get_default('vrf', 'route_target_import')
end

#default_route_target_import_evpnObject



169
170
171
# File 'lib/cisco_node_utils/vrf_af.rb', line 169

def default_route_target_import_evpn
  config_get_default('vrf', 'route_target_import_evpn')
end

#destroyObject



52
53
54
# File 'lib/cisco_node_utils/vrf_af.rb', line 52

def destroy
  config_set('vrf', 'address_family', set_args_keys(state: 'no'))
end

#route_target_both_autoObject

PROPERTIES #



86
87
88
# File 'lib/cisco_node_utils/vrf_af.rb', line 86

def route_target_both_auto
  config_get('vrf', 'route_target_both_auto', @get_args)
end

#route_target_both_auto=(state) ⇒ Object



90
91
92
93
94
# File 'lib/cisco_node_utils/vrf_af.rb', line 90

def route_target_both_auto=(state)
  route_target_feature_enable
  set_args_keys(state: (state ? '' : 'no'))
  config_set('vrf', 'route_target_both_auto', @set_args)
end

#route_target_both_auto_evpnObject




101
102
103
# File 'lib/cisco_node_utils/vrf_af.rb', line 101

def route_target_both_auto_evpn
  config_get('vrf', 'route_target_both_auto_evpn', @get_args)
end

#route_target_both_auto_evpn=(state) ⇒ Object



105
106
107
108
109
# File 'lib/cisco_node_utils/vrf_af.rb', line 105

def route_target_both_auto_evpn=(state)
  route_target_feature_enable
  set_args_keys(state: (state ? '' : 'no'))
  config_set('vrf', 'route_target_both_auto_evpn', @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.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/cisco_node_utils/vrf_af.rb', line 176

def route_target_delta(should, is, prop)
  route_target_feature_enable
  delta_hash = Utils.delta_add_remove(should, is)
  return if delta_hash.values.flatten.empty?
  [:add, :remove].each do |action|
    CiscoLogger.debug("#{prop}" \
      "#{@get_args}\n #{action}: #{delta_hash[action]}")
    delta_hash[action].each do |community|
      state = (action == :add) ? '' : 'no'
      set_args_keys(state: state, community: community)
      config_set('vrf', prop, @set_args)
    end
  end
end

#route_target_exportObject




116
117
118
119
# File 'lib/cisco_node_utils/vrf_af.rb', line 116

def route_target_export
  cmds = config_get('vrf', 'route_target_export', @get_args)
  cmds.sort
end

#route_target_export=(should) ⇒ Object



121
122
123
# File 'lib/cisco_node_utils/vrf_af.rb', line 121

def route_target_export=(should)
  route_target_delta(should, route_target_export, 'route_target_export')
end

#route_target_export_evpnObject




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

def route_target_export_evpn
  cmds = config_get('vrf', 'route_target_export_evpn', @get_args)
  cmds.sort
end

#route_target_export_evpn=(should) ⇒ Object



135
136
137
138
# File 'lib/cisco_node_utils/vrf_af.rb', line 135

def route_target_export_evpn=(should)
  route_target_delta(should, route_target_export_evpn,
                     'route_target_export_evpn')
end

#route_target_feature_enableObject



76
77
78
79
80
# File 'lib/cisco_node_utils/vrf_af.rb', line 76

def route_target_feature_enable
  Feature.bgp_enable
  Feature.nv_overlay_enable
  Feature.nv_overlay_evpn_enable
end

#route_target_importObject




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

def route_target_import
  cmds = config_get('vrf', 'route_target_import', @get_args)
  cmds.sort
end

#route_target_import=(should) ⇒ Object



150
151
152
# File 'lib/cisco_node_utils/vrf_af.rb', line 150

def route_target_import=(should)
  route_target_delta(should, route_target_import, 'route_target_import')
end

#route_target_import_evpnObject




159
160
161
162
# File 'lib/cisco_node_utils/vrf_af.rb', line 159

def route_target_import_evpn
  cmds = config_get('vrf', 'route_target_import_evpn', @get_args)
  cmds.sort
end

#route_target_import_evpn=(should) ⇒ Object



164
165
166
167
# File 'lib/cisco_node_utils/vrf_af.rb', line 164

def route_target_import_evpn=(should)
  route_target_delta(should, route_target_import_evpn,
                     'route_target_import_evpn')
end

#set_args_keys(hash = {}) ⇒ Object

rubocop:disable Style/AccessorMethodName



71
72
73
74
# File 'lib/cisco_node_utils/vrf_af.rb', line 71

def set_args_keys(hash={}) # rubocop:disable Style/AccessorMethodName
  set_args_keys_default
  @set_args = @get_args.merge!(hash) unless hash.empty?
end

#set_args_keys_defaultObject



65
66
67
68
69
# File 'lib/cisco_node_utils/vrf_af.rb', line 65

def set_args_keys_default
  keys = { afi: @afi, safi: @safi }
  keys[:vrf] = @vrf unless @vrf == 'default'
  @get_args = @set_args = keys
end

#validate_args(vrf, af) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/cisco_node_utils/vrf_af.rb', line 56

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