From 514ac43d0bb8db9ccc91044d44424b6313dcc1ff Mon Sep 17 00:00:00 2001 From: abelCoronado93 Date: Thu, 1 Jun 2017 11:51:50 +0200 Subject: [PATCH] Bug #4925 onevm save: nic model lost in new template --- src/oca/ruby/opennebula/virtual_machine.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index 9b59eb0c8f..c26cf5744b 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -754,6 +754,7 @@ module OpenNebula # # @return [Integer, OpenNebula::Error] the new Template ID in case of # success, error otherwise + REMOVE_VNET_ATTRS = %w{AR_ID BRIDGE CLUSTER_ID IP MAC TARGET NIC_ID NETWORK_ID VN_MAD SECURITY_GROUPS} def save_as_template(name, persistent=nil) img_ids = [] new_tid = nil @@ -851,21 +852,18 @@ module OpenNebula end self.each('TEMPLATE/NIC') do |nic| + nic_id = nic["NIC_ID"] if nic_id.nil? || nic_id.empty? rc = Error.new('The NIC_ID is missing from the VM template') raise end - - net_id = nic["NETWORK_ID"] - - if !net_id.nil? && !net_id.empty? - replace << "NIC = [ NETWORK_ID = #{net_id} ]\n" - else - # This NIC does not use a Virtual Network - replace << self.template_like_str( - "TEMPLATE", true, "NIC[NIC_ID=#{nic_id}]") << "\n" + REMOVE_VNET_ATTRS.each do |attr| + nic.delete_element(attr) end + + replace << self.template_like_str( + "TEMPLATE", true, "NIC[#{nic}]") << "\n" end # Required by the Sunstone Cloud View