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

bug #295: Images are disabled if have to be written in the repo

This commit is contained in:
Ruben S. Montero 2010-08-01 17:44:58 +02:00
parent 42bf46e21a
commit 971031f326
2 changed files with 64 additions and 25 deletions

View File

@ -3,21 +3,21 @@ require 'fileutils'
module OpenNebula
class ImageRepository
def create(image, template, copy=true)
if image.nil?
error_msg = "Image could not be found, aborting."
result = OpenNebula::Error.new(error_msg)
end
# ------ Allocate the Image ------
result = image.allocate(template)
if OpenNebula.is_error?(result)
if OpenNebula.is_error?(result)
puts result.message
exit -1
end
# ------ Copy the Image file ------
image.info
@ -38,7 +38,7 @@ module OpenNebula
image['TEMPLATE/TYPE'] == 'DATABLOCK'
# --- Empty DATABLOCK ---
result = dd(image['TEMPLATE/SIZE'], image['SOURCE'])
if !OpenNebula.is_error?(result)
result = mkfs(image['TEMPLATE/FSTYPE'], image['SOURCE'])
end
@ -49,21 +49,21 @@ module OpenNebula
# ------ Enable the Image ------
if !OpenNebula.is_error?(result)
if !OpenNebula.is_error?(result)
image.enable
else
image.delete
end
return result
end
def delete(image)
if image.nil?
error_msg = "Image could not be found, aborting."
result = OpenNebula::Error.new(error_msg)
end
result = image.info
if !OpenNebula.is_error?(result)
@ -75,32 +75,32 @@ module OpenNebula
result = remove(file_path)
end
end
return result
end
end
def update_source(image, source)
if image.nil?
error_msg = "Image could not be found, aborting."
result = OpenNebula::Error.new(error_msg)
end
result = image.info
if !OpenNebula.is_error?(result)
# Disable the Image for a safe overwriting
# image.disable
image.disable
result = move(source, image['SOURCE'])
# image.enable
image.enable
end
return result
end
private
FS_UTILS = {
:dd => "env dd",
:mkfs => "env mkfs"
@ -120,7 +120,7 @@ module OpenNebula
return nil
end
def move(path, source)
if source.nil? or path.nil?
return OpenNebula::Error.new("copy Image: missing parameters.")
@ -172,7 +172,7 @@ module OpenNebula
return nil
end
def remove(source)
if File.exists?(source)
begin
@ -181,7 +181,7 @@ module OpenNebula
return OpenNebula::Error.new(e.message)
end
end
return nil
end
end

View File

@ -904,6 +904,8 @@ error_common:
void VirtualMachine::release_disk_images()
{
string iid;
string saveas;
int saveas_id;
int num_disks;
vector<Attribute const * > disks;
@ -939,12 +941,49 @@ void VirtualMachine::release_disk_images()
continue;
}
if (img->release_image() == true)
img->release_image();
// -------------- DISABLE THIS IMAGE IF OVERWRITTEN --------------------
saveas = disk->vector_value("SAVE_AS");
saveas_id = -1;
if ( !saveas.empty() )
{
ipool->update(img);
if (saveas == id)
{
img->enable(false);
}
else
{
saveas_id = atoi(saveas.c_str())
}
}
// ----------------------- UPDATE IMAGE --------------------------------
ipool->update(img);
img->unlock();
// ------------------- DISABLE IMAGE TO BE SAVED -----------------------
if (saveas_id != -1)
{
img = ipool->get(saveas_id,true);
if ( img == 0 )
{
continue;
}
img->enable(false);
ipool->update(img);
img->unlock();
}
}
}