Class: Cisco::VxlanVtepVni

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

Overview

VxlanVtepVni - node utility for vxlan vtep vni members.

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(name, vni, assoc_vrf = false, instantiate = true) ⇒ VxlanVtepVni

Returns a new instance of VxlanVtepVni.



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

def initialize(name, vni, assoc_vrf=false, instantiate=true)
  @name = name
  @vni = vni
  @assoc_vrf = assoc_vrf

  set_args_keys_default
  create if instantiate
end

Instance Attribute Details

#assoc_vrfObject (readonly)

Returns the value of attribute assoc_vrf.



27
28
29
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 27

def assoc_vrf
  @assoc_vrf
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 27

def name
  @name
end

#vniObject (readonly)

Returns the value of attribute vni.



27
28
29
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 27

def vni
  @vni
end

Class Method Details

.vnisObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 38

def self.vnis
  hash = {}
  VxlanVtep.vteps.each do |name, _obj|
    hash[name] = {}
    get_args = { name: name }
    vni_list = config_get('vxlan_vtep_vni', 'all_vnis', get_args)
    next if vni_list.nil?
    vni_list.each do |vni, assoc_vrf|
      assoc_vrf = assoc_vrf.nil? ? false : true
      hash[name][vni] = VxlanVtepVni.new(name, vni, assoc_vrf, false)
    end
  end
  hash
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
56
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 53

def ==(other)
  (name == other.name) && (vni == other.vni) &&
    (assoc_vrf == other.assoc_vrf)
end

#createObject



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

def create
  # The configuration for this resource can be either of the following:
  # - member nve 5000
  # - member nve 5000 associate-vrf
  # They are mutually exclusive and one must be removed before the other
  # can be configured.
  set_args_keys(state: '')
  if create_with_associate_vrf?
    destroy_existing('vni_without_vrf')
  else
    destroy_existing('vni_with_vrf')
  end
  config_set('vxlan_vtep', 'vni', @set_args)
end

#create_with_associate_vrf?Boolean

rubocop:enable Style/AccessorMethodNamefor

Returns:

  • (Boolean)


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

def create_with_associate_vrf?
  !@set_args[:assoc_vrf].eql?('')
end

#default_ingress_replicationObject



143
144
145
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 143

def default_ingress_replication
  config_get_default('vxlan_vtep_vni', 'ingress_replication')
end

#default_multicast_groupObject



182
183
184
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 182

def default_multicast_group
  config_get_default('vxlan_vtep_vni', 'multicast_group')
end

#default_peer_listObject



205
206
207
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 205

def default_peer_list
  config_get_default('vxlan_vtep_vni', 'peer_list')
end

#default_suppress_arpObject



230
231
232
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 230

def default_suppress_arp
  config_get_default('vxlan_vtep_vni', 'suppress_arp')
end

#destroyObject



98
99
100
101
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 98

def destroy
  set_args_keys(state: 'no')
  config_set('vxlan_vtep', 'vni', @set_args)
end

#destroy_existing(key) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 75

def destroy_existing(key)
  getargs = { name: @name, vni: @vni, state: '' }
  return unless config_get('vxlan_vtep', key, getargs)
  getargs[:assoc_vrf] = key.eql?('vni_with_vrf') ? 'associate-vrf' : ''
  getargs[:state] = 'no'
  config_set('vxlan_vtep', 'vni', getargs)
end

#ingress_replicationObject

PROPERTIES #



107
108
109
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 107

def ingress_replication
  config_get('vxlan_vtep_vni', 'ingress_replication', @get_args)
end

#ingress_replication=(protocol) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 125

def ingress_replication=(protocol)
  return if protocol.to_s == ingress_replication
  # Only set ingress_replicatin to the default value if it's not already.
  if protocol.to_s == default_ingress_replication &&
     (ingress_replication != default_ingress_replication)
    set_args_keys(state: 'no', protocol: ingress_replication)
    config_set('vxlan_vtep_vni', 'ingress_replication', @set_args)
  else
    # Multicast group and ingress replication are mutually exclusive
    # properties, so remove multicast_group first
    unless multicast_group.empty?
      set_args_keys(state: 'no', ip_start: '', ip_end: '')
      config_set('vxlan_vtep_vni', 'multicast_group', @set_args)
    end
    remove_add_ingress_replication(protocol.to_s)
  end
end

#multicast_groupObject



147
148
149
150
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 147

