Merge branch 'bug-868'

This commit is contained in:
Ruben S. Montero committed 2011-10-27 01:43:28 +02:00
commit 76243c5ea8
14 files changed
+208 -49

No files matched your search

+5 -25
View File
@@ -156,32 +156,12 @@ public:
}
/**
* Set enum type
* @return 0 on success, -1 otherwise
* Sets the Image type.
*
* @param _type the new type. It will be transformed to upper case
* @return 0 on success, -1 otherwise
*/
int set_type(const string& _type)
{
int rc = 0;
if ( _type == "OS" )
{
type = OS;
}
else if ( _type == "CDROM" )
{
type = CDROM;
}
else if ( _type == "DATABLOCK" )
{
type = DATABLOCK;
}
else
{
rc = -1;
}
return rc;
}
int set_type(string& _type);
/**
* Publish or unpublish an image
+24 -4
View File
@@ -30,8 +30,9 @@ class RequestManagerImage: public Request
{
protected:
RequestManagerImage(const string& method_name,
const string& help)
:Request(method_name,"A:sib",help)
const string& help,
const string& params)
:Request(method_name,params,help)
{
Nebula& nd = Nebula::instance();
pool = nd.get_ipool();
@@ -55,7 +56,8 @@ class ImageEnable : public RequestManagerImage
{
public:
ImageEnable():
RequestManagerImage("ImageEnable", "Enables or disables an image"){};
RequestManagerImage("ImageEnable", "Enables or disables an image",
"A:sib"){};
~ImageEnable(){};
@@ -71,7 +73,8 @@ class ImagePersistent : public RequestManagerImage
public:
ImagePersistent():
RequestManagerImage("ImagePersistent",
"Makes an image persistent or non-persistent"){};
"Makes an image persistent or non-persistent",
"A:sib"){};
~ImagePersistent(){};
@@ -79,6 +82,23 @@ public:
RequestAttributes& att);
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ImageChangeType : public RequestManagerImage
{
public:
ImageChangeType():
RequestManagerImage("ImageChangeType",
"Changes the type of an image",
"A:sis"){};
~ImageChangeType(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
+10
View File
@@ -159,6 +159,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
end
chtype_desc = <<-EOT.unindent
Changes the Image group
EOT
command :chtype, chtype_desc,[:range, :imageid_list], :type do
helper.perform_actions(args[0],options,"Type changed") do |image|
image.chtype(args[1])
end
end
disable_desc = <<-EOT.unindent
Disables the given Image
EOT
+13 -2
View File
@@ -36,6 +36,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
helper = OneVMHelper.new
TYPE={
:name => "type",
:short => "-t type",
:large => "--type type",
:format => String,
:description => "Type of the new Image"
}
########################################################################
# Global Options
########################################################################
@@ -142,14 +151,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
States: ANY
EOT
command :saveas, saveas_desc, :vmid, :diskid, :img_name do
command :saveas, saveas_desc, :vmid, :diskid, :img_name, :options=>[TYPE] do
disk_id = args[1].to_i
image_name = args[2]
image_type = options[:type] || ""
verbose = "disk #{disk_id} prepared to be saved in " <<
"the image #{image_name}"
helper.perform_action(args[0],options,verbose) do |vm|
res = vm.save_as(disk_id, image_name)
res = vm.save_as(disk_id, image_name, image_type)
if !OpenNebula.is_error?(res)
puts "Image ID: #{res}"
+29 -2
View File
@@ -103,8 +103,6 @@ int Image::insert(SqlDB *db, string& error_str)
get_template_attribute("TYPE", type_att);
TO_UPPER(type_att);
if ( type_att.empty() == true )
{
type_att = ImagePool::default_type();
@@ -524,3 +522,32 @@ int Image::disk_attribute( VectorAttribute * disk,
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Image::set_type(string& _type)
{
int rc = 0;
TO_UPPER(_type);
if ( _type == "OS" )
{
type = OS;
}
else if ( _type == "CDROM" )
{
type = CDROM;
}
else if ( _type == "DATABLOCK" )
{
type = DATABLOCK;
}
else
{
rc = -1;
}
return rc;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
@@ -35,6 +35,7 @@ public class Image extends PoolElement
private static final String ENABLE = METHOD_PREFIX + "enable";
private static final String PUBLISH = METHOD_PREFIX + "publish";
private static final String CHOWN = METHOD_PREFIX + "chown";
private static final String CHTYPE = METHOD_PREFIX + "chtype";
private static final String[] IMAGE_STATES =
{"INIT", "READY", "USED", "DISABLED"};
@@ -162,6 +163,19 @@ public class Image extends PoolElement
return client.call(CHOWN, id, uid, gid);
}
/**
* Changes the Image type
*
* @param client XML-RPC Client.
* @param id The image id of the target image we want to modify.
* @param type The new Image type
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse chtype(Client client, int id, String type)
{
return client.call(CHTYPE, id, type);
}
// =================================
// Instanced object XML-RPC methods
// =================================
@@ -296,6 +310,17 @@ public class Image extends PoolElement
return chown(-1, gid);
}
/**
* Changes the Image type
*
* @param type The new Image type
* @return If an error occurs the error message contains the reason.
*/
public OneResponse chtype(String type)
{
return chtype(client, id, type);
}
// =================================
// Helpers
// =================================
@@ -292,7 +292,22 @@ public class VirtualMachine extends PoolElement{
*/
public OneResponse savedisk(int diskId, String imageName)
{
return client.call(SAVEDISK, id ,diskId, imageName);
return savedisk(diskId, imageName, "");
}
/**
* Sets the specified vm's disk to be saved in a new image when the
* VirtualMachine shutdowns.
*
* @param diskId ID of the disk to be saved.
* @param imageName Name of the new Image that will be created.
* @param imageType Type of the new image. Set to empty string to use
* the default type
* @return If an error occurs the error message contains the reason.
*/
public OneResponse savedisk(int diskId, String imageName, String imageType)
{
return client.call(SAVEDISK, id ,diskId, imageName, imageType);
}
/**
+15 -1
View File
@@ -33,7 +33,8 @@ module OpenNebula
:publish => "image.publish",
:persistent => "image.persistent",
:delete => "image.delete",
:chown => "image.chown"
:chown => "image.chown",
:chtype => "image.chtype"
}
IMAGE_STATES=%w{INIT READY USED DISABLED LOCKED ERROR}
@@ -145,6 +146,19 @@ module OpenNebula
super(IMAGE_METHODS[:chown], uid, gid)
end
# Changes the Image type
# @param type [String] new Image type
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def chtype(type)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(IMAGE_METHODS[:chtype], @pe_id, type)
rc = nil if !OpenNebula.is_error?(rc)
return rc
end
#######################################################################
# Helpers to get Image information
#######################################################################
+8 -2
View File
@@ -217,13 +217,19 @@ module OpenNebula
# @param disk_id [Integer] ID of the disk to be saved
# @param image_name [String] Name for the new image where the
# disk will be saved
# @param image_type [String] Type of the new image. Set to empty string
# to use the default type
#
# @return [Integer, OpenNebula::Error] the new Image ID in case of
# success, error otherwise
def save_as(disk_id, image_name)
def save_as(disk_id, image_name, image_type="")
return Error.new('ID not defined') if !@pe_id
rc = @client.call(VM_METHODS[:savedisk], @pe_id, disk_id, image_name)
rc = @client.call(VM_METHODS[:savedisk],
@pe_id,
disk_id,
image_name,
image_type)
return rc
end
+2
View File
@@ -264,6 +264,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr template_publish(new TemplatePublish());
xmlrpc_c::methodPtr vn_publish(new VirtualNetworkPublish());
xmlrpc_c::methodPtr image_publish(new ImagePublish());
xmlrpc_c::methodPtr image_chtype(new ImageChangeType());
// Delete Methods
xmlrpc_c::methodPtr host_delete(new HostDelete());
@@ -383,6 +384,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.image.delete", image_delete);
RequestManagerRegistry.addMethod("one.image.info", image_info);
RequestManagerRegistry.addMethod("one.image.chown", image_chown);
RequestManagerRegistry.addMethod("one.image.chtype", image_chtype);
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
+48
View File
@@ -112,3 +112,51 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList,
success_response(id, att);
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
int id = xmlrpc_c::value_int(paramList.getInt(1));
string type = xmlrpc_c::value_string(paramList.getString(2));
int rc;
Image * image;
string err_msg;
if ( basic_authorization(id, att) == false )
{
return;
}
image = static_cast<Image *>(pool->get(id,true));
if ( image == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(auth_object),id),
att);
return;
}
rc = image->set_type(type);
if ( rc != 0 )
{
err_msg = "Unknown type " + type;
failure_response(INTERNAL,request_error(err_msg,""), att);
image->unlock();
return;
}
pool->update(image);
image->unlock();
success_response(id, att);
}
+6
View File
@@ -394,6 +394,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
int id = xmlrpc_c::value_int(paramList.getInt(1));
int disk_id = xmlrpc_c::value_int(paramList.getInt(2));
string img_name = xmlrpc_c::value_string(paramList.getString(3));
string img_type = xmlrpc_c::value_string(paramList.getString(4));
VirtualMachine * vm;
string vm_owner;
@@ -412,6 +413,11 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
oss << "PUBLIC = NO " << endl;
oss << "SOURCE = - " << endl;
if ( img_type != "" )
{
oss << "TYPE = " << img_type << endl;
}
itemplate = new ImageTemplate;
itemplate->parse(oss.str(), &error_char);
@@ -88,7 +88,7 @@ module OpenNebulaJSON
end
def save_as(params=Hash.new)
super(params['disk_id'].to_i, params['image_name'])
super(params['disk_id'].to_i, params['image_name'], params['type'])
end
def chown(params=Hash.new)
+6 -11
View File
@@ -812,7 +812,7 @@ function setupSaveasDialog(){
var id = $('#vm_id',this).text();
var disk_id = $('#vm_disk_id',this).val();
var image_name = $('#image_name',this).val();
//var type = $('#image_type',this).val();
var type = $('#image_type',this).val();
if (!id.length || !disk_id.length || !image_name.length) {
notifyError("Skipping VM "+id+
@@ -821,8 +821,8 @@ function setupSaveasDialog(){
else {
var obj = {
disk_id : disk_id,
image_name : image_name
//type: type
image_name : image_name,
type: type
};
args.push(id);
Sunstone.runAction("VM.saveas",id,obj);
@@ -865,20 +865,15 @@ function popUpSaveasDialog(elems){
<label for="image_name">Image name:</label>\
<input type="text" id="image_name" name="image_name" value="" />\
</div>\
<!-- not used anymore\
<div>\
<label for="img_attr_value">Type:</label>\
<select id="image_type" name="image_type">\
<option value="">Default</option>\
<option value="disk">Disk</option>\
<option value="floppy">Floppy</option>\
<option value="">Default (current image type)</option>\
<option value="os">OS</option>\
<option value="datablock">Datablock</option>\
<option value="cdrom">CD-ROM</option>\
<option value="swap">Swap</option>\
<option value="fs">FS</option>\
<option value="block">Block</option>\
</select>\
</div>\
-->\
</fieldset>\
</div>';
$('#saveas_tabs',dialog).append(tab);