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

M #-: check image state when importing (#895)

This commit is contained in:
Alejandro Huertas Herrero 2021-03-01 13:44:00 +01:00 committed by GitHub
parent 3e6d3d53a6
commit 97f2a05196
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,6 +75,17 @@ module OpenNebula::TemplateExt
return [image, ids]
end
i_state = OpenNebula::Image::IMAGE_STATES[
image['STATE'].to_i
]
unless %w[LOCKED READY USED].include?(i_state)
logger.fatal "Wrong image state #{i_state}" if logger
rollback(ids)
return [image, ids]
end
logger.info "Adding disk with image #{image.id}" if logger
tmpl, main = create_app_template(image, idx)
@ -209,8 +220,14 @@ module OpenNebula::TemplateExt
# - content for VM template
#-------------------------------------------------------------------
def create_app_template(image, idx = 0)
# Wait until the image is READY to safe copy it to the MP
image.wait('READY') if Integer(image['STATE']) != 1
i_state = OpenNebula::Image::IMAGE_STATES[image['STATE'].to_i]
# If the image is used, there is no need to wait until it is
# ready because the image is already ready to be copied
if i_state != 'USED' && Integer(image['STATE']) != 1
# Wait until the image is READY to safe copy it to the MP
image.wait('READY')
end
# Rename to avoid clashing names
app_name = "#{image['NAME']}-#{SecureRandom.hex[0..9]}"