mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-26 06:50:09 +03:00
feature #200: Images can now modify a DISK attribute vector to include correct BUS and TARGET.
This commit is contained in:
parent
d2dea176cb
commit
c16631873f
@ -55,22 +55,22 @@ public:
|
||||
friend ostream& operator<<(ostream& os, Image& i);
|
||||
|
||||
// *************************************************************************
|
||||
// Virtual Network Public Methods
|
||||
// Image Public Methods
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Function to print the Image object into a string in plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
/**
|
||||
* Function to print the Image object into a string in plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
|
||||
/**
|
||||
* Function to print the Image object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
/**
|
||||
* Function to print the Image object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
/**
|
||||
* Get the Image unique identifier IID, that matches the OID of the object
|
||||
@ -98,7 +98,7 @@ public:
|
||||
{
|
||||
return name;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set enum type
|
||||
* @return 0 on success, -1 otherwise
|
||||
@ -133,13 +133,25 @@ public:
|
||||
* @return boolean true if the image can be used
|
||||
*/
|
||||
bool get_image(bool overwrite);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Releases an image being used by a VM
|
||||
*/
|
||||
void release_image();
|
||||
|
||||
|
||||
/**
|
||||
* Modifies the given disk attribute to set the target value.
|
||||
* * OS images will be mounted at prefix + a: hda, sda.
|
||||
* * Prefix + b is reserved for the contex cdrom.
|
||||
* * CDROM images will be at prefix + c: hdc, sdc.
|
||||
* * Several DATABLOCK images can be mounted, they will be set to
|
||||
* prefix + (d + index) : hdd, hde, hdf...
|
||||
* returns: 0 if the disk was not modified
|
||||
* 1 if the disk was modified correctly
|
||||
* -1 in case of error
|
||||
*/
|
||||
int get_disk_attribute(VectorAttribute * disk, int index);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Template
|
||||
|
@ -36,38 +36,27 @@ class ImagePool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
ImagePool(SqlDB * db,
|
||||
ImagePool(SqlDB * db,
|
||||
const string& _source_prefix,
|
||||
const string& _default_type,
|
||||
const string& _default_bus):
|
||||
const string& _default_dev_prefix):
|
||||
PoolSQL(db,Image::table),
|
||||
source_prefix(_source_prefix)
|
||||
{
|
||||
if (_default_type != "OS" ||
|
||||
_default_type != "CDROM" ||
|
||||
_default_type != "DATABLOCK")
|
||||
{
|
||||
NebulaLog::log("IMG", Log::ERROR,
|
||||
"Bad default for image type, setting OS");
|
||||
default_type = "OS";
|
||||
}
|
||||
else
|
||||
{
|
||||
default_type = _default_type;
|
||||
}
|
||||
|
||||
if (_default_bus != "IDE" ||
|
||||
_default_bus != "SCSI")
|
||||
{
|
||||
NebulaLog::log("IMG", Log::ERROR,
|
||||
"Bad default for bus type, setting IDE");
|
||||
default_bus = "IDE";
|
||||
}
|
||||
else
|
||||
{
|
||||
default_bus = _default_bus;
|
||||
}
|
||||
};
|
||||
source_prefix(_source_prefix),
|
||||
default_dev_prefix(_default_dev_prefix)
|
||||
{
|
||||
if (_default_type != "OS" ||
|
||||
_default_type != "CDROM" ||
|
||||
_default_type != "DATABLOCK")
|
||||
{
|
||||
NebulaLog::log("IMG", Log::ERROR,
|
||||
"Bad default for image type, setting OS");
|
||||
default_type = "OS";
|
||||
}
|
||||
else
|
||||
{
|
||||
default_type = _default_type;
|
||||
}
|
||||
};
|
||||
|
||||
~ImagePool(){};
|
||||
|
||||
@ -179,9 +168,9 @@ private:
|
||||
string default_type;
|
||||
|
||||
/**
|
||||
* Default bus type
|
||||
* Default device prefix
|
||||
**/
|
||||
string default_bus;
|
||||
string default_dev_prefix;
|
||||
|
||||
/**
|
||||
* Factory method to produce Image objects
|
||||
|
@ -363,7 +363,7 @@ string& Image::to_str(string& str) const
|
||||
"SOURCE = " << source << endl <<
|
||||
"STATE = " << state << endl <<
|
||||
"RUNNING_VMS = " << running_vms << endl <<
|
||||
"TEMPLATE" << endl
|
||||
"TEMPLATE" << endl
|
||||
<< image_template.to_str(template_str)
|
||||
<< endl;
|
||||
|
||||
@ -400,6 +400,7 @@ bool Image::get_image(bool overwrite)
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
// TODO update?
|
||||
void Image::release_image()
|
||||
{
|
||||
@ -410,3 +411,72 @@ void Image::release_image()
|
||||
state = READY;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Image::get_disk_attribute(VectorAttribute * disk, int index)
|
||||
{
|
||||
string target = "";
|
||||
string bus = "";
|
||||
|
||||
// The BUS attribute isn't mandatory.
|
||||
|
||||
get_template_attribute("BUS", bus);
|
||||
|
||||
if( !bus.empty() ) // If the image has a BUS defined ...
|
||||
{
|
||||
string disk_bus = disk->vector_value("BUS");
|
||||
|
||||
if( disk_bus.empty() ) // ... and the disk doesn't have already one
|
||||
{
|
||||
disk->replace("BUS", bus);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If the disk has already a user-defined target, then it will be used.
|
||||
// First, check if it exists.
|
||||
target = disk->vector_value("TARGET");
|
||||
|
||||
|
||||
if ( target.empty() )
|
||||
{
|
||||
// Generate the target from the image's prefix and type
|
||||
|
||||
get_template_attribute("DEV_PREFIX", target);
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case OS:
|
||||
target += "a";
|
||||
break;
|
||||
case CDROM:
|
||||
target += "c";
|
||||
break;
|
||||
case DATABLOCK:
|
||||
// Multiple datablocks can be defined, and they are mounted as
|
||||
// sdd, sde, sdf...
|
||||
|
||||
if( index < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
char letter = ('d' + index);
|
||||
target += letter;
|
||||
break;
|
||||
};
|
||||
|
||||
// "Replace" inserts the name-value pair even if it doesn't exist.
|
||||
disk->replace("TARGET", target);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
|
@ -32,6 +32,7 @@ int ImagePool::allocate (
|
||||
string source = "";
|
||||
string type = "";
|
||||
string original_path = "";
|
||||
string dev_prefix = "";
|
||||
|
||||
ostringstream tmp_hashstream;
|
||||
ostringstream tmp_sourcestream;
|
||||
@ -113,6 +114,19 @@ int ImagePool::allocate (
|
||||
goto error_original_path;
|
||||
}
|
||||
|
||||
// DEV_PREFIX template attribute must exist for every image, if it
|
||||
// isn't present it will be set to the default value.
|
||||
|
||||
img->get_template_attribute("DEV_PREFIX", dev_prefix);
|
||||
|
||||
if( dev_prefix.empty() )
|
||||
{
|
||||
SingleAttribute * dev_att =
|
||||
new SingleAttribute("DEV_PREFIX", default_dev_prefix);
|
||||
|
||||
img->image_template.set(dev_att);
|
||||
}
|
||||
|
||||
|
||||
img->running_vms = 0;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user