1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-22 17:57:46 +03:00

Merge branch 'one-2.0'

Conflicts:
	include/RequestManager.h
	src/host/Host.cc
	src/rm/RequestManagerPoolInfo.cc
	src/um/UserPool.cc
This commit is contained in:
Ruben S. Montero 2010-09-03 00:08:30 +02:00
commit 2e76eba305
209 changed files with 4535 additions and 4398 deletions

View File

@ -155,6 +155,11 @@ else:
shutil.rmtree('src/nebula/.xmlrpc_test', True)
shutil.rmtree('src/scheduler/.xmlrpc_test', True)
# libxml2
main_env.ParseConfig('xml2-config --libs --cflags')
# SCONS scripts to build
build_scripts=[
'src/sql/SConstruct',

View File

@ -73,7 +73,7 @@ private:
* @param clid the id assigned to the cluster
* @return the id assigned to the cluster or -1 in case of failure
*/
int allocate(int * clid, string name, SqlDB *db);
int allocate(int * clid, string name, SqlDB *db, string& error_str);
/**
* Returns the xml representation of the given cluster

View File

@ -165,7 +165,7 @@ private:
* @param db pointer to the database.
* @return 0 on success.
*/
int insert(SqlDB * db);
int insert(SqlDB * db, string& error_str);
/**
* Reads the history record from the DB
@ -173,7 +173,7 @@ private:
* @return 0 on success.
*/
int select(SqlDB * db);
/**
* Updates the history record
* @param db pointer to the database.
@ -187,11 +187,11 @@ private:
* @return 0 on success.
*/
int drop(SqlDB * db);
/**
* Execute an INSERT or REPLACE Sql query.
* Execute an INSERT or REPLACE Sql query.
* @param db The SQL DB
* @param replace Execute an INSERT or a REPLACE
* @param replace Execute an INSERT or a REPLACE
* @return 0 on success
*/
int insert_replace(SqlDB *db, bool replace);

View File

@ -18,8 +18,8 @@
#define HOST_H_
#include "PoolSQL.h"
#include "HostShare.h"
#include "HostTemplate.h"
#include "HostShare.h"
#include "ClusterPool.h"
using namespace std;
@ -454,11 +454,9 @@ private:
{
ostringstream oss_host(Host::db_bootstrap);
ostringstream oss_share(HostShare::db_bootstrap);
ostringstream oss_templ(HostTemplate::db_bootstrap);
db->exec(oss_host);
db->exec(oss_share);
db->exec(oss_templ);
};
protected:
@ -489,7 +487,8 @@ protected:
TM_MAD = 5,
LAST_MON_TIME = 6,
CLUSTER = 7,
LIMIT = 8
TEMPLATE = 8,
LIMIT = 9
};
static const char * db_names;
@ -510,7 +509,7 @@ protected:
* @param db pointer to the db
* @return 0 on success
*/
virtual int insert(SqlDB *db);
virtual int insert(SqlDB *db, string& error_str);
/**
* Writes/updates the Hosts data fields in the database.

View File

@ -48,10 +48,11 @@ public:
*/
int allocate (
int * oid,
string hostname,
string im_mad_name,
string vmm_mad_name,
string tm_mad_name);
const string& hostname,
const string& im_mad_name,
const string& vmm_mad_name,
const string& tm_mad_name,
string& error_str);
/**
* Function to get a Host from the pool, if the object is not in memory
@ -169,9 +170,9 @@ public:
* @param clid the id assigned to the cluster
* @return the id assigned to the cluster or -1 in case of failure
*/
int allocate_cluster(int * clid, string name)
int allocate_cluster(int * clid, const string& name, string& error_str)
{
return cluster_pool.allocate(clid, name, db);
return cluster_pool.allocate(clid, name, db, error_str);
};
/**

View File

@ -182,7 +182,7 @@ private:
* @param db pointer to the db
* @return 0 on success
*/
int insert(SqlDB * db);
int insert(SqlDB * db, string& error_str);
/**
* Writes/updates the HostShare data fields in the database.
@ -197,13 +197,13 @@ private:
* @return 0 on success
*/
int drop(SqlDB * db);
/**
* Execute an INSERT or REPLACE Sql query.
* Execute an INSERT or REPLACE Sql query.
* @param db The SQL DB
* @param replace Execute an INSERT or a REPLACE
* @param replace Execute an INSERT or a REPLACE
* @return 0 one success
*/
*/
int insert_replace(SqlDB *db, bool replace);
/**

View File

@ -17,30 +17,22 @@
#ifndef HOST_TEMPLATE_H_
#define HOST_TEMPLATE_H_
#include "TemplateSQL.h"
#include "Template.h"
using namespace std;
/**
* Host Template class, it represents the attributes of a Host
*/
class HostTemplate : public TemplateSQL
class HostTemplate : public Template
{
public:
HostTemplate(int tid = -1,
const char separator = '='):
TemplateSQL(table,tid,true,separator,"TEMPLATE"){};
HostTemplate() : Template(true,'=',"TEMPLATE"){};
~HostTemplate(){};
private:
friend class Host;
static const char * table;
static const char * db_bootstrap;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -109,6 +109,15 @@ public:
return (public_img == 1);
};
/**
* Returns true if the image is persistent
* @return true if the image is persistent
*/
bool isPersistent()
{
return (persistent_img == 1);
};
/**
* Set enum type
* @return 0 on success, -1 otherwise
@ -183,16 +192,51 @@ public:
* @param pub true to publish the image
* @return 0 on success
*/
void publish(bool pub)
bool publish(bool pub)
{
bool success = false;
if (pub == true)
{
public_img = 1;
if (!isPersistent())
{
public_img = 1;
success = true;
}
}
else
{
public_img = 0;
success = true;
}
return success;
}
/**
* Set/Unset an image as persistent
* @param persistent true to make an image persistent
* @return 0 on success
*/
bool persistent(bool persis)
{
bool success = false;
if (persis == true)
{
if (!isPublic() && running_vms == 0)
{
persistent_img = 1;
success = true;
}
}
else
{
persistent_img = 0;
success = true;
}
return success;
}
/**
@ -273,9 +317,30 @@ public:
* Removes an Image attribute
* @param name of the attribute
*/
int remove_template_attribute(SqlDB * db, const string& name)
int remove_template_attribute(const string& name)
{
return image_template->remove_attribute(db, name);
return image_template->erase(name);
}
/**
* Adds a new attribute to the template (replacing it if
* already defined), the image's mutex SHOULD be locked
* @param name of the new attribute
* @param value of the new attribute
* @return 0 on success
*/
int replace_template_attribute(
const string& name,
const string& value)
{
SingleAttribute * sattr;
image_template->erase(name);
sattr = new SingleAttribute(name,value);
image_template->set(sattr);
return 0;
}
private:
@ -310,6 +375,11 @@ private:
*/
int public_img;
/**
* Persistency of the Image
*/
int persistent_img;
/**
* Registration time
*/
@ -367,10 +437,8 @@ private:
static void bootstrap(SqlDB * db)
{
ostringstream oss_image(Image::db_bootstrap);
ostringstream oss_templ(ImageTemplate::db_bootstrap);
db->exec(oss_image);
db->exec(oss_templ);
};
@ -402,12 +470,13 @@ protected:
NAME = 2, /* Image name */
TYPE = 3, /* 0) OS 1) CDROM 2) DATABLOCK */
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 = 8, /* Number of VMs using the img */
LIMIT = 9
PERSISTENT = 5, /* Peristency (YES OR NO) */
REGTIME = 6, /* Time of registration */
SOURCE = 7, /* Path to the image */
STATE = 8, /* 0) INIT 1) ALLOCATED */
RUNNING_VMS = 9, /* Number of VMs using the img */
TEMPLATE = 10, /* Image template xml data */
LIMIT = 11
};
static const char * db_names;
@ -428,7 +497,7 @@ protected:
* @param db pointer to the db
* @return 0 on success
*/
virtual int insert(SqlDB *db);
virtual int insert(SqlDB *db, string& error_str);
/**
* Writes/updates the Images data fields in the database.

View File

@ -57,7 +57,8 @@ public:
int allocate (
int uid,
ImageTemplate * img_template,
int * oid);
int * oid,
string& error_str);
/**
* Function to get a Image from the pool, if the object is not in memory
@ -120,34 +121,6 @@ public:
return rc;
};
/** Modify an image attribute in the template (Image MUST be locked)
* @param image pointer to Image
* @param name of the attribute to be changed
* @param new value for the attribute
* @return 0 on success, -1 otherwise
*/
int replace_attribute(
Image * image,
const string& name,
const string& value)
{
SingleAttribute * sattr = new SingleAttribute(name,value);
return image->image_template->replace_attribute(db,sattr);
}
/** Delete an image attribute in the template (Image MUST be locked)
* @param image pointer to Image
* @param name of the attribute to be removed
* @return 0 on success, -1 otherwise
*/
int remove_attribute(
Image * image,
const string& name)
{
return image->image_template->remove_attribute(db, name);
}
/**
* Bootstraps the database table(s) associated to the Image pool
*/

View File

@ -17,29 +17,19 @@
#ifndef IMAGE_TEMPLATE_H_
#define IMAGE_TEMPLATE_H_
#include "TemplateSQL.h"
#include "Template.h"
using namespace std;
/**
* Image Template class, it represents the attributes of a Host
*/
class ImageTemplate : public TemplateSQL
class ImageTemplate : public Template
{
public:
ImageTemplate(int tid = -1,
const char separator = '='):
TemplateSQL(table,tid,true,separator,"TEMPLATE"){};
ImageTemplate() : Template(true,'=',"TEMPLATE"){};
~ImageTemplate(){};
private:
friend class Image;
friend class ImagePool;
static const char * table;
static const char * db_bootstrap;
};
/* -------------------------------------------------------------------------- */

View File

@ -34,11 +34,13 @@ public:
HostPool * _hpool,
time_t _timer_period,
time_t _monitor_period,
const string& _remotes_location,
vector<const Attribute*>& _mads)
:MadManager(_mads),
hpool(_hpool),
timer_period(_timer_period),
monitor_period(_monitor_period)
monitor_period(_monitor_period),
remotes_location(_remotes_location)
{
am.addListener(this);
};
@ -46,7 +48,7 @@ public:
~InformationManager(){};
/**
* This functions starts the associated listener thread, and creates a
* This functions starts the associated listener thread, and creates a
* new thread for the Information Manager. This thread will wait in
* an action loop till it receives ACTION_FINALIZE.
* @return 0 on success.
@ -63,12 +65,12 @@ public:
};
/**
*
*
*/
void load_mads(int uid=0);
/**
*
*
*/
void finalize()
{
@ -90,28 +92,33 @@ private:
* Timer period for the Virtual Machine Manager.
*/
time_t timer_period;
/**
* Host monitoring interval
*/
time_t monitor_period;
/**
* Path for the remote action programs
*/
string remotes_location;
/**
* Action engine for the Manager
*/
ActionManager am;
/**
* Function to execute the Manager action loop method within a new pthread
* Function to execute the Manager action loop method within a new pthread
* (requires C linkage)
*/
friend void * im_action_loop(void *arg);
/**
* Returns a pointer to a Information Manager MAD. The driver is
* Returns a pointer to a Information Manager MAD. The driver is
* searched by its name and owned by gwadmin with uid=0.
* @param name of the driver
* @return the VM driver owned by uid 0, with attribute "NAME" equal to
* @return the VM driver owned by uid 0, with attribute "NAME" equal to
* name or 0 in not found
*/
const InformationManagerDriver * get(

View File

@ -30,7 +30,7 @@ using namespace std;
/**
* InformationManagerDriver provides a base class to implement IM
* Drivers. This class implements the protocol and recover functions
* from the Mad interface. This class may be used to further specialize
* from the Mad interface. This class may be used to further specialize
* the IM driver.
*/
class InformationManagerDriver : public Mad
@ -42,35 +42,28 @@ public:
const map<string,string>& attrs,
bool sudo,
HostPool * pool):
Mad(userid,attrs,sudo),hpool(pool)
{}
;
Mad(userid,attrs,sudo),hpool(pool){};
virtual ~InformationManagerDriver()
{}
;
virtual ~InformationManagerDriver(){};
/**
* Implements the IM driver protocol.
* @param message the string read from the driver
*/
void protocol(
string& message);
void protocol(string& message);
/**
* TODO: What do we need here? just poll the Hosts to recover..
*/
void recover();
/**
* Sends a monitor request to the MAD: "MONITOR ID HOSTNAME -"
* @param oid the virtual machine id.
* @param host the hostname
* @param conf the filename of the deployment file
* @param update the remotes directory in host
*/
void monitor (
int oid,
const string& host) const;
void monitor(int oid, const string& host, bool update) const;
private:
/**
@ -78,8 +71,7 @@ private:
*/
HostPool * hpool;
friend class InformationManager;
friend class InformationManager;
};
/* -------------------------------------------------------------------------- */

View File

@ -284,7 +284,7 @@ private:
* @param db pointer to the database.
* @return 0 on success.
*/
int insert(SqlDB * db);
int insert(SqlDB * db, string& error_str);
/**
* Leases are added/removed/updated through add/del interface

View File

@ -203,7 +203,7 @@ public:
static string version()
{
return "OpenNebula 1.5.0";
return "OpenNebula 1.9.80";
};
void start();
@ -232,10 +232,12 @@ private:
{
nebula_location = "/";
mad_location = "/usr/lib/one/mads/";
etc_location = "/etc/one/";
log_location = "/var/log/one/";
var_location = "/var/lib/one/";
mad_location = "/usr/lib/one/mads/";
etc_location = "/etc/one/";
log_location = "/var/log/one/";
var_location = "/var/lib/one/";
hook_location = "/usr/share/one/hooks/";
remotes_location = "/usr/lib/one/remotes/";
}
else
{
@ -246,10 +248,12 @@ private:
nebula_location += "/";
}
mad_location = nebula_location + "lib/mads/";
etc_location = nebula_location + "etc/";
log_location = nebula_location + "var/";
var_location = nebula_location + "var/";
mad_location = nebula_location + "lib/mads/";
etc_location = nebula_location + "etc/";
log_location = nebula_location + "var/";
var_location = nebula_location + "var/";
hook_location = nebula_location + "share/hooks/";
remotes_location = nebula_location + "lib/remotes/";
}
};
@ -345,6 +349,9 @@ private:
string etc_location;
string log_location;
string var_location;
string hook_location;
string remotes_location;
string hostname;
// ---------------------------------------------------------------

View File

@ -64,21 +64,29 @@ public:
}
static void log(
const char * module,
const Log::MessageType type,
const char * message)
const char * module,
const Log::MessageType type,
const char * message)
{
logger->log(module,type,message);
};
static void log(
const char * module,
const Log::MessageType type,
const char * module,
const Log::MessageType type,
const ostringstream& message)
{
logger->log(module,type,message.str().c_str());
};
static void log(
const char * module,
const Log::MessageType type,
const string& message)
{
logger->log(module,type,message.c_str());
};
private:
NebulaLog(){};
~NebulaLog(){};

View File

@ -49,7 +49,8 @@ protected:
* @return 0 on success
*/
virtual int insert(
SqlDB * db) = 0;
SqlDB * db,
string& error_str) = 0;
/**
* Updates the ObjectSQL in the database.

View File

@ -46,7 +46,7 @@ public:
* @param table the name of the table supporting the pool (to set the oid
* counter). If null the OID counter is not updated.
*/
PoolSQL(SqlDB * _db, const char * table=0);
PoolSQL(SqlDB * _db, const char * table);
virtual ~PoolSQL();
@ -57,7 +57,8 @@ public:
* @return the oid assigned to the object or -1 in case of failure
*/
virtual int allocate(
PoolObjectSQL *objsql);
PoolObjectSQL *objsql,
string& error_str);
/**
* Gets an object from the pool (if needed the object is loaded from the

View File

@ -57,7 +57,7 @@ public:
;
/**
* This functions starts the associated listener thread (XML server), and
* This functions starts the associated listener thread (XML server), and
* creates a new thread for the Request Manager. This thread will wait in
* an action loop till it receives ACTION_FINALIZE.
* @return 0 on success.
@ -74,7 +74,7 @@ public:
};
/**
*
*
*/
void finalize()
{
@ -110,17 +110,17 @@ private:
* Pointer to the Host Pool, to access hosts
*/
HostPool * hpool;
/**
* Pointer to the VN Pool, to access Virtual Netowrks
*/
VirtualNetworkPool * vnpool;
/**
* Pointer to the User Pool, to access users
*/
UserPool * upool;
/**
* Pointer to the Image Pool, to access images
*/
@ -130,10 +130,10 @@ private:
* Port number where the connection will be open
*/
int port;
/*
* FD for the XML server socket
*/
*/
int socket_fd;
/**
@ -164,16 +164,16 @@ private:
void do_action(const string & action, void * arg);
void register_xml_methods();
int setup_socket();
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Error Messages
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
/**
* Logs authorization errors
* @param method name of the RM method where the error arose
@ -183,17 +183,17 @@ private:
* @param id id of the object, -1 for Pool
* @returns string for logging
*/
static string authorization_error (const string& method,
const string &action,
const string &object,
static string authorization_error (const string& method,
const string &action,
const string &object,
int uid,
int id)
{
ostringstream oss;
oss << "[" << method << "]" << " User [" << uid << "] not authorized"
<< " to perform " << action << " on " << object;
oss << "[" << method << "]" << " User [" << uid << "] not authorized"
<< " to perform " << action << " on " << object;
if ( id != -1 )
{
oss << " [" << id << "].";
@ -202,25 +202,25 @@ private:
{
oss << " Pool";
}
return oss.str();
}
/**
* Logs authenticate errors
* @param method name of the RM method where the error arose
* @returns string for logging
*/
*/
static string authenticate_error (const string& method)
{
ostringstream oss;
oss << "[" << method << "]" << " User couldn't be authenticated," <<
" aborting call.";
return oss.str();
}
/**
* Logs get object errors
* @param method name of the RM method where the error arose
@ -228,52 +228,52 @@ private:
* @param id of the object over which the get failed
* @returns string for logging
*/
static string get_error (const string& method,
const string &object,
static string get_error (const string& method,
const string &object,
int id)
{
ostringstream oss;
oss << "[" << method << "]" << " Error getting " <<
oss << "[" << method << "]" << " Error getting " <<
object;
if ( id != -1 )
{
oss << " [" << id << "].";
}
else
{
oss << " Pool.";
oss << " Pool.";
}
return oss.str();
}
/**
* Logs action errors
* @param method name of the RM method where the error arose
* @param action that triggered the error
* @param object over which the action was applied
* @param id id of the object, -1 for Pool, -2 for no-id objects
* @param id id of the object, -1 for Pool, -2 for no-id objects
* (allocate error, parse error)
* @param rc returned error code (NULL to ignore)
* @returns string for logging
*/
static string action_error (const string& method,
const string &action,
const string &object,
const string &action,
const string &object,
int id,
int rc)
{
ostringstream oss;
oss << "[" << method << "]" << " Error trying to " << action << " "
<< object;
switch(id)
{
case -2:
break;
break;
case -1:
oss << "Pool.";
break;
@ -281,15 +281,15 @@ private:
oss << " [" << id << "].";
break;
}
if ( rc != 0 )
{
oss << " Returned error code [" << rc << "].";
oss << " Returned error code [" << rc << "].";
}
return oss.str();
}
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// XML-RPC Methods
@ -297,7 +297,7 @@ private:
// ----------------------------------------------------------------------
/* ---------------------------------------------------------------------- */
/* Virtual Machine Interface */
/* Virtual Machine Interface */
/* ---------------------------------------------------------------------- */
class VirtualMachineAllocate: public xmlrpc_c::method
{
@ -327,9 +327,9 @@ private:
ImagePool * ipool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class VirtualMachineDeploy: public xmlrpc_c::method
{
public:
@ -356,7 +356,7 @@ private:
HostPool * hpool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class VirtualMachineAction: public xmlrpc_c::method
@ -384,7 +384,7 @@ private:
};
/* ---------------------------------------------------------------------- */
class VirtualMachineMigrate: public xmlrpc_c::method
{
public:
@ -410,10 +410,10 @@ private:
VirtualMachinePool * vmpool;
HostPool * hpool;
UserPool * upool;
};
};
/* ---------------------------------------------------------------------- */
class VirtualMachineInfo: public xmlrpc_c::method
{
public:
@ -478,7 +478,7 @@ private:
vmpool(_vmpool),
upool(_upool)
{
_signature="A:si";
_signature="A:sibi";
_help="Returns the virtual machine pool";
};
@ -491,10 +491,10 @@ private:
private:
VirtualMachinePool * vmpool;
UserPool * upool;
};
};
/* ---------------------------------------------------------------------- */
/* Host Interface */
/* Host Interface */
/* ---------------------------------------------------------------------- */
class HostAllocate: public xmlrpc_c::method
@ -522,7 +522,7 @@ private:
};
/* ---------------------------------------------------------------------- */
class HostInfo: public xmlrpc_c::method
{
public:
@ -548,7 +548,7 @@ private:
};
/* ---------------------------------------------------------------------- */
class HostPoolInfo: public xmlrpc_c::method
{
public:
@ -573,7 +573,7 @@ private:
};
/* ---------------------------------------------------------------------- */
class HostDelete: public xmlrpc_c::method
{
public:
@ -597,9 +597,9 @@ private:
HostPool * hpool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class HostEnable: public xmlrpc_c::method
{
public:
@ -622,7 +622,7 @@ private:
private:
HostPool * hpool;
UserPool * upool;
};
};
/* ---------------------------------------------------------------------- */
/* Cluster Interface */
@ -784,10 +784,10 @@ private:
/* ---------------------------------------------------------------------- */
/* Virtual Network Interface */
/* Virtual Network Interface */
/* ---------------------------------------------------------------------- */
class VirtualNetworkAllocate: public xmlrpc_c::method
{
public:
@ -810,10 +810,10 @@ private:
private:
VirtualNetworkPool * vnpool;
UserPool * upool;
};
};
/* ---------------------------------------------------------------------- */
class VirtualNetworkInfo: public xmlrpc_c::method
{
public:
@ -832,14 +832,14 @@ private:
void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retvalP);
private:
VirtualNetworkPool * vnpool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class VirtualNetworkPoolInfo: public xmlrpc_c::method
{
public:
@ -862,7 +862,7 @@ private:
VirtualNetworkPool * vnpool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class VirtualNetworkPublish: public xmlrpc_c::method
@ -916,10 +916,10 @@ private:
};
/* ---------------------------------------------------------------------- */
/* User Management Interface */
/* User Management Interface */
/* ---------------------------------------------------------------------- */
class UserAllocate: public xmlrpc_c::method
{
public:
@ -1001,7 +1001,7 @@ private:
private:
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
/* Image Pool Interface */
/* ---------------------------------------------------------------------- */
@ -1027,10 +1027,10 @@ private:
private:
ImagePool * ipool;
UserPool * upool;
};
};
/* ---------------------------------------------------------------------- */
class ImageDelete: public xmlrpc_c::method
{
public:
@ -1052,8 +1052,8 @@ private:
private:
ImagePool * ipool;
UserPool * upool;
};
};
/* ---------------------------------------------------------------------- */
class ImageInfo: public xmlrpc_c::method
@ -1077,8 +1077,8 @@ private:
private:
ImagePool * ipool;
UserPool * upool;
};
};
/* ---------------------------------------------------------------------- */
class ImageUpdate: public xmlrpc_c::method
@ -1103,7 +1103,7 @@ private:
ImagePool * ipool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class ImageRemoveAttribute: public xmlrpc_c::method
@ -1128,7 +1128,7 @@ private:
ImagePool * ipool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class ImagePublish: public xmlrpc_c::method
@ -1153,7 +1153,32 @@ private:
ImagePool * ipool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class ImagePersistent: public xmlrpc_c::method
{
public:
ImagePersistent(ImagePool * _ipool,
UserPool * _upool):
ipool(_ipool),
upool(_upool)
{
_signature="A:sib";
_help="Make an Image (non)persistent";
};
~ImagePersistent(){};
void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retvalP);
private:
ImagePool * ipool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class ImageEnable: public xmlrpc_c::method
@ -1178,7 +1203,7 @@ private:
ImagePool * ipool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class ImagePoolInfo: public xmlrpc_c::method
@ -1205,7 +1230,7 @@ private:
};
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -21,6 +21,9 @@
#include <map>
#include <vector>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include "Attribute.h"
using namespace std;
@ -165,12 +168,36 @@ public:
friend ostream& operator<<(ostream& os, const Template& t);
/**
* Rebuilds the template from a xml formatted string
* @param xml_str The xml-formatted string
*
* @return 0 on success, -1 otherwise
*/
int from_xml(const string &xml_str);
protected:
/**
* The template attributes
*/
multimap<string,Attribute *> attributes;
/**
* Builds a SingleAttribute from the given node
* @param node The xml element to build the attribute from.
*
* @return the attribute, or 0 if the node doesn't contain a single att.
*/
Attribute* single_xml_att(const xmlNode * node);
/**
* Builds a VectorAttribute from the given node
* @param node The xml element to build the attribute from.
*
* @return the attribute, or 0 if the node doesn't contain a vector att.
*/
Attribute* vector_xml_att(const xmlNode * node);
private:
bool replace_mode;

