From c5ff0b02a782f48afa5947f438f3d30e2d7cf601 Mon Sep 17 00:00:00 2001 From: onenhansen <92747003+onenhansen@users.noreply.github.com> Date: Mon, 4 Jul 2022 04:06:35 -0600 Subject: [PATCH] F #5818: Service template duplicate name autofixing (#2215) (cherry picked from commit 534c0a51271164a477c8c7f90e2a70a22fb6ee89) --- src/oca/ruby/opennebula/marketplaceapp_ext.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/oca/ruby/opennebula/marketplaceapp_ext.rb b/src/oca/ruby/opennebula/marketplaceapp_ext.rb index 8ff1d1c1e9..6c341e975f 100644 --- a/src/oca/ruby/opennebula/marketplaceapp_ext.rb +++ b/src/oca/ruby/opennebula/marketplaceapp_ext.rb @@ -603,6 +603,7 @@ module OpenNebula::MarketPlaceAppExt # :names = [name_a, name_b, ...] exported = {} idx = 0 + idy = 0 # Store IDs of created resources images = [] @@ -627,9 +628,25 @@ module OpenNebula::MarketPlaceAppExt obj.extend(MarketPlaceAppExt) + # Fix name if duplcates exist + imgp = OpenNebula::ImagePool.new(@client) + imgp.info + img_names = imgp.retrieve_elements('/IMAGE_POOL/IMAGE/NAME') + + opt_name = options[:name] + + if img_names.include? "#{opt_name}-#{obj_name}-#{idx}" + idy = 0 + while img_names.include? \ + "#{opt_name}_#{idy}-#{obj_name}-#{idx}" + idy += 1 + end + opt_name = "#{opt_name}_#{idy}" + end + rc = obj.export( :dsid => options[:dsid], - :name => "#{options[:name]}-#{obj_name}-#{idx}", + :name => "#{opt_name}-#{obj_name}-#{idx}", :notemplate => options[:notemplate] )