def multicast_group
  g1, g2 = config_get('vxlan_vtep_vni', 'multicast_group', @get_args)
  g2.nil? ? g1 : g1 + ' ' + g2
end

#multicast_group=(range) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 159

def multicast_group=(range)
  if range == default_multicast_group
    # Due to CSCux78514, trying to remove multicast-group in CLI
    # when ingress replication is configured results in removing
    # ingress replication from nvgen. So be careful and negate
    # Multicast-group only is it is configured.
    unless multicast_group.empty?
      set_args_keys(state: 'no', ip_start: '', ip_end: '')
      config_set('vxlan_vtep_vni', 'multicast_group', @set_args)
    end
  else
    ip_start, ip_end = range.split(' ')
    ip_end = '' if ip_end.nil?
    # Since multicast group and ingress replication are exclusive
    # properties, remove ingress replication first
    unless ingress_replication.empty?
      set_args_keys(state: 'no', protocol: ingress_replication)
      config_set('vxlan_vtep_vni', 'ingress_replication', @set_args)
    end
    remove_add_multicast_group(ip_start, ip_end)
  end
end

#peer_listObject



186
187
188
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 186

def peer_list
  config_get('vxlan_vtep_vni', 'peer_list', @get_args)
end

#peer_list=(should_list) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 190

def peer_list=(should_list)
  delta_hash = Utils.delta_add_remove(should_list, peer_list)
  return if delta_hash.values.flatten.empty?
  [:add, :remove].each do |action|
    CiscoLogger.debug('peer_list' \
      "#{@get_args}\n #{action}: #{delta_hash[action]}")
    delta_hash[action].each do |peer|
      state = (action == :add) ? '' : 'no'
      @set_args[:state] = state
      @set_args[:peer] = peer
      config_set('vxlan_vtep_vni', 'peer_list', @set_args)
    end
  end
end

#remove_add_ingress_replication(protocol) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 111

def remove_add_ingress_replication(protocol)
  if ingress_replication.empty?
    set_args_keys(state: '', protocol: protocol)
    config_set('vxlan_vtep_vni', 'ingress_replication', @set_args)
  else
    # Sadly, the only way to change between protocols is to
    # first remove the existing protocol.
    set_args_keys(state: 'no', protocol: ingress_replication)
    config_set('vxlan_vtep_vni', 'ingress_replication', @set_args)
    set_args_keys(state: '', protocol: protocol)
    config_set('vxlan_vtep_vni', 'ingress_replication', @set_args)
  end
end

#remove_add_multicast_group(ip_start, ip_end) ⇒ Object



152
153
154
155
156
157
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 152

def remove_add_multicast_group(ip_start, ip_end)
  set_args_keys(state: 'no', ip_start: '', ip_end: '')
  config_set('vxlan_vtep_vni', 'multicast_group', @set_args)
  set_args_keys(state: '', ip_start: ip_start, ip_end: ip_end)
  config_set('vxlan_vtep_vni', 'multicast_group', @set_args)
end

#set_args_keys(hash = {}) ⇒ Object

rubocop:disable Style/AccessorMethodName



65
66
67
68
# File 'lib/cisco_node_utils/vxlan_vtep_vni.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_defaultObject



58
59
60
61
62
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 58

def set_args_keys_default
  keys = { name: @name, vni: @vni }
  keys[:assoc_vrf] = @assoc_vrf ? 'associate-vrf' : ''
  @get_args = @set_args = keys
end

#suppress_arpObject



209
210
211
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 209

def suppress_arp
  config_get('vxlan_vtep_vni', 'suppress_arp', @get_args)
end

#suppress_arp=(state) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/cisco_node_utils/vxlan_vtep_vni.rb', line 213

def suppress_arp=(state)
  if state
    set_args_keys(state: '')
    # Host reachability must be enabled for this property
    VxlanVtep.new(@name).host_reachability = 'evpn'
    config_set('vxlan_vtep_vni', 'suppress_arp', @set_args)
  else
    set_args_keys(state: 'no')
    # Remove suppress-arp only if it is configured. Suppress-arp needs
    # free TCAM region for arp-ether ACL. Customers who don't need
    # suppress-arp, needn't see cli failures warning about TCAM regions
    # issued due to 'no suppress-arp'. Note that for suppress-arp, default
    # is 'false' which is no suppress-arp
    config_set('vxlan_vtep_vni', 'suppress_arp', @set_args) if suppress_arp
  end
end