1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-15 23:24:09 +03:00

Merge branch 'feature-200' of dsa-research.org:one into feature-200

This commit is contained in:
Tino Vázquez 2010-06-24 19:29:12 +02:00
commit fb22839839
3 changed files with 40 additions and 79 deletions

View File

@ -35,7 +35,8 @@ Image::Image(int _uid):
type(OS),
regtime(time(0)),
source(""),
state(INIT)
state(INIT),
running_vms(0)
{};
Image::~Image(){};

View File

@ -47,6 +47,7 @@ ImagePool::ImagePool( SqlDB * db,
PoolSQL(db,Image::table),
source_prefix(_source_prefix),
default_type(_default_type),
default_dev_prefix(_default_dev_prefix)
{
ostringstream sql;
@ -61,11 +62,6 @@ ImagePool::ImagePool( SqlDB * db,
"Bad default for image type, setting OS");
default_type = "OS";
}
else
{
default_type = _default_type;
}
// Read from the DB the existing images, and build the ID:Name map
set_callback(static_cast<Callbackable::Callback>(&ImagePool::init_cb));
@ -92,19 +88,17 @@ int ImagePool::allocate (
int * oid)
{
Image * img;
string name = "";
string source = "";
string type = "";
string public_attr = "";
string original_path = "";
string dev_prefix = "";
ostringstream tmp_hashstream;
ostringstream tmp_sourcestream;
string name;
string source;
string type;
string public_attr;
string dev_prefix;
char * error_msg;
int rc;
ostringstream tmp_hashstream;
ostringstream tmp_sourcestream;
// ---------------------------------------------------------------------
// Build a new Image object
@ -124,6 +118,9 @@ int ImagePool::allocate (
// ---------------------------------------------------------------------
// Check default image attributes
// ---------------------------------------------------------------------
// ------------ NAME --------------------
img->get_template_attribute("NAME", name);
if ( name.empty() == true )
@ -131,8 +128,9 @@ int ImagePool::allocate (
goto error_name;
}
img->image_template.erase("NAME");
img->name = name;
// ------------ TYPE --------------------
img->get_template_attribute("TYPE", type);
@ -140,25 +138,21 @@ int ImagePool::allocate (
{
type = default_type;
}
else
if (img->set_type(type) != 0)
{
img->image_template.erase("TYPE");
goto error_type;
}
// ------------ PUBLIC --------------------
img->get_template_attribute("PUBLIC", public_attr);
IMAGE_TO_UPPER( public_attr );
img->image_template.erase("PUBLIC");
img->get_template_attribute("ORIGINAL_PATH", original_path);
IMAGE_TO_UPPER(public_attr);
if ( (type == "OS" || type == "CDROM") &&
original_path.empty() == true )
{
goto error_original_path;
}
img->public_img = (public_attr == "YES");
// DEV_PREFIX template attribute must exist for every image, if it
// isn't present it will be set to the default value.
// ------------ PREFIX --------------------
img->get_template_attribute("DEV_PREFIX", dev_prefix);
@ -170,26 +164,14 @@ int ImagePool::allocate (
img->image_template.set(dev_att);
}
// ------------ SOURCE (path to store the image)--------------------
img->running_vms = 0;
// Generate path to store the image
tmp_hashstream << uid << ":" << name;
tmp_sourcestream << source_prefix << "/";
tmp_sourcestream << sha1_digest(tmp_hashstream.str());
img->name = name;
img->source = tmp_sourcestream.str();
img->public_img = (public_attr == "YES");
if (img->set_type(type) != 0)
{
goto error_type;
}
img->source = tmp_sourcestream.str();
// ---------------------------------------------------------------------
// Insert the Object in the pool
@ -202,7 +184,10 @@ int ImagePool::allocate (
return -1;
}
// ---------------------------------------------------------------------
// Add the image name to the map of image_names
// ---------------------------------------------------------------------
image_names.insert(make_pair(name, *oid));
return *oid;
@ -213,10 +198,6 @@ error_name:
error_type:
NebulaLog::log("IMG", Log::ERROR, "Incorrect TYPE in image template");
goto error_common;
error_original_path:
NebulaLog::log("IMG", Log::ERROR,
"ORIGINAL_PATH compulsory and not present in image template of this type.");
goto error_common;
error_common:
delete img;
*oid = -1;
@ -305,4 +286,3 @@ string ImagePool::sha1_digest(const string& pass)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -186,11 +186,9 @@ public:
CPPUNIT_ASSERT( img != 0 );
// Image object should be cached. Let's change some template attributes
img->update_template_attribute(db, description_name, new_description);
img->update_template_attribute(db, attr_name, new_attr_value);
img->remove_template_attribute(db, "ORIGINAL_PATH");
pool->update(img);
ip->replace_attribute(img, description_name, new_description);
ip->replace_attribute(img, attr_name, new_attr_value);
ip->remove_attribute(img, "ORIGINAL_PATH");
img->unlock();
@ -398,27 +396,13 @@ public:
oid = allocate(0);
img = imp->get(oid, false);
img->get_disk_attribute(disk, 0);
img->disk_attribute(&disk, 0);
value = disk->vector_value("TARGET");
CPPUNIT_ASSERT( value == "hda" );
// clean up
delete disk;
value = "";
// This time, set a target for this disk
disk = new VectorAttribute("DISK");
disk->replace("TARGET", "sdw");
img->get_disk_attribute(disk, 0);
value = disk->vector_value("TARGET");
CPPUNIT_ASSERT(value == "sdw");
// clean up
delete disk;
value = "";
@ -433,13 +417,11 @@ public:
img = imp->get(oid, false);
img->get_disk_attribute(disk, 0);
img->disk_attribute(&disk, 0);
value = disk->vector_value("TARGET");
CPPUNIT_ASSERT(value == "hdc");
// clean up
delete disk;
value = "";
@ -454,12 +436,11 @@ public:
img = imp->get(oid, false);
img->get_disk_attribute(disk, 0);
img->disk_attribute(&disk, 0);
value = disk->vector_value("TARGET");
CPPUNIT_ASSERT(value == "hdd");
// clean up
delete disk;
value = "";
@ -474,7 +455,7 @@ public:
img = imp->get(oid, false);
img->get_disk_attribute(disk, 2);
img->disk_attribute(&disk, 2);
value = disk->vector_value("TARGET");
CPPUNIT_ASSERT(value == "sdf");
@ -503,7 +484,7 @@ public:
// A disk without a BUS attribute should not have it added.
disk = new VectorAttribute("DISK");
img->get_disk_attribute(disk, 0);
img->disk_attribute(&disk, 0);
value = "";
value = disk->vector_value("BUS");
@ -511,7 +492,7 @@ public:
value = "";
value = disk->vector_value("SOURCE");
CPPUNIT_ASSERT( value ==
CPPUNIT_ASSERT( value ==
"source_prefix/7e997f5fdc26712ac64eac8385fc81632b4bf024" );
// clean up
@ -522,8 +503,7 @@ public:
disk = new VectorAttribute("DISK");
disk->replace("BUS", "SCSI");
img->get_disk_attribute(disk, 0);
img->disk_attribute(&disk, 0);
value = disk->vector_value("BUS");
CPPUNIT_ASSERT( value == "SCSI" );
@ -623,7 +603,7 @@ public:
ImagePool * imp = static_cast<ImagePool*>(pool);
ostringstream oss;
int oid, rc;
int rc;
allocate(0);
allocate(1);
@ -648,7 +628,7 @@ public:
{
ImagePool * imp = static_cast<ImagePool*>(pool);
int oid, rc;
int rc;
ostringstream oss;
ostringstream where;