1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

M #-: fix minor bugs in provision (#820)

This commit is contained in:
Alejandro Huertas Herrero 2021-02-17 11:08:58 +01:00 committed by GitHub
parent 1f66009577
commit 8e5a915c6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 38 deletions

View File

@ -168,6 +168,15 @@ module OneProvision
{ :state => tf_state, :conf => tf_conf }
end
# Adds Terraform information to the provision
def add_tf(state, conf)
@body['tf'] = {} unless @body['tf']
@body['tf']['state'] = state
@body['tf']['conf'] = conf
update
end
# Get OpenNebula information for specific objects
#
# @param object [String] Object to check
@ -322,11 +331,7 @@ module OneProvision
update_hosts(ips, ids)
if state && conf
@body['tf'] = {}
@body['tf']['state'] = state
@body['tf']['conf'] = conf
end
add_tf(state, conf) if state && conf
update
end
@ -460,10 +465,7 @@ module OneProvision
return [-1, rc.message] if OpenNebula.is_error?(rc)
# If it is an array, a host has been deleted
if rc.is_a? Array
@body['tf']['state'] = rc[0]
@body['tf']['conf'] = rc[1]
end
add_tf(rc[0], rc[1]) if rc.is_a? Array
@body['provision'][path][object].delete_if do |obj|
true if obj['id'].to_s == id.to_s
@ -623,7 +625,7 @@ module OneProvision
ret = obj.create
resource_objects[r] = [] unless resource_objects[r]
if ret.is_a? Array
if ret.is_a? Hash
# Marketplace app
unless resource_objects['images']
resource_objects['images'] = []
@ -633,8 +635,11 @@ module OneProvision
resource_objects['templates'] = []
end
resource_objects['images'] << ret[0]
resource_objects['templates'] << ret[1]
resource_objects['images'] << ret[:image] if ret[:image]
if ret[:template]
resource_objects['templates'] << ret[:template]
end
else
resource_objects[r] << { 'id' => ret,
'name' => obj.one['NAME'] }

View File

@ -54,6 +54,7 @@ module OneProvision
rc = app.info
Utils.exception(rc)
app.extend(MarketPlaceAppExt)
url_args = "tag=#{@p_template['tag']}" if @p_template['tag']
@ -67,44 +68,52 @@ module OneProvision
:vmtemplate_name => @p_template['vmname'],
:url_args => url_args
)
Utils.exception(rc[:image].first) if rc[:image]
Utils.exception(rc[:vmtemplate].first) if rc[:vmtemplate]
# get new IDs
image_id = rc[:image].first
template_id = rc[:vmtemplate].first
OneProvisionLogger.debug(
"Image created with ID: #{image_id}"
)
OneProvisionLogger.debug(
"Template created with ID: #{template_id}"
)
# get new created template and update it with provision ID
@template = Template.new
@template.info(template_id)
p_id = @p_template['provision']['id']
ret = {}
# get new created image and update it with provision ID
@image = Image.new
p_id = @p_template['provision']['id']
if image_id
OneProvisionLogger.debug(
"Image created with ID: #{image_id}"
)
@image.info(image_id)
@image.update_provision_info({ 'wait' => wait,
'wait_timeout' => timeout,
'id' => p_id })
@image = Image.new
@template.update_provision_info({ 'id' => p_id })
@image.info(image_id)
@image.update_provision_info({ 'wait' => wait,
'wait_timeout' => timeout,
'id' => p_id })
# Change permissions and ownership
@image.template_chown(@p_template)
@image.template_chmod(@p_template)
@template.template_chown(@p_template)
@template.template_chmod(@p_template)
@image.template_chown(@p_template)
@image.template_chmod(@p_template)
ret = [{ 'id' => image_id, 'name' => @image.one['NAME'] },
{ 'id' => template_id, 'name' => @template.one['NAME'] }]
ret[:image] = { 'id' => image_id,
'name' => @image.one['NAME'] }
end
# get new created template and update it with provision ID
if template_id
OneProvisionLogger.debug(
"Template created with ID: #{template_id}"
)
@template = Template.new
@template.info(template_id)
@template.update_provision_info({ 'id' => p_id })
@template.template_chown(@p_template)
@template.template_chmod(@p_template)
ret[:template] = { 'id' => template_id,
'name' => @template.one['NAME'] }
end
return ret unless wait

View File

@ -151,6 +151,12 @@ module OneProvision
)
unless s && s.success?
@state = File.read("#{tempdir}/terraform.tfstate")
conf = Base64.encode64(Zlib::Deflate.deflate(@conf))
state = Base64.encode64(Zlib::Deflate.deflate(@state))
provision.add_tf(state, conf)
STDERR.puts '[ERROR] Hosts provision failed!!! ' \
'Please log in to your console to delete ' \
'left resources'