1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-24 21:34:01 +03:00

Bug #2353 #2354: disk_type is not removed from template, is processed in update, and is case insensitive

This commit is contained in:
Carlos Martín 2013-10-02 16:21:46 +02:00
parent 6d447c0831
commit ff384e6b01
3 changed files with 58 additions and 13 deletions

View File

@ -98,6 +98,13 @@ public:
}
};
/**
* Return the string representation of a DiskType
* @param s_disk_type string representing the DiskTypr
* @return the DiskType (defaults to FILE)
*/
static DiskType str_to_disk_type(string& s_disk_type);
/**
* Image State
*/

View File

@ -174,22 +174,13 @@ int Datastore::insert(SqlDB *db, string& error_str)
disk_type = Image::FILE;
erase_template_attribute("DISK_TYPE", s_disk_type);
if ( type == IMAGE_DS )
{
erase_template_attribute("DISK_TYPE", s_disk_type);
disk_type = Image::str_to_disk_type(s_disk_type);
if (s_disk_type == "BLOCK")
{
disk_type = Image::BLOCK;
}
else if (s_disk_type == "CDROM")
{
disk_type = Image::CD_ROM;
}
else if (s_disk_type == "RBD")
{
disk_type = Image::RBD;
}
add_template_attribute("DISK_TYPE", Image::disk_type_to_str(disk_type));
}
if ( tm_mad.empty() == true )
@ -427,6 +418,7 @@ int Datastore::replace_template(const string& tmpl_str, string& error_str)
string new_ds_mad;
string new_tm_mad;
string s_ds_type;
string new_disk_type;
DatastoreType new_ds_type;
Template * new_tmpl = new DatastoreTemplate;
@ -501,6 +493,26 @@ int Datastore::replace_template(const string& tmpl_str, string& error_str)
replace_template_attribute("TYPE", type_to_str(type));
/* ---------------------------------------------------------------------- */
/* Set the DISK_TYPE (class & template) */
/* ---------------------------------------------------------------------- */
erase_template_attribute("DISK_TYPE", new_disk_type);
if ( type == IMAGE_DS )
{
if (!new_disk_type.empty())
{
disk_type = Image::str_to_disk_type(new_disk_type);
}
add_template_attribute("DISK_TYPE", Image::disk_type_to_str(disk_type));
}
else
{
disk_type = Image::FILE;
}
/* ---------------------------------------------------------------------- */
/* Set the DS_MAD of the Datastore (class & template) */
/* ---------------------------------------------------------------------- */

View File

@ -27,6 +27,7 @@
#include "AuthManager.h"
#include "UserPool.h"
#include "NebulaUtil.h"
#define TO_UPPER(S) transform(S.begin(),S.end(),S.begin(),(int(*)(int))toupper)
@ -705,3 +706,28 @@ Image::ImageType Image::str_to_type(string& str_type)
return it;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
Image::DiskType Image::str_to_disk_type(string& s_disk_type)
{
Image::DiskType type = FILE;
one_util::toupper(s_disk_type);
if (s_disk_type == "BLOCK")
{
type = Image::BLOCK;
}
else if (s_disk_type == "CDROM")
{
type = Image::CD_ROM;
}
else if (s_disk_type == "RBD")
{
type = Image::RBD;
}
return type;
}