View File

@ -1,130 +0,0 @@
/* ------------------------------------------------------------------------ */
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* ------------------------------------------------------------------------ */
#ifndef TEMPLATE_SQL_H_
#define TEMPLATE_SQL_H_
#include <iostream>
#include <map>
#include <vector>
#include "Template.h"
#include "SqlDB.h"
#include "ObjectSQL.h"
using namespace std;
/**
* SQL Template class, it provides DB support for template objects
*/
class TemplateSQL : public Template, public ObjectSQL
{
public:
TemplateSQL(
const char * _table,
int template_id = -1,
bool replace = false,
const char separator = '=',
const char * xml_root = "TEMPLATE"):
Template(replace,separator,xml_root),table(_table),id(template_id)
{};
virtual ~TemplateSQL(){};
protected:
//Database implementation variables
const char * table;
static const char * db_names;
//Template attributes
/**
* Template unique identification.
*/
int id;
/**
* Writes the template in the DB
* @param db pointer to the database.
* @return 0 on success.
*/
int insert(SqlDB * db);
/**
* Updates the template in the DB
* @param db pointer to the database.
* @return 0 on success.
*/
int update(SqlDB *db);
/**
* Reads the template (identified by its id) from the DB
* @param db pointer to the database.
* @return 0 on success.
*/
int select(SqlDB *db);
/**
* Removes the template from the DB
* @param db pointer to the database.
*/
int drop(SqlDB *db);
/**
* Execute an INSERT or REPLACE Sql query.
* @param db The SQL DB
* @param replace Execute an INSERT or a REPLACE
* @return 0 one success
*/
int insert_replace(SqlDB *db, bool replace);
/**
* Removes a template attribute from the DB. If there are multiple
* attributes with the same name, only one will be replaced. The
* attribute MUST be allocated in the heap.
* @param db pointer to the database.
* @param attribute pointer to the new attribute.
*/
int replace_attribute(SqlDB * db, Attribute * attribute);
/**
* Insert a given attribute (MUST be allocated in the heap) in the template
* and updates the DB.
* @param db pointer to the database.
* @param attribute pointer to the new attribute
*/
int insert_attribute(SqlDB * db, Attribute * attribute);
/**
* Remove a given attribute from the template and the DB.
* @param db pointer to the database.
* @param name name of the attribute
*/
int remove_attribute(SqlDB * db, const string& name);
/**
* Callback to recover template attributes (TemplateSQL::select)
*/
int select_cb(void *nil, int num, char **values, char **names);
};
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
#endif /*TEMPLATE_SQL_H_*/

View File

@ -235,7 +235,7 @@ protected:
* @param db pointer to the db
* @return 0 on success
*/
virtual int insert(SqlDB *db);
virtual int insert(SqlDB *db, string& error_str);
/**
* Writes/updates the User data fields in the database.

View File

@ -48,10 +48,11 @@ public:
* @return the oid assigned to the object or -1 in case of failure
*/
int allocate (
int * oid,
string hostname,
string password,
bool enabled);
int * oid,
string hostname,
string password,
bool enabled,
string& error_str);
/**
* Function to get a User from the pool, if the object is not in memory

View File

@ -598,6 +598,28 @@ public:
vm_template->get(str,value);
}
/**
* Adds a new attribute to the template (replacing it if
* already defined), the vm's mutex SHOULD be locked
* @param name of the new attribute
* @param value of the new attribute
* @return 0 on success
*/
int replace_template_attribute(
string& name,
string& value)
{
SingleAttribute * sattr;
vm_template->erase(name);
sattr = new SingleAttribute(name,value);
vm_template->set(sattr);
return 0;
}
/**
* Generates a XML string for the template of the VM
* @param xml the string to store the XML description.
@ -713,7 +735,7 @@ public:
* Get all disk images for this Virtual Machine
* @return 0 if success
*/
int get_disk_images();
int get_disk_images(string &error_str);
/**
* Releases all disk images taken by this Virtual Machine
@ -869,11 +891,9 @@ private:
static void bootstrap(SqlDB * db)
{
ostringstream oss_vm(VirtualMachine::db_bootstrap);
ostringstream oss_tmpl(VirtualMachineTemplate::db_bootstrap);
ostringstream oss_hist(History::db_bootstrap);
db->exec(oss_vm);
db->exec(oss_tmpl);
db->exec(oss_hist);
};
@ -925,44 +945,6 @@ private:
return -1;
};
/**
* Updates the template of a VM, adding a new attribute (replacing it if
* already defined), the vm's mutex SHOULD be locked
* @param db pointer to the database
* @param name of the new attribute
* @param value of the new attribute
* @return 0 on success
*/
int update_template_attribute(
SqlDB * db,
string& name,
string& value)
{
SingleAttribute * sattr;
int rc;
sattr = new SingleAttribute(name,value);
rc = vm_template->replace_attribute(db,sattr);
if (rc != 0)
{
delete sattr;
}
return rc;
}
/**
* Inserts a new attribute in the template of a VM, also the DB is
* updated. The vm's mutex SHOULD be locked
* @param db pointer to the database
* @param attribute the new attribute for the template
* @return 0 on success
*/
int insert_template_attribute(SqlDB * db, Attribute * attribute)
{
return vm_template->insert_attribute(db,attribute);
}
// -------------------------------------------------------------------------
// Attribute Parser
@ -1023,7 +1005,8 @@ protected:
NET_TX = 11,
NET_RX = 12,
LAST_SEQ = 13,
LIMIT = 14
TEMPLATE = 14,
LIMIT = 15
};
static const char * table;
@ -1044,7 +1027,7 @@ protected:
* @param db pointer to the db
* @return 0 on success
*/
virtual int insert(SqlDB * db);
virtual int insert(SqlDB * db, string& error_str);
/**
* Writes/updates the Virtual Machine data fields in the database.
@ -1074,6 +1057,18 @@ protected:
* @return 0 on success
*/
static int dump(ostringstream& oss, int num, char ** values, char ** names);
/**
* Dumps the contect of a set of VirtualMachine objects in the given stream
* using XML format
* @param oss the output stream
* @param num the number of columns read from the DB
* @param names the column names
* @param vaues the column values
* @return 0 on success
*/
static int dump_extended( ostringstream& oss,
int num, char ** values, char ** names);
};
#endif /*VIRTUAL_MACHINE_H_*/

View File

@ -32,7 +32,9 @@ class VirtualMachinePool : public PoolSQL
{
public:
VirtualMachinePool(SqlDB * db, vector<const Attribute *> hook_mads);
VirtualMachinePool(SqlDB * db,
vector<const Attribute *> hook_mads,
const string& hook_location);
~VirtualMachinePool(){};
@ -48,8 +50,9 @@ public:
int allocate (
int uid,
VirtualMachineTemplate *vm_template,
int * oid,
bool on_hold = false);
int * oid,
string& error_str,
bool on_hold = false);
/**
* Function to get a VM from the pool, if the object is not in memory
@ -90,22 +93,6 @@ public:
// Virtual Machine DB access functions
//--------------------------------------------------------------------------
/**
* Updates the template of a VM, adding a new attribute (replacing it if
* already defined), the vm's mutex SHOULD be locked
* @param vm pointer to the virtual machine object
* @param name of the new attribute
* @param value of the new attribute
* @return 0 on success
*/
int update_template_attribute(
VirtualMachine * vm,
string& name,
string& value)
{
return vm->update_template_attribute(db,name,value);
}
/**
* Updates the history record of a VM, the vm's mutex SHOULD be locked
* @param vm pointer to the virtual machine object
@ -145,7 +132,24 @@ public:
*
* @return 0 on success
*/
int dump(ostringstream& oss, const string& where);
int dump(ostringstream& oss, const string& where)
{
return dump(oss, true, -1, where);
}
/**
* Dumps the VM pool in XML format. A filter can be also added to the query
* Also the hostname where the VirtualMachine is running is added to the
* pool
* @param oss the output stream to dump the pool contents
* @param where filter for the objects, defaults to all
* @param extended condition to include history and username data
* @param state include only VMs in this state. -1 means any state,
* except DONE
*
* @return 0 on success
*/
int dump(ostringstream& oss, bool extended, int state, const string& where);
private:
/**
@ -166,6 +170,17 @@ private:
* @return 0 on success
*/
int dump_cb(void * _oss, int num, char **values, char **names);
/**
* Callback function to get output the vm pool in XML format
* (VirtualMachinePool::dump)
* @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 dump_extended_cb(void * _oss, int num, char **values, char **names);
};
#endif /*VIRTUAL_MACHINE_POOL_H_*/

View File

@ -17,29 +17,25 @@
#ifndef VIRTUAL_MACHINE_TEMPLATE_H_
#define VIRTUAL_MACHINE_TEMPLATE_H_
#include "TemplateSQL.h"
#include "Template.h"
using namespace std;
/**
* Virtual Machine Template class, it represents a VM configuration file.
*/
class VirtualMachineTemplate : public TemplateSQL
class VirtualMachineTemplate : public Template
{
public:
VirtualMachineTemplate(int tid = -1):
TemplateSQL(table,tid,false,'=',"TEMPLATE"){};
VirtualMachineTemplate():
Template(false,'=',"TEMPLATE"){};
~VirtualMachineTemplate(){};
private:
friend class VirtualMachine;
static const char * table;
static const char * db_bootstrap;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -313,11 +313,9 @@ private:
static void bootstrap(SqlDB * db)
{
ostringstream oss_vnet(VirtualNetwork::db_bootstrap);
ostringstream oss_templ(VirtualNetworkTemplate::db_bootstrap);
ostringstream oss_lease(Leases::db_bootstrap);
db->exec(oss_vnet);
db->exec(oss_templ);
db->exec(oss_lease);
};
@ -337,34 +335,6 @@ private:
int vn_drop(SqlDB * db);
/**
* Updates the template of a VNW, adding a new attribute (replacing it if
* already defined), the VN's mutex SHOULD be locked
* @param db pointer to the DB
* @param name of the new attribute
* @param value of the new attribute
* @return 0 on success
*/
int update_template_attribute(
SqlDB * db,
string& name,
string& value)
{
SingleAttribute * sattr;
int rc;
sattr = new SingleAttribute(name,value);
rc = vn_template->replace_attribute(db,sattr);
if (rc != 0)
{
delete sattr;
}
return rc;
}
protected:
//**************************************************************************
@ -387,7 +357,8 @@ protected:
TYPE = 3,
BRIDGE = 4,
PUBLIC = 5,
LIMIT = 6
TEMPLATE = 6,
LIMIT = 7
};
static const char * table;
@ -408,7 +379,7 @@ protected:
* @param db pointer to the db
* @return 0 on success
*/
int insert(SqlDB * db);
int insert(SqlDB * db, string& error_str);
/**
* Writes/updates the Virtual Network data fields in the database.
@ -428,9 +399,7 @@ protected:
{
int rc;
rc = vn_template->drop(db);
rc += leases->drop(db);
rc = leases->drop(db);
rc += vn_drop(db);

View File

@ -49,7 +49,8 @@ public:
int allocate (
int uid,
VirtualNetworkTemplate * vn_template,
int * oid);
int * oid,
string& error_str);
/**
* Function to get a VN from the pool, if the object is not in memory
@ -96,22 +97,6 @@ public:
*/
void authorize_nic(VectorAttribute * nic, AuthRequest * ar);
/**
* Updates the template of a VN, adding a new attribute (replacing it if
* already defined), the VN's mutex SHOULD be locked
* @param vn pointer to the virtual network object
* @param name of the new attribute
* @param value of the new attribute
* @return 0 on success
*/
int update_template_attribute(
VirtualNetwork * vn,
string& name,
string& value)
{
return vn->update_template_attribute(db,name,value);
};
/**
* Bootstraps the database table(s) associated to the VirtualNetwork pool
*/

View File

