1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

feature #200: Public attribute moved to main image sql table.

This commit is contained in:
Carlos Martín 2010-06-07 16:21:58 +02:00 committed by Constantino Vázquez Blanco
parent 6580699fec
commit 9b8862eb4c
4 changed files with 54 additions and 11 deletions

View File

@ -287,6 +287,11 @@ private:
*/
ImageType type;
/**
* Public scope of the Image
*/
string public_img;
/**
* Registration time
*/
@ -370,12 +375,13 @@ protected:
UID = 1, /* Image owner id */
NAME = 2, /* Image name */
TYPE = 3, /* 0) OS 1) CDROM 2) DATABLOCK */
REGTIME = 4, /* Time of registration */
SOURCE = 5, /* Path to the image */
STATE = 6, /* 0) INIT 1) ALLOCATED */
PUBLIC = 4, /* Public scope (YES OR NO) */
REGTIME = 5, /* Time of registration */
SOURCE = 6, /* Path to the image */
STATE = 7, /* 0) INIT 1) ALLOCATED */
/* 2) READY 3) USED */
RUNNING_VMS = 7, /* Number of VMs using the img */
LIMIT = 8
RUNNING_VMS = 8, /* Number of VMs using the img */
LIMIT = 9
};
static const char * db_names;

View File

@ -156,6 +156,11 @@ private:
**/
string default_type;
/**
* Default public scope
**/
string default_public;
/**
* Default device prefix
**/

View File

@ -44,12 +44,12 @@ Image::~Image(){};
const char * Image::table = "image_pool";
const char * Image::db_names = "(oid, uid, name, type, regtime, "
const char * Image::db_names = "(oid, uid, name, type, public, regtime, "
"source, state, running_vms)";
const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool ("
"oid INTEGER PRIMARY KEY, uid INTEGER, name VARCHAR(128), "
"type INTEGER, regtime INTEGER, source TEXT, state INTEGER, "
"type INTEGER, public TEXT, regtime INTEGER, source TEXT, state INTEGER, "
"running_vms INTEGER, UNIQUE(name) )";
/* ------------------------------------------------------------------------ */
@ -61,6 +61,7 @@ int Image::select_cb(void * nil, int num, char **values, char ** names)
(!values[UID]) ||
(!values[NAME]) ||
(!values[TYPE]) ||
(!values[PUBLIC]) ||
(!values[REGTIME]) ||
(!values[SOURCE]) ||
(!values[STATE]) ||
@ -76,6 +77,7 @@ int Image::select_cb(void * nil, int num, char **values, char ** names)
name = values[NAME];
type = static_cast<ImageType>(atoi(values[TYPE]));
public_img = values[PUBLIC];
regtime = static_cast<time_t>(atoi(values[REGTIME]));
source = values[SOURCE];
@ -194,6 +196,7 @@ int Image::insert_replace(SqlDB *db, bool replace)
int rc;
char * sql_name;
char * sql_public;
char * sql_source;
// Update the Image
@ -205,6 +208,12 @@ int Image::insert_replace(SqlDB *db, bool replace)
goto error_name;
}
sql_public = db->escape_str(public_img.c_str());
if ( sql_public == 0 )
{
goto error_public;
}
sql_source = db->escape_str(source.c_str());
@ -229,6 +238,7 @@ int Image::insert_replace(SqlDB *db, bool replace)
<< uid << ","
<< "'" << sql_name << "',"
<< type << ","
<< "'" << sql_public << "',"
<< regtime << ","
<< "'" << sql_source << "',"
<< state << ","
@ -237,11 +247,14 @@ int Image::insert_replace(SqlDB *db, bool replace)
rc = db->exec(oss);
db->free_str(sql_name);
db->free_str(sql_public);
db->free_str(sql_source);
return rc;
error_source:
db->free_str(sql_public);
error_public:
db->free_str(sql_name);
error_name:
return -1;
@ -256,6 +269,7 @@ int Image::dump(ostringstream& oss, int num, char **values, char **names)
(!values[UID]) ||
(!values[NAME]) ||
(!values[TYPE]) ||
(!values[PUBLIC]) ||
(!values[REGTIME]) ||
(!values[SOURCE]) ||
(!values[STATE]) ||
@ -271,6 +285,7 @@ int Image::dump(ostringstream& oss, int num, char **values, char **names)
"<UID>" << values[UID] << "</UID>" <<
"<NAME>" << values[NAME] << "</NAME>" <<
"<TYPE>" << values[TYPE] << "</TYPE>" <<
"<PUBLIC>" << values[PUBLIC] << "</PUBLIC>" <<
"<REGTIME>" << values[REGTIME] << "</REGTIME>" <<
"<SOURCE>" << values[SOURCE] << "</SOURCE>" <<
"<STATE>" << values[STATE] << "</STATE>" <<
@ -333,6 +348,7 @@ string& Image::to_xml(string& xml) const
"<UID>" << uid << "</UID>" <<
"<NAME>" << name << "</NAME>" <<
"<TYPE>" << type << "</TYPE>" <<
"<PUBLIC>" << public_img << "</PUBLIC>" <<
"<REGTIME>" << regtime << "</REGTIME>" <<
"<SOURCE>" << source << "</SOURCE>" <<
"<STATE>" << state << "</STATE>" <<
@ -359,6 +375,7 @@ string& Image::to_str(string& str) const
"UID = " << uid << endl <<
"NAME = " << name << endl <<
"TYPE = " << type << endl <<
"PUBLIC = " << public_img << endl <<
"REGTIME = " << regtime << endl <<
"SOURCE = " << source << endl <<
"STATE = " << state << endl <<

View File

@ -67,6 +67,8 @@ ImagePool::ImagePool( SqlDB * db,
default_type = _default_type;
}
default_public = "NO";
// Read from the DB the existing images, and build the ID:Name map
set_callback(static_cast<Callbackable::Callback>(&ImagePool::init_cb));
@ -93,6 +95,7 @@ int ImagePool::allocate (
string name = "";
string source = "";
string type = "";
string public_attr = "";
string original_path = "";
string dev_prefix = "";
@ -142,6 +145,17 @@ int ImagePool::allocate (
img->image_template.erase("TYPE");
}
img->get_template_attribute("PUBLIC", public_attr);
if ( public_attr.empty() == true )
{
public_attr = default_public;
}
else
{
img->image_template.erase("PUBLIC");
}
img->get_template_attribute("ORIGINAL_PATH", original_path);
if ( (type == "OS" || type == "CDROM") &&
@ -175,6 +189,7 @@ int ImagePool::allocate (
img->name = name;
img->source = tmp_sourcestream.str();
img->public_img = public_attr;
if (img->set_type(type) != 0)
{