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

feature #3987: Allow RBD DISK_TYPE for System DS. Generate KVM

deployment files for RBD volatile disks
This commit is contained in:
Ruben S. Montero 2015-10-29 16:55:53 +01:00
parent d52f54ad19
commit b15594e759
3 changed files with 130 additions and 68 deletions

View File

@ -305,6 +305,18 @@ private:
virtual ~Datastore();
/**
* Sets the DISK_TYPE attribute for the datastore. This function will
* check the type against the supported DiskTypes for each datastore type
* (SYSTEM, IMAGE and FILE).
* @param s_dt DISK_TYPE in string form. If empty Image::FILE will be used
* @param error description if any. The string is upcased
*
* @return -1 if an inconsistent assigment is found
*
*/
int set_ds_disk_type(string& s_dt, string& error);
// *************************************************************************
// DataBase implementation (Private)
// *************************************************************************

View File

@ -50,6 +50,7 @@ Datastore::Datastore(
tm_mad(""),
base_path(""),
type(IMAGE_DS),
disk_type(Image::FILE),
total_mb(0),
free_mb(0),
used_mb(0),
@ -149,10 +150,9 @@ void Datastore::disk_attribute(
}
}
//Initialize TYPE for volatile disks
if (disk->vector_value("TYPE").empty())
if (VirtualMachine::is_volatile(disk))
{
disk->replace("TYPE", Image::disk_type_to_str(get_disk_type()));
disk->replace("DISK_TYPE", Image::disk_type_to_str(get_disk_type()));
}
}
@ -299,6 +299,90 @@ error:
return -1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Datastore::set_ds_disk_type(string& s_dt, string& error)
{
if (s_dt.empty())
{
disk_type = Image::FILE;
}
else
{
disk_type = Image::str_to_disk_type(s_dt);
}
switch(type)
{
case IMAGE_DS:
switch(disk_type)
{
//Valid disk types for Image DS
case Image::FILE:
case Image::BLOCK:
case Image::RBD:
case Image::GLUSTER:
case Image::SHEEPDOG:
break;
case Image::CD_ROM:
case Image::RBD_CDROM:
case Image::SHEEPDOG_CDROM:
case Image::GLUSTER_CDROM:
error = "Invalid DISK_TYPE for an Image Datastore.";
return -1;
case Image::NONE:
error = "Unknown DISK_TYPE in template.";
return -1;
}
break;
case SYSTEM_DS:
switch(disk_type)
{
//Valid disk types for System DS
case Image::FILE:
case Image::RBD:
break;
case Image::GLUSTER:
case Image::SHEEPDOG:
case Image::BLOCK:
case Image::CD_ROM:
case Image::RBD_CDROM:
case Image::SHEEPDOG_CDROM:
case Image::GLUSTER_CDROM:
error = "Invalid DISK_TYPE for a System Datastore.";
return -1;
case Image::NONE:
error = "Unknown DISK_TYPE in template.";
return -1;
}
break;
case FILE_DS:
disk_type = Image::FILE;
break;
}
switch(type)
{
case IMAGE_DS:
case SYSTEM_DS:
add_template_attribute("DISK_TYPE", Image::disk_type_to_str(disk_type));
break;
case FILE_DS:
break;
}
return 0;
}
/* -------------------------------------------------------------------------- */
int Datastore::insert(SqlDB *db, string& error_str)
{
int rc;
@ -365,36 +449,16 @@ int Datastore::insert(SqlDB *db, string& error_str)
erase_template_attribute("DISK_TYPE", s_disk_type);
disk_type = Image::FILE;
if ( type == IMAGE_DS )
if (set_ds_disk_type(s_disk_type, error_str) == -1)
{
if (!s_disk_type.empty())
{
disk_type = Image::str_to_disk_type(s_disk_type);
switch(disk_type)
{
case Image::NONE:
goto error_disk_type;
break;
case Image::RBD_CDROM:
case Image::SHEEPDOG_CDROM:
case Image::GLUSTER_CDROM:
goto error_invalid_disk_type;
break;
default:
break;
}
}
add_template_attribute("DISK_TYPE", Image::disk_type_to_str(disk_type));
goto error_common;
}
if ( tm_mad.empty() == true )
{
goto error_empty_tm;
}
//--------------------------------------------------------------------------
// Insert the Datastore
//--------------------------------------------------------------------------
@ -415,14 +479,6 @@ error_empty_tm:
error_str = "No TM_MAD in template.";
goto error_common;
error_disk_type:
error_str = "Unknown DISK_TYPE in template.";
goto error_common;
error_invalid_disk_type:
error_str = "Invalid DISK_TYPE in template.";
goto error_common;
error_common:
NebulaLog::log("DATASTORE", Log::ERROR, error_str);
return -1;
@ -638,14 +694,14 @@ int Datastore::post_update_template(string& error_str)
string new_ds_mad;
string new_tm_mad;
string s_ds_type;
string new_disk_type_st;
string new_disk_type;
string new_base_path;
Image::DiskType new_disk_type;
DatastoreType old_ds_type;
DatastoreType new_ds_type;
DatastoreType old_ds_type = type;
Image::DiskType old_disk_type = disk_type;
/* ---------------------------------------------------------------------- */
/* Set the TYPE of the Datastore (class & template) */
/* ---------------------------------------------------------------------- */
@ -678,6 +734,24 @@ int Datastore::post_update_template(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 (!new_disk_type.empty())
{
if ( set_ds_disk_type(new_disk_type, error_str) == -1 )
{
//Rollback variable changes
type = old_ds_type;
disk_type = old_disk_type;
return -1;
}
}
/* ---------------------------------------------------------------------- */
/* Set the TM_MAD of the Datastore (class & template) */
/* ---------------------------------------------------------------------- */
@ -694,7 +768,8 @@ int Datastore::post_update_template(string& error_str)
if (set_tm_mad(new_tm_mad, error_str) != 0)
{
type = old_ds_type;
type = old_ds_type;
disk_type = old_disk_type;
return -1;
}
@ -706,31 +781,6 @@ int Datastore::post_update_template(string& error_str)
replace_template_attribute("TM_MAD", tm_mad);
}
/* ---------------------------------------------------------------------- */
/* Set the DISK_TYPE (class & template) */
/* ---------------------------------------------------------------------- */
erase_template_attribute("DISK_TYPE", new_disk_type_st);
if ( type == IMAGE_DS )
{
if (!new_disk_type_st.empty())
{
new_disk_type = Image::str_to_disk_type(new_disk_type_st);
if (new_disk_type != Image::NONE)
{
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

@ -113,6 +113,7 @@ int LibVirtDriver::deployment_description_kvm(
const VectorAttribute * context;
string type = "";
string disk_type = "";
string target = "";
string bus = "";
string ro = "";
@ -438,6 +439,7 @@ int LibVirtDriver::deployment_description_kvm(
}
type = disk->vector_value("TYPE");
disk_type = disk->vector_value("DISK_TYPE");
target = disk->vector_value("TARGET");
ro = disk->vector_value("READONLY");
driver = disk->vector_value("DRIVER");
@ -513,17 +515,15 @@ int LibVirtDriver::deployment_description_kvm(
// ---- Disk type and source for the image ----
one_util::toupper(type);
if ( type == "BLOCK" )
{
file << "\t\t<disk type='block' device='disk'>" << endl
<< "\t\t\t<source dev='" << vm->get_remote_system_dir()
<< "/disk." << disk_id << "'/>" << endl;
}
else if ( type == "RBD" || type == "RBD_CDROM" )
else if ( type == "RBD" || type == "RBD_CDROM" || disk_type == "RBD" )
{
if (type == "RBD")
if (type == "RBD" || disk_type == "RBD")
{
file << "\t\t<disk type='network' device='disk'>" << endl;
}