@ -17,29 +17,22 @@
#ifndef VIRTUAL_NETWORK_TEMPLATE_H_
#define VIRTUAL_NETWORK_TEMPLATE_H_
#include "TemplateSQL.h"
#include "Template.h"
using namespace std;
/**
* Virtual Network Template class, it represents a VN configuration file.
*/
class VirtualNetworkTemplate : public TemplateSQL
class VirtualNetworkTemplate : public Template
{
public:
VirtualNetworkTemplate(int tid = -1):
TemplateSQL(table,tid,false,'=',"TEMPLATE"){};
VirtualNetworkTemplate():
Template(false,'=',"TEMPLATE"){};
~VirtualNetworkTemplate(){};
private:
friend class VirtualNetwork;
static const char * table;
static const char * db_bootstrap;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -14,10 +14,42 @@
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "VirtualNetworkTemplate.h"
#ifndef MEM_COLLECTOR_H_
#define MEM_COLLECTOR_H_
const char * VirtualNetworkTemplate::table = "vn_template";
#define MEM_COLLECTOR_CHUNK 100
const char * VirtualNetworkTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS"
" vn_template (id INTEGER, name TEXT, type INTEGER, value TEXT)";
/**
* mem_collector. A simple struct to track strdup'ed strings in lex parsers.
* It prevents memory leaks in case of parse errors
*/
typedef struct mem_collector_
{
char** str_buffer;
int size;
int next;
} mem_collector;
/**
* Initialize mem_collector internal memory buffers. MUST be called before
* using any relared function
* @param mc pointer to the mem_collector
*/
void mem_collector_init(mem_collector * mc);
/**
* Frees mem_collector internal resources.
* @param mc pointer to the mem_collector
*/
void mem_collector_cleanup(mem_collector * mc);
/**
* Strdup's a string
* @param mc pointer to the mem_collector
* @param str string to be copied
* @return pointer to the new string
*/
char * mem_collector_strdup(mem_collector *mc, const char * str);
#endif /*MEM_COLLECTOR_H_*/

View File

@ -99,7 +99,7 @@ if [ -z "$ROOT" ] ; then
RUN_LOCATION="/var/run/one"
LOCK_LOCATION="/var/lock/one"
INCLUDE_LOCATION="/usr/include"
SHARE_LOCATION="/usr/share/doc/opennebula"
SHARE_LOCATION="/usr/share/one"
if [ "$CLIENT" = "no" ]; then
MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \
@ -151,10 +151,9 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \
$ETC_LOCATION/im_xen \
$ETC_LOCATION/im_ec2 \
$ETC_LOCATION/im_eh \
$ETC_LOCATION/vmm_kvm \
$ETC_LOCATION/vmm_xen \
$ETC_LOCATION/vmm_ec2 \
$ETC_LOCATION/vmm_eh \
$ETC_LOCATION/vmm_sh \
$ETC_LOCATION/tm_nfs \
$ETC_LOCATION/tm_ssh \
$ETC_LOCATION/tm_dummy \
@ -164,7 +163,13 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \
$ETC_LOCATION/ec2query_templates \
$ETC_LOCATION/occi_templates"
LIB_DIRS="$LIB_LOCATION/im_probes \
LIB_DIRS="$LIB_LOCATION/remotes \
$LIB_LOCATION/remotes/im \
$LIB_LOCATION/remotes/im/common.d \
$LIB_LOCATION/remotes/im/kvm.d \
$LIB_LOCATION/remotes/im/xen.d \
$LIB_LOCATION/remotes/vmm/xen \
$LIB_LOCATION/remotes/vmm/kvm \
$LIB_LOCATION/ruby \
$LIB_LOCATION/ruby/OpenNebula \
$LIB_LOCATION/ruby/cloud/ \
@ -207,20 +212,25 @@ INSTALL_FILES[2]="LIB_FILES:$LIB_LOCATION"
INSTALL_FILES[3]="RUBY_LIB_FILES:$LIB_LOCATION/ruby"
INSTALL_FILES[4]="RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula"
INSTALL_FILES[5]="MADS_LIB_FILES:$LIB_LOCATION/mads"
INSTALL_FILES[6]="IM_PROBES_LIB_FILES:$LIB_LOCATION/im_probes"
INSTALL_FILES[7]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs"
INSTALL_FILES[8]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh"
INSTALL_FILES[9]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy"
INSTALL_FILES[10]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm"
INSTALL_FILES[11]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples"
INSTALL_FILES[12]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm"
INSTALL_FILES[13]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks"
INSTALL_FILES[14]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud"
INSTALL_FILES[15]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe"
INSTALL_FILES[16]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views"
INSTALL_FILES[17]="ECO_BIN_FILES:$BIN_LOCATION"
INSTALL_FILES[18]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi"
INSTALL_FILES[19]="OCCI_BIN_FILES:$BIN_LOCATION"
INSTALL_FILES[6]="IM_PROBES_FILES:$LIB_LOCATION/remotes/im"
INSTALL_FILES[7]="IM_PROBES_COMMON_FILES:$LIB_LOCATION/remotes/im/common.d"
INSTALL_FILES[8]="IM_PROBES_KVM_FILES:$LIB_LOCATION/remotes/im/kvm.d"
INSTALL_FILES[9]="IM_PROBES_XEN_FILES:$LIB_LOCATION/remotes/im/xen.d"
INSTALL_FILES[10]="VMM_SH_KVM_SCRIPTS:$LIB_LOCATION/remotes/vmm/kvm"
INSTALL_FILES[11]="VMM_SH_XEN_SCRIPTS:$LIB_LOCATION/remotes/vmm/xen"
INSTALL_FILES[12]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs"
INSTALL_FILES[13]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh"
INSTALL_FILES[14]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy"
INSTALL_FILES[15]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm"
INSTALL_FILES[16]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples"
INSTALL_FILES[17]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm"
INSTALL_FILES[18]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks"
INSTALL_FILES[19]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud"
INSTALL_FILES[20]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe"
INSTALL_FILES[21]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views"
INSTALL_FILES[22]="ECO_BIN_FILES:$BIN_LOCATION"
INSTALL_FILES[23]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi"
INSTALL_FILES[24]="OCCI_BIN_FILES:$BIN_LOCATION"
INSTALL_ECO_CLIENT_FILES[0]="COMMON_CLOUD_CLIENT_LIB_FILES:$LIB_LOCATION/ruby/cloud"
INSTALL_ECO_CLIENT_FILES[1]="ECO_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/econe"
@ -231,24 +241,21 @@ INSTALL_OCCI_CLIENT_FILES[1]="OCCI_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/occ
INSTALL_OCCI_CLIENT_FILES[2]="OCCI_BIN_CLIENT_FILES:$BIN_LOCATION"
INSTALL_ETC_FILES[0]="ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[1]="VMM_XEN_ETC_FILES:$ETC_LOCATION/vmm_xen"
INSTALL_ETC_FILES[2]="VMM_KVM_ETC_FILES:$ETC_LOCATION/vmm_kvm"
INSTALL_ETC_FILES[3]="VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2"
INSTALL_ETC_FILES[4]="VMM_EH_ETC_FILES:$ETC_LOCATION/vmm_eh"
INSTALL_ETC_FILES[5]="IM_XEN_ETC_FILES:$ETC_LOCATION/im_xen"
INSTALL_ETC_FILES[6]="IM_KVM_ETC_FILES:$ETC_LOCATION/im_kvm"
INSTALL_ETC_FILES[7]="IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2"
INSTALL_ETC_FILES[8]="IM_EH_ETC_FILES:$ETC_LOCATION/im_eh"
INSTALL_ETC_FILES[9]="TM_NFS_ETC_FILES:$ETC_LOCATION/tm_nfs"
INSTALL_ETC_FILES[10]="TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh"
INSTALL_ETC_FILES[11]="TM_DUMMY_ETC_FILES:$ETC_LOCATION/tm_dummy"
INSTALL_ETC_FILES[12]="TM_LVM_ETC_FILES:$ETC_LOCATION/tm_lvm"
INSTALL_ETC_FILES[13]="HM_ETC_FILES:$ETC_LOCATION/hm"
INSTALL_ETC_FILES[14]="AUTH_ETC_FILES:$ETC_LOCATION/auth"
INSTALL_ETC_FILES[15]="ECO_ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[16]="ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates"
INSTALL_ETC_FILES[17]="OCCI_ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[18]="OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates"
INSTALL_ETC_FILES[1]="VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2"
INSTALL_ETC_FILES[2]="VMM_EH_ETC_FILES:$ETC_LOCATION/vmm_eh"
INSTALL_ETC_FILES[3]="VMM_SH_ETC_FILES:$ETC_LOCATION/vmm_sh"
INSTALL_ETC_FILES[4]="IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2"
INSTALL_ETC_FILES[5]="IM_EH_ETC_FILES:$ETC_LOCATION/im_eh"
INSTALL_ETC_FILES[6]="TM_NFS_ETC_FILES:$ETC_LOCATION/tm_nfs"
INSTALL_ETC_FILES[7]="TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh"
INSTALL_ETC_FILES[8]="TM_DUMMY_ETC_FILES:$ETC_LOCATION/tm_dummy"
INSTALL_ETC_FILES[9]="TM_LVM_ETC_FILES:$ETC_LOCATION/tm_lvm"
INSTALL_ETC_FILES[10]="HM_ETC_FILES:$ETC_LOCATION/hm"
INSTALL_ETC_FILES[11]="AUTH_ETC_FILES:$ETC_LOCATION/auth"
INSTALL_ETC_FILES[14]="ECO_ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[15]="ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates"
INSTALL_ETC_FILES[16]="OCCI_ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[17]="OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates"
#-------------------------------------------------------------------------------
# Binary files, to be installed under $BIN_LOCATION
@ -278,10 +285,7 @@ LIB_FILES=""
# Ruby library files, to be installed under $LIB_LOCATION/ruby
#-------------------------------------------------------------------------------
RUBY_LIB_FILES="src/mad/ruby/one_mad.rb \
src/mad/ruby/one_ssh.rb \
src/mad/ruby/ThreadScheduler.rb \
src/mad/ruby/ActionManager.rb \
RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \
src/mad/ruby/CommandManager.rb \
src/mad/ruby/OpenNebulaDriver.rb \
src/mad/ruby/VirtualMachineDriver.rb \
@ -306,29 +310,33 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \
src/oca/ruby/OpenNebula/VirtualNetworkPool.rb \
src/oca/ruby/OpenNebula/Image.rb \
src/oca/ruby/OpenNebula/ImagePool.rb \
src/oca/ruby/OpenNebula/ImageRepository.rb \
src/oca/ruby/OpenNebula/Cluster.rb \
src/oca/ruby/OpenNebula/ClusterPool.rb \
src/oca/ruby/OpenNebula/XMLUtils.rb"
#-------------------------------------------------------------------------------
# Driver executable files, to be installed under $LIB_LOCATION/mads
#-------------------------------------------------------------------------------
MADS_LIB_FILES="src/mad/sh/madcommon.sh \
src/tm_mad/tm_common.sh \
src/vmm_mad/xen/one_vmm_xen.rb \
src/vmm_mad/xen/one_vmm_xen \
src/vmm_mad/kvm/one_vmm_kvm.rb \
src/vmm_mad/kvm/one_vmm_kvm \
src/vmm_mad/sh/one_vmm_sh.rb \
src/vmm_mad/sh/one_vmm_sh \
src/vmm_mad/ec2/one_vmm_ec2.rb \
src/vmm_mad/ec2/one_vmm_ec2 \
src/vmm_mad/eh/one_vmm_eh.rb \
src/vmm_mad/eh/one_vmm_eh \
src/vmm_mad/dummy/one_vmm_dummy.rb \
src/vmm_mad/dummy/one_vmm_dummy \
src/im_mad/im_ssh/one_im_ssh.rb \
src/im_mad/im_ssh/one_im_ssh \
src/im_mad/ec2/one_im_ec2.rb \
src/im_mad/ec2/one_im_ec2 \
src/im_mad/eh/one_im_eh.rb \
src/im_mad/eh/one_im_eh \
src/im_mad/dummy/one_im_dummy.rb \
src/im_mad/dummy/one_im_dummy \
src/tm_mad/one_tm \
src/tm_mad/one_tm.rb \
src/hm_mad/one_hm.rb \
@ -337,14 +345,45 @@ MADS_LIB_FILES="src/mad/sh/madcommon.sh \
src/authm_mad/one_auth_mad"
#-------------------------------------------------------------------------------
# Information Manager Probes, to be installed under $LIB_LOCATION/im_probes
# VMM SH Driver KVM scripts, to be installed under $REMOTES_LOCATION/vmm/kvm
#-------------------------------------------------------------------------------
IM_PROBES_LIB_FILES="src/im_mad/xen/xen.rb \
src/im_mad/kvm/kvm.rb \
src/im_mad/host_probes/architecture.sh \
src/im_mad/host_probes/cpu.sh \
src/im_mad/host_probes/name.sh"
VMM_SH_KVM_SCRIPTS="src/vmm_mad/remotes/kvm/cancel \
src/vmm_mad/remotes/kvm/deploy \
src/vmm_mad/remotes/kvm/kvmrc \
src/vmm_mad/remotes/kvm/migrate \
src/vmm_mad/remotes/kvm/poll \
src/vmm_mad/remotes/kvm/restore \
src/vmm_mad/remotes/kvm/save \
src/vmm_mad/remotes/kvm/shutdown"
#-------------------------------------------------------------------------------
# VMM SH Driver Xen scripts, to be installed under $REMOTES_LOCATION/vmm/xen
#-------------------------------------------------------------------------------
VMM_SH_XEN_SCRIPTS="src/vmm_mad/remotes/xen/cancel \
src/vmm_mad/remotes/xen/deploy \
src/vmm_mad/remotes/xen/xenrc \
src/vmm_mad/remotes/xen/migrate \
src/vmm_mad/remotes/xen/poll \
src/vmm_mad/remotes/xen/restore \
src/vmm_mad/remotes/xen/save \
src/vmm_mad/remotes/xen/shutdown"
#-------------------------------------------------------------------------------
# Information Manager Probes, to be installed under $LIB_LOCATION/remotes
#-------------------------------------------------------------------------------
IM_PROBES_FILES="src/im_mad/remotes/run_probes"
IM_PROBES_COMMON_FILES="src/im_mad/remotes/common.d/architecture.sh \
src/im_mad/remotes/common.d/cpu.sh \
src/im_mad/remotes/common.d/name.sh"
IM_PROBES_XEN_FILES="src/im_mad/remotes/xen.d/xen.rb"
IM_PROBES_KVM_FILES="src/im_mad/remotes/kvm.d/kvm.rb"
#-------------------------------------------------------------------------------
# Transfer Manager commands, to be installed under $LIB_LOCATION/tm_commands
@ -389,37 +428,27 @@ ETC_FILES="share/etc/oned.conf \
#-------------------------------------------------------------------------------
# Virtualization drivers config. files, to be installed under $ETC_LOCATION
# - xen, $ETC_LOCATION/vmm_xen
# - kvm, $ETC_LOCATION/vmm_kvm
# - ec2, $ETC_LOCATION/vmm_ec2
# - eh, $ETC_LOCATION/vmm_eh
# - sh, $ETC_LOCATION/vmm_sh
#-------------------------------------------------------------------------------
VMM_XEN_ETC_FILES="src/vmm_mad/xen/vmm_xenrc \
src/vmm_mad/xen/vmm_xen.conf"
VMM_KVM_ETC_FILES="src/vmm_mad/kvm/vmm_kvmrc \
src/vmm_mad/kvm/vmm_kvm.conf"
VMM_EC2_ETC_FILES="src/vmm_mad/ec2/vmm_ec2rc \
src/vmm_mad/ec2/vmm_ec2.conf"
VMM_EH_ETC_FILES="src/vmm_mad/eh/vmm_ehrc \
src/vmm_mad/eh/vmm_eh.conf"
VMM_SH_ETC_FILES="src/vmm_mad/sh/vmm_shrc \
src/vmm_mad/sh/vmm_sh_kvm.conf \
src/vmm_mad/sh/vmm_sh_xen.conf"
#-------------------------------------------------------------------------------
# Information drivers config. files, to be installed under $ETC_LOCATION
# - xen, $ETC_LOCATION/im_xen
# - kvm, $ETC_LOCATION/im_kvm
# - ec2, $ETC_LOCATION/im_ec2
#-------------------------------------------------------------------------------
IM_XEN_ETC_FILES="src/im_mad/xen/im_xenrc \
src/im_mad/xen/im_xen.conf"
IM_KVM_ETC_FILES="src/im_mad/kvm/im_kvmrc \
src/im_mad/kvm/im_kvm.conf"
IM_EC2_ETC_FILES="src/im_mad/ec2/im_ec2rc \
src/im_mad/ec2/im_ec2.conf"
@ -579,19 +608,6 @@ if [ "$UNINSTALL" = "no" ] ; then
done
fi
# --- Prepare oned.conf ---
if [ "$UNINSTALL" = "no" -a "$CLIENT" = "no" ]; then
TEMPLATE=share/etc/oned.conf.template
SOURCE=share/etc/oned.conf
cp $TEMPLATE $SOURCE
HOOKS_LOCATION=$SHARE_LOCATION/hooks
sed -i -e "s%\[HOOKS_LOCATION\]%$HOOKS_LOCATION%" \
$SOURCE
sed -i -e "s%\[IMAGES_LOCATION\]%$IMAGES_LOCATION%" \
$SOURCE
fi
# --- Install/Uninstall files ---
do_file() {

View File

@ -82,7 +82,7 @@ MAC_PREFIX = "02:00"
# vd KVM virtual disk
#*******************************************************************************
IMAGE_REPOSITORY_PATH = [IMAGES_LOCATION]
#IMAGE_REPOSITORY_PATH = /srv/cloud/var/images
DEFAULT_IMAGE_TYPE = "OS"
DEFAULT_DEVICE_PREFIX = "hd"
@ -103,22 +103,26 @@ DEFAULT_DEVICE_PREFIX = "hd"
# /etc/one/ if OpenNebula was installed in /)
#*******************************************************************************
#IM_MAD = [
# name = "im_xen",
# executable = "one_im_ssh",
# arguments = "im_xen/im_xen.conf" ]
#-------------------------------------------------------------------------------
# KVM Information Driver Manager sample configuration
# KVM Information Driver Manager Configuration
#-------------------------------------------------------------------------------
IM_MAD = [
name = "im_kvm",
executable = "one_im_ssh",
arguments = "im_kvm/im_kvm.conf" ]
arguments = "kvm" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# EC2 Information Driver Manager sample configuration
# XEN Information Driver Manager Configuration
#-------------------------------------------------------------------------------
#IM_MAD = [
# name = "im_xen",
# executable = "one_im_ssh",
# arguments = "xen" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# EC2 Information Driver Manager Configuration
#-------------------------------------------------------------------------------
#IM_MAD = [
# name = "im_ec2",
@ -126,6 +130,12 @@ IM_MAD = [
# arguments = "im_ec2/im_ec2.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Dummy Information Driver Manager Configuration
#-------------------------------------------------------------------------------
#IM_MAD = [ name="im_dummy", executable="one_im_dummy"]
#-------------------------------------------------------------------------------
#*******************************************************************************
# Virtualization Driver Configuration
#*******************************************************************************
@ -147,24 +157,30 @@ IM_MAD = [
# type : driver type, supported drivers: xen, kvm, xml
#*******************************************************************************
#VM_MAD = [
# name = "vmm_xen",
# executable = "one_vmm_xen",
# default = "vmm_xen/vmm_xen.conf",
# type = "xen" ]
#-------------------------------------------------------------------------------
# KVM Virtualization Driver Manager sample configuration
# KVM Virtualization Driver Manager Configuration
#-------------------------------------------------------------------------------
VM_MAD = [
name = "vmm_kvm",
executable = "one_vmm_kvm",
default = "vmm_kvm/vmm_kvm.conf",
executable = "one_vmm_sh",
arguments = "kvm",
default = "vmm_sh/vmm_sh_kvm.conf",
type = "kvm" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# EC2 Virtualization Driver Manager sample configuration
# XEN Virtualization Driver Manager Configuration
#-------------------------------------------------------------------------------
#VM_MAD = [
# name = "vmm_xen",
# executable = "one_vmm_sh",
# arguments = "xen",
# default = "vmm_sh/vmm_sh_xen.conf",
# type = "xen" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# EC2 Virtualization Driver Manager Configuration
# arguments: default values for the EC2 driver, can be an absolute path or
# relative to $ONE_LOCATION/etc (or /etc/one/ if OpenNebula was
# installed in /).
@ -176,6 +192,12 @@ VM_MAD = [
# type = "xml" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Dummy Virtualization Driver Configuration
#-------------------------------------------------------------------------------
#VM_MAD = [ name="vmm_dummy", executable="one_vmm_dummy", type="xml" ]
#-------------------------------------------------------------------------------
#*******************************************************************************
# Transfer Manager Driver Configuration
#*******************************************************************************
@ -192,13 +214,8 @@ VM_MAD = [
# /etc/one/ if OpenNebula was installed in /)
#*******************************************************************************
#TM_MAD = [
# name = "tm_ssh",
# executable = "one_tm",
# arguments = "tm_ssh/tm_ssh.conf" ]
#-------------------------------------------------------------------------------
# NFS Transfer Manager Driver sample configuration
# NFS Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
TM_MAD = [
name = "tm_nfs",
@ -207,7 +224,16 @@ TM_MAD = [
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Dummy Transfer Manager Driver sample configuration
# SSH Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
#TM_MAD = [
# name = "tm_ssh",
# executable = "one_tm",
# arguments = "tm_ssh/tm_ssh.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Dummy Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
#TM_MAD = [
# name = "tm_dummy",
@ -216,7 +242,7 @@ TM_MAD = [
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# LVM Transfer Manager Driver sample configuration
# LVM Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
#TM_MAD = [
# name = "tm_lvm",
@ -244,7 +270,9 @@ TM_MAD = [
# - SHUTDOWN, after the VM is shutdown
# - STOP, after the VM is stopped (including VM image transfers)
# - DONE, after the VM is deleted or shutdown
# command : use absolute path here
# command : path can be absolute or relative to $ONE_LOCATION/share/hooks
# case of self-contained installation or relative to
# /usr/share/one/hooks in case of system-wide installation
# arguments : for the hook. You can access to VM template variables with $
# - $ATTR, the value of an attribute e.g. $NAME or $VMID
# - $ATTR[VAR], the value of a vector e.g. $NIC[MAC]
@ -266,7 +294,7 @@ HM_MAD = [
VM_HOOK = [
name = "image",
on = "DONE",
command = "[HOOKS_LOCATION]/image.rb",
command = "image.rb",
arguments = "$VMID" ]
#-------------------------------------------------------------------------------

View File

@ -26,6 +26,8 @@ DISK = [
target = "sda2",
readonly = "no" ]
DISK = [ IMAGE ="Ubuntu Server" ]
# --- 1 NIC ---
NIC = [ mac="00:ff:72:17:20:27"]

View File

@ -37,6 +37,7 @@ end
client = Client.new()
img_repo = ImageRepository.new
vm = VirtualMachine.new(
VirtualMachine.build_xml(vm_id),
@ -52,17 +53,8 @@ vm.each('TEMPLATE/DISK') do |disk|
Image.build_xml(image_id),
client)
result = image.info
exit -1 if OpenNebula.is_error?(result)
# Disable the Image for a safe overwriting
# image.disable
# Save the image file
result = image.move(source_path, image['SOURCE'])
result = img_repo.update_source(image, source_path)
exit -1 if OpenNebula.is_error?(result)
# image.enable
end
end

View File

@ -16,11 +16,12 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
if [ -z "$ONE_LOCATION" ]; then
if [ -z "$ONE_LOCATION" ]; then
ONE_PID=/var/run/one/oned.pid
ONE_SCHEDPID=/var/run/one/sched.pid
ONE_CONF=/etc/one/oned.conf
ONE_DB=/var/lib/one/one.db
ONE_LOG=/var/log/one/oned.log
ONED=/usr/bin/oned
ONE_SCHEDULER=/usr/bin/mm_sched
@ -31,29 +32,31 @@ else
ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid
ONE_CONF=$ONE_LOCATION/etc/oned.conf
ONE_DB=$ONE_LOCATION/var/one.db
ONE_LOG=$ONE_LOCATION/var/oned.log
ONED=$ONE_LOCATION/bin/oned
ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched
LOCK_FILE=$ONE_LOCATION/var/.lock
fi
fi
setup()
{
PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2`
PORT=$(sed -n '/^[ \t]*PORT/s/^.*PORT\s*=\s*\([0-9]\+\)\s*.*$/\1/p' \
$ONE_CONF)
if [ $? -ne 0 ]; then
echo "Can not find PORT in $ONE_CONF."
exit 1
fi
if [ -f $LOCK_FILE ]; then
if [ -f $ONE_PID ]; then
ONEPID=`cat $ONE_PID`
ps $ONEPID > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first."
exit 1
exit 1
fi
fi
if [ -f $ONE_SCHEDPID ]; then
@ -73,12 +76,12 @@ start()
{
if [ ! -x "$ONED" ]; then
echo "Can not find $ONED."
exit 1
exit 1
fi
if [ ! -x "$ONE_SCHEDULER" ]; then
echo "Can not find $ONE_SCHEDULER."
exit 1
exit 1
fi
if [ ! -f "$ONE_DB" ]; then
@ -91,28 +94,34 @@ start()
fi
fi
fi
# Backup oned.log
if [ "$BACKUP" = "true" ];then
[ -f "$ONE_LOG" ] && cp $ONE_LOG{,.$(date '+%Y%m%d%H%M')}
fi
# Start the one daemon
$ONED -f 2>&1 &
$ONED -f 2>&1 &
LASTRC=$?
LASTPID=$!
if [ $LASTRC -ne 0 ]; then
echo "Error executing $ONED"
exit 1
exit 1
else
echo $LASTPID > $ONE_PID
fi
sleep 1
ps $LASTPID > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error executing $ONED."
exit 1
fi
# Start the scheduler
# The following command line arguments are supported by mm_shed:
# [-p port] to connect to oned - default: 2633
@ -123,7 +132,7 @@ start()
# - default: 30
# [-h host dispatch] max number of VMs dispatched to a given host in each
# scheduling action - default: 1
$ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1&
LASTRC=$?
@ -131,11 +140,11 @@ start()
if [ $LASTRC -ne 0 ]; then
echo "Error executing $ONE_SCHEDULER"
exit 1
exit 1
else
echo $LASTPID > $ONE_SCHEDPID
fi
echo "oned and scheduler started"
}
@ -159,7 +168,7 @@ stop()
kill `cat $ONE_PID` > /dev/null 2>&1
# Kill the scheduler
kill `cat $ONE_SCHEDPID` > /dev/null 2>&1
# Remove pid files
@ -170,6 +179,10 @@ stop()
echo "oned and scheduler stopped"
}
if [ "$1" = "-b" ]; then
BACKUP=true
shift
fi
case "$1" in
start)
@ -180,7 +193,10 @@ case "$1" in
stop
;;
*)
echo "Usage: one {start|stop}" >&2
echo "Usage: one [-b] {start|stop}" >&2
echo "Options:" >&2
echo " -b Backup log file." >&2
exit 3
;;
esac

View File

@ -85,7 +85,13 @@ TESTS=`find $TWD_DIR -name test -type d | grep -v ruby`
for i in $TESTS ; do
cd $BASE_DIR
echo ; echo
echo "#####################################################################"
echo "#####################################################################"
echo "Doing $i ..."
echo "#####################################################################"
echo "#####################################################################"
echo ; echo
cd $i
if [ "$CLEAR" = "yes" ] ; then
@ -95,7 +101,13 @@ for i in $TESTS ; do
scons $BUILD_ARGS
else
for j in `ls test*` ; do
$CALLER ./$j $TEST_ARGS
if [ -x $j ] ; then
echo ; echo "---------------------------------------------------------------------"
echo "Test Program: $j"
echo "---------------------------------------------------------------------"
$CALLER ./$j $TEST_ARGS
echo "---------------------------------------------------------------------"
fi
done
fi
done

View File

@ -100,9 +100,10 @@ void AuthManagerDriver::protocol(
else
return;
getline(is,info);
if (action == "LOG")
{
getline(is,info);
NebulaLog::log("AuM",Log::INFO,info.c_str());
}
else if (result == "SUCCESS")
@ -111,7 +112,6 @@ void AuthManagerDriver::protocol(
}
else
{
getline(is,info);
authm->notify_request(id,false,info);
}

View File

@ -31,6 +31,9 @@
#include <ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
using namespace std;
@ -54,7 +57,13 @@ class AuthManagerTest : public CppUnit::TestFixture
public:
AuthManagerTest(){};
~AuthManagerTest(){};
~AuthManagerTest(){
/*OpenSSL internal tables are allocated when an application starts up.
Since such tables do not grow in size over time they are harmless. */
EVP_cleanup() ;
CRYPTO_cleanup_all_ex_data();
};
/* ********************************************************************* */

View File

@ -74,6 +74,9 @@ main_env.Append(CPPFLAGS=[
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
# libxml2
main_env.ParseConfig('xml2-config --libs --cflags')
sqlite=ARGUMENTS.get('sqlite', 'yes')
if sqlite=='yes':
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])

View File

@ -77,7 +77,7 @@ class SshAuth
time=Time.now.to_i+expire
proxy_text="#{user}:#{time}"
proxy_crypted=encrypt(proxy_text)
proxy="#{user}:ssh:#{proxy_crypted}"
proxy="#{user}:plain:#{proxy_crypted}"
file=get_proxy_file
file.write(proxy)
file.close

View File

@ -31,7 +31,7 @@ Options:
EOT
ONE_VERSION=<<-EOT
OpenNebula 1.5.0
OpenNebula 1.9.80
Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
EOT

View File

@ -189,6 +189,9 @@ Commands:
* top (Lists hosts continuously)
onehost top
* sync (synchronizes probes with remote hosts)
onehost sync
EOT
def text_commands
@ -359,6 +362,14 @@ when "disable"
end
end
when "sync"
check_parameters("sync", 0)
if ONE_LOCATION
FileUtils.touch "#{ONE_LOCATION}/lib/remotes"
else
FileUtils.touch "/var/lib/one/remotes"
end
else
onehost_opts.print_help
exit -1

View File

@ -78,6 +78,13 @@ ShowTableImage={
:proc => lambda {|d,e|
if d["PUBLIC"].to_i == 1 then "Yes" else "No" end}
},
:persistent => {
:name => "PERSISTENT",
:desc => "Whether the Image is persistent or not",
:size => 3,
:proc => lambda {|d,e|
if d["PERSISTENT"].to_i == 1 then "Yes" else "No" end}
},
:state => {
:name => "STAT",
:desc => "State of the Image",
@ -94,7 +101,7 @@ ShowTableImage={
},
:default => [:id, :user, :name, :type, :regtime,
:public, :state, :runningvms]
:public, :persistent, :state, :runningvms]
}
@ -217,6 +224,12 @@ Commands:
* unpublish (Unpublish an Image)
oneimage unpublish <image_id>
* persistent (Makes an Image persistent)
oneimage persistent <image_id>
* nonpersistent (Makes an Image non persistent)
oneimage nonpersistent <image_id>
* list (Shows Images in the pool)
oneimage list <filter_flag>
@ -251,6 +264,11 @@ EOT
table.print_help
end
def special_options(opts, options)
opts.on_tail("-n", "--no-cp", "Do not copy the source") do |o|
options[:no_cp]=true
end
end
end
@ -300,58 +318,18 @@ result=[false, "Unknown error"]
command=ARGV.shift
img_repo = OpenNebula::ImageRepository.new
case command
when "register", "create", "add"
# ---------- Get the Template ------------
when "register", "create", "add"
check_parameters("register", 1)
template = get_template(ARGV[0])
# ---------- Allocate the Image file ------------
image = OpenNebula::Image.new(
OpenNebula::Image.build_xml,
get_one_client)
result = image.allocate(template)
if !is_successful?(result)
puts result.message
exit -1
end
image = OpenNebula::Image.new(OpenNebula::Image.build_xml, get_one_client)
# ---------- Copy the Image file ------------
image.info
if image['TEMPLATE/PATH']
file_path = image['TEMPLATE/PATH']
if !File.exists?(file_path)
error_msg = "Image file could not be found, aborting."
result = OpenNebula::Error.new(error_msg)
end
result = image.copy(file_path, image['SOURCE'])
elsif image['TEMPLATE/SIZE'] and
image['TEMPLATE/FSTYPE'] and
image['TEMPLATE/TYPE'] == 'DATABLOCK'
result = image.mk_datablock(
image['TEMPLATE/SIZE'],
image['TEMPLATE/FSTYPE'],
image['SOURCE'])
else
error_msg = "Image not present, aborting."
result = OpenNebula::Error.new(error_msg)
end
if is_successful?(result)
image.enable
result = img_repo.create(image, template, !ops[:no_cp])
if is_successful?(result)
puts "ID: " + image.id.to_s if ops[:verbose]
exit 0
else
image.delete
end
@ -421,6 +399,28 @@ when "unpublish"
puts "Image unpublished" if ops[:verbose]
end
when "persistent"
check_parameters("publish", 1)
image_id=get_image_id(ARGV[0])
image=OpenNebula::Image.new_with_id(image_id, get_one_client)
result=image.persistent
if is_successful?(result)
puts "Image made persistent" if ops[:verbose]
end
when "nonpersistent"
check_parameters("nonpersistent", 1)
image_id=get_image_id(ARGV[0])
image=OpenNebula::Image.new_with_id(image_id, get_one_client)
result=image.nonpersistent
if is_successful?(result)
puts "Image made nonpersistent" if ops[:verbose]
end
when "list"
ops.merge!(get_user_flags)
if !ops[:xml]
@ -494,22 +494,14 @@ when "delete"
args=expand_args(ARGV)
args.each do |param|
image_id=get_image_id(param)
image=OpenNebula::Image.new_with_id(image_id, get_one_client)
result = image.info
image_id = get_image_id(param)
image = OpenNebula::Image.new(
OpenNebula::Image.build_xml(image_id),
get_one_client)
result = img_repo.delete(image)
if is_successful?(result)
file_path = image['SOURCE']
result=image.delete
if is_successful?(result)
FileUtils.rm(file_path) if File.exists?(file_path)
puts "Image correctly deleted" if ops[:verbose]
end
puts "Image correctly deleted" if ops[:verbose]
end
end

View File

@ -344,7 +344,7 @@ Commands:
* resume (Resumes the execution of a saved VM)
onevm resume <vm_id>
* saveas (Set the specified vm's disk to be saved in a new image (image_name)
* saveas (Set the specified vms disk to be saved in a new image (image_name)
when the vm shutdowns)
onevm saveas <vm_id> <disk_id> <image_name>
@ -785,6 +785,21 @@ true)
puts
print_header(str_h1,"VIRTUAL MACHINE MONITORING",false)
poll_attrs = {
"USED MEMORY" => "MEMORY",
"USED CPU" => "CPU",
"NET_TX" => "NET_TX",
"NET_RX" => "NET_RX"
}
poll_attrs.each do |k,v|
puts str % [k,vm[v]]
end
puts
print_header(str_h1,"VIRTUAL MACHINE TEMPLATE",false)
puts vm.template_str

View File

@ -58,6 +58,7 @@ class CloudServer
@one_client = Client.new()
@user_pool = UserPool.new(@one_client)
@img_repo = OpenNebula::ImageRepository.new
end
#
@ -110,47 +111,23 @@ class CloudServer
if file
if file[:tempfile]
file_path = file[:tempfile].path
template = image.to_one_template
template << "\nPATH = #{file_path}"
else
error_msg = "Image not present, aborting."
error = OpenNebula::Error.new(error_msg)
return error
end
if !File.exists?(file_path)
error_msg = "Image file could not be found, aborting."
error = OpenNebula::Error.new(error_msg)
return error
end
end
# ---------- Allocate the Image file ------------
rc = @img_repo.create(image, template)
rc = image.allocate(image.to_one_template)
file[:tempfile].unlink
if OpenNebula.is_error?(rc)
return rc
end
# ---------- Copy the Image file ------------
image.info
if file_path
rc = image.copy(file_path, image['SOURCE'])
file[:tempfile].unlink
elsif image['TEMPLATE/SIZE'] and
image['TEMPLATE/FSTYPE'] and
image['TEMPLATE/TYPE'] == 'DATABLOCK'
rc = image.mk_datablock(
image['TEMPLATE/SIZE'],
image['TEMPLATE/FSTYPE'],
image['SOURCE'])
end
if OpenNebula.is_error?(rc)
image.delete
return rc
end
return nil
end

View File

@ -49,11 +49,11 @@ class EC2QueryServer < CloudServer
'susp' => :pending,
'done' => :terminated,
'fail' => :terminated,
'prol' => :pend,
'prol' => :pending,
'boot' => :running,
'runn' => :running,
'migr' => :running,
'save' => :pend,
'save' => :pending,
'epil' => :shutdown,
'shut' => :shutdown,
'fail' => :terminated,

View File

@ -311,10 +311,13 @@ class OCCIServer < CloudServer
end
# --- Create and Add the new Image ---
occixml = request.params['occixml']
occixml = occixml[:tempfile].read if occixml.class == Hash
image = ImageOCCI.new(
Image.build_xml,
get_client(request.env),
request.params['occixml'])
occixml)
rc = add_image(image, request.params['file'])
return rc, 500 if OpenNebula.is_error?(rc)
@ -355,7 +358,7 @@ class OCCIServer < CloudServer
get_client(request.env))
# --- Delete the Image ---
rc = image.delete
rc = @img_repo.delete(image)
return rc, 500 if OpenNebula::is_error?(rc)
return "", 204

View File

@ -0,0 +1,10 @@
<COMPUTE>
<NAME>MyCompute</NAME>
<INSTANCE_TYPE>large</INSTANCE_TYPE>
<DISK>
<STORAGE href="http://www.opennebula.org/storage/4"/>
</DISK>
<NIC>
<NETWORK href="http://www.opennebula.org/network/2"/>
</NIC>
</COMPUTE>

View File

@ -23,7 +23,8 @@ lib_name='nebula_common'
# Sources to generate the library
source_files=[
'ActionManager.cc',
'Attribute.cc'
'Attribute.cc',
'mem_collector.c'
]
# Build library

View File

@ -0,0 +1,90 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include <stdlib.h>
#include <string.h>
#include "mem_collector.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void mem_collector_init(mem_collector * mc)
{
int i;
mc->str_buffer = (char **) malloc (sizeof(char*) * MEM_COLLECTOR_CHUNK);
mc->size = MEM_COLLECTOR_CHUNK;
mc->next = 0;
for (i=0; i< mc->size ; i++)
{
mc->str_buffer[i] = 0;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void mem_collector_cleanup(mem_collector * mc)
{
int i;
for (i=0; i< mc->size ; i++)
{
if ( mc->str_buffer[i] != 0 )
{
free(mc->str_buffer[i]);
}
else /* No str's left in the pool */
{
break;
}
}
free(mc->str_buffer);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
char * mem_collector_strdup(mem_collector *mc, const char * str)
{
int i, old_size;
char * new_str;
if ( mc->next == mc->size )
{
old_size = mc->size;
mc->size = mc->size + MEM_COLLECTOR_CHUNK;
mc->str_buffer = (char **) realloc(mc->str_buffer,
sizeof(char*) * mc->size);
for ( i = old_size ; i < mc->size ; i++)
{
mc->str_buffer[i] = 0;
}
}
new_str = strdup(str);
mc->str_buffer[mc->next++] = new_str;
return new_str;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -63,3 +63,4 @@ main_env.Append(LDFLAGS=["-g"])
main_env.Program('test_sa','single_attribute.cc')
main_env.Program('test_va','vector_attribute.cc')
main_env.Program('test_am','action_manager.cc')
main_env.Program('test_collector','mem_collector.cc')

View File

@ -0,0 +1,117 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
extern "C"
{
#include "mem_collector.h"
}
#include <string.h>
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
using namespace std;
class MemCollectorTest : public CppUnit::TestFixture
{
public:
void setUp()
{
}
void tearDown()
{
}
void test_all_free()
{
mem_collector mc;
mem_collector_init(&mc);
char * st1 = mem_collector_strdup(&mc,"HOLA");
char * st2 = mem_collector_strdup(&mc,"ADIOS");
char * st3 = mem_collector_strdup(&mc,"HELLO");
char * st4 = mem_collector_strdup(&mc,"BYE");
CPPUNIT_ASSERT(strcmp(mc.str_buffer[0],"HOLA")==0);
CPPUNIT_ASSERT(strcmp(mc.str_buffer[1],"ADIOS")==0);
CPPUNIT_ASSERT(strcmp(mc.str_buffer[2],"HELLO")==0);
CPPUNIT_ASSERT(strcmp(mc.str_buffer[3],"BYE")==0);
//Check the content of the strings
CPPUNIT_ASSERT(strcmp(st1,"HOLA")==0);
CPPUNIT_ASSERT(strcmp(st2,"ADIOS")==0);
CPPUNIT_ASSERT(strcmp(st3,"HELLO")==0);
CPPUNIT_ASSERT(strcmp(st4,"BYE")==0);
mem_collector_cleanup(&mc);
CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK);
}
void test_realloc()
{
mem_collector mc;
int max_size;
max_size = (MEM_COLLECTOR_CHUNK * 3) + 5;
mem_collector_init(&mc);
for (int i=0; i < max_size ; i++)
{
mem_collector_strdup(&mc,"HOLA");
}
for (int i=0; i < max_size ; i++)
{
CPPUNIT_ASSERT(strcmp(mc.str_buffer[i],"HOLA")==0);
}
mem_collector_cleanup(&mc);
CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK * 4);
}
static CppUnit::TestSuite * suite()
{
CppUnit::TestSuite *ts=new CppUnit::TestSuite("mem_collector Tests");
ts->addTest(new CppUnit::TestCaller<MemCollectorTest>(
"test_all_free() Test",
&MemCollectorTest::test_all_free));
ts->addTest(new CppUnit::TestCaller<MemCollectorTest>(
"test_realloc() Test",
&MemCollectorTest::test_realloc));
return ts;
}
};
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner tr;
tr.addTest(MemCollectorTest::suite());
tr.run();
return 0;
}

View File

@ -30,7 +30,7 @@ const string ClusterPool::DEFAULT_CLUSTER_NAME = "default";
/* -------------------------------------------------------------------------- */
int ClusterPool::allocate(int * clid, string name, SqlDB *db)
int ClusterPool::allocate(int * clid, string name, SqlDB *db, string& error_str)
{
int rc;
map<int, string>::iterator it;
@ -60,16 +60,16 @@ int ClusterPool::allocate(int * clid, string name, SqlDB *db)
error_existing_name:
oss << "Could not allocate new cluster: Name \""
<< name << "\" already exists.";
oss << "Could not allocate new cluster: "
<< name << ", already exists.";
goto error_common;
error_db:
oss << "Could not allocate new cluster \"" << name
<< "\": Database returned error code " << rc << ".";
oss << "Could not allocate new cluster " << name << ".";
goto error_common;
error_common:
error_str = oss.str();
NebulaLog::log("CLUSTER", Log::ERROR, oss);
*clid = -1;

View File

@ -41,10 +41,9 @@ Host::Host(
tm_mad_name(_tm_mad_name),
last_monitored(0),
cluster(ClusterPool::DEFAULT_CLUSTER_NAME),
host_template(id)
host_template()
{}
Host::~Host(){}
/* ************************************************************************ */
@ -54,13 +53,13 @@ Host::~Host(){}
const char * Host::table = "host_pool";
const char * Host::db_names = "(oid,host_name,state,im_mad,vm_mad,"
"tm_mad,last_mon_time, cluster)";
"tm_mad,last_mon_time, cluster, template)";
const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool ("
"oid INTEGER PRIMARY KEY,host_name VARCHAR(512), state INTEGER,"
"oid INTEGER PRIMARY KEY,host_name VARCHAR(256), state INTEGER,"
"im_mad VARCHAR(128),vm_mad VARCHAR(128),tm_mad VARCHAR(128),"
"last_mon_time INTEGER, cluster VARCHAR(128), "
"UNIQUE(host_name, im_mad, vm_mad, tm_mad) )";
"last_mon_time INTEGER, cluster VARCHAR(128), template TEXT, "
"UNIQUE(host_name))";
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
@ -75,6 +74,7 @@ int Host::select_cb(void * nil, int num, char **values, char ** names)
(!values[TM_MAD]) ||
(!values[LAST_MON_TIME]) ||
(!values[CLUSTER]) ||
(!values[TEMPLATE]) ||
(num != LIMIT ))
{
return -1;
@ -92,7 +92,8 @@ int Host::select_cb(void * nil, int num, char **values, char ** names)
cluster = values[CLUSTER];
host_template.id = oid;
host_template.from_xml(values[TEMPLATE]);
host_share.hsid = oid;
return 0;
@ -122,9 +123,6 @@ int Host::select(SqlDB *db)
return -1;
}
// Get the template
rc = host_template.select(db);
if ( rc != 0 )
{
return -1;
@ -144,37 +142,22 @@ int Host::select(SqlDB *db)
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Host::insert(SqlDB *db)
int Host::insert(SqlDB *db, string& error_str)
{
int rc;
map<int,HostShare *>::iterator iter;
// Set up the template ID, to insert it
if ( host_template.id == -1 )
{
host_template.id = oid;
}
// Set up the share ID, to insert it
if ( host_share.hsid == -1 )
{
host_share.hsid = oid;
}
// Update the Template
rc = host_template.insert(db);
if ( rc != 0 )
{
return rc;
}
// Update the HostShare
rc = host_share.insert(db);
rc = host_share.insert(db, error_str);
if ( rc != 0 )
{
host_template.drop(db);
return rc;
}
@ -183,7 +166,7 @@ int Host::insert(SqlDB *db)
if ( rc != 0 )
{
host_template.drop(db);
error_str = "Error inserting Host in DB.";
host_share.drop(db);
return rc;
@ -199,14 +182,6 @@ int Host::update(SqlDB *db)
{
int rc;
// Update the Template needed by the monitoring action from IM
rc = host_template.update(db);
if ( rc != 0 )
{
return rc;
}
// Update the HostShare
rc = host_share.update(db);
@ -235,12 +210,14 @@ int Host::insert_replace(SqlDB *db, bool replace)
ostringstream oss;
int rc;
string xml_template;
char * sql_hostname;
char * sql_im_mad_name;
char * sql_tm_mad_name;
char * sql_vmm_mad_name;
char * sql_cluster;
char * sql_template;
// Update the Host
@ -279,6 +256,14 @@ int Host::insert_replace(SqlDB *db, bool replace)
goto error_cluster;
}
host_template.to_xml(xml_template);
sql_template = db->escape_str(xml_template.c_str());
if ( sql_template == 0 )
{
goto error_template;
}
if(replace)
{
oss << "REPLACE";
@ -291,14 +276,15 @@ int Host::insert_replace(SqlDB *db, bool replace)
// Construct the SQL statement to Insert or Replace
oss <<" INTO "<< table <<" "<< db_names <<" VALUES ("
<< oid << ","
<< "'" << sql_hostname << "',"
<< state << ","
<< "'" << sql_im_mad_name << "',"
<< "'" << sql_vmm_mad_name << "',"
<< "'" << sql_tm_mad_name << "',"
<< last_monitored << ","
<< "'" << sql_cluster << "')";
<< oid << ","
<< "'" << sql_hostname << "',"
<< state << ","
<< "'" << sql_im_mad_name << "',"
<< "'" << sql_vmm_mad_name << "',"
<< "'" << sql_tm_mad_name << "',"
<< last_monitored << ","
<< "'" << sql_cluster << "',"
<< "'" << sql_template << "')";
rc = db->exec(oss);
@ -307,9 +293,12 @@ int Host::insert_replace(SqlDB *db, bool replace)
db->free_str(sql_tm_mad_name);
db->free_str(sql_vmm_mad_name);
db->free_str(sql_cluster);
db->free_str(sql_template);
return rc;
error_template:
db->free_str(sql_cluster);
error_cluster:
db->free_str(sql_vmm_mad_name);
error_vmm:
@ -335,6 +324,7 @@ int Host::dump(ostringstream& oss, int num, char **values, char **names)
(!values[TM_MAD]) ||
(!values[LAST_MON_TIME]) ||
(!values[CLUSTER]) ||
(!values[TEMPLATE]) ||
(num != LIMIT + HostShare::LIMIT ))
{
return -1;
@ -349,7 +339,8 @@ int Host::dump(ostringstream& oss, int num, char **values, char **names)
"<VM_MAD>" << values[VM_MAD] <<"</VM_MAD>" <<
"<TM_MAD>" << values[TM_MAD] <<"</TM_MAD>" <<
"<LAST_MON_TIME>"<< values[LAST_MON_TIME]<<"</LAST_MON_TIME>"<<
"<CLUSTER>" << values[CLUSTER] <<"</CLUSTER>";
"<CLUSTER>" << values[CLUSTER] <<"</CLUSTER>" <<
values[TEMPLATE];
HostShare::dump(oss,num - LIMIT, values + LIMIT, names + LIMIT);
@ -366,8 +357,6 @@ int Host::drop(SqlDB * db)
ostringstream oss;
int rc;
host_template.drop(db);
host_share.drop(db);
oss << "DELETE FROM " << table << " WHERE oid=" << oid;

View File

@ -70,10 +70,11 @@ HostPool::HostPool(SqlDB* db):PoolSQL(db,Host::table)
int HostPool::allocate (
int * oid,
string hostname,
string im_mad_name,
string vmm_mad_name,
string tm_mad_name)
const string& hostname,
const string& im_mad_name,
const string& vmm_mad_name,
const string& tm_mad_name,
string& error_str)
{
Host * host;
@ -87,7 +88,7 @@ int HostPool::allocate (
// Insert the Object in the pool
*oid = PoolSQL::allocate(host);
*oid = PoolSQL::allocate(host, error_str);
return *oid;
}

View File

@ -197,12 +197,17 @@ int HostShare::select(SqlDB * db)
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int HostShare::insert(SqlDB * db)
int HostShare::insert(SqlDB * db, string& error_str)
{
int rc;
rc = insert_replace(db, false);
if ( rc == -1 )
{
error_str = "Error inserting Host Share in DB.";
}
return rc;
}
@ -225,7 +230,7 @@ int HostShare::insert_replace(SqlDB *db, bool replace)
{
ostringstream oss;
int rc;
if(replace)
{
oss << "REPLACE";
@ -234,7 +239,7 @@ int HostShare::insert_replace(SqlDB *db, bool replace)
{
oss << "INSERT";
}
oss << " INTO " << table << " "<< db_names <<" VALUES ("
<< hsid << ","
<< disk_usage <<","<< mem_usage <<","<< cpu_usage<< ","
@ -242,7 +247,7 @@ int HostShare::insert_replace(SqlDB *db, bool replace)
<< free_disk <<","<< free_mem <<","<< free_cpu << ","
<< used_disk <<","<< used_mem <<","<< used_cpu << ","
<< running_vms<< ")";
rc = db->exec(oss);
return rc;

View File

@ -1,24 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "HostTemplate.h"
const char * HostTemplate::table = "host_attributes";
const char * HostTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS "
"host_attributes (id INTEGER, name VARCHAR(256), type INTEGER, value TEXT, "
"PRIMARY KEY(id,name))";

View File

@ -25,7 +25,6 @@ source_files=[
'Host.cc',
'HostShare.cc',
'HostPool.cc',
'HostTemplate.cc',
'ClusterPool.cc',
]

View File

@ -54,34 +54,34 @@ const string xmls[] =
const string xml_dump =
"<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
"</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
"</LAST_MON_TIME><CLUSTER>default</CLUSTER><TEMPLATE></TEMPLATE><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
"_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
"MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
"SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST>"
"<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
"ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
"ON_TIME><CLUSTER>default</CLUSTER><TEMPLATE></TEMPLATE><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
"M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
"<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
"U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
"SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>2</ID><N"
"AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><TEMPLATE></TEMPLATE><HOS"
"T_SHARE><HID>2</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
"_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
"MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
"U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
"NING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>3</ID><NAME>another "
"name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><TEMPLATE></TEMPLATE><HOST_SHAR"
"E><HID>3</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
"U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
"D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
"MS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>4</ID><NAME>host</NAME><ST"
"ATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad"
"</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>4</HID>"
"</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><TEMPLATE></TEMPLATE><HOST_SHARE><HID>4</HID>"
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0"
"</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED"
@ -91,33 +91,35 @@ const string xml_dump =
const string xml_dump_like_a =
"<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
"</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
"</LAST_MON_TIME><CLUSTER>default</CLUSTER><TEMPLATE></TEMPLATE><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
"_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
"MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
"SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST>"
"<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
"ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
"ON_TIME><CLUSTER>default</CLUSTER><TEMPLATE></TEMPLATE><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
"M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
"<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
"U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
"SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>2</ID><N"
"AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><TEMPLATE></TEMPLATE><HOS"
"T_SHARE><HID>2</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
"_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
"MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
"U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
"NING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>3</ID><NAME>another "
"name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><TEMPLATE></TEMPLATE><HOST_SHAR"
"E><HID>3</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
"U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
"D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
"MS>0</RUNNING_VMS></HOST_SHARE></HOST></HOST_POOL>";
const string host0_updated =
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE><ATT_A><![CDATA[VALUE_A]]></ATT_A><ATT_B><![CDATA[VALUE_B]]></ATT_B></TEMPLATE></HOST>";
const string cluster_default =
"<CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER>";
@ -149,6 +151,7 @@ class HostPoolTest : public PoolTest
CPPUNIT_TEST (cluster_dump);
CPPUNIT_TEST (set_cluster);
CPPUNIT_TEST (remove_cluster);
CPPUNIT_TEST (update_info);
CPPUNIT_TEST_SUITE_END ();
@ -166,9 +169,10 @@ protected:
int allocate(int index)
{
int oid;
int oid;
string err;
return ((HostPool*)pool)->allocate(&oid, names[index], im_mad,
vmm_mad, tm_mad);
vmm_mad, tm_mad, err);
};
void check(int index, PoolObjectSQL* obj)
@ -189,9 +193,9 @@ protected:
public:
HostPoolTest(){};
HostPoolTest(){xmlInitParser();};
~HostPoolTest(){};
~HostPoolTest(){xmlCleanupParser();};
/* ********************************************************************* */
@ -232,33 +236,30 @@ public:
int rc, oid_0, oid_1;
HostPool * hp = static_cast<HostPool *>(pool);
Host * host;
string err;
string tm_mad_2 = "another_tm_mad";
// If we try to allocate two hosts with the same name and drivers,
// should fail
rc = hp->allocate(&oid_0, names[0], im_mad, vmm_mad, tm_mad);
rc = hp->allocate(&oid_0, names[0], im_mad, vmm_mad, tm_mad, err);
CPPUNIT_ASSERT( oid_0 == 0 );
CPPUNIT_ASSERT( rc == oid_0 );
rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad);
rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad, err);
CPPUNIT_ASSERT( oid_1 == -1 );
CPPUNIT_ASSERT( rc == oid_1 );
// But if the drivers change, the hostname can be repeated
rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad_2);
CPPUNIT_ASSERT( oid_1 == 1 );
// the hostname can not be repeated if the drivers change
rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad_2, err);
CPPUNIT_ASSERT( oid_1 == -1 );
CPPUNIT_ASSERT( rc == oid_1 );
// Get the hosts and check them
host = hp->get(oid_0, false);
CPPUNIT_ASSERT( host != 0 );
CPPUNIT_ASSERT( host->get_tm_mad() == tm_mad );
host = hp->get(oid_1, false);
CPPUNIT_ASSERT( host != 0 );
CPPUNIT_ASSERT( host->get_tm_mad() == tm_mad_2 );
}
/* ********************************************************************* */
@ -267,10 +268,12 @@ public:
{
string names[] = {"a", "a name", "a_name", "another name", "host"};
int rc, oid;
string err;
for(int i=0; i<5; i++)
{
((HostPool*)pool)->allocate(&oid, names[i], im_mad, vmm_mad, tm_mad);
((HostPool*)pool)->allocate(&oid, names[i],
im_mad, vmm_mad, tm_mad, err);
}
ostringstream oss;
@ -289,10 +292,12 @@ public:
{
string names[] = {"a", "a name", "a_name", "another name", "host"};
int rc, oid;
string err;
for(int i=0; i<5; i++)
{
((HostPool*)pool)->allocate(&oid, names[i], im_mad, vmm_mad, tm_mad);
((HostPool*)pool)->allocate(&oid, names[i],
im_mad, vmm_mad, tm_mad, err);
}
@ -318,12 +323,13 @@ public:
Host * host;
HostPool * hp = static_cast<HostPool *>(pool);
ostringstream oss;
string err;
for(i=0, oss.str(""); i<20; i++,oss.str(""))
{
oss << "host" << i;
hp->allocate(&oid, oss.str().c_str(), im_mad, vmm_mad, tm_mad);
hp->allocate(&oid, oss.str().c_str(), im_mad, vmm_mad, tm_mad, err);
CPPUNIT_ASSERT(oid == i);
if (i >=8 )
@ -368,8 +374,9 @@ public:
{
HostPool * hp = static_cast<HostPool *>(pool);
int clid, rc;
string err;
rc = hp->allocate_cluster(&clid, "new_cluster");
rc = hp->allocate_cluster(&clid, "new_cluster", err);
CPPUNIT_ASSERT( rc == clid );
CPPUNIT_ASSERT( clid == 1 );
@ -377,7 +384,7 @@ public:
"<CLUSTER><ID>1</ID><NAME>new_cluster</NAME></CLUSTER>");
// Try to allocate using the same name
rc = hp->allocate_cluster(&clid, "new_cluster");
rc = hp->allocate_cluster(&clid, "new_cluster", err);
CPPUNIT_ASSERT( rc == clid );
CPPUNIT_ASSERT( clid == -1 );
}
@ -388,13 +395,14 @@ public:
{
HostPool * hp = static_cast<HostPool *>(pool);
int clid, rc;
string err;
// Drop a non-existing cluster
rc = hp->drop_cluster(20);
CPPUNIT_ASSERT( rc == -1 );
// Allocate a cluster and drop it
rc = hp->allocate_cluster(&clid, "new_cluster");
rc = hp->allocate_cluster(&clid, "new_cluster", err);
CPPUNIT_ASSERT( clid == 1);
rc = hp->drop_cluster(clid);
@ -412,18 +420,19 @@ public:
HostPool * hp = static_cast<HostPool *>(pool);
int clid, rc;
ostringstream oss;
string err;
// Allocate some clusters
rc = hp->allocate_cluster(&clid, "cluster_a");
rc = hp->allocate_cluster(&clid, "cluster_a", err);
CPPUNIT_ASSERT( rc == 1 );
rc = hp->allocate_cluster(&clid, "cluster_b");
rc = hp->allocate_cluster(&clid, "cluster_b", err);
CPPUNIT_ASSERT( rc == 2 );
rc = hp->allocate_cluster(&clid, "cluster_c");
rc = hp->allocate_cluster(&clid, "cluster_c", err);
CPPUNIT_ASSERT( rc == 3 );
rc = hp->allocate_cluster(&clid, "cluster_d");
rc = hp->allocate_cluster(&clid, "cluster_d", err);
CPPUNIT_ASSERT( rc == 4 );
// Drop id 2
@ -431,7 +440,7 @@ public:
CPPUNIT_ASSERT( rc == 0 );
// Next one should use id 5, because the biggest id is 4
rc = hp->allocate_cluster(&clid, "cluster_e");
rc = hp->allocate_cluster(&clid, "cluster_e", err);
CPPUNIT_ASSERT( rc == 5 );
// Drop id 5
@ -439,7 +448,7 @@ public:
CPPUNIT_ASSERT( rc == 0 );
// Next one should use id 5, because the biggest id is 4 again
rc = hp->allocate_cluster(&clid, "cluster_f");
rc = hp->allocate_cluster(&clid, "cluster_f", err);
CPPUNIT_ASSERT( rc == 5 );
}
@ -451,18 +460,19 @@ public:
HostPool * hp = static_cast<HostPool *>(pool);
int clid, rc;
ostringstream oss;
string err;
// Allocate some clusters
rc = hp->allocate_cluster(&clid, "cluster_a");
rc = hp->allocate_cluster(&clid, "cluster_a", err);
CPPUNIT_ASSERT( rc == 1 );
rc = hp->allocate_cluster(&clid, "cluster_b");
rc = hp->allocate_cluster(&clid, "cluster_b", err);
CPPUNIT_ASSERT( rc == 2 );
rc = hp->allocate_cluster(&clid, "cluster_c");
rc = hp->allocate_cluster(&clid, "cluster_c", err);
CPPUNIT_ASSERT( rc == 3 );
rc = hp->allocate_cluster(&clid, "cluster_d");
rc = hp->allocate_cluster(&clid, "cluster_d", err);
CPPUNIT_ASSERT( rc == 4 );
@ -482,14 +492,16 @@ public:
HostPool * hp = static_cast<HostPool *>(pool);
Host* host;
int clid, rc, oid;
string xml_str;
string xml_str, err;
// Allocate a host
oid = allocate(0);
CPPUNIT_ASSERT(oid >= 0);
host = hp->get(0, false);
CPPUNIT_ASSERT(host != 0);
rc = hp->allocate_cluster(&clid, "cluster_a");
rc = hp->allocate_cluster(&clid, "cluster_a", err);
CPPUNIT_ASSERT( rc == 1 );
rc = hp->set_cluster(host, clid);
@ -514,14 +526,16 @@ public:
HostPool * hp = static_cast<HostPool *>(pool);
Host* host;
int clid, rc, oid;
string xml_str;
string xml_str, err;
// Allocate a host
oid = allocate(0);
CPPUNIT_ASSERT(oid >= 0);
host = hp->get(0, false);
CPPUNIT_ASSERT(host != 0);
rc = hp->allocate_cluster(&clid, "cluster_a");
rc = hp->allocate_cluster(&clid, "cluster_a", err);
CPPUNIT_ASSERT( rc == 1 );
// Set host 0 to cluster 1
@ -540,6 +554,40 @@ public:
host->to_xml(xml_str);
check(0, host);
}
/* ********************************************************************* */
void update_info()
{
int rc;
int oid_1;
HostPool * hp = static_cast<HostPool *>(pool);
Host* host;
string str;
oid_1 = allocate(0);
host = hp->get(oid_1, false);
CPPUNIT_ASSERT( host != 0 );
string info = "ATT_A=VALUE_A ATT_B=VALUE_B";
rc = host->update_info(info);
CPPUNIT_ASSERT(rc == 0);
pool->update(host);
host = hp->get(oid_1,false);
CPPUNIT_ASSERT( host != 0 );
CPPUNIT_ASSERT( host->to_xml(str) == host0_updated );
//Now force access to DB
pool->clean();
host = hp->get(oid_1,false);
CPPUNIT_ASSERT( host != 0 );
CPPUNIT_ASSERT( host->to_xml(str) == host0_updated );
}
};

View File

@ -67,6 +67,10 @@ main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
# libxml2
main_env.ParseConfig('xml2-config --libs --cflags')
sqlite=ARGUMENTS.get('sqlite', 'yes')
if sqlite=='yes':
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])

View File

@ -17,6 +17,9 @@
#include "InformationManager.h"
#include "NebulaLog.h"
#include <sys/types.h>
#include <sys/stat.h>
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -145,7 +148,7 @@ void InformationManager::timer_action()
istringstream iss;
// -------------- Max. number of hosts to monitor. ---------------------
int host_limit = 10;
int host_limit = 15;
mark = mark + timer_period;
@ -164,6 +167,16 @@ void InformationManager::timer_action()
thetime = time(0);
struct stat sb;
if (stat(remotes_location.c_str(), &sb) == -1)
{
sb.st_mtime = 0;
NebulaLog::log("InM",Log::ERROR,"Could not stat remotes directory, "
"will not update remotes.");
}
for(it=discovered_hosts.begin();it!=discovered_hosts.end();it++)
{
host = hpool->get(it->first,true);
@ -204,7 +217,15 @@ void InformationManager::timer_action()
}
else
{
imd->monitor(it->first,host->get_hostname());
bool update_remotes = false;
if ((sb.st_mtime != 0) &&
(sb.st_mtime > host->get_last_monitored()))
{
update_remotes = true;
}
imd->monitor(it->first,host->get_hostname(),update_remotes);
host->set_state(Host::MONITORING);
}

View File

@ -23,13 +23,13 @@
/* Driver ASCII Protocol Implementation */
/* ************************************************************************** */
void InformationManagerDriver::monitor (
const int oid,
const string& host) const
void InformationManagerDriver::monitor(int oid,
const string& host,
bool update) const
{
ostringstream os;
os << "MONITOR " << oid << " " << host << endl;
os << "MONITOR " << oid << " " << host << " " << update << endl;
write(os);
}
@ -39,8 +39,8 @@ void InformationManagerDriver::monitor (
void InformationManagerDriver::protocol(
string& message)
{
istringstream is(message);
{
istringstream is(message);
//stores the action name
string action;
//stores the action result
@ -51,7 +51,7 @@ void InformationManagerDriver::protocol(
ostringstream ess;
string hinfo;
Host * host;
// Parse the driver message
if ( is.good() )
@ -84,61 +84,61 @@ void InformationManagerDriver::protocol(
// -----------------------
// Protocol implementation
// -----------------------
if ( action == "MONITOR" )
{
host = hpool->get(id,true);
if ( host == 0 )
{
goto error_host;
}
if (result == "SUCCESS")
{
size_t pos;
{
size_t pos;
int rc;
ostringstream oss;
getline (is,hinfo);
for (pos=hinfo.find(',');pos!=string::npos;pos=hinfo.find(','))
{
hinfo.replace(pos,1,"\n");
}
hinfo += "\n";
oss << "Host " << id << " successfully monitored."; //, info: "<< hinfo;
NebulaLog::log("InM",Log::DEBUG,oss);
rc = host->update_info(hinfo);
if (rc != 0)
{
goto error_parse_info;
}
}
}
else
{
goto error_driver_info;
goto error_driver_info;
}
host->touch(true);
hpool->update(host);
host->unlock();
host->unlock();
}
else if (action == "LOG")
{
string info;
getline(is,info);
NebulaLog::log("InM",Log::INFO,info.c_str());
}
return;
error_driver_info:
@ -146,27 +146,27 @@ error_driver_info:
NebulaLog::log("InM", Log::ERROR, ess);
goto error_common_info;
error_parse_info:
ess << "Error parsing host information: " << hinfo;
NebulaLog::log("InM",Log::ERROR,ess);
error_common_info:
host->touch(false);
hpool->update(host);
host->unlock();
return;
error_host:
ess << "Could not get host " << id;
NebulaLog::log("InM",Log::ERROR,ess);
return;
error_parse:
ess << "Error while parsing driver message: " << message;

34
src/im_mad/dummy/one_im_dummy Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
# Complutense de Madrid (dsa-research.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
if [ -z "${ONE_LOCATION}" ]; then
MADCOMMON=/usr/lib/one/mads/madcommon.sh
VAR_LOCATION=/var/lib/one
else
MADCOMMON=$ONE_LOCATION/lib/mads/madcommon.sh
VAR_LOCATION=$ONE_LOCATION/var
fi
. $MADCOMMON
# Go to var directory ONE_LOCATION/var or /var/lib/one
cd $VAR_LOCATION
# Execute the actual MAD
execute_mad $*

View File

@ -0,0 +1,78 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
# Complutense de Madrid (dsa-research.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
ETC_LOCATION="/etc/one/"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
ETC_LOCATION=ONE_LOCATION+"/etc/"
end
$: << RUBY_LIB_LOCATION
require 'OpenNebulaDriver'
require 'CommandManager'
#-------------------------------------------------------------------------------
# The SSH Information Manager Driver
#-------------------------------------------------------------------------------
class DummyInformationManager < OpenNebulaDriver
#---------------------------------------------------------------------------
# Init the driver
#---------------------------------------------------------------------------
def initialize(num)
super(num, true)
# register actions
register_action(:MONITOR, method("action_monitor"))
end
#---------------------------------------------------------------------------
# Execute the sensor array in the remote host
#---------------------------------------------------------------------------
def action_monitor(number, host, not_used)
results = "HYPERVISOR=dummy,"
results << "NAME=#{host},"
results << "TOTALCPU=800,"
results << "CPUSPEED=2.2GHz,"
results << "TOTALMEMORY=16777216,"
results << "USEDMEMORY=0,"
results << "FREEMEMORY=16777216,"
results << "FREECPU=800,"
results << "USEDCPU=0"
send_message("MONITOR", RESULT[:success], number, results)
end
end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Information Manager main program
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
im = DummyInformationManager.new(15)
im.start_driver

View File

@ -1,3 +0,0 @@
#!/bin/sh
echo ARCH=`uname -m`

View File

@ -1,9 +0,0 @@
#!/bin/sh
if [ -f /proc/cpuinfo ]; then
echo -n "MODELNAME=\""
grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | sed -e 's/^ *//' | sed -e 's/$/"/'
fi

View File

@ -1,5 +0,0 @@
#!/bin/sh
echo HOSTNAME=`uname -n`

View File

@ -47,7 +47,7 @@ export_rc_vars $DRIVERRC
# Go to var directory ONE_LOCATION/var or /var/lib/one
cd $VAR_LOCATION
LOG_FILE=$DRIVER_NAME
LOG_FILE=one_im_ssh_$DRIVER_NAME
# Execute the actual MAD
execute_mad $*

View File

@ -22,127 +22,19 @@ if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
ETC_LOCATION="/etc/one/"
PROBE_LOCATION="/usr/lib/one/im_probes/"
REMOTES_LOCATION="/usr/lib/one/remotes"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
ETC_LOCATION=ONE_LOCATION+"/etc/"
PROBE_LOCATION=ONE_LOCATION+"/lib/im_probes/"
REMOTES_LOCATION=ONE_LOCATION+"/lib/remotes/"
end
$: << RUBY_LIB_LOCATION
require 'pp'
require 'digest/md5'
require 'fileutils'
require 'OpenNebulaDriver'
require 'CommandManager'
#-------------------------------------------------------------------------------
# This class holds the information of a IM probe and the methods to copy the
# script to the remote hosts and run it
#-------------------------------------------------------------------------------
class Sensor
#---------------------------------------------------------------------------
# Class constructor init the remote script name and working directory
#---------------------------------------------------------------------------
def initialize(name, script, remote_dir)
id = Digest::MD5.hexdigest("#{name}#{script}")
@script = script
@remote_script = "#{remote_dir}/one_im-#{id}"
@remote_dir = remote_dir
end
#---------------------------------------------------------------------------
# Sends the monitor probe script to the remote host and execute it
#---------------------------------------------------------------------------
def execute(host, log_proc)
script_text = File.read @script
src = "'mkdir -p #{@remote_dir}; cat > #{@remote_script};" \
" if [ \"x$?\" != \"x0\" ]; then exit -1; fi;" \
" chmod +x #{@remote_script}; #{@remote_script}'"
cmd = SSHCommand.run(src, host, log_proc, script_text)
case cmd.code
when 0
# Splits the output by lines, strips each line and gets only
# lines that have something
value = cmd.stdout.split("\n").collect {|v|
v2 = v.strip
if v2 == ""
nil
else
v2
end
}.compact.join(",")
else
nil
end
end
end
#-------------------------------------------------------------------------------
# This class is an array of sensor probes to be executed by the information
# driver. The class is built on top of the Sensor class
#-------------------------------------------------------------------------------
class SensorList < Array
#---------------------------------------------------------------------------
# Initialize the class
#---------------------------------------------------------------------------
def initialize(config_file, remote_dir)
super(0)
@remote_dir = remote_dir
load_sensors(config_file)
end
#---------------------------------------------------------------------------
# Execute all sensors in the list in the given host
#---------------------------------------------------------------------------
def execute_sensors(host, log_proc)
results = Array.new
self.each {|sensor|
results << sensor.execute(host, log_proc)
}
results
end
private
#---------------------------------------------------------------------------
# Load sensors from a configuration file
#---------------------------------------------------------------------------
def load_sensors(file)
f = open(file, "r")
f.each_line {|line|
l = line.strip.gsub(/#.*$/, "")
case l
when ""
when /^[^=]+=[^=]+$/
(name, script)=l.split("=")
name.strip!
script.strip!
script = "#{PROBE_LOCATION}#{script}" if script[0] != ?/
self << Sensor.new(name, script, @remote_dir)
else
STDERR.puts "Malformed line in configuration file: #{line}"
end
}
f.close
end
end
#-------------------------------------------------------------------------------
# The SSH Information Manager Driver
#-------------------------------------------------------------------------------
@ -151,26 +43,35 @@ class InformationManager < OpenNebulaDriver
#---------------------------------------------------------------------------
# Init the driver
#---------------------------------------------------------------------------
def initialize(config_file, remote_dir, num)
def initialize(remote_dir, hypervisor, num)
super(num, true)
@sensor_list=SensorList.new(config_file, remote_dir)
@hypervisor = hypervisor
@remote_dir = remote_dir
# register actions
register_action(:MONITOR, method("action_monitor"))
end
#---------------------------------------------------------------------------
# Execute the sensor array in the remote host
# Execute the run_probes in the remote host
#---------------------------------------------------------------------------
def action_monitor(number, host)
def action_monitor(number, host, do_update)
if do_update == "1"
# Use SCP to sync:
sync_cmd = "scp -r #{REMOTES_LOCATION}/. #{host}:#{@remote_dir}"
# Use rsync to sync:
# sync_cmd = "rsync -Laz #{REMOTES_LOCATION} #{host}:#{@remote_dir}"
LocalCommand.run(sync_cmd)
else
end
results = @sensor_list.execute_sensors(host, log_method(number))
cmd = SSHCommand.run("#{@remote_dir}/im/run_probes #{@hypervisor}",
host)
information=results.select{|res| res && !res.empty? }.join(",")
if information and !information.empty?
send_message("MONITOR", RESULT[:success], number, information)
if cmd.code == 0
send_message("MONITOR", RESULT[:success], number, cmd.stdout)
else
send_message("MONITOR", RESULT[:failure], number,
"Could not monitor host #{host}.")
@ -184,22 +85,10 @@ end
# Information Manager main program
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
im_conf = ARGV.last
if !im_conf || File.exists?(im_conf)
puts "You need to specify config file."
exit(-1)
end
im_conf = "#{ETC_LOCATION}#{im_conf}" if im_conf[0] != ?/
if !File.exists?(im_conf)
puts "Configuration file #{im_conf} does not exists."
exit(-1)
end
remote_dir = ENV["IM_REMOTE_DIR"]
remote_dir = "/tmp/one-im" if !remote_dir
remote_dir = "/tmp/one" if !remote_dir
im = InformationManager.new(im_conf, "#{remote_dir}/", 15)
hypervisor = ARGV[0]||''
im = InformationManager.new(remote_dir, hypervisor, 15)
im.start_driver

View File

@ -1,8 +0,0 @@
#-------------------------------------------------------------------------------
# Probes for KVM hosts add as many monitorization sensors as you need
#-------------------------------------------------------------------------------
cpuarchitecture=architecture.sh
nodename=name.sh
cpu=cpu.sh
kvm=kvm.rb

View File

@ -1,3 +1,5 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
@ -13,5 +15,5 @@
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
LIBVIRT_DEFAULT_URI="qemu:///system"
echo ARCH=`uname -m`

View File

@ -1,3 +1,5 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
@ -14,10 +16,10 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
#---------------------------------------------------------------------------
# Path to Xen utilities
#---------------------------------------------------------------------------
if [ -f /proc/cpuinfo ]; then
XENTOP_PATH="/usr/sbin/xentop"
echo -n "MODELNAME=\""
grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | sed -e 's/^ *//' | sed -e 's/$/"/'
fi
XM_PATH="/usr/sbin/xm"

View File

@ -1,3 +1,5 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
@ -14,9 +16,6 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
# To change the directory where the IM probes are copied on the remote node
# uncomment and change the path of IM_REMOTE_DIR
#
#IM_REMOTE_DIR=/tmp/ne_im_scripts
echo HOSTNAME=`uname -n`

44
src/im_mad/remotes/run_probes Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
HYPERVISOR_DIR=$1.d
SCRIPTS_DIR=`dirname $0`
cd $SCRIPTS_DIR
function run_dir {
(
DIR=$1
cd $DIR
for i in `ls *`;do
if [ -x "$i" ]; then
./$i
fi
done
)
}
data=$(
run_dir 'common.d'
if [ -d "$HYPERVISOR_DIR" ]; then
run_dir $HYPERVISOR_DIR
fi
)
echo $data | tr '\n' ' '

View File

@ -1,8 +0,0 @@
#-------------------------------------------------------------------------------
# Probes for Xen hosts add as many monitorization sensors as you need
#-------------------------------------------------------------------------------
cpuarchitecture=architecture.sh
nodename=name.sh
cpu=cpu.sh
xen=xen.rb

View File

@ -66,28 +66,30 @@ Image::~Image()
const char * Image::table = "image_pool";
const char * Image::db_names = "(oid, uid, name, type, public, regtime, "
"source, state, running_vms)";
const char * Image::db_names = "(oid, uid, name, type, public, persistent, regtime, "
"source, state, running_vms, template)";
const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool ("
"oid INTEGER PRIMARY KEY, uid INTEGER, name VARCHAR(128), "
"type INTEGER, public INTEGER, regtime INTEGER, source TEXT, state INTEGER, "
"running_vms INTEGER, UNIQUE(name) )";
"type INTEGER, public INTEGER, persistent INTEGER, regtime INTEGER, source TEXT, state INTEGER, "
"running_vms INTEGER, template TEXT, UNIQUE(name) )";
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Image::select_cb(void * nil, int num, char **values, char ** names)
{
if ((!values[OID]) ||
(!values[UID]) ||
(!values[NAME]) ||
(!values[TYPE]) ||
(!values[PUBLIC]) ||
(!values[REGTIME]) ||
(!values[SOURCE]) ||
(!values[STATE]) ||
(!values[RUNNING_VMS]) ||
if ((!values[OID]) ||
(!values[UID]) ||
(!values[NAME]) ||
(!values[TYPE]) ||
(!values[PUBLIC]) ||
(!values[PERSISTENT]) ||
(!values[REGTIME]) ||
(!values[SOURCE]) ||
(!values[STATE]) ||
(!values[RUNNING_VMS]) ||
(!values[TEMPLATE]) ||
(num != LIMIT ))
{
return -1;
@ -98,9 +100,10 @@ int Image::select_cb(void * nil, int num, char **values, char ** names)
name = values[NAME];
type = static_cast<ImageType>(atoi(values[TYPE]));
public_img = atoi(values[PUBLIC]);
regtime = static_cast<time_t>(atoi(values[REGTIME]));
type = static_cast<ImageType>(atoi(values[TYPE]));
public_img = atoi(values[PUBLIC]);
persistent_img = atoi(values[PERSISTENT]);
regtime = static_cast<time_t>(atoi(values[REGTIME]));
source = values[SOURCE];
@ -108,7 +111,7 @@ int Image::select_cb(void * nil, int num, char **values, char ** names)
running_vms = atoi(values[RUNNING_VMS]);
image_template->id = oid;
image_template->from_xml(values[TEMPLATE]);
return 0;
}
@ -136,15 +139,6 @@ int Image::select(SqlDB *db)
return -1;
}
// Get the template
rc = image_template->select(db);
if ( rc != 0 )
{
return -1;
}
return 0;
}
@ -152,13 +146,14 @@ int Image::select(SqlDB *db)
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Image::insert(SqlDB *db)
int Image::insert(SqlDB *db, string& error_str)
{
int rc;
string source_att;
string type_att;
string public_attr;
string persistent_attr;
string dev_prefix;
ostringstream tmp_hashstream;
@ -204,6 +199,23 @@ int Image::insert(SqlDB *db)
public_img = (public_attr == "YES");
// ------------ PERSISTENT --------------------
get_template_attribute("PERSISTENT", persistent_attr);
image_template->erase("PERSISTENT");
transform (persistent_attr.begin(), persistent_attr.end(), persistent_attr.begin(),
(int(*)(int))toupper);
persistent_img = (persistent_attr == "YES");
// An image cannot be public and persistent simultaneously
if ( public_img && persistent_img )
{
goto error_public_and_persistent;
}
// ------------ PREFIX --------------------
get_template_attribute("DEV_PREFIX", dev_prefix);
@ -225,46 +237,36 @@ int Image::insert(SqlDB *db)
source = tmp_sourcestream.str();
// ------------ INSERT THE TEMPLATE --------------------
if ( image_template->id == -1 )
{
image_template->id = oid;
}
state = DISABLED;
rc = image_template->insert(db);
if ( rc != 0 )
{
return rc;
}
//--------------------------------------------------------------------------
// Insert the Image
//--------------------------------------------------------------------------
rc = insert_replace(db, false);
if ( rc != 0 )
if ( rc == -1 )
{
image_template->drop(db);
return rc;
error_str = "Error inserting Image in DB.";
}
return 0;
return rc;
error_name:
NebulaLog::log("IMG", Log::ERROR, "NAME not present in image template");
error_str = "NAME not present in image template.";
goto error_common;
error_type:
NebulaLog::log("IMG", Log::ERROR, "Incorrect TYPE in image template");
error_str = "Incorrect TYPE in image template.";
goto error_common;
error_public_and_persistent:
error_str = "Image cannot be public and persistent.";
goto error_common;
error_common:
NebulaLog::log("IMG", Log::ERROR, error_str);
return -1;
}
@ -285,10 +287,13 @@ int Image::insert_replace(SqlDB *db, bool replace)
int rc;
string xml_template;
char * sql_name;
char * sql_source;
char * sql_template;
// Update the Image
// Update the Image
sql_name = db->escape_str(name.c_str());
@ -304,6 +309,14 @@ int Image::insert_replace(SqlDB *db, bool replace)
goto error_source;
}
image_template->to_xml(xml_template);
sql_template = db->escape_str(xml_template.c_str());
if ( sql_template == 0 )
{
goto error_template;
}
if(replace)
{
oss << "REPLACE";
@ -321,18 +334,23 @@ int Image::insert_replace(SqlDB *db, bool replace)
<< "'" << sql_name << "',"
<< type << ","
<< public_img << ","
<< persistent_img << ","
<< regtime << ","
<< "'" << sql_source << "',"
<< state << ","
<< running_vms << ")";
<< running_vms << ","
<< "'" << sql_template << "')";
rc = db->exec(oss);
db->free_str(sql_name);
db->free_str(sql_source);
db->free_str(sql_template);
return rc;
error_template:
db->free_str(sql_source);
error_source:
db->free_str(sql_name);
error_name:
@ -344,15 +362,17 @@ error_name:
int Image::dump(ostringstream& oss, int num, char **values, char **names)
{
if ((!values[OID]) ||
(!values[UID]) ||
(!values[NAME]) ||
(!values[TYPE]) ||
(!values[PUBLIC]) ||
(!values[REGTIME]) ||
(!values[SOURCE]) ||
(!values[STATE]) ||
(!values[RUNNING_VMS]) ||
if ((!values[OID]) ||
(!values[UID]) ||
(!values[NAME]) ||
(!values[TYPE]) ||
(!values[PUBLIC]) ||
(!values[PERSISTENT]) ||
(!values[REGTIME]) ||
(!values[SOURCE]) ||
(!values[STATE]) ||
(!values[RUNNING_VMS]) ||
(!values[TEMPLATE]) ||
(num != LIMIT + 1))
{
return -1;
@ -366,10 +386,12 @@ int Image::dump(ostringstream& oss, int num, char **values, char **names)
"<NAME>" << values[NAME] << "</NAME>" <<
"<TYPE>" << values[TYPE] << "</TYPE>" <<
"<PUBLIC>" << values[PUBLIC] << "</PUBLIC>" <<
"<PERSISTENT>" << values[PERSISTENT] << "</PERSISTENT>" <<
"<REGTIME>" << values[REGTIME] << "</REGTIME>" <<
"<SOURCE>" << values[SOURCE] << "</SOURCE>" <<
"<STATE>" << values[STATE] << "</STATE>" <<
"<RUNNING_VMS>" << values[RUNNING_VMS] << "</RUNNING_VMS>" <<
values[TEMPLATE] <<
"</IMAGE>";
return 0;
@ -389,8 +411,6 @@ int Image::drop(SqlDB * db)
return -1;
}
image_template->drop(db);
oss << "DELETE FROM " << table << " WHERE oid=" << oid;
rc = db->exec(oss);
@ -425,20 +445,19 @@ string& Image::to_xml(string& xml) const
string template_xml;
ostringstream oss;
oss <<
"<IMAGE>" <<
"<ID>" << oid << "</ID>" <<
"<UID>" << uid << "</UID>" <<
"<NAME>" << name << "</NAME>" <<
"<TYPE>" << type << "</TYPE>" <<
"<PUBLIC>" << public_img << "</PUBLIC>" <<
"<REGTIME>" << regtime << "</REGTIME>" <<
"<SOURCE>" << source << "</SOURCE>" <<
"<STATE>" << state << "</STATE>" <<
"<RUNNING_VMS>" << running_vms << "</RUNNING_VMS>" <<
image_template->to_xml(template_xml) <<
"<ID>" << oid << "</ID>" <<
"<UID>" << uid << "</UID>" <<
"<NAME>" << name << "</NAME>" <<
"<TYPE>" << type << "</TYPE>" <<
"<PUBLIC>" << public_img << "</PUBLIC>" <<
"<PERSISTENT>" << persistent_img << "</PERSISTENT>" <<
"<REGTIME>" << regtime << "</REGTIME>" <<
"<SOURCE>" << source << "</SOURCE>" <<
"<STATE>" << state << "</STATE>" <<
"<RUNNING_VMS>" << running_vms << "</RUNNING_VMS>" <<
image_template->to_xml(template_xml) <<
"</IMAGE>";
xml = oss.str();
@ -456,15 +475,16 @@ string& Image::to_str(string& str) const
ostringstream os;
os <<
"ID = " << oid << endl <<
"UID = " << uid << endl <<
"NAME = " << name << endl <<
"TYPE = " << type << endl <<
"PUBLIC = " << public_img << endl <<
"REGTIME = " << regtime << endl <<
"SOURCE = " << source << endl <<
"STATE = " << state << endl <<
"RUNNING_VMS = " << running_vms << endl <<
"ID = " << oid << endl <<
"UID = " << uid << endl <<
"NAME = " << name << endl <<
"TYPE = " << type << endl <<
"PUBLIC = " << public_img << endl <<
"PERSISTENT = " << persistent_img << endl <<
"REGTIME = " << regtime << endl <<
"SOURCE = " << source << endl <<
"STATE = " << state << endl <<
"RUNNING_VMS = " << running_vms << endl <<
"TEMPLATE" << endl
<< image_template->to_str(template_str)
<< endl;
@ -490,7 +510,14 @@ int Image::acquire_image()
break;
case USED:
running_vms++;
if (persistent_img)
{
rc = -1;
}
else
{
running_vms++;
}
break;
case DISABLED:
@ -539,17 +566,21 @@ int Image::disk_attribute( VectorAttribute * disk,
ImageType* img_type)
{
string bus;
string target;
ostringstream iid;
*img_type = type;
bus = disk->vector_value("BUS");
target = disk->vector_value("TARGET");
iid << oid;
string template_bus;
string template_target;
string prefix;
get_template_attribute("BUS", template_bus);
get_template_attribute("TARGET", template_target);
get_template_attribute("DEV_PREFIX", prefix);
//--------------------------------------------------------------------------
@ -571,24 +602,31 @@ int Image::disk_attribute( VectorAttribute * disk,
new_disk.insert(make_pair("IMAGE_ID", iid.str()));
new_disk.insert(make_pair("SOURCE", source));
if (bus.empty())
{
if (!template_bus.empty())
{
new_disk.insert(make_pair("BUS",template_bus));
}
}
else
if (!bus.empty())
{
new_disk.insert(make_pair("BUS",bus));
}
else if (!template_bus.empty())
{
new_disk.insert(make_pair("BUS",template_bus));
}
//---------------------------------------------------------------------------
// TYPE, READONLY, CLONE, and SAVE attributes
//---------------------------------------------------------------------------
new_disk.insert(make_pair("CLONE","YES"));
new_disk.insert(make_pair("SAVE","NO"));
if ( persistent_img )
{
new_disk.insert(make_pair("CLONE","NO"));
new_disk.insert(make_pair("SAVE","YES"));
new_disk.insert(make_pair("SAVE_AS", iid.str())); // Tells the hook to overwrite
}
else
{
new_disk.insert(make_pair("CLONE","YES"));
new_disk.insert(make_pair("SAVE","NO"));
}
switch(type)
{
@ -608,23 +646,35 @@ int Image::disk_attribute( VectorAttribute * disk,
// TARGET attribute
//---------------------------------------------------------------------------
switch(type)
if (!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;
new_disk.insert(make_pair("TARGET", target));
}
else if (!template_target.empty())
{
new_disk.insert(make_pair("TARGET", template_target));
}
else
{
switch(type)
{
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;
}
new_disk.insert(make_pair("TARGET", prefix));
}
new_disk.insert(make_pair("TARGET", prefix));
disk->replace(new_disk);

View File

@ -90,7 +90,8 @@ ImagePool::ImagePool( SqlDB * db,
int ImagePool::allocate (
int uid,
ImageTemplate* img_template,
int * oid)
int * oid,
string& error_str)
{
Image * img;
string name;
@ -105,7 +106,7 @@ int ImagePool::allocate (
// ---------------------------------------------------------------------
// Insert the Object in the pool
// ---------------------------------------------------------------------
*oid = PoolSQL::allocate(img);
*oid = PoolSQL::allocate(img, error_str);
// ---------------------------------------------------------------------
// Add the image name to the map of image_names

View File

@ -1,22 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "ImageTemplate.h"
const char * ImageTemplate::table = "image_attributes";
const char * ImageTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS"
" image_attributes (id INTEGER, name TEXT, type INTEGER, value TEXT)";

View File

@ -22,7 +22,6 @@ lib_name='nebula_image'
# Sources to generate the library
source_files=[
'ImageTemplate.cc',
'Image.cc',
'ImagePool.cc'
]

View File

@ -31,6 +31,7 @@ const string templates[] =
{
"NAME = \"Image one\"\n"
"ORIGINAL_PATH = /tmp/image_test\n"
"PERSISTENT = YES\n"
"DESCRIPTION = \"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.\"\n",
"NAME = \"Second Image\"\n"
@ -48,20 +49,19 @@ const string templates[] =
const string xmls[] =
{
"<IMAGE><ID>0</ID><UID>0</UID><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><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><ORIGINAL_PATH><![CDATA[/tmp/image_test]]></ORIGINAL_PATH></TEMPLATE></IMAGE>",
"<IMAGE><ID>0</ID><UID>0</UID><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198</SOURCE><STATE>3</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><ORIGINAL_PATH><![CDATA[/tmp/image_test]]></ORIGINAL_PATH></TEMPLATE></IMAGE>",
"<IMAGE><ID>1</ID><UID>1</UID><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><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><ORIGINAL_PATH><![CDATA[/tmp/image_second_test]]></ORIGINAL_PATH></TEMPLATE></IMAGE>",
"<IMAGE><ID>1</ID><UID>1</UID><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f3</SOURCE><STATE>3</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><ORIGINAL_PATH><![CDATA[/tmp/image_second_test]]></ORIGINAL_PATH></TEMPLATE></IMAGE>",
"<IMAGE><ID>0</ID><UID>2</UID><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><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><ORIGINAL_PATH><![CDATA[/tmp/image_test]]></ORIGINAL_PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE>"
"<IMAGE><ID>0</ID><UID>2</UID><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/e50b0c738be9d431475bf5859629e5580301a7d6</SOURCE><STATE>3</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><ORIGINAL_PATH><![CDATA[/tmp/image_test]]></ORIGINAL_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>one_user_test</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>A user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f3</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS></IMAGE><IMAGE><ID>2</ID><UID>2</UID><USERNAME>B user</USERNAME><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/e50b0c738be9d431475bf5859629e5580301a7d6</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS></IMAGE></IMAGE_POOL>";
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><USERNAME>one_user_test</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198</SOURCE><STATE>3</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><ORIGINAL_PATH><![CDATA[/tmp/image_test]]></ORIGINAL_PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>A user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f3</SOURCE><STATE>3</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><ORIGINAL_PATH><![CDATA[/tmp/image_second_test]]></ORIGINAL_PATH></TEMPLATE></IMAGE><IMAGE><ID>2</ID><UID>2</UID><USERNAME>B 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>3</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><ORIGINAL_PATH><![CDATA[/tmp/image_test]]></ORIGINAL_PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE></IMAGE_POOL>";
const string xml_dump_where =
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><USERNAME>one_user_test</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>A user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f3</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS></IMAGE></IMAGE_POOL>";
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><USERNAME>one_user_test</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198</SOURCE><STATE>3</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><ORIGINAL_PATH><![CDATA[/tmp/image_test]]></ORIGINAL_PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>A user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f3</SOURCE><STATE>3</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><ORIGINAL_PATH><![CDATA[/tmp/image_second_test]]></ORIGINAL_PATH></TEMPLATE></IMAGE></IMAGE_POOL>";
const string replacement = "0000000000";
@ -84,16 +84,23 @@ public:
ImageTemplate * img_template;
char * error_msg = 0;
int rc;
string err;
img_template = new ImageTemplate;
rc = img_template->parse(stemplate,&error_msg);
if( rc == 0 )
{
return ImagePool::allocate(uid, img_template, oid);
return ImagePool::allocate(uid, img_template, oid, err);
}
else
{
if (error_msg != 0 )
{
free(error_msg);
}
delete img_template;
return -2;
}
};
@ -119,7 +126,7 @@ class ImagePoolTest : public PoolTest
CPPUNIT_TEST ( target_generation );
CPPUNIT_TEST ( bus_source_assignment );
CPPUNIT_TEST ( public_attribute );
CPPUNIT_TEST ( disk_overwrite );
CPPUNIT_TEST ( persistence );
CPPUNIT_TEST ( imagepool_disk_attribute );
CPPUNIT_TEST ( dump );
CPPUNIT_TEST ( dump_where );
@ -174,6 +181,7 @@ protected:
// So the ONE_AUTH environment is forced to point to a test one_auth
// file.
ostringstream oss;
string err;
oss << getenv("PWD") << "/one_auth";
setenv("ONE_AUTH", oss.str().c_str(), 1);
@ -188,17 +196,17 @@ protected:
string pass_1 = "A pass";
string pass_2 = "B pass";
user_pool->allocate(&uid_1, username_1, pass_1, true);
user_pool->allocate(&uid_2, username_2, pass_2, true);
user_pool->allocate(&uid_1, username_1, pass_1, true, err);
user_pool->allocate(&uid_2, username_2, pass_2, true, err);
delete user_pool;
};
public:
ImagePoolTest(){};
ImagePoolTest(){xmlInitParser();};
~ImagePoolTest(){};
~ImagePoolTest(){xmlCleanupParser();};
/* ********************************************************************* */
@ -255,9 +263,11 @@ public:
CPPUNIT_ASSERT( img != 0 );
// Image object should be cached. Let's change some template attributes
ip->replace_attribute(img, description_name, new_description);
ip->replace_attribute(img, attr_name, new_attr_value);
ip->remove_attribute(img, "ORIGINAL_PATH");
img->replace_template_attribute(description_name, new_description);
img->replace_template_attribute(attr_name, new_attr_value);
img->remove_template_attribute("ORIGINAL_PATH");
ip->update(img);
img->unlock();
@ -466,7 +476,7 @@ public:
CPPUNIT_ASSERT( oid == 0 );
img->enable(true);
img->disk_attribute(disk, &index, img_type);
img->disk_attribute(disk, &index, &img_type);
value = disk->vector_value("TARGET");
@ -488,7 +498,7 @@ public:
img = imp->get(oid, false);
img->enable(true);
img->disk_attribute(disk, &index, img_type);
img->disk_attribute(disk, &index, &img_type);
value = disk->vector_value("TARGET");
CPPUNIT_ASSERT(value == "hdc");
@ -509,7 +519,7 @@ public:
img = imp->get(oid, false);
img->enable(true);
img->disk_attribute(disk, &index, img_type);
img->disk_attribute(disk, &index, &img_type);
value = disk->vector_value("TARGET");
CPPUNIT_ASSERT(value == "hde");
@ -530,7 +540,7 @@ public:
img = imp->get(oid, false);
img->enable(true);
img->disk_attribute(disk, &index, img_type);
img->disk_attribute(disk, &index, &img_type);
value = disk->vector_value("TARGET");
CPPUNIT_ASSERT(value == "sdf");
@ -548,7 +558,7 @@ public:
Image * img;
VectorAttribute * disk;
int oid;
int rc, oid;
string value;
int index = 0;
Image::ImageType img_type;
@ -562,7 +572,8 @@ public:
disk = new VectorAttribute("DISK");
img->enable(true);
img->disk_attribute(disk, &index, img_type);
rc = img->disk_attribute(disk, &index, &img_type);
CPPUNIT_ASSERT( rc == 0 );
value = "";
value = disk->vector_value("BUS");
@ -574,6 +585,7 @@ public:
"source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198" );
// clean up
img->release_image();
delete disk;
// ---------------------------------------------------------------------
@ -582,7 +594,8 @@ public:
disk->replace("BUS", "SCSI");
img->enable(true);
img->disk_attribute(disk, &index, img_type);
rc = img->disk_attribute(disk, &index, &img_type);
CPPUNIT_ASSERT( rc == 0 );
value = disk->vector_value("BUS");
CPPUNIT_ASSERT( value == "SCSI" );
@ -596,137 +609,6 @@ public:
delete disk;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void disk_overwrite()
{
ImagePool * imp = static_cast<ImagePool *>(pool);
Image * img;
VectorAttribute * disk;
int oid, rc;
string value;
int index = 0;
Image::ImageType img_type;
// ---------------------------------------------------------------------
// Allocate an OS type image
oid = allocate(0);
CPPUNIT_ASSERT( oid > -1 );
img = imp->get(oid, false);
// Disk with overwrite=yes, save_as empty
disk = new VectorAttribute("DISK");
disk->replace("OVERWRITE", "yes");
img->enable(true);
rc = img->disk_attribute(disk, &index, img_type);
CPPUNIT_ASSERT( rc == 0 );
value = disk->vector_value("OVERWRITE");
CPPUNIT_ASSERT( value == "YES" );
value = "";
value = disk->vector_value("SAVE_AS");
CPPUNIT_ASSERT( value == "" );
value = "";
value = disk->vector_value("CLONE");
CPPUNIT_ASSERT( value == "NO" );
value = "";
value = disk->vector_value("SAVE");
CPPUNIT_ASSERT( value == "YES" );
value = "";
value = disk->vector_value("READONLY");
CPPUNIT_ASSERT( value == "NO" );
// clean up
delete disk;
// ---------------------------------------------------------------------
// Allocate an OS type image
oid = allocate(1);
CPPUNIT_ASSERT( oid > -1 );
img = imp->get(oid, false);
// Disk with overwrite=no, save_as not empty
disk = new VectorAttribute("DISK");
disk->replace("OVERWRITE", "NO");
disk->replace("SAVE_AS", "path_to_save");
img->enable(true);
rc = img->disk_attribute(disk, &index, img_type);
CPPUNIT_ASSERT( rc == 0 );
value = "";
value = disk->vector_value("OVERWRITE");
CPPUNIT_ASSERT( value == "NO" );
value = "";
value = disk->vector_value("SAVE_AS");
CPPUNIT_ASSERT( value == "path_to_save" );
value = "";
value = disk->vector_value("CLONE");
CPPUNIT_ASSERT( value == "YES" );
value = "";
value = disk->vector_value("SAVE");
CPPUNIT_ASSERT( value == "YES" );
value = "";
value = disk->vector_value("READONLY");
CPPUNIT_ASSERT( value == "NO" );
// clean up
delete disk;
// ---------------------------------------------------------------------
// Allocate an OS type image
oid = allocate(2);
CPPUNIT_ASSERT( oid > -1 );
img = imp->get(oid, false);
// Disk with overwrite=no, save_as not present
disk = new VectorAttribute("DISK");
disk->replace("OVERWRITE", "NO");
img->enable(true);
rc = img->disk_attribute(disk, &index, img_type);
CPPUNIT_ASSERT( rc == 0 );
value = "";
value = disk->vector_value("OVERWRITE");
CPPUNIT_ASSERT( value == "NO" );
value = "";
value = disk->vector_value("SAVE_AS");
CPPUNIT_ASSERT( value == "" );
value = "";
value = disk->vector_value("CLONE");
CPPUNIT_ASSERT( value == "YES" );
value = "";
value = disk->vector_value("SAVE");
CPPUNIT_ASSERT( value == "NO" );
value = "";
value = disk->vector_value("READONLY");
CPPUNIT_ASSERT( value == "NO" );
// clean up
delete disk;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -736,7 +618,7 @@ public:
Image * img;
VectorAttribute * disk;
int oid_0, oid_1;
int oid_0, oid_1, index;
string value;
Image::ImageType img_type;
@ -770,7 +652,7 @@ public:
disk = new VectorAttribute("DISK");
disk->replace("IMAGE", "Image 0");
((ImagePool*)imp)->disk_attribute(disk, 0, img_type);
((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type);
value = "";
value = disk->vector_value("TARGET");
@ -787,7 +669,7 @@ public:
disk = new VectorAttribute("DISK");
disk->replace("IMAGE_ID", "1");
((ImagePool*)imp)->disk_attribute(disk, 0, img_type);
((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type);
value = "";
value = disk->vector_value("TARGET");
@ -877,6 +759,108 @@ public:
i++;
}
bool success;
// img 0 is not public.
img = imp->get( 0, false );
CPPUNIT_ASSERT( img != 0 );
success = img->publish(false);
CPPUNIT_ASSERT( success == true );
CPPUNIT_ASSERT( img->isPublic() == false );
success = img->publish(true);
CPPUNIT_ASSERT( success == true );
CPPUNIT_ASSERT( img->isPublic() == true );
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void persistence()
{
int oid;
bool success;
ImagePoolFriend * imp = static_cast<ImagePoolFriend *>(pool);
Image * img;
string templates [] =
{
"NAME = \"Image 1\"\n"
"PERSISTENT = NO\n"
"PUBLIC = NO\n",
"NAME = \"Image 2\"\n"
"PERSISTENT = NO\n"
"PUBLIC = YES\n",
"NAME = \"Image 3\"\n"
"PERSISTENT = YES\n"
"PUBLIC = NO\n",
"NAME = \"Image 4\"\n"
"PERSISTENT = YES\n"
"PUBLIC = YES\n",
"END"
};
bool results[] = { true, true, true, false };
bool persistent[] = { false, false, true };
int i = 0;
while( templates[i] != "END" )
{
imp->allocate(0, templates[i], &oid);
//cout << endl << i << " : exp. " << results[i] << " got " << (oid >= 0);
CPPUNIT_ASSERT( (oid >= 0) == results[i] );
if( oid >= 0 )
{
img = imp->get( oid, false );
CPPUNIT_ASSERT( img != 0 );
CPPUNIT_ASSERT( img->isPersistent() == persistent[i] );
}
i++;
}
// img 0 is not persistent
img = imp->get( 0, false );
CPPUNIT_ASSERT( img != 0 );
// make it persistent
success = img->persistent(true);
CPPUNIT_ASSERT( success == true );
CPPUNIT_ASSERT( img->isPersistent() == true );
// it isn't public, try to unpublish
success = img->publish(false);
CPPUNIT_ASSERT( success == true );
CPPUNIT_ASSERT( img->isPublic() == false );
// try to publish, should fail because it is persistent
success = img->publish(true);
CPPUNIT_ASSERT( success == false );
CPPUNIT_ASSERT( img->isPublic() == false );
// make it non-persistent
success = img->persistent(false);
CPPUNIT_ASSERT( success == true );
CPPUNIT_ASSERT( img->isPersistent() == false );
// it isn't public, try to unpublish
success = img->publish(false);
CPPUNIT_ASSERT( success == true );
CPPUNIT_ASSERT( img->isPublic() == false );
// try to publish, now it should be possible
success = img->publish(true);
CPPUNIT_ASSERT( success == true );
CPPUNIT_ASSERT( img->isPublic() == true );
}
/* -------------------------------------------------------------------------- */
@ -901,9 +885,9 @@ public:
string result = oss.str();
result.replace(138, 10, replacement);
result.replace(403, 10, replacement);
result.replace(671, 10, replacement);
result.replace(164, 10, replacement);
result.replace(1154, 10, replacement);
result.replace(1684, 10, replacement);
CPPUNIT_ASSERT( result == xml_dump );
}
@ -931,9 +915,8 @@ public:
CPPUNIT_ASSERT(rc == 0);
string result = oss.str();
result.replace(138, 10, replacement);
result.replace(403, 10, replacement);
result.replace(164, 10, replacement);
result.replace(1154, 10, replacement);
CPPUNIT_ASSERT( result == xml_dump_where );
}

View File

@ -80,6 +80,9 @@ main_env.Append(LIBS=[
main_env.Append(LIBPATH=["/usr/lib/mysql"])
main_env.Append(CPPPATH=["/usr/include/mysql"])
# libxml2
main_env.ParseConfig('xml2-config --libs --cflags')
sqlite=ARGUMENTS.get('sqlite', 'yes')
if sqlite=='yes':
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])

View File

@ -612,6 +612,7 @@ void LifeCycleManager::cancel_success_action(int vid)
return;
}
vm->set_running_etime(the_time);
vm->set_etime(the_time);
vm->set_reason(History::CANCEL);

View File

@ -112,7 +112,7 @@ class ActionManager
return
end
arity=@actions[aname][:method].arity
arity=@actions[aname][:method].arity
if arity < 0
# Last parameter is an array
@ -140,13 +140,18 @@ class ActionManager
def cancel_action(action_id)
@threads_mutex.synchronize {
thread = @action_running[action_id]
action = @action_running[action_id]
if action
thread = action[:thread]
else
thread = nil
end
if thread
thread.kill
@num_running -= 1
@action_running.delete(action_id)
delete_running_action(action_id)
@threads_cond.signal
else
@ -159,8 +164,7 @@ class ActionManager
def start_listener
while true
@threads_mutex.synchronize {
while ((@concurrency - @num_running)==0) ||
@action_queue.size==0
while ((@concurrency - @num_running)==0) || empty_queue
@threads_cond.wait(@threads_mutex)
return if (@finalize && @num_running == 0)
@ -170,11 +174,23 @@ class ActionManager
}
end
end
private
def delete_running_action(action_id)
@action_running.delete(action_id)
end
def get_runable_action
@action_queue.shift
end
def empty_queue
@action_queue.size==0
end
def run_action
action = @action_queue.shift
action = get_runable_action
if action
@num_running += 1
@ -185,13 +201,14 @@ private
@threads_mutex.synchronize {
@num_running -= 1
@action_running.delete(action[:id])
delete_running_action(action[:id])
@threads_cond.signal
}
}
@action_running[action[:id]] = thread
action[:thread] = thread
@action_running[action[:id]] = action
else
action[:method].call(*action[:args])
@ -212,6 +229,17 @@ if __FILE__ == $0
@am.register_action(:SLEEP,method("sleep_action"))
# @am.register_action(:SLEEP,Proc.new{|s,i| p s ; sleep(s)})
@am.register_action(:NOP,method("nop_action"))
def @am.get_runable_action
action = super
puts "getting: #{action.inspect}"
action
end
def @am.delete_running_action(action_id)
puts "deleting: #{action_id}"
super(action_id)
end
end
def sleep_action(secs, id)
@ -223,6 +251,7 @@ if __FILE__ == $0
def nop_action
p " - Just an action"
end
end
s = Sample.new

View File

@ -1,131 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require 'thread'
=begin rdoc
Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
This class manages a pool of threads with a maximun number of concurrent running jobs.
== Example
Creates 1000 threads that sleep 1 second and executes them with a concurrency of 100.
th=ThreadScheduler.new(100)
1000.times {
th.new_thread {
sleep 1
}
}
=end
class ThreadScheduler
# Creates a new thread pool
#
# +concurrent_number+ is the maximun number of threads that can run
# at the same time
def initialize(concurrent_number=10)
@concurrent_number=concurrent_number
@thread_queue=Array.new
@running_threads=0
@threads_mutex=Mutex.new
@threads_cond=ConditionVariable.new
start_thread_runner
end
# Creates a new job that will be placed on the queue. It will be scheduled
# when there is room at the selected concurrency level. Job is a block.
def new_thread(&block)
@threads_mutex.synchronize {
@thread_queue<<block
if @running_threads < @concurrent_number
# Awakes thread runner only if there is room for a new thread
@threads_cond.signal
end
}
end
# Kills the thread that manages job queues. Should be called before
# exiting
def shutdown
@thread_runner.kill!
end
private
# Selects new jobs to be run as threads
#
# NOTE: should be called inside a syncronize block
def run_new_thread
thread = @thread_queue.shift
if thread
@running_threads += 1
Thread.new {
thread.call
@threads_mutex.synchronize {
# Tell thread runner that the thread has finished
@running_threads -= 1
@threads_cond.signal
}
}
end
end
def start_thread_runner
@thread_runner=Thread.new {
while true
@threads_mutex.synchronize {
while ((@concurrent_number-@running_threads)==0) ||
@thread_queue.size==0
@threads_cond.wait(@threads_mutex)
end
run_new_thread
}
end
}
end
end
if __FILE__ == $0
th=ThreadScheduler.new(20)
100.times {|n|
100.times {|m|
th.new_thread {
puts "Starting #{m+n*100}"
sleep 1
#puts "Finishing #{m+n*100}"
}
}
}
th.new_thread {
sleep 4
th.shutdown
exit(0)
}
sleep 3600
end

View File

@ -59,12 +59,16 @@ class VirtualMachineDriver < OpenNebulaDriver
:deleted => 'd',
:unknown => '-'
}
HOST_ARG = 1
# -------------------------------------------------------------------------
# Register default actions for the protocol
# -------------------------------------------------------------------------
def initialize(concurrency=10, threaded=true)
super(concurrency,threaded)
@hosts = Array.new
register_action(ACTION[:deploy].to_sym, method("deploy"))
register_action(ACTION[:shutdown].to_sym, method("shutdown"))
@ -152,6 +156,54 @@ class VirtualMachineDriver < OpenNebulaDriver
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:poll],RESULT[:failure],id,error)
end
private
def delete_running_action(action_id)
action=@action_running[action_id]
if action
@hosts.delete(action[:args][HOST_ARG])
@action_running.delete(action_id)
end
end
def get_first_runable
action_index=@action_queue.index do |action|
if action[:args][HOST_ARG]
!@hosts.include? action[:args][HOST_ARG]
else
true
end
end
return action_index
end
def get_runable_action
action_index=get_first_runable
if action_index
action=@action_queue[action_index]
else
action=nil
end
if action
@hosts << action[:args][HOST_ARG] if action[:args][HOST_ARG]
@action_queue.delete_at(action_index)
end
STDERR.puts "action: #{action.inspect}"
STDERR.puts "queue: #{@action_queue.inspect}"
STDERR.puts "hosts: #{@hosts.inspect}"
STDERR.flush
return action
end
def empty_queue
get_first_runable==nil
end
end
if __FILE__ == $0

View File

@ -1,179 +0,0 @@
# --------------------------------------------------------------------------
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# --------------------------------------------------------------------------
require "thread"
# Author:: dsa-research.org
# Copyright:: (c) 2007 Universidad Computense de Madrid
# License:: Apache License
# This class provides basic messaging and logging functionality.
#
# A MAD inherits this class and only has to provide methods
# for each action it wants to receive. This methods will be
# named action_<name_of_the_action>. For example a method that
# handles INIT message should be like this:
#
# def action_init(args)
# call_some_function(args[2], args[3])
# send_message("INIT", "SUCCESS")
# end
class ONEMad
##
# Debug constants
##
ERROR, DEBUG=[0,1]
# * +num_params_in+: number of parameters that mensages will have
# * +num_params_out+: number of parameters that mensages sent back
# will have
def initialize(num_params_in, num_params_out=nil)
@num_params=num_params_in
if !num_params_out
@num_params_out=num_params_in
else
@num_params_out=num_params_out
end
@debug_level = -1
@send_mutex=Mutex.new
end
# Sends a message to the logger
def log(str, level)
if level == ERROR
str = "------- ERROR ---------------\n" +
str + "\n-----------------------------"
end
if @debug_level != -1 and level <= @debug_level
str.split("\n").each{|line|
@logger.puts(Time.now.ctime + ": " + line.strip)
@logger.flush
}
end
end
# Sets the logger file, this can be an open file
def set_logger(logger, level)
@debug_level = level.to_i
@logger=logger
end
# Main loop that will get messages from STDIN and call any
# action associated to the message.
def loop
while true
exit(-1) if STDIN.eof?
str=STDIN.gets
next if !str
line=str.split(/\s+/)
log(str,DEBUG)
args=Array.new
args+=line[0..(@num_params-2)]
args<<line[(@num_params-1)..-1].join(' ') if line.length>=@num_params
process args
end
end
# Sends a message to ONE, this takes an array with the message and arguments.
# If the message is shorter than the number of parameters specified in the
# initialization more marameters will be added containing '-'.
def send_message(*args)
@send_mutex.synchronize {
to_send=args
if args.length<@num_params_out
(@num_params_out-args.length).times{ to_send<<'-' }
end
STDOUT.puts to_send.join(' ')
STDOUT.flush
log(to_send.join(' '),DEBUG)
}
end
# Sends a log message to ONE. The +message+ can be multiline, it will
# be automatically splitted by lines.
def mad_log(command, number, message)
msg=message.strip
msg.each_line {|line|
send_message("LOG", "-", number, line.strip)
}
end
# Proceses each message received, called by +loop+.
def process(args)
return nil if !args or !args[0]
action=args[0].downcase
if self.respond_to?("action_#{action}")
self.action_debug(args)
self.send("action_#{action}", args)
else
self.action_debug(args)
end
end
# Action called when there is not a handler for a message. By default it
# logs the message, but can be redefined to do any other thing.
def action_debug(args)
#@logger.puts(args.join(';'))
end
# Default FINALIZE action. Exists the program.
def action_finalize(args)
exit(0)
end
# Functions for VM deployment
# TODO: Move elsewhere
def get_local_deployment_file(remote_deployment_file)
local_deployment_file=nil
one_location=ENV["ONE_LOCATION"]
if one_location == nil
var_location = "/var/lib/one/"
else
var_location = one_location + "/var/"
end
m=remote_deployment_file.match(/.*?\/(\d+)\/images\/(deployment.\d+)$/)
local_deployment_file="#{var_location}#{m[1]}/#{m[2]}" if m
return local_deployment_file
end
def execute_local_command(cmd_string)
command=SSHCommand.new(cmd_string)
stdout, stderr=command.exec_local_command(cmd_string)
exit_code=command.get_exit_code(stderr)
if exit_code!=0
return stderr
else
nil
end
end
end

View File

@ -1,199 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
=begin rdoc
Here will be a description of SSH library and an example on
how to use it.
=end
require 'pp'
require 'open3'
require 'thread'
require 'ThreadScheduler'
# This class holds a command that will be executed on a remote host
# using ssh. Commands can have an associated callback that will be
# after they finish.
class SSHCommand
attr_accessor :value, :code, :stdout, :stderr, :command
attr_accessor :callback
# Creates a new command
def initialize(command)
@command=command
@callback=nil
end
# Runs the command on the specified host
def run(host)
(@stdout, @stderr)=execute(host, @command)
@code=get_exit_code(@stderr)
end
# Executes callback associated to this command
def exec_callback(num)
if @callback
@callback.call(self, num)
end
end
#private
# Gets exit code from STDERR
def get_exit_code(str)
tmp=str.scan(/^ExitCode: (\d*)$/)
return nil if !tmp[0]
tmp[0][0].to_i
end
# Executes a command in a remote machine
def execute(host, command)
std=exec_remote_command(host, command)
[std[1].read, std[2].read]
end
# Low level local command execution
def exec_local_command(command)
std=Open3.popen3(
"#{command} ;"+
" echo ExitCode: $? 1>&2")
[std[1].read, std[2].read]
end
# Low level remote command execution
def exec_remote_command(host, command)
Open3.popen3(
"ssh -n #{host} #{command} ;"+
" echo ExitCode: $? 1>&2")
end
end
class SSHCommandList < Array
=begin
def clone_actions
new_array=Array.new
self.each {|s|
new_array << s.clone
}
new_array
end
=end
end
# An action is composed by one or more SSHCommands that will be executed in an
# specific host. It holds a number that is the command identifier for a MAD.
class SSHAction
attr_accessor :callback
def initialize(number, host, actions)
@number=number
@host=host
if actions.is_a?(SSHCommandList) || actions.is_a?(Array)
@actions=clone_actions(actions)
else
@actions=SSHCommandList.new
@actions<<actions
# Really needed
@actions=clone_actions(@actions)
end
@finished=false
@callback=nil
end
def finished
@finished
end
def run
run_actions
@finished=true
end
def run_actions
@actions.each {|a|
a.run(@host)
}
end
def exec_callbacks
@actions.each {|a|
a.exec_callback(@number)
}
if @callback
@callback.call(@actions, @number)
end
end
private
# Clone an array of sensors
def clone_actions(actions)
actions.collect{|a| a.clone }
end
end
module SSHActionController
def init_actions(num=10)
@thread_scheduler=ThreadScheduler.new(num)
end
def send_ssh_action(action)
@thread_scheduler.new_thread {
action.run
action.exec_callbacks
}
end
def action_finalize(args)
@thread_scheduler.shutdown
super(args)
end
end
=begin
EXAMPLE
def action_poll(args)
action_name=args[0]
action_number=args[1]
action_host=args[2]
action_dom=args[3]
poll=SSHCommand.new("xm poll #{action_dom}")
poll.callback = lambda {|a,num|
if a.code==0
STDOUT.puts("POLL #{num} SUCCESS #{a.stdout}")
else
STDOUT.puts("POLL #{num} FAILURE #{a.stderr}")
end
STDOUT.flush
}
cmd_list=SSHCommandList.new
cmd_list<<poll
poll_action=SSHAction.new(action_number, action_host, cmd_list)
send_ssh_action(poll_action)
end
=end

View File

@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdexcept>
#include <libxml/parser.h>
#include <signal.h>
#include <unistd.h>
@ -63,6 +64,15 @@ void Nebula::start()
throw runtime_error("Could not load nebula configuration file.");
}
string config_fname = log_location + "config";
ofstream config_file(config_fname.c_str(), ios_base::trunc & ios_base::out);
if (config_file.fail() == false)
{
config_file << *nebula_configuration << endl;
config_file.close();
}
// -----------------------------------------------------------
// Log system
// -----------------------------------------------------------
@ -108,13 +118,17 @@ void Nebula::start()
NebulaLog::log("ONE",Log::INFO,"----------------------------------------");
os.str("");
os << "\n--------------------------------------------";
os << "\n----------------------------------\n";
os << *nebula_configuration;
os << "\n--------------------------------------------";
os << "----------------------------------";
NebulaLog::log("ONE",Log::INFO,os);
// -----------------------------------------------------------
// Initialize the XML library
// -----------------------------------------------------------
xmlInitParser();
// -----------------------------------------------------------
// Pools
// -----------------------------------------------------------
@ -224,7 +238,7 @@ void Nebula::start()
nebula_configuration->get("VM_HOOK", vm_hooks);
vmpool = new VirtualMachinePool(db, vm_hooks);
vmpool = new VirtualMachinePool(db, vm_hooks,hook_location);
hpool = new HostPool(db);
nebula_configuration->get("MAC_PREFIX", mac_prefix);
@ -235,12 +249,6 @@ void Nebula::start()
upool = new UserPool(db);
nebula_configuration->get("IMAGE_REPOSITORY_PATH", repository_path);
if (repository_path.empty()) // Defaults to ONE_LOCATION/var
{
repository_path = var_location;
}
nebula_configuration->get("DEFAULT_IMAGE_TYPE", default_image_type);
nebula_configuration->get("DEFAULT_DEVICE_PREFIX",
default_device_prefix);
@ -345,7 +353,11 @@ void Nebula::start()
nebula_configuration->get("IM_MAD", im_mads);
im = new InformationManager(hpool,timer_period,monitor_period,im_mads);
im = new InformationManager(hpool,
timer_period,
monitor_period,
remotes_location,
im_mads);
}
catch (bad_alloc&)
{
@ -532,6 +544,9 @@ void Nebula::start()
pthread_join(rm->get_thread_id(),0);
pthread_join(hm->get_thread_id(),0);
//XML Library
xmlCleanupParser();
NebulaLog::log("ONE", Log::INFO, "All modules finalized, exiting.\n");
}

View File

@ -31,60 +31,114 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location)
{
ostringstream os;
SingleAttribute * attribute;
VectorAttribute * vattribute;
string value;
conf_file = etc_location + conf_name;
// MANAGER_TIMER
value = "15";
attribute = new SingleAttribute("MANAGER_TIMER",value);
conf_default.insert(make_pair(attribute->name(),attribute));
/*
#*******************************************************************************
# Daemon configuration attributes
#-------------------------------------------------------------------------------
# HOST_MONITORING_INTERVAL
# VM_POLLING_INTERVAL
# VM_DIR
# PORT
# DB
# VNC_BASE_PORT
#*******************************************************************************
*/
// MONITOR_INTERVAL
value = "600";
attribute = new SingleAttribute("HOST_MONITORING_INTERVAL",value);
conf_default.insert(make_pair(attribute->name(),attribute));
// POLL_INTERVAL
value = "300";
value = "600";
attribute = new SingleAttribute("VM_POLLING_INTERVAL",value);
conf_default.insert(make_pair(attribute->name(),attribute));
// MANAGER_TIMER
value = "30";
attribute = new SingleAttribute("MANAGER_TIMER",value);
conf_default.insert(make_pair(attribute->name(),attribute));
// MONITOR_INTERVAL
value = "300";
attribute = new SingleAttribute("HOST_MONITORING_INTERVAL",value);
conf_default.insert(make_pair(attribute->name(),attribute));
//XML-RPC Server PORT
value = "2633";
attribute = new SingleAttribute("PORT",value);
conf_default.insert(make_pair(attribute->name(),attribute));
//VM_DIR
//VM_DIR
attribute = new SingleAttribute("VM_DIR",var_location);
conf_default.insert(make_pair(attribute->name(),attribute));
//MAC_PREFIX
value = "00:01";
attribute = new SingleAttribute("MAC_PREFIX",value);
//XML-RPC Server PORT
value = "2633";
attribute = new SingleAttribute("PORT",value);
conf_default.insert(make_pair(attribute->name(),attribute));
//NETWORK_SIZE
value = "254";
attribute = new SingleAttribute("NETWORK_SIZE",value);
conf_default.insert(make_pair(attribute->name(),attribute));
//DB CONFIGURATION
map<string,string> vvalue;
vvalue.insert(make_pair("BACKEND","sqlite"));
//NETWORK_SIZE
vattribute = new VectorAttribute("DB",vvalue);
conf_default.insert(make_pair(attribute->name(),vattribute));
//VNC_BASE_PORT
value = "5900";
attribute = new SingleAttribute("VNC_BASE_PORT",value);
conf_default.insert(make_pair(attribute->name(),attribute));
//DEBUG_LEVEL
value = Log::WARNING;
attribute = new SingleAttribute("DEBUG_LEVEL",value);
conf_default.insert(make_pair(attribute->name(),attribute));
//XML-RPC Server PORT
value = "2633";
attribute = new SingleAttribute("PORT",value);
conf_default.insert(make_pair(attribute->name(),attribute));
/*
#*******************************************************************************
# Physical Networks configuration
#*******************************************************************************
# NETWORK_SIZE
# MAC_PREFIX
#*******************************************************************************
*/
//MAC_PREFIX
value = "02:00";
attribute = new SingleAttribute("MAC_PREFIX",value);
conf_default.insert(make_pair(attribute->name(),attribute));
//NETWORK_SIZE
value = "254";
attribute = new SingleAttribute("NETWORK_SIZE",value);
conf_default.insert(make_pair(attribute->name(),attribute));
/*
#*******************************************************************************
# 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";
attribute = new SingleAttribute("DEFAULT_IMAGE_TYPE",value);
conf_default.insert(make_pair(attribute->name(),attribute));
//DEFAULT_DEVICE_PREFIX
value = "hd";
attribute = new SingleAttribute("DEFAULT_DEVICE_PREFIX",value);
conf_default.insert(make_pair(attribute->name(),attribute));
}
@ -95,31 +149,31 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location)
int NebulaTemplate::load_configuration()
{
char * error = 0;
map<string, Attribute *>::iterator iter, j;
map<string, Attribute *>::iterator iter, j;
int rc;
string aname;
Attribute * attr;
rc = parse(conf_file.c_str(), &error);
if ( rc != 0 && error != 0)
{
cout << "\nError while parsing configuration file:\n" << error << endl;
free(error);
return -1;
}
for(iter=conf_default.begin();iter!=conf_default.end();)
{
aname = iter->first;
attr = iter->second;
j = attributes.find(aname);
if ( j == attributes.end() )
{
attributes.insert(make_pair(aname,attr));
@ -131,7 +185,7 @@ int NebulaTemplate::load_configuration()
conf_default.erase(iter++);
}
}
return 0;
}

View File

@ -15,6 +15,7 @@ require 'OpenNebula/VirtualNetwork'
require 'OpenNebula/VirtualNetworkPool'
require 'OpenNebula/Image'
require 'OpenNebula/ImagePool'
require 'OpenNebula/ImageRepository'
require 'OpenNebula/User'
require 'OpenNebula/UserPool'
require 'OpenNebula/Host'
@ -32,7 +33,7 @@ module OpenNebula
# -------------------------------------------------------------------------
class Error
attr_reader :message
# +message+ a description of the error
def initialize(message=nil)
@message=message
@ -50,21 +51,21 @@ module OpenNebula
def self.is_error?(value)
value.class==OpenNebula::Error
end
# -------------------------------------------------------------------------
# The client class, represents the connection with the core and handles the
# xml-rpc calls.
# -------------------------------------------------------------------------
class Client
attr_accessor :one_auth
begin
require 'xmlparser'
XMLPARSER=true
rescue LoadError
XMLPARSER=false
end
def initialize(secret=nil, endpoint=nil)
if secret
one_secret = secret
@ -86,8 +87,8 @@ module OpenNebula
one_secret=~/^(.+?):(.+)$/
user=$1
password=$2
if password.match(/^ssh:/)
if password.match(/^plain:/)
@one_auth = "#{user}:#{password.split(':').last}"
else
@one_auth = "#{user}:#{Digest::SHA1.hexdigest(password)}"
@ -100,24 +101,26 @@ module OpenNebula
else
@one_endpoint="http://localhost:2633/RPC2"
end
@server=XMLRPC::Client.new2(@one_endpoint)
end
def call(action, *args)
server=XMLRPC::Client.new2(@one_endpoint)
if XMLPARSER
server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
@server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
end
begin
response = server.call("one."+action, @one_auth, *args)
response = @server.call_async("one."+action, @one_auth, *args)
if response[0] == false
Error.new(response[1])
else
response[1] #response[1..-1]
response[1] #response[1..-1]
end
rescue Exception => e
Error.new(e.message)
Error.new(e.message)
end
end
end

View File

@ -7,13 +7,14 @@ module OpenNebula
# Constants and Class Methods
# ---------------------------------------------------------------------
IMAGE_METHODS = {
:info => "image.info",
:allocate => "image.allocate",
:update => "image.update",
:rmattr => "image.rmattr",
:enable => "image.enable",
:publish => "image.publish",
:delete => "image.delete"
:info => "image.info",
:allocate => "image.allocate",
:update => "image.update",
:rmattr => "image.rmattr",
:enable => "image.enable",
:publish => "image.publish",
:persistent => "image.persistent",
:delete => "image.delete"
}
IMAGE_STATES=%w{INIT READY USED DISABLED}
@ -55,7 +56,6 @@ module OpenNebula
super(xml,client)
@client = client
@immanager = ImageManager.new
end
#######################################################################
@ -109,27 +109,22 @@ module OpenNebula
def unpublish
set_publish(false)
end
# Makes the Image persistent
def persistent
set_persistent(true)
end
# Makes the Image non persistent
def nonpersistent
set_persistent(false)
end
# Deletes the Image
def delete()
super(IMAGE_METHODS[:delete])
end
def copy(path, source)
@immanager.copy(path, source)
end
def move(path, source)
@immanager.move(path, source)
end
def mk_datablock(size, fstype, source)
rc = @immanager.dd(size, source)
return rc if OpenNebula.is_error?(rc)
@immanager.mkfs(fstype, source)
end
#######################################################################
# Helpers to get Image information
@ -184,6 +179,15 @@ module OpenNebula
return rc
end
def set_persistent(persistence)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(IMAGE_METHODS[:persistent], @pe_id, persistence)
rc = nil if !OpenNebula.is_error?(rc)
return rc
end
def do_rm_attr(name)
return Error.new('ID not defined') if !@pe_id
@ -195,81 +199,4 @@ module OpenNebula
end
end
class ImageManager
# ---------------------------------------------------------------------
# Constants and Class Methods
# ---------------------------------------------------------------------
FS_UTILS = {
:dd => "env dd",
:mkfs => "env mkfs"
}
def copy(path, source)
if source.nil? or path.nil?
return OpenNebula::Error.new("copy Image: missing parameters.")
end
begin
FileUtils.copy(path, source)
FileUtils.chmod(0660, source)
rescue Exception => e
return OpenNebula::Error.new(e.message)
end
return nil
end
def move(path, source)
if source.nil? or path.nil?
return OpenNebula::Error.new("copy Image: missing parameters.")
end
begin
FileUtils.move(path, source)
FileUtils.chmod(0660, source)
rescue Exception => e
return OpenNebula::Error.new(e.message)
end
return nil
end
def dd(size, source)
if source.nil? or size.nil?
return OpenNebula::Error.new("dd Image: missing parameters.")
end
command = ""
command << FS_UTILS[:dd]
command << " if=/dev/zero of=#{source} ibs=1 count=1"
command << " obs=1048576 seek=#{size}"
local_command=LocalCommand.run(command)
if local_command.code!=0
return OpenNebula::Error.new("dd Image: in dd command.")
end
return nil
end
def mkfs(fstype, source)
if source.nil? or fstype.nil?
return OpenNebula::Error.new("mkfs Image: missing parameters.")
end
command = ""
command << FS_UTILS[:mkfs]
command << " -t #{fstype} -F #{source}"
local_command=LocalCommand.run(command)
if local_command.code!=0
return OpenNebula::Error.new("mkfs Image: in mkfs command.")
end
return nil
end
end
end

View File

@ -0,0 +1,185 @@
require 'OpenNebula/Image'
require 'fileutils'
module OpenNebula
class ImageRepository
def create(image, template, copy=true)
if image.nil?
error_msg = "Image could not be found, aborting."
result = OpenNebula::Error.new(error_msg)
end
# ------ Allocate the Image ------
result = image.allocate(template)
if OpenNebula.is_error?(result)
puts result.message
exit -1
end
# ------ Copy the Image file ------
image.info
if image['TEMPLATE/PATH']
if copy
# --- CDROM, DATABLOCK or OS based on a PATH ---
file_path = image['TEMPLATE/PATH']
if !File.exists?(file_path)
error_msg = "Image file could not be found, aborting."
result = OpenNebula::Error.new(error_msg)
end
result = copy(file_path, image['SOURCE'])
end
elsif image['TEMPLATE/SIZE'] and image['TEMPLATE/FSTYPE'] and \
image['TEMPLATE/TYPE'] == 'DATABLOCK'
# --- Empty DATABLOCK ---
result = dd(image['TEMPLATE/SIZE'], image['SOURCE'])
if !OpenNebula.is_error?(result)
result = mkfs(image['TEMPLATE/FSTYPE'], image['SOURCE'])
end
else
error_msg = "Image not present, aborting."
result = OpenNebula::Error.new(error_msg)
end
# ------ Enable the Image ------
if !OpenNebula.is_error?(result)
image.enable
else
image.delete
end
return result
end
def delete(image)
if image.nil?
error_msg = "Image could not be found, aborting."
result = OpenNebula::Error.new(error_msg)
end
result = image.info
if !OpenNebula.is_error?(result)
file_path = image['SOURCE']
result = image.delete
if !OpenNebula.is_error?(result)
result = remove(file_path)
end
end
return result
end
def update_source(image, source)
if image.nil?
error_msg = "Image could not be found, aborting."
result = OpenNebula::Error.new(error_msg)
end
result = image.info
if !OpenNebula.is_error?(result)
result = move(source, image['SOURCE'])
image.enable
end
return result
end
private
FS_UTILS = {
:dd => "env dd",
:mkfs => "env mkfs"
}
def copy(path, source)
if source.nil? or path.nil?
return OpenNebula::Error.new("copy Image: missing parameters.")
end
begin
FileUtils.copy(path, source)
FileUtils.chmod(0660, source)
rescue Exception => e
return OpenNebula::Error.new(e.message)
end
return nil
end
def move(path, source)
if source.nil? or path.nil?
return OpenNebula::Error.new("copy Image: missing parameters.")
end
begin
FileUtils.move(path, source)
FileUtils.chmod(0660, source)
rescue Exception => e
return OpenNebula::Error.new(e.message)
end
return nil
end
def dd(size, source)
if source.nil? or size.nil?
return OpenNebula::Error.new("dd Image: missing parameters.")
end
command = ""
command << FS_UTILS[:dd]
command << " if=/dev/zero of=#{source} ibs=1 count=1"
command << " obs=1048576 seek=#{size}"
local_command=LocalCommand.run(command)
if local_command.code!=0
return OpenNebula::Error.new("dd Image: in dd command.")
end
return nil
end
def mkfs(fstype, source)
if source.nil? or fstype.nil?
return OpenNebula::Error.new("mkfs Image: missing parameters.")
end
command = ""
command << FS_UTILS[:mkfs]
command << " -t #{fstype} -F #{source}"
local_command=LocalCommand.run(command)
if local_command.code!=0
return OpenNebula::Error.new("mkfs Image: in mkfs command.")
end
return nil
end
def remove(source)
if File.exists?(source)
begin
FileUtils.rm(source)
rescue Exception => e
return OpenNebula::Error.new(e.message)
end
end
return nil
end
end
end

View File

@ -94,7 +94,8 @@ PoolSQL::~PoolSQL()
/* -------------------------------------------------------------------------- */
int PoolSQL::allocate(
PoolObjectSQL *objsql)
PoolObjectSQL *objsql,
string& error_str)
{
int rc;
@ -109,7 +110,7 @@ int PoolSQL::allocate(
objsql->oid = ++lastOID;
rc = objsql->insert(db);
rc = objsql->insert(db,error_str);
if ( rc != 0 )
{

View File

@ -85,7 +85,7 @@ int TestObjectSQL::select(SqlDB *db)
/* -------------------------------------------------------------------------- */
int TestObjectSQL::insert(SqlDB *db)
int TestObjectSQL::insert(SqlDB *db, string& str)
{
ostringstream oss;

View File

@ -43,7 +43,7 @@ public:
int select(SqlDB *db);
int insert(SqlDB *db);
int insert(SqlDB *db, string& err);
int update(SqlDB *db);

View File

@ -53,9 +53,10 @@ private:
int create_allocate(int n, string st)
{
string err;
TestObjectSQL *obj = new TestObjectSQL(n,st);
return pool->allocate(obj);
return pool->allocate(obj, err);
};
public:

View File

@ -312,6 +312,9 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr image_publish(new
RequestManager::ImagePublish(ipool, upool));
xmlrpc_c::methodPtr image_persistent(new
RequestManager::ImagePersistent(ipool, upool));
xmlrpc_c::methodPtr image_enable(new
RequestManager::ImageEnable(ipool, upool));
@ -368,15 +371,16 @@ void RequestManager::register_xml_methods()
/* Image related methods*/
RequestManagerRegistry.addMethod("one.image.allocate",image_allocate);
RequestManagerRegistry.addMethod("one.image.delete", image_delete);
RequestManagerRegistry.addMethod("one.image.info", image_info);
RequestManagerRegistry.addMethod("one.image.update", image_update);
RequestManagerRegistry.addMethod("one.image.rmattr", image_rm_attribute);
RequestManagerRegistry.addMethod("one.image.publish", image_publish);
RequestManagerRegistry.addMethod("one.image.enable", image_enable);
RequestManagerRegistry.addMethod("one.image.allocate", image_allocate);
RequestManagerRegistry.addMethod("one.image.delete", image_delete);
RequestManagerRegistry.addMethod("one.image.info", image_info);
RequestManagerRegistry.addMethod("one.image.update", image_update);
RequestManagerRegistry.addMethod("one.image.rmattr", image_rm_attribute);
RequestManagerRegistry.addMethod("one.image.publish", image_publish);
RequestManagerRegistry.addMethod("one.image.persistent", image_persistent);
RequestManagerRegistry.addMethod("one.image.enable", image_enable);
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
};

View File

@ -28,6 +28,7 @@ void RequestManager::VirtualMachineAllocate::execute(
{
string session;
string str_template;
string error_str;
const string method_name = "VirtualMachineAllocate";
@ -123,12 +124,14 @@ void RequestManager::VirtualMachineAllocate::execute(
//--------------------------------------------------------------------------
// Allocate the VirtualMAchine
//--------------------------------------------------------------------------
rc = VirtualMachineAllocate::vmpool->allocate(uid,vm_template,&vid,false);
rc = VirtualMachineAllocate::vmpool->allocate(uid,
vm_template,
&vid,
error_str,
false);
if ( rc < 0 )
{
goto error_allocate;
}
arrayData.push_back(xmlrpc_c::value_boolean(true));
@ -163,7 +166,8 @@ error_parse:
goto error_common;
error_allocate:
oss.str(action_error(method_name, "CREATE", "VM", -2, rc));
oss << action_error(method_name, "CREATE", "VM", -2, 0);
oss << " " << error_str;
goto error_common;
error_common:

View File

@ -27,10 +27,11 @@ void RequestManager::ClusterAllocate::execute(
xmlrpc_c::value * const retval)
{
string session;
string error_str;
string clustername;
int id;
const string method_name = "ClusterAllocate";
int rc;
@ -68,7 +69,7 @@ void RequestManager::ClusterAllocate::execute(
}
// Perform the allocation in the hostpool
rc = ClusterAllocate::hpool->allocate_cluster(&id, clustername);
rc = ClusterAllocate::hpool->allocate_cluster(&id, clustername, error_str);
if ( rc == -1 )
{
@ -95,7 +96,8 @@ error_authorize:
goto error_common;
error_cluster_allocate:
oss.str(action_error(method_name, "CREATE", "CLUSTER", -2, rc));
oss << action_error(method_name, "CREATE", "CLUSTER", -2, 0);
oss << " " << error_str;
goto error_common;
error_common:

Some files were not shown because too many files have changed in this diff Show More