diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 00b0a8e5b19..564e52ad45b 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -970,7 +970,7 @@ def attach_nic(id, drv_message) ] } ] - elsif nic_alias && external + elsif nic_alias steps = [ # Execute pre-attach networking setup { @@ -1072,6 +1072,15 @@ def detach_nic(id, drv_message) :action => :clean } ] + elsif nic_alias + steps = [ + # Execute post-boot networking setup + { + :driver => :vnm, + :action => :post, + :parameters => [:deploy_id] + } + ] else steps = [] end diff --git a/src/vnm_mad/remotes/lib/security_groups_iptables.rb b/src/vnm_mad/remotes/lib/security_groups_iptables.rb index a5cd8c09bb3..35616a6ace7 100644 --- a/src/vnm_mad/remotes/lib/security_groups_iptables.rb +++ b/src/vnm_mad/remotes/lib/security_groups_iptables.rb @@ -334,6 +334,14 @@ def self.vars(vm, nic, sg_id = nil) vars[:set_sg_out] = "#{vars[:chain]}-#{sg_id}-o" end + vars[:nic_aliases] = [] + + unless nic[:alias_ids].nil? + nic[:alias_ids].split(',').each do |id| + vars[:nic_aliases] << vm.nic_alias(id) + end + end + vars end @@ -426,6 +434,10 @@ def self.nic_pre(vm, nic) [:ip, :vrouter_ip].each do |key| ipv4s << nic[key] if !nic[key].nil? && !nic[key].empty? + vars[:nic_aliases].each do |nic_alias| + ipv4s << nic_alias[key] \ + if !nic_alias[key].nil? && !nic_alias[key].empty? + end end if !ipv4s.empty? @@ -453,6 +465,10 @@ def self.nic_pre(vm, nic) [:ip6, :ip6_global, :ip6_link, :ip6_ula].each do |key| ipv6s << nic[key] if !nic[key].nil? && !nic[key].empty? + vars[:nic_aliases].each do |nic_alias| + ipv6s << nic_alias[key] \ + if !nic_alias[key].nil? && !nic_alias[key].empty? + end end if !ipv6s.empty? diff --git a/src/vnm_mad/remotes/lib/sg_driver.rb b/src/vnm_mad/remotes/lib/sg_driver.rb index 915f66d2b6b..1c232a02d04 100644 --- a/src/vnm_mad/remotes/lib/sg_driver.rb +++ b/src/vnm_mad/remotes/lib/sg_driver.rb @@ -79,10 +79,18 @@ def activate(do_all=false) SGIPTables.global_bootstrap attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID'] if !do_all + attach_nic_alias_id = nil + if !do_all + attach_nic_alias_id = @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID'] + attach_nic_alias_parent_id = + @vm["TEMPLATE/NIC_ALIAS[NIC_ID=#{attach_nic_alias_id}]/PARENT_ID"] + end # Process the rules process do |nic| next if attach_nic_id && attach_nic_id != nic[:nic_id] + next if attach_nic_alias_id && \ + attach_nic_alias_parent_id != nic[:nic_id] if nic[:security_groups].nil? nic[:security_groups] = "0" @@ -123,9 +131,17 @@ def deactivate(do_all=false) begin attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID'] if !do_all + attach_nic_alias_id = nil + if !do_all + attach_nic_alias_id = @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID'] + attach_nic_alias_parent_id = + @vm["TEMPLATE/NIC_ALIAS[NIC_ID=#{attach_nic_alias_id}]/PARENT_ID"] + end @vm.nics.each do |nic| next if attach_nic_id && attach_nic_id != nic[:nic_id] + next if attach_nic_alias_id && \ + attach_nic_alias_parent_id != nic[:nic_id] SGIPTables.nic_deactivate(@vm, nic) end diff --git a/src/vnm_mad/remotes/lib/vm.rb b/src/vnm_mad/remotes/lib/vm.rb index 2b2313699d4..701cc678216 100644 --- a/src/vnm_mad/remotes/lib/vm.rb +++ b/src/vnm_mad/remotes/lib/vm.rb @@ -38,22 +38,10 @@ def initialize(vm_root, xpath_filter, deploy_id) @deploy_id = nil if deploy_id == '-' - nics = VNMNetwork::Nics.new(hypervisor) - - @vm_root.elements.each(xpath_filter) do |nic_element| - nic = nics.new_nic - - nic_build_hash(nic_element, nic) - - if !VNMMAD.pre_action? - nic.get_info(self) - nic.get_tap(self) - end - - nics << nic - end - - @nics = nics + @nics = nics_build(xpath_filter) + @nic_aliases = [] + @nic_aliases = nics_build('TEMPLATE/NIC_ALIAS') \ + if !xpath_filter.nil? && xpath_filter.include?('TEMPLATE/NIC') end # Iterator on each NIC of the VM @@ -65,6 +53,19 @@ def each_nic(block) end end + # Get NIC_ALIAS by NIC_ID + # @param element [String] the NIC_ID + # @return [Hash] the NIC_ALIAS + def nic_alias(id) + if @nic_aliases + @nic_aliases.each do |the_nic| + return the_nic if the_nic[:nic_id] == id + end + end + + nil + end + # Access an XML Element of the VM # @param element [String] element name # @return [String] value of the element or nil if not found @@ -121,6 +122,27 @@ def nic_build_hash(nic_element, nic) end end + # Method to build the list of NIC/NIC_ALIAS + # @param xpath_filter [String] XML NIC/NIC_ALIAS document + def nics_build(xpath_filter) + nics = VNMNetwork::Nics.new(hypervisor) + + @vm_root.elements.each(xpath_filter) do |nic_element| + nic = nics.new_nic + + nic_build_hash(nic_element, nic) + + if !VNMMAD.pre_action? + nic.get_info(self) + nic.get_tap(self) + end + + nics << nic + end + + nics + end + end end