1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-14 01:57:24 +03:00

B #5794: preserve marketplace VM template (#1907)

This commit is contained in:
Alejandro Huertas Herrero 2022-04-06 11:44:52 +02:00 committed by GitHub
parent ec33af3a3c
commit 399a85596c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 10 deletions

View File

@ -188,7 +188,12 @@ module OpenNebula::MarketPlaceAppExt
if is_vcenter &&
!options[:notemplate] &&
(!options[:template] || options[:template] == -1)
tmpl = create_vcenter_template(ds, options, image)
tmpl = create_vcenter_template(
ds,
options,
self['TEMPLATE/VMTEMPLATE64'],
image
)
if OpenNebula.is_error?(tmpl)
rc_info[:vmtemplate] = [tmpl]
@ -303,10 +308,11 @@ module OpenNebula::MarketPlaceAppExt
# Create a VM template in vCenter in order to use it when
# deploying an app from the marketplace
#
# @param ds [OpenNebula::Datastore] Datastore information
# @param options [Hash] Export options
# @param image [OpenNebula::Image] Image information
def create_vcenter_template(ds, options, image = nil)
# @param ds [OpenNebula::Datastore] Datastore information
# @param options [Hash] Export options
# @param template [String] App template
# @param image [OpenNebula::Image] Image information
def create_vcenter_template(ds, options, template, image = nil)
ret = {}
keys = %w[VCENTER_TEMPLATE_REF
VCENTER_CCR_REF
@ -384,15 +390,25 @@ module OpenNebula::MarketPlaceAppExt
end
tmpl = <<-EOT
NAME = "#{options[:vmtemplate_name] || options[:name]}"
CPU = "1"
VCPU = "1"
MEMORY = "128"
NAME = "#{options[:vmtemplate_name] || options[:name]}"
HYPERVISOR = "vcenter"
EOT
tmpl << "DISK = [ IMAGE_ID = \"#{image.id}\" ]" if image
template ||= ''
template = Base64.decode64(template)
template.split("\n").each do |line|
# Legacy, some apps in the marketplace have the sched
# requirement to just be run on KVM, with this
# the template cannot be run on vCenter, so don't add
# it in the final VM template
next if line =~ /SCHED_REQUIREMENTS/ || line.empty?
tmpl << "#{line}\n"
end
ret.each do |key, value|
tmpl << "#{key}=\"#{value}\"\n"
end

View File

@ -118,7 +118,9 @@ begin
spec_hash[:uuid] = drv_action['TEMPLATE/OS/UUID'] \
unless drv_action['TEMPLATE/OS/UUID'].nil?
unless drv_action['TEMPLATE/OS/FIRMWARE'].nil?
firmware = drv_action['TEMPLATE/OS/FIRMWARE']
unless firmware.nil? || firmware.empty?
spec_hash[:firmware] = drv_action['TEMPLATE/OS/FIRMWARE']
end