mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-30 22:50:10 +03:00
Merge branch 'master' of git.opennebula.org:one
This commit is contained in:
commit
7c6987fc74
@ -39,6 +39,17 @@ public:
|
||||
attribute_name.end(),
|
||||
attribute_name.begin(),
|
||||
(int(*)(int))toupper);
|
||||
|
||||
// FIX Attribute name if it does not conform XML element
|
||||
// naming conventions
|
||||
|
||||
int size = attribute_name.size();
|
||||
|
||||
if ((size >0 && !isalpha(aname[0]))||
|
||||
(size >=3 && (aname[0]=='X' && aname[1]=='M' && aname[2]=='L')))
|
||||
{
|
||||
attribute_name.insert(0,"ONE_");
|
||||
}
|
||||
};
|
||||
|
||||
virtual ~Attribute(){};
|
||||
|
@ -103,6 +103,15 @@ public:
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source path of the image
|
||||
* @return source of image
|
||||
*/
|
||||
void set_source(const string& _source)
|
||||
{
|
||||
source = _source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the image
|
||||
* @return type
|
||||
@ -250,14 +259,6 @@ public:
|
||||
*/
|
||||
int disk_attribute(VectorAttribute * disk, int* index, ImageType* img_type);
|
||||
|
||||
/**
|
||||
* Generates the source path for the repository.
|
||||
* @param uid of the image owner
|
||||
* @param name of the image
|
||||
* @return source for the image
|
||||
*/
|
||||
static string generate_source(int uid, const string& name);
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -70,12 +70,13 @@ private:
|
||||
*/
|
||||
//Template driver_conf;
|
||||
|
||||
void cp(int oid, const string& source, const string& destination) const;
|
||||
void cp(int oid, const string& source) const;
|
||||
|
||||
/**
|
||||
* Sends a move request to the MAD: "MV IMAGE_ID SRC_PATH DST_PATH"
|
||||
* @param oid the image id.
|
||||
* @param destination is the path to the image to be created
|
||||
* @param destination is a driver specific location or "-" if not
|
||||
* initialized
|
||||
* @param size_mb of the image to be created
|
||||
*/
|
||||
void mv(int oid, const string& source, const string& destination) const;
|
||||
@ -83,12 +84,10 @@ private:
|
||||
/**
|
||||
* Sends a make filesystem request to the MAD: "MKFS IMAGE_ID PATH SIZE_MB"
|
||||
* @param oid the image id.
|
||||
* @param destination is the path to the image to be created
|
||||
* @param fs type
|
||||
* @param size_mb of the image to be created
|
||||
*/
|
||||
void mkfs(int oid,
|
||||
const string& destination,
|
||||
const string& fs,
|
||||
const string& size_mb) const;
|
||||
/**
|
||||
|
@ -39,7 +39,6 @@ class ImagePool : public PoolSQL
|
||||
public:
|
||||
|
||||
ImagePool(SqlDB * db,
|
||||
const string& _source_prefix,
|
||||
const string& _default_type,
|
||||
const string& _default_dev_prefix);
|
||||
|
||||
@ -146,11 +145,6 @@ public:
|
||||
*/
|
||||
void authorize_disk(VectorAttribute * disk, int uid, AuthRequest * ar);
|
||||
|
||||
static const string& source_prefix()
|
||||
{
|
||||
return _source_prefix;
|
||||
};
|
||||
|
||||
static const string& default_type()
|
||||
{
|
||||
return _default_type;
|
||||
@ -165,10 +159,6 @@ private:
|
||||
//--------------------------------------------------------------------------
|
||||
// Configuration Attributes for Images
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Path to the image repository
|
||||
**/
|
||||
static string _source_prefix;
|
||||
|
||||
/**
|
||||
* Default image type
|
||||
|
@ -43,11 +43,11 @@ class MySqlDB : public SqlDB
|
||||
{
|
||||
public:
|
||||
|
||||
MySqlDB(const string& server,
|
||||
int port,
|
||||
const string& user,
|
||||
const string& password,
|
||||
const char * database);
|
||||
MySqlDB(const string& _server,
|
||||
int _port,
|
||||
const string& _user,
|
||||
const string& _password,
|
||||
const string& _database);
|
||||
|
||||
~MySqlDB();
|
||||
|
||||
@ -81,6 +81,19 @@ private:
|
||||
*/
|
||||
MYSQL * db;
|
||||
|
||||
/**
|
||||
* MySQL Connection parameters
|
||||
*/
|
||||
string server;
|
||||
|
||||
int port;
|
||||
|
||||
string user;
|
||||
|
||||
string password;
|
||||
|
||||
string database;
|
||||
|
||||
/**
|
||||
* Fine-grain mutex for DB access
|
||||
*/
|
||||
@ -113,7 +126,7 @@ public:
|
||||
int port,
|
||||
string user,
|
||||
string password,
|
||||
const char * database)
|
||||
string database)
|
||||
{
|
||||
throw runtime_error("Aborting oned, MySQL support not compiled!");
|
||||
};
|
||||
|
@ -189,11 +189,10 @@ public:
|
||||
const string& name,
|
||||
const string& value)
|
||||
{
|
||||
SingleAttribute * sattr;
|
||||
SingleAttribute * sattr = new SingleAttribute(name,value);
|
||||
|
||||
obj_template->erase(name);
|
||||
obj_template->erase(sattr->name());
|
||||
|
||||
sattr = new SingleAttribute(name,value);
|
||||
obj_template->set(sattr);
|
||||
|
||||
return 0;
|
||||
|
@ -97,7 +97,6 @@ public:
|
||||
virtual UserPool* create_upool(SqlDB* db);
|
||||
|
||||
virtual ImagePool* create_ipool( SqlDB* db,
|
||||
string repository_path,
|
||||
string default_image_type,
|
||||
string default_device_prefix);
|
||||
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
if (mysql)
|
||||
{
|
||||
db = new MySqlDB( "localhost",0,
|
||||
"oneadmin","oneadmin",NULL);
|
||||
"oneadmin","oneadmin",db_name);
|
||||
|
||||
ostringstream oss1;
|
||||
oss1 << "DROP DATABASE IF EXISTS " << db_name;
|
||||
|
@ -543,6 +543,7 @@ LVM_TM_COMMANDS_LIB_FILES="src/tm_mad/lvm/tm_clone.sh \
|
||||
IMAGE_DRIVER_FS_SCRIPTS="src/image_mad/remotes/fs/cp \
|
||||
src/image_mad/remotes/fs/mkfs \
|
||||
src/image_mad/remotes/fs/mv \
|
||||
src/image_mad/remotes/fs/fsrc \
|
||||
src/image_mad/remotes/fs/rm"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -82,9 +82,6 @@ MAC_PREFIX = "02:00"
|
||||
#*******************************************************************************
|
||||
# Image Repository Configuration
|
||||
#*******************************************************************************
|
||||
# IMAGE_REPOSITORY_PATH: Define the path to the image repository, by default
|
||||
# is set to $ONE_LOCATION/var/images
|
||||
#
|
||||
# DEFAULT_IMAGE_TYPE: This can take values
|
||||
# OS Image file holding an operating system
|
||||
# CDROM Image file holding a CDROM
|
||||
@ -96,8 +93,6 @@ MAC_PREFIX = "02:00"
|
||||
# xvd XEN Virtual Disk
|
||||
# vd KVM virtual disk
|
||||
#*******************************************************************************
|
||||
|
||||
#IMAGE_REPOSITORY_PATH = /srv/cloud/var/images
|
||||
DEFAULT_IMAGE_TYPE = "OS"
|
||||
DEFAULT_DEVICE_PREFIX = "hd"
|
||||
|
||||
|
@ -41,7 +41,7 @@ Image::Image(int _uid,
|
||||
user_name(_user_name),
|
||||
type(OS),
|
||||
regtime(time(0)),
|
||||
source(""),
|
||||
source("-"),
|
||||
state(INIT),
|
||||
running_vms(0)
|
||||
{
|
||||
@ -78,22 +78,6 @@ const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool ("
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
string Image::generate_source(int uid, const string& name)
|
||||
{
|
||||
ostringstream tmp_hashstream;
|
||||
ostringstream tmp_sourcestream;
|
||||
|
||||
tmp_hashstream << uid << ":" << name;
|
||||
|
||||
tmp_sourcestream << ImagePool::source_prefix() << "/";
|
||||
tmp_sourcestream << sha1_digest(tmp_hashstream.str());
|
||||
|
||||
return tmp_sourcestream.str();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Image::insert(SqlDB *db, string& error_str)
|
||||
{
|
||||
int rc;
|
||||
@ -103,6 +87,7 @@ int Image::insert(SqlDB *db, string& error_str)
|
||||
string public_attr;
|
||||
string persistent_attr;
|
||||
string dev_prefix;
|
||||
string source_attr;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Check default image attributes
|
||||
@ -163,16 +148,17 @@ int Image::insert(SqlDB *db, string& error_str)
|
||||
{
|
||||
SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX",
|
||||
ImagePool::default_dev_prefix());
|
||||
|
||||
obj_template->set(dev_att);
|
||||
}
|
||||
|
||||
// ------------ PATH & SOURCE --------------------
|
||||
|
||||
get_template_attribute("PATH", path_attr);
|
||||
get_template_attribute("SOURCE", source);
|
||||
get_template_attribute("SOURCE", source_attr);
|
||||
|
||||
// The template should contain PATH or SOURCE
|
||||
if ( source.empty() && path_attr.empty() )
|
||||
if ( source_attr.empty() && path_attr.empty() )
|
||||
{
|
||||
string size_attr;
|
||||
string fstype_attr;
|
||||
@ -198,14 +184,13 @@ int Image::insert(SqlDB *db, string& error_str)
|
||||
goto error_size_format;
|
||||
}
|
||||
}
|
||||
else if ( !source.empty() && !path_attr.empty() )
|
||||
else if ( !source_attr.empty() && !path_attr.empty() )
|
||||
{
|
||||
goto error_path_and_source;
|
||||
}
|
||||
|
||||
if (source.empty())
|
||||
else if ( !source_attr.empty() )
|
||||
{
|
||||
source = Image::generate_source(uid,name);
|
||||
source = source_attr;
|
||||
}
|
||||
|
||||
state = LOCKED; //LOCKED till the ImageManager copies it to the Repository
|
||||
@ -447,31 +432,21 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
get_template_attribute("DEV_PREFIX", prefix);
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// NEW DISK ATTRIBUTES
|
||||
// BASE DISK ATTRIBUTES
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
map<string,string> new_disk;
|
||||
disk->replace("IMAGE", name);
|
||||
disk->replace("IMAGE_ID", iid.str());
|
||||
disk->replace("SOURCE", source);
|
||||
|
||||
new_disk.insert(make_pair("IMAGE", name));
|
||||
new_disk.insert(make_pair("IMAGE_ID", iid.str()));
|
||||
new_disk.insert(make_pair("SOURCE", source));
|
||||
|
||||
if (!bus.empty())
|
||||
if (bus.empty() && !template_bus.empty()) //BUS in Image, not in DISK
|
||||
{
|
||||
new_disk.insert(make_pair("BUS",bus));
|
||||
}
|
||||
else if (!template_bus.empty())
|
||||
{
|
||||
new_disk.insert(make_pair("BUS",template_bus));
|
||||
disk->replace("BUS",template_bus);
|
||||
}
|
||||
|
||||
if (!driver.empty())
|
||||
if (driver.empty() && !template_driver.empty())//DRIVER in Image,not in DISK
|
||||
{
|
||||
new_disk.insert(make_pair("DRIVER",driver));
|
||||
}
|
||||
else if (!template_driver.empty())
|
||||
{
|
||||
new_disk.insert(make_pair("DRIVER",template_driver));
|
||||
disk->replace("DRIVER",template_driver);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@ -480,26 +455,26 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
|
||||
if ( persistent_img )
|
||||
{
|
||||
new_disk.insert(make_pair("CLONE","NO"));
|
||||
new_disk.insert(make_pair("SAVE","YES"));
|
||||
disk->replace("CLONE","NO");
|
||||
disk->replace("SAVE","YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
new_disk.insert(make_pair("CLONE","YES"));
|
||||
new_disk.insert(make_pair("SAVE","NO"));
|
||||
disk->replace("CLONE","YES");
|
||||
disk->replace("SAVE","NO");
|
||||
}
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case OS:
|
||||
case DATABLOCK:
|
||||
new_disk.insert(make_pair("TYPE","DISK"));
|
||||
new_disk.insert(make_pair("READONLY","NO"));
|
||||
disk->replace("TYPE","DISK");
|
||||
disk->replace("READONLY","NO");
|
||||
break;
|
||||
|
||||
case CDROM:
|
||||
new_disk.insert(make_pair("TYPE","CDROM"));
|
||||
new_disk.insert(make_pair("READONLY","YES"));
|
||||
disk->replace("TYPE","CDROM");
|
||||
disk->replace("READONLY","YES");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -507,67 +482,37 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
// TARGET attribute
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
if (!target.empty())
|
||||
if (target.empty()) //No TARGET in DISK attribute
|
||||
{
|
||||
new_disk.insert(make_pair("TARGET", target));
|
||||
}
|
||||
else if (!template_target.empty())
|
||||
{
|
||||
new_disk.insert(make_pair("TARGET", template_target));
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(type)
|
||||
if (!template_target.empty())
|
||||
{
|
||||
case OS:
|
||||
prefix += "a";
|
||||
break;
|
||||
|
||||
case CDROM:
|
||||
prefix += "c"; // b is for context
|
||||
break;
|
||||
|
||||
case DATABLOCK:
|
||||
prefix += static_cast<char>(('e'+ *index));
|
||||
*index = *index + 1;
|
||||
break;
|
||||
|
||||
disk->replace("TARGET", template_target);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case OS:
|
||||
prefix += "a";
|
||||
break;
|
||||
|
||||
new_disk.insert(make_pair("TARGET", prefix));
|
||||
case CDROM:
|
||||
prefix += "c"; // b is for context
|
||||
break;
|
||||
|
||||
case DATABLOCK:
|
||||
prefix += static_cast<char>(('e'+ *index));
|
||||
*index = *index + 1;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
disk->replace("TARGET", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
disk->replace(new_disk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string Image::sha1_digest(const string& pass)
|
||||
{
|
||||
EVP_MD_CTX mdctx;
|
||||
unsigned char md_value[EVP_MAX_MD_SIZE];
|
||||
unsigned int md_len;
|
||||
ostringstream oss;
|
||||
|
||||
EVP_MD_CTX_init(&mdctx);
|
||||
EVP_DigestInit_ex(&mdctx, EVP_sha1(), NULL);
|
||||
|
||||
EVP_DigestUpdate(&mdctx, pass.c_str(), pass.length());
|
||||
|
||||
EVP_DigestFinal_ex(&mdctx,md_value,&md_len);
|
||||
EVP_MD_CTX_cleanup(&mdctx);
|
||||
|
||||
for(unsigned int i = 0; i<md_len; i++)
|
||||
{
|
||||
oss << setfill('0') << setw(2) << hex << nouppercase
|
||||
<< (unsigned short) md_value[i];
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
@ -122,7 +122,7 @@ void ImageManager::move_image(Image *img, const string& source)
|
||||
}
|
||||
|
||||
oss << "Moving disk " << source << " to repository image "
|
||||
<< img->get_oid() << " as " << img->get_source();
|
||||
<< img->get_oid();
|
||||
|
||||
imd->mv(img->get_oid(),source,img->get_source());
|
||||
|
||||
@ -400,7 +400,7 @@ int ImageManager::register_image(int iid)
|
||||
if ( img->get_type() == Image::DATABLOCK &&
|
||||
!size.empty() && !fs.empty() )
|
||||
{
|
||||
imd->mkfs(img->get_oid(), img->get_source(), fs, size);
|
||||
imd->mkfs(img->get_oid(), fs, size);
|
||||
|
||||
oss << "Creating disk at " << img->get_source() << " of "
|
||||
<< size << "Mb with format " << fs;
|
||||
@ -416,9 +416,8 @@ int ImageManager::register_image(int iid)
|
||||
}
|
||||
else //PATH -> COPY TO REPOSITORY AS SOURCE
|
||||
{
|
||||
imd->cp(img->get_oid(), path, img->get_source());
|
||||
oss << "Copying image " << path
|
||||
<< " to repository as " << img->get_source();
|
||||
imd->cp(img->get_oid(), path);
|
||||
oss << "Copying " << path <<" to repository for image "<<img->get_oid();
|
||||
}
|
||||
|
||||
NebulaLog::log("ImM",Log::INFO,oss);
|
||||
|
@ -27,12 +27,11 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ImageManagerDriver::cp(int oid,
|
||||
const string& source,
|
||||
const string& destination) const
|
||||
const string& source) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
os << "CP " << oid << " " << source << " " << destination << endl;
|
||||
os << "CP " << oid << " " << source << endl;
|
||||
|
||||
write(os);
|
||||
}
|
||||
@ -53,14 +52,12 @@ void ImageManagerDriver::mv(int oid,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManagerDriver::mkfs(int oid,
|
||||
const string& destination,
|
||||
const string& fs,
|
||||
const string& size_mb) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
os << "MKFS " << oid << " " << destination << " " <<
|
||||
fs << " " << size_mb << endl;
|
||||
os << "MKFS " << oid << " " << fs << " " << size_mb << endl;
|
||||
write(os);
|
||||
}
|
||||
|
||||
@ -146,7 +143,21 @@ void ImageManagerDriver::protocol(
|
||||
{
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
string source;
|
||||
|
||||
if ( is.good() )
|
||||
{
|
||||
is >> source >> ws;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
{
|
||||
goto error_cp;
|
||||
}
|
||||
|
||||
image->set_source(source);
|
||||
image->set_state(Image::READY);
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
NebulaLog::log("ImM", Log::INFO, "Image copied and ready to use.");
|
||||
@ -160,6 +171,23 @@ void ImageManagerDriver::protocol(
|
||||
{
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
if (image->get_source() == "-")
|
||||
{
|
||||
string source;
|
||||
|
||||
if ( is.good() )
|
||||
{
|
||||
is >> source >> ws;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
{
|
||||
goto error_mv;
|
||||
}
|
||||
|
||||
image->set_source(source);
|
||||
}
|
||||
|
||||
image->set_state(Image::READY);
|
||||
ipool->update(image);
|
||||
|
||||
@ -174,7 +202,21 @@ void ImageManagerDriver::protocol(
|
||||
{
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
string source;
|
||||
|
||||
if ( is.good() )
|
||||
{
|
||||
is >> source >> ws;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
{
|
||||
goto error_mkfs;
|
||||
}
|
||||
|
||||
image->set_source(source);
|
||||
image->set_state(Image::READY);
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
NebulaLog::log("ImM", Log::INFO, "Image created and ready to use");
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
string ImagePool::_source_prefix;
|
||||
string ImagePool::_default_type;
|
||||
string ImagePool::_default_dev_prefix;
|
||||
|
||||
@ -32,7 +31,6 @@ string ImagePool::_default_dev_prefix;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
ImagePool::ImagePool(SqlDB * db,
|
||||
const string& __source_prefix,
|
||||
const string& __default_type,
|
||||
const string& __default_dev_prefix):
|
||||
PoolSQL(db,Image::table)
|
||||
@ -40,7 +38,6 @@ ImagePool::ImagePool(SqlDB * db,
|
||||
ostringstream sql;
|
||||
|
||||
// Init static defaults
|
||||
_source_prefix = __source_prefix;
|
||||
_default_type = __default_type;
|
||||
_default_dev_prefix = __default_dev_prefix;
|
||||
|
||||
|
@ -50,19 +50,19 @@ const string templates[] =
|
||||
|
||||
const string xmls[] =
|
||||
{
|
||||
"<IMAGE><ID>0</ID><UID>0</UID><USERNAME>A user</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE>",
|
||||
"<IMAGE><ID>0</ID><UID>0</UID><USERNAME>A user</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE>",
|
||||
|
||||
"<IMAGE><ID>1</ID><UID>1</UID><USERNAME>B user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f3</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE>",
|
||||
"<IMAGE><ID>1</ID><UID>1</UID><USERNAME>B user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE>",
|
||||
|
||||
"<IMAGE><ID>0</ID><UID>2</UID><USERNAME>C user</USERNAME><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/e50b0c738be9d431475bf5859629e5580301a7d6</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE>"
|
||||
"<IMAGE><ID>0</ID><UID>2</UID><USERNAME>C user</USERNAME><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE>"
|
||||
};
|
||||
|
||||
|
||||
// This xml dump result has the STIMEs modified to 0000000000
|
||||
const string xml_dump =
|
||||
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><USERNAME>A user</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>B user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f3</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>2</ID><UID>2</UID><USERNAME>C user</USERNAME><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/e50b0c738be9d431475bf5859629e5580301a7d6</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE></IMAGE_POOL>";
|
||||
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><USERNAME>A user</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>B user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>2</ID><UID>2</UID><USERNAME>C user</USERNAME><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE></IMAGE_POOL>";
|
||||
const string xml_dump_where =
|
||||
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><USERNAME>A user</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>B user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f3</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE></IMAGE_POOL>";
|
||||
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><USERNAME>A user</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>B user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE></IMAGE_POOL>";
|
||||
|
||||
const string replacement = "0000000000";
|
||||
|
||||
@ -70,12 +70,10 @@ class ImagePoolFriend : public ImagePool
|
||||
{
|
||||
public:
|
||||
ImagePoolFriend(SqlDB * db,
|
||||
const string& _source_prefix,
|
||||
const string& _default_type,
|
||||
const string& _default_dev_prefix):
|
||||
|
||||
ImagePool( db,
|
||||
_source_prefix,
|
||||
_default_type,
|
||||
_default_dev_prefix){};
|
||||
|
||||
@ -147,7 +145,7 @@ protected:
|
||||
PoolSQL* create_pool(SqlDB* db)
|
||||
{
|
||||
ImagePoolFriend * imp =
|
||||
new ImagePoolFriend(db, "source_prefix", "OS", "hd");
|
||||
new ImagePoolFriend(db, "OS", "hd");
|
||||
return imp;
|
||||
};
|
||||
|
||||
@ -201,7 +199,7 @@ public:
|
||||
|
||||
// Create a new pool, using the same DB. This new pool should read the
|
||||
// allocated images.
|
||||
imp = new ImagePool(db, "source_prefix", "OS", "hd");
|
||||
imp = new ImagePool(db,"OS", "hd");
|
||||
|
||||
img = imp->get(names[0], uids[0], false);
|
||||
CPPUNIT_ASSERT( img != 0 );
|
||||
@ -565,8 +563,7 @@ public:
|
||||
|
||||
value = "";
|
||||
value = disk->vector_value("SOURCE");
|
||||
CPPUNIT_ASSERT( value ==
|
||||
"source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198" );
|
||||
CPPUNIT_ASSERT( value == "-" );
|
||||
|
||||
// clean up
|
||||
//img->release_image();
|
||||
@ -586,8 +583,7 @@ public:
|
||||
|
||||
value = "";
|
||||
value = disk->vector_value("SOURCE");
|
||||
CPPUNIT_ASSERT( value ==
|
||||
"source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198" );
|
||||
CPPUNIT_ASSERT( value == "-" );
|
||||
|
||||
// clean up
|
||||
delete disk;
|
||||
@ -874,15 +870,15 @@ public:
|
||||
string result = oss.str();
|
||||
|
||||
result.replace(157, 10, replacement);
|
||||
result.replace(1129, 10, replacement);
|
||||
result.replace(1641, 10, replacement);
|
||||
result.replace(1076, 10, replacement);
|
||||
result.replace(1535, 10, replacement);
|
||||
|
||||
/*
|
||||
if( result != xml_dump )
|
||||
{
|
||||
cout << endl << result << endl << xml_dump << endl;
|
||||
}
|
||||
//*/
|
||||
*/
|
||||
|
||||
CPPUNIT_ASSERT( result == xml_dump );
|
||||
}
|
||||
@ -909,14 +905,14 @@ public:
|
||||
|
||||
string result = oss.str();
|
||||
result.replace(157, 10, replacement);
|
||||
result.replace(1129, 10, replacement);
|
||||
result.replace(1076, 10, replacement);
|
||||
|
||||
|
||||
/*
|
||||
if( result != xml_dump_where )
|
||||
{
|
||||
cout << endl << result << endl << xml_dump_where << endl;
|
||||
}
|
||||
//*/
|
||||
|
||||
|
||||
CPPUNIT_ASSERT( result == xml_dump_where );
|
||||
}
|
||||
|
@ -69,19 +69,19 @@ class ImageDriver < OpenNebulaDriver
|
||||
# Image Manager Protocol Actions (generic implementation
|
||||
# -------------------------------------------------------------------------
|
||||
def mv(id, src, dst)
|
||||
local_action("#{@actions_path}/mv #{src} #{dst}",id,:mv)
|
||||
local_action("#{@actions_path}/mv #{src} #{dst} #{id}",id,ACTION[:mv])
|
||||
end
|
||||
|
||||
def cp(id, src, dst)
|
||||
local_action("#{@actions_path}/cp #{src} #{dst}",id,:cp)
|
||||
def cp(id, src)
|
||||
local_action("#{@actions_path}/cp #{src} #{id}",id,ACTION[:cp])
|
||||
end
|
||||
|
||||
def rm(id, dst)
|
||||
local_action("#{@actions_path}/rm #{dst}",id,:rm)
|
||||
local_action("#{@actions_path}/rm #{dst} #{id}",id,ACTION[:rm])
|
||||
end
|
||||
|
||||
def mkfs(id, dst, fs, size)
|
||||
local_action("#{@actions_path}/mkfs #{dst} #{fs} #{size}",id,:mkfs)
|
||||
def mkfs(id, fs, size)
|
||||
local_action("#{@actions_path}/mkfs #{fs} #{size} #{id}",id,ACTION[:mkfs])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
# Several SRC types are supported
|
||||
###############################################################################
|
||||
|
||||
# ------------ Set up the environment to source common tools ------------
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
@ -30,11 +30,13 @@ else
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
# ------------ Copy the image to the repository ------------
|
||||
source $(dirname $0)/fsrc
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
ID=$2
|
||||
DST=`generate_image_path`
|
||||
|
||||
# ------------ Copy the image to the repository -------------
|
||||
|
||||
case $SRC in
|
||||
http://*)
|
||||
@ -51,3 +53,5 @@ http://*)
|
||||
esac
|
||||
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
|
||||
echo "$DST"
|
||||
|
@ -30,15 +30,20 @@ else
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
source $(dirname $0)/fsrc
|
||||
|
||||
# ------------ Create the image to the repository ------------
|
||||
|
||||
DST=$1
|
||||
FSTYPE=$2
|
||||
SIZE=$3
|
||||
FSTYPE=$1
|
||||
SIZE=$2
|
||||
ID=$3
|
||||
|
||||
DST=`generate_image_path`
|
||||
|
||||
exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M" \
|
||||
"Could not create image $DST"
|
||||
exec_and_log "$MKFS -t $FSTYPE -F $DST" \
|
||||
"Unable to create filesystem $FSTYPE in $DST"
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
|
||||
echo "$DST"
|
||||
|
@ -30,11 +30,20 @@ else
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
# ------------ Move the image to the repository ------------
|
||||
source $(dirname $0)/fsrc
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
ID=$3
|
||||
|
||||
# ------------ Generate a filename for the image ------------
|
||||
|
||||
if [ $DST -eq "-" ] ; then
|
||||
DST=`generate_image_path`
|
||||
fi
|
||||
|
||||
# ------------ Move the image to the repository ------------
|
||||
|
||||
|
||||
case $SRC in
|
||||
http://*)
|
||||
@ -51,3 +60,5 @@ http://*)
|
||||
esac
|
||||
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
|
||||
echo "$DST"
|
||||
|
@ -29,6 +29,7 @@ else
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
source $(dirname $0)/fsrc
|
||||
|
||||
# ------------ Remove the image to the repository ------------
|
||||
|
||||
|
@ -208,7 +208,7 @@ void Nebula::start()
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
db = new MySqlDB(server,port,user,passwd,0);
|
||||
db = new MySqlDB(server,port,user,passwd,db_name);
|
||||
|
||||
oss << "CREATE DATABASE IF NOT EXISTS " << db_name;
|
||||
rc = db->exec(oss);
|
||||
@ -246,7 +246,6 @@ void Nebula::start()
|
||||
{
|
||||
string mac_prefix;
|
||||
int size;
|
||||
string repository_path;
|
||||
string default_image_type;
|
||||
string default_device_prefix;
|
||||
|
||||
@ -266,13 +265,11 @@ void Nebula::start()
|
||||
|
||||
upool = new UserPool(db);
|
||||
|
||||
nebula_configuration->get("IMAGE_REPOSITORY_PATH", repository_path);
|
||||
nebula_configuration->get("DEFAULT_IMAGE_TYPE", default_image_type);
|
||||
nebula_configuration->get("DEFAULT_DEVICE_PREFIX",
|
||||
default_device_prefix);
|
||||
|
||||
ipool = new ImagePool(db,
|
||||
repository_path,
|
||||
default_image_type,
|
||||
default_device_prefix);
|
||||
|
||||
|
@ -126,17 +126,10 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location)
|
||||
#*******************************************************************************
|
||||
# Image Repository Configuration
|
||||
#*******************************************************************************
|
||||
# IMAGE_REPOSITORY_PATH
|
||||
# DEFAULT_IMAGE_TYPE
|
||||
# DEFAULT_DEVICE_PREFIX
|
||||
#*******************************************************************************
|
||||
*/
|
||||
//IMAGE_REPOSITORY_PATH
|
||||
value = var_location + "/images";
|
||||
|
||||
attribute = new SingleAttribute("IMAGE_REPOSITORY_PATH",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
//DEFAULT_IMAGE_TYPE
|
||||
value = "OS";
|
||||
|
||||
|
@ -102,7 +102,6 @@ void RequestManager::VirtualMachineSaveDisk::execute(
|
||||
|
||||
oss << "NAME= " << img_name << endl;
|
||||
oss << "PUBLIC = NO " << endl;
|
||||
oss << "SOURCE = " << Image::generate_source(uid,img_name);
|
||||
|
||||
img_template = new ImageTemplate;
|
||||
|
||||
|
@ -29,7 +29,6 @@ void RequestManager::TemplateInfo::execute(
|
||||
string session;
|
||||
|
||||
int oid;
|
||||
int uid; // owner user id
|
||||
int rc; // Requesting user id
|
||||
VMTemplate * vm_template;
|
||||
|
||||
@ -55,8 +54,6 @@ void RequestManager::TemplateInfo::execute(
|
||||
goto error_get;
|
||||
}
|
||||
|
||||
uid = vm_template->get_uid();
|
||||
|
||||
// Check if it is a valid user
|
||||
rc = TemplateInfo::upool->authenticate(session);
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "MySqlDB.h"
|
||||
#include <mysql/errmsg.h>
|
||||
|
||||
/*********
|
||||
* Doc: http://dev.mysql.com/doc/refman/5.5/en/c-api-function-overview.html
|
||||
@ -23,12 +24,17 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
MySqlDB::MySqlDB(
|
||||
const string& server,
|
||||
int port,
|
||||
const string& user,
|
||||
const string& password,
|
||||
const char * database)
|
||||
const string& _server,
|
||||
int _port,
|
||||
const string& _user,
|
||||
const string& _password,
|
||||
const string& _database)
|
||||
{
|
||||
server = _server;
|
||||
port = _port;
|
||||
user = _user;
|
||||
password = _password;
|
||||
database = _database;
|
||||
|
||||
// Initialize the MySQL library
|
||||
mysql_library_init(0, NULL, NULL);
|
||||
@ -38,7 +44,7 @@ MySqlDB::MySqlDB(
|
||||
|
||||
// Connect to the server
|
||||
if (!mysql_real_connect(db, server.c_str(), user.c_str(),
|
||||
password.c_str(), database, port, NULL, 0))
|
||||
password.c_str(), 0, port, NULL, 0))
|
||||
{
|
||||
throw runtime_error("Could not open database.");
|
||||
}
|
||||
@ -81,8 +87,27 @@ int MySqlDB::exec(ostringstream& cmd, Callbackable* obj)
|
||||
const char * err_msg = mysql_error(db);
|
||||
int err_num = mysql_errno(db);
|
||||
|
||||
oss << "SQL command was: " << c_str;
|
||||
oss << ", error " << err_num << " : " << err_msg;
|
||||
if( err_num == CR_SERVER_GONE_ERROR || err_num == CR_SERVER_LOST )
|
||||
{
|
||||
oss << "MySQL connection error " << err_num << " : " << err_msg;
|
||||
|
||||
// Try to re-connect
|
||||
if (mysql_real_connect(db, server.c_str(), user.c_str(),
|
||||
password.c_str(), database.c_str(),
|
||||
port, NULL, 0))
|
||||
{
|
||||
oss << "... Reconnected.";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "... Reconnection attempt failed.";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "SQL command was: " << c_str;
|
||||
oss << ", error " << err_num << " : " << err_msg;
|
||||
}
|
||||
|
||||
NebulaLog::log("ONE",Log::ERROR,oss);
|
||||
|
||||
|
@ -183,7 +183,6 @@ void Nebula::start()
|
||||
{
|
||||
string mac_prefix = "00:00";
|
||||
int size = 1;
|
||||
string repository_path;
|
||||
string default_image_type;
|
||||
string default_device_prefix;
|
||||
|
||||
@ -210,7 +209,6 @@ void Nebula::start()
|
||||
if (tester->need_image_pool)
|
||||
{
|
||||
ipool = tester->create_ipool(db,
|
||||
repository_path,
|
||||
default_image_type,
|
||||
default_device_prefix);
|
||||
}
|
||||
|
@ -41,12 +41,10 @@ UserPool* NebulaTest::create_upool(SqlDB* db)
|
||||
}
|
||||
|
||||
ImagePool* NebulaTest::create_ipool( SqlDB* db,
|
||||
string repository_path,
|
||||
string default_image_type,
|
||||
string default_device_prefix)
|
||||
{
|
||||
return new ImagePool(db,repository_path,default_image_type,
|
||||
default_device_prefix);
|
||||
return new ImagePool(db,default_image_type,default_device_prefix);
|
||||
}
|
||||
|
||||
ClusterPool* NebulaTest::create_cpool(SqlDB* db)
|
||||
|
@ -491,9 +491,9 @@ public:
|
||||
|
||||
string result = oss.str();
|
||||
|
||||
result.replace(128, 10, replacement);
|
||||
result.replace(391, 10, replacement);
|
||||
result.replace(656, 10, replacement);
|
||||
result.replace(130, 10, replacement);
|
||||
result.replace(393, 10, replacement);
|
||||
result.replace(658, 10, replacement);
|
||||
|
||||
/*
|
||||
if( result != xml_dump )
|
||||
@ -527,8 +527,8 @@ public:
|
||||
|
||||
string result = oss.str();
|
||||
|
||||
result.replace(128, 10, replacement);
|
||||
result.replace(391, 10, replacement);
|
||||
result.replace(130, 10, replacement);
|
||||
result.replace(393, 10, replacement);
|
||||
|
||||
/*
|
||||
if( result != xml_dump_where )
|
||||
|
@ -53,7 +53,9 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
string bus = "";
|
||||
string ro = "";
|
||||
string driver = "";
|
||||
string default_driver = "";
|
||||
string cache = "";
|
||||
string default_driver = "";
|
||||
string default_driver_cache = "";
|
||||
bool readonly;
|
||||
|
||||
const VectorAttribute * nic;
|
||||
@ -62,6 +64,9 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
string bridge = "";
|
||||
string script = "";
|
||||
string model = "";
|
||||
string ip = "";
|
||||
string filter = "";
|
||||
string default_filter = "";
|
||||
|
||||
const VectorAttribute * graphics;
|
||||
|
||||
@ -251,9 +256,8 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
attrs.clear();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Disks
|
||||
// DEVICES SECTION
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
file << "\t<devices>" << endl;
|
||||
|
||||
if (emulator == "kvm")
|
||||
@ -268,6 +272,9 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
file << "\t\t<emulator>" << emulator_path << "</emulator>" << endl;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Disks
|
||||
// ------------------------------------------------------------------------
|
||||
get_default("DISK","DRIVER",default_driver);
|
||||
|
||||
if (default_driver.empty())
|
||||
@ -275,6 +282,15 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
default_driver = "raw";
|
||||
}
|
||||
|
||||
get_default("DISK","CACHE",default_driver_cache);
|
||||
|
||||
if (default_driver_cache.empty())
|
||||
{
|
||||
default_driver_cache = "default";
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
num = vm->get_template_attribute("DISK",attrs);
|
||||
|
||||
for (int i=0; i < num ;i++)
|
||||
@ -291,6 +307,7 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
ro = disk->vector_value("READONLY");
|
||||
bus = disk->vector_value("BUS");
|
||||
driver = disk->vector_value("DRIVER");
|
||||
cache = disk->vector_value("CACHE");
|
||||
|
||||
if (target.empty())
|
||||
{
|
||||
@ -363,11 +380,22 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
|
||||
if ( !driver.empty() )
|
||||
{
|
||||
file << driver << "'/>" << endl;
|
||||
file << driver;
|
||||
}
|
||||
else
|
||||
{
|
||||
file << default_driver << "'/>" << endl;
|
||||
file << default_driver;
|
||||
}
|
||||
|
||||
file << "' cache='";
|
||||
|
||||
if ( !cache.empty() )
|
||||
{
|
||||
file << cache << "'/>" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
file << default_driver_cache << "'/>" << endl;
|
||||
}
|
||||
|
||||
file << "\t\t</disk>" << endl;
|
||||
@ -419,6 +447,8 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
// Network interfaces
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
get_default("NIC","FILTER",default_filter);
|
||||
|
||||
num = vm->get_template_attribute("NIC",attrs);
|
||||
|
||||
for(int i=0; i<num; i++)
|
||||
@ -435,6 +465,8 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
target = nic->vector_value("TARGET");
|
||||
script = nic->vector_value("SCRIPT");
|
||||
model = nic->vector_value("MODEL");
|
||||
ip = nic->vector_value("IP");
|
||||
filter = nic->vector_value("FILTER");
|
||||
|
||||
if ( bridge.empty() )
|
||||
{
|
||||
@ -466,8 +498,29 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
file << "\t\t\t<model type='" << model << "'/>" << endl;
|
||||
}
|
||||
|
||||
file << "\t\t</interface>" << endl;
|
||||
if (!ip.empty() )
|
||||
{
|
||||
string * the_filter = 0;
|
||||
|
||||
if (!filter.empty())
|
||||
{
|
||||
the_filter = &filter;
|
||||
}
|
||||
else if (!default_filter.empty())
|
||||
{
|
||||
the_filter = &default_filter;
|
||||
}
|
||||
|
||||
if ( the_filter != 0 )
|
||||
{
|
||||
file <<"\t\t\t<filterref filter='"<< *the_filter <<"'/>"<<endl;
|
||||
file << "\t\t\t\t<parameter name='IP' value='"
|
||||
<< ip << "'/>" << endl;
|
||||
file << "\t\t\t</filterref>" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
file << "\t\t</interface>" << endl;
|
||||
}
|
||||
|
||||
attrs.clear();
|
||||
|
@ -453,6 +453,9 @@ void VirtualMachineManagerDriver::protocol(
|
||||
int net_rx = -1;
|
||||
char state = '-';
|
||||
|
||||
string monitor_str = is.str();
|
||||
bool parse_error = false;
|
||||
|
||||
while(is.good())
|
||||
{
|
||||
is >> tmp >> ws;
|
||||
@ -461,12 +464,8 @@ void VirtualMachineManagerDriver::protocol(
|
||||
|
||||
if ( pos == string::npos )
|
||||
{
|
||||
os.str("");
|
||||
os << "Error parsing monitoring attribute: " << tmp;
|
||||
|
||||
vm->log("VMM",Log::ERROR,os);
|
||||
|
||||
break;
|
||||
parse_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp.replace(pos,1," ");
|
||||
@ -475,7 +474,13 @@ void VirtualMachineManagerDriver::protocol(
|
||||
|
||||
tiss.str(tmp);
|
||||
|
||||
tiss >> var;
|
||||
tiss >> var >> ws;
|
||||
|
||||
if (!tiss.good())
|
||||
{
|
||||
parse_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (var == "USEDMEMORY")
|
||||
{
|
||||
@ -502,8 +507,7 @@ void VirtualMachineManagerDriver::protocol(
|
||||
string val;
|
||||
|
||||
os.str("");
|
||||
os << "Unknown monitoring attribute (adding/updating"
|
||||
<< " template): " << tmp;
|
||||
os << "Adding custom monitoring attribute: " << tmp;
|
||||
|
||||
vm->log("VMM",Log::WARNING,os);
|
||||
|
||||
@ -513,6 +517,20 @@ void VirtualMachineManagerDriver::protocol(
|
||||
}
|
||||
}
|
||||
|
||||
if (parse_error)
|
||||
{
|
||||
os.str("");
|
||||
os << "Error parsing monitoring str:\"" << monitor_str <<"\"";
|
||||
|
||||
vm->log("VMM",Log::ERROR,os);
|
||||
|
||||
vm->set_template_error_message(os.str());
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
vm->update_info(memory,cpu,net_tx,net_rx);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
@ -23,7 +23,8 @@
|
||||
# - cpu
|
||||
# - vcpu
|
||||
# - features [acpi, pae]
|
||||
# - disk [driver ]A
|
||||
# - disk [driver, cache]
|
||||
# - nic [filter]
|
||||
|
||||
#EMULATOR = /usr/libexec/qemu-kvm
|
||||
|
||||
@ -33,4 +34,6 @@
|
||||
OS = [ boot = "hd", arch = "i686" ]
|
||||
FEATURES = [ PAE = "no", ACPI = "yes" ]
|
||||
|
||||
DISK = [ driver = "raw" ]
|
||||
DISK = [ driver = "raw" , cache = "default"]
|
||||
|
||||
NIC = [ filter = "clean-traffic" ]
|
||||
|
@ -571,15 +571,11 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
{
|
||||
int rc;
|
||||
|
||||
string model;
|
||||
string ip;
|
||||
string mac;
|
||||
|
||||
ostringstream vnid;
|
||||
|
||||
map<string,string> new_nic;
|
||||
|
||||
model = nic->vector_value("MODEL");
|
||||
ip = nic->vector_value("IP");
|
||||
vnid << oid;
|
||||
|
||||
@ -605,18 +601,11 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
// NEW NIC ATTRIBUTES
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
new_nic.insert(make_pair("NETWORK" ,name));
|
||||
new_nic.insert(make_pair("MAC" ,mac));
|
||||
new_nic.insert(make_pair("BRIDGE" ,bridge));
|
||||
new_nic.insert(make_pair("NETWORK_ID",vnid.str()));
|
||||
new_nic.insert(make_pair("IP" ,ip));
|
||||
|
||||
if (!model.empty())
|
||||
{
|
||||
new_nic.insert(make_pair("MODEL",model));
|
||||
}
|
||||
|
||||
nic->replace(new_nic);
|
||||
nic->replace("NETWORK" ,name);
|
||||
nic->replace("NETWORK_ID",vnid.str());
|
||||
nic->replace("BRIDGE" ,bridge);
|
||||
nic->replace("MAC" ,mac);
|
||||
nic->replace("IP" ,ip);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user