Class: Cisco::Vni
Overview
node_utils class for Vni
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#vni_id ⇒ Object
readonly
Returns the value of attribute vni_id.
Class Method Summary collapse
-
.feature_vni_enable ⇒ Object
TBD: move this to feature.rb.
-
.feature_vni_enabled ⇒ Object
feature vni.
- .mt_full_support ⇒ Object
- .mt_lite_support ⇒ Object
- .vnis ⇒ Object
Instance Method Summary collapse
- #bridge_domain ⇒ Object
- #bridge_domain=(domain) ⇒ Object
- #cli_error_check(result) ⇒ Object
- #create ⇒ Object
- #default_bridge_domain ⇒ Object
- #default_encap_dot1q ⇒ Object
- #default_shutdown ⇒ Object
- #destroy ⇒ Object
-
#encap_dot1q=(val, prev_val = nil) ⇒ Object
TODO: This method will be refactored as part of US52662 def encap_dot1q final_hash = {} show = show(“sh encapsulation profile | inc ‘vni [0-9,]*’ p 1”) debug(“show class is #showshow.class and show op is #NodeUtil#show”) return final_hash if show == {} match_pat = /vni (S+).*dot1qs+([ 0-9,-]+)vni ([ 0-9,-]+)/m split_pat = /encapsulation profile / pair_arr = show.split(split_pat) pair_arr.each do |pair| match_arr = match_pat.match(pair) next if match_arr.nil? debug “match arr 1 : #1 2: #2 ” \ “3: #3” key_arr = (match_arr.split(/,/)).map do |x| x.strip! if /-/.match(x) x.gsub!(‘-’, ‘..’) else x end end val_arr = (match_arr.split(/,/)).map do |x| x.strip! if /-/.match(x) x.gsub!(‘-’, ‘..’) else x end end.
-
#initialize(vni_id, instantiate = true) ⇒ Vni
constructor
A new instance of Vni.
- #shutdown ⇒ Object
- #shutdown=(state) ⇒ Object
Methods inherited from NodeUtil
config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show
Constructor Details
#initialize(vni_id, instantiate = true) ⇒ Vni
Returns a new instance of Vni.
40 41 42 43 44 45 |
# File 'lib/cisco_node_utils/vni.rb', line 40 def initialize(vni_id, instantiate=true) @vni_id = vni_id.to_s fail ArgumentError, 'Invalid value(non-numeric VNI id)' unless @vni_id[/^\d+$/] create if instantiate end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/cisco_node_utils/vni.rb', line 38 def name @name end |
#vni_id ⇒ Object (readonly)
Returns the value of attribute vni_id.
38 39 40 |
# File 'lib/cisco_node_utils/vni.rb', line 38 def vni_id @vni_id end |
Class Method Details
.feature_vni_enable ⇒ Object
TBD: move this to feature.rb
67 68 69 70 |
# File 'lib/cisco_node_utils/vni.rb', line 67 def self.feature_vni_enable # TBD: move this to feature.rb Feature. config_set('vni', 'feature') end |
.feature_vni_enabled ⇒ Object
feature vni
59 60 61 62 63 64 65 |
# File 'lib/cisco_node_utils/vni.rb', line 59 def self.feature_vni_enabled config_get('vni', 'feature') rescue Cisco::CliError => e # cmd will syntax reject when feature is not enabled raise unless e.clierror =~ /Syntax error/ return false end |
.mt_full_support ⇒ Object
72 73 74 |
# File 'lib/cisco_node_utils/vni.rb', line 72 def self.mt_full_support config_get('vni', 'mt_full_support') end |
.mt_lite_support ⇒ Object
76 77 78 |
# File 'lib/cisco_node_utils/vni.rb', line 76 def self.mt_lite_support config_get('vni', 'mt_lite_support') end |
Instance Method Details
#bridge_domain ⇒ Object
194 195 196 197 |
# File 'lib/cisco_node_utils/vni.rb', line 194 def bridge_domain bd_arr = config_get('vni', 'bridge_domain', vni: @vni_id) bd_arr.first.to_i end |
#bridge_domain=(domain) ⇒ Object
199 200 201 202 203 204 205 |
# File 'lib/cisco_node_utils/vni.rb', line 199 def bridge_domain=(domain) # TBD: ACTIVATE SHOULD BE SEPARATE SETTER AND POSSIBLY RENAMED state = (domain) ? '' : 'no' config_set('vni', 'bridge_domain_activate', state: state, domain: domain) config_set('vni', 'bridge_domain', state: state, domain: domain, vni: @vni_id) end |
#cli_error_check(result) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/cisco_node_utils/vni.rb', line 89 def cli_error_check(result) # The NXOS vni cli does not raise an exception in some conditions and # instead just displays a STDOUT error message; thus NXAPI does not detect # the failure and we must catch it by inspecting the "body" hash entry # returned by NXAPI. This cli behavior is unlikely to change. fail result[2]['body'] if /ERROR:/.match(result[2]['body'].to_s) end |
#create ⇒ Object
80 81 82 83 |
# File 'lib/cisco_node_utils/vni.rb', line 80 def create Vni.feature_vni_enable unless Vni.feature_vni_enabled config_set('vni', 'create', vni: @vni_id) if Vni.mt_full_support end |
#default_bridge_domain ⇒ Object
207 208 209 |
# File 'lib/cisco_node_utils/vni.rb', line 207 def default_bridge_domain config_get_default('vni', 'bridge_domain') end |
#default_encap_dot1q ⇒ Object
190 191 192 |
# File 'lib/cisco_node_utils/vni.rb', line 190 def default_encap_dot1q config_get_default('vni', 'encap_dot1q') end |
#default_shutdown ⇒ Object
223 224 225 |
# File 'lib/cisco_node_utils/vni.rb', line 223 def default_shutdown config_get_default('vni', 'shutdown') end |
#destroy ⇒ Object
85 86 87 |
# File 'lib/cisco_node_utils/vni.rb', line 85 def destroy config_set('vni', 'destroy', vni: @vni_id) end |
#encap_dot1q=(val, prev_val = nil) ⇒ Object
TODO: This method will be refactored as part of US52662 def encap_dot1q
final_hash = {}
show = show("sh encapsulation profile | inc 'vni [0-9,]*' p 1")
debug("show class is #{show.class} and show op is #{show}")
return final_hash if show == {}
match_pat = /vni (\S+).*dot1q\s+([ 0-9,\-]+)vni ([ 0-9,\-]+)/m
split_pat = /encapsulation profile /
pair_arr = show.split(split_pat)
pair_arr.each do |pair|
match_arr = match_pat.match(pair)
next if match_arr.nil?
debug "match arr 1 : #{match_arr[1]} 2: #{match_arr[2]} " \
"3: #{match_arr[3]}"
key_arr = (match_arr[3].split(/,/)).map do |x|
x.strip!
if /-/.match(x)
x.gsub!('-', '..')
else
x
end
end
val_arr = (match_arr[2].split(/,/)).map do |x|
x.strip!
if /-/.match(x)
x.gsub!('-', '..')
else
x
end
end
debug "key_arr = #{key_arr} val_arr = #{val_arr}"
index = 0
value = nil
key_arr.each do |key|
# puts "checking |#{key}| against |#{@vni_id}|"
# puts "checking #{key.class} against #{my_vni.class}"
if /\.\./.match(key)
range = eval(key) ###################### *MUSTFIX* REMOVE eval
if range.include?(@vni_id.to_i)
val_range = eval(val_arr[index]) ##### *MUSTFIX* REMOVE eval
position = @vni_id.to_i - range.begin
value = val_range.begin + position
value = value.to_s
debug "matched #{@vni_id} value is #{value}"
break
end
elsif key == @vni_id
value = val_arr[index]
debug "matched #{key} value is #{value}"
end
index += 1
end
unless value.nil?
# final_hash[match_arr[1]] = value.to_i
final_hash[match_arr[1]] = value
end
end # pair.each
final_hash
end # end of encap_dot1q
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/cisco_node_utils/vni.rb', line 159 def encap_dot1q=(val, prev_val=nil) # TBD REFACTOR debug "val is of class #{val.class} and is #{val} prev is #{prev_val}" # When prev_val is nil, HashDiff doesn't do a `+' on each element, so this if prev_val.nil? val.each do |fresh_profile, fresh_dot1q| config_set('vni', 'encap_dot1q', fresh_profile, '', fresh_dot1q, @vni_id) end return end require 'hashdiff' hash_diff = HashDiff.diff(prev_val, val) debug "hsh diff ; #{hash_diff}" return if hash_diff == [] hash_diff.each do |diff| result = case diff[0] when /\+/ config_set('vni', 'encap_dot1q', diff[1], '', diff[2], @vni_id) when /\-/ config_set('vni', 'encap_dot1q', diff[1], 'no', diff[2], @vni_id) when /~/ config_set('vni', 'encap_dot1q', diff[1], 'no', diff[2], @vni_id) config_set('vni', 'encap_dot1q', diff[1], '', diff[3], @vni_id) end cli_error_check(result) end rescue CliError => e raise "[vni #{@vni_id}] '#{e.command}' : #{e.clierror}" end |
#shutdown ⇒ Object
211 212 213 |
# File 'lib/cisco_node_utils/vni.rb', line 211 def shutdown config_get('vni', 'shutdown', vni: @vni_id) end |
#shutdown=(state) ⇒ Object
215 216 217 218 219 220 221 |
# File 'lib/cisco_node_utils/vni.rb', line 215 def shutdown=(state) state = (state) ? '' : 'no' result = config_set('vni', 'shutdown', state: state, vni: @vni_id) cli_error_check(result) rescue CliError => e raise "[vni #{@vni_id}] '#{e.command}' : #{e.clierror}" end |