From 3c5d407b2dfc29f92249827196d70536fd9d0f54 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 1 Apr 2021 19:52:31 +0000 Subject: [PATCH] M #-: Support for NIC_ALIAS in elastic driver --- src/vmm_mad/exec/one_vmm_exec.rb | 13 +++++--- src/vnm_mad/remotes/elastic/elastic.rb | 16 ++++++--- src/vnm_mad/remotes/lib/nic.rb | 2 +- src/vnm_mad/remotes/lib/vm.rb | 45 ++++++++++++++++++++++++++ src/vnm_mad/remotes/lib/vnm_driver.rb | 16 +++++++++ 5 files changed, 82 insertions(+), 10 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 982d21fec4..a6854cccaf 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -974,18 +974,20 @@ class ExecDriver < VirtualMachineDriver nic_alias = true end - external = true if xml_data.elements["#{base_tmpl}/EXTERNAL"] - begin source = xml_data.elements["#{base_tmpl}/BRIDGE"] mac = xml_data.elements["#{base_tmpl}/MAC"] target = xml_data.elements["#{base_tmpl}/TARGET"] vn_mad = xml_data.elements["#{base_tmpl}/VN_MAD"] + external = xml_data.elements["#{base_tmpl}/EXTERNAL"] + source = source.text.strip mac = mac.text.strip target = target.text.strip vn_mad = vn_mad.text.strip + + external = !external.nil? || vn_mad == 'elastic' rescue StandardError send_message(action, RESULT[:failure], id, 'Missing VN_MAD, BRIDGE, TARGET or MAC in VM NIC') @@ -1095,11 +1097,14 @@ class ExecDriver < VirtualMachineDriver nic_alias = true end - external = true if xml_data.elements["#{base_tmpl}/EXTERNAL"] - begin mac = xml_data.elements["#{base_tmpl}/MAC"] mac = mac.text.strip + + external = xml_data.elements["#{base_tmpl}/EXTERNAL"] + vn_mad = xml_data.elements["#{base_tmpl}/VN_MAD"].text.strip + + external = !external.nil? || vn_mad == 'elastic' rescue StandardError send_message(action, RESULT[:failure], id, "Error in #{ACTION[:detach_nic]}, MAC needed in NIC") diff --git a/src/vnm_mad/remotes/elastic/elastic.rb b/src/vnm_mad/remotes/elastic/elastic.rb index 2e3ef425e7..4968c1d5cc 100644 --- a/src/vnm_mad/remotes/elastic/elastic.rb +++ b/src/vnm_mad/remotes/elastic/elastic.rb @@ -68,8 +68,9 @@ class ElasticDriver < VNMMAD::VNMDriver provider = ElasticDriver.provider(@provider, @host) attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID'] + attach_nic_id ||= @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID'] - process do |nic| + process_all do |nic| next if attach_nic_id && attach_nic_id != nic[:nic_id] cmds.add :ip, "route add #{nic[:ip]}/32 dev #{nic[:bridge]}" @@ -89,8 +90,9 @@ class ElasticDriver < VNMMAD::VNMDriver provider = ElasticDriver.provider(@provider, @host) attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID'] + attach_nic_id ||= @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID'] - process do |nic| + process_all do |nic| next if attach_nic_id && attach_nic_id != nic[:nic_id] cmds.add :ip, "route del #{nic[:ip]}/32 dev #{nic[:bridge]} | true" @@ -98,7 +100,7 @@ class ElasticDriver < VNMMAD::VNMDriver provider.deactivate(cmds, nic) if provider.respond_to? :deactivate - next if nic[:conf][:keep_empty_bridge] + next if nic[:parent_nic] || nic[:conf][:keep_empty_bridge] cmds.add :ip, "link delete #{nic[:bridge]} | true" end @@ -117,7 +119,9 @@ class ElasticDriver < VNMMAD::VNMDriver assigned = [] attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID'] - rc = @vm.each_nic do |nic| + attach_nic_id ||= @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID'] + + rc = @vm.each_nic_all do |nic| next if attach_nic_id && attach_nic_id != nic[:nic_id] # pass aws_allocation_id if present @@ -144,7 +148,9 @@ class ElasticDriver < VNMMAD::VNMDriver return if provider.nil? attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID'] - @vm.each_nic do |nic| + attach_nic_id ||= @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID'] + + @vm.each_nic_all do |nic| next if attach_nic_id && attach_nic_id != nic[:nic_id] provider.unassign(nic[:ip], nic[:external_ip]) diff --git a/src/vnm_mad/remotes/lib/nic.rb b/src/vnm_mad/remotes/lib/nic.rb index 7c60abc1db..95e2b91d2c 100644 --- a/src/vnm_mad/remotes/lib/nic.rb +++ b/src/vnm_mad/remotes/lib/nic.rb @@ -41,7 +41,7 @@ module VNMMAD ######################################################################## # Hypervisor specific implementation of network interfaces. Each class # implements the following interface: - # - get_info to populste the VM.vm_info Hash + # - get_info to populate the VM.vm_info Hash # - get_tap to set the [:tap] attribute with the associated NIC ######################################################################## diff --git a/src/vnm_mad/remotes/lib/vm.rb b/src/vnm_mad/remotes/lib/vm.rb index f6e0d18ee7..e3051bddd3 100644 --- a/src/vnm_mad/remotes/lib/vm.rb +++ b/src/vnm_mad/remotes/lib/vm.rb @@ -54,6 +54,26 @@ module VNMMAD end @nics = nics + + nics_alias = VNMNetwork::Nics.new(hypervisor) + xpath_alias = xpath_filter.gsub('TEMPLATE/NIC', + 'TEMPLATE/NIC_ALIAS') + + @vm_root.elements.each(xpath_alias) do |nic_element| + nic = nics_alias.new_nic + + nic_build_hash(nic_element, nic) + + parent = @nics.select do |n| + n[:nic_id] == nic[:parent_id] + end + + nic[:parent_nic] = parent.first + + nics_alias << nic + end + + @nics_alias = nics_alias end # Iterator on each NIC of the VM @@ -65,6 +85,31 @@ module VNMMAD end end + # Iterator on each NIC_ALIAS of the VM + def each_nic_alias(&block) + return if @nics_alias.nil? + + @nics_alias.each do |the_nic| + block.call(the_nic) + end + end + + def each_nic_all(&block) + all_nics = @nics + + if all_nics + all_nics += @nics_alias + else + all_nics = @nics_alias + end + + return if all_nics.nil? + + all_nics.each do |the_nic| + block.call(the_nic) + end + end + # Access an XML Element of the VM # @param element [String] element name # @return [String] value of the element or nil if not found diff --git a/src/vnm_mad/remotes/lib/vnm_driver.rb b/src/vnm_mad/remotes/lib/vnm_driver.rb index 03a6edaf60..014b466ebb 100644 --- a/src/vnm_mad/remotes/lib/vnm_driver.rb +++ b/src/vnm_mad/remotes/lib/vnm_driver.rb @@ -80,6 +80,22 @@ module VNMMAD end end + # Executes the given block on each NIC + def process_all + @vm.each_nic do |nic| + add_nic_conf(nic) + add_bridge_conf(nic) + add_ovs_bridge_conf(nic) + add_ip_link_conf(nic) + + yield(nic) + end + + @vm.each_nic_alias do |nic| + yield(nic) + end + end + # Parse network configuration and add it to the nic def add_nic_conf(nic) return if nic[:conf] && nic[:conf].instance_of?(Hash)