mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-13 13:17:39 +03:00
feature #200: ImagePool's contructor changed to load existing images from the DB.
This commit is contained in:
parent
2cb9de488d
commit
9fe40f27c9
@ -39,24 +39,7 @@ public:
|
||||
ImagePool(SqlDB * db,
|
||||
const string& _source_prefix,
|
||||
const string& _default_type,
|
||||
const string& _default_dev_prefix):
|
||||
PoolSQL(db,Image::table),
|
||||
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;
|
||||
}
|
||||
};
|
||||
const string& _default_dev_prefix);
|
||||
|
||||
~ImagePool(){};
|
||||
|
||||
@ -190,7 +173,16 @@ private:
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump_cb(void * _oss, int num, char **values, char **names);
|
||||
|
||||
|
||||
/**
|
||||
* Callback function to build the image_names map
|
||||
* @param num the number of columns read from the DB
|
||||
* @param names the column names
|
||||
* @param vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int init_cb(void *nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* "Encrypts" the password with SHA1 digest
|
||||
* @param password
|
||||
|
@ -22,6 +22,68 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImagePool::init_cb(void *nil, int num, char **values, char **names)
|
||||
{
|
||||
if ( num == 0 || values == 0 || values[0] == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
image_names.insert(make_pair(values[1],atoi(values[0])));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
ImagePool::ImagePool( SqlDB * db,
|
||||
const string& _source_prefix,
|
||||
const string& _default_type,
|
||||
const string& _default_dev_prefix):
|
||||
|
||||
PoolSQL(db,Image::table),
|
||||
source_prefix(_source_prefix),
|
||||
default_dev_prefix(_default_dev_prefix)
|
||||
{
|
||||
ostringstream sql;
|
||||
int rc;
|
||||
|
||||
// Set default type
|
||||
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;
|
||||
}
|
||||
|
||||
// Read from the DB the existing images, and build the ID:Name map
|
||||
set_callback(static_cast<Callbackable::Callback>(&ImagePool::init_cb));
|
||||
|
||||
sql << "SELECT oid, name FROM " << Image::table;
|
||||
|
||||
rc = db->exec(sql, this);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
NebulaLog::log("IMG", Log::ERROR,
|
||||
"Could not load the existing images from the DB.");
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImagePool::allocate (
|
||||
int uid,
|
||||
const string& stemplate,
|
||||
|
Loading…
Reference in New Issue
Block a user