1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-21 01:57:37 +03:00

Merge branch 'feature-1013'

This commit is contained in:
Ruben S. Montero 2012-10-11 17:11:20 +02:00
commit 3c3f129ae5
20 changed files with 392 additions and 274 deletions

View File

@ -26,7 +26,9 @@ using namespace std;
class GroupPool : public PoolSQL
{
public:
GroupPool(SqlDB * db);
GroupPool(SqlDB * db,
vector<const Attribute *> hook_mads,
const string& remotes_location);
~GroupPool(){};

View File

@ -25,6 +25,8 @@ using namespace std;
//Forward definition of Hookable
class Hookable;
class PoolObjectSQL;
/**
* This class is an abstract representation of a hook, provides a method to
* check if the hook has to be executed, and a method to invoke the hook. The
@ -74,6 +76,15 @@ public:
*/
virtual void do_hook(void *arg) = 0;
/**
* Parses the arguments of the hook using a generic $ID identifier, and
* the target object. $TEMPLATE will be the base64 encoding of the
* template and $ID the oid of the object.
* @param obj pointer to the object executing the hook for
* @param the resulting parser arguments
*/
void parse_hook_arguments(PoolObjectSQL * obj,
string& parsed);
protected:
/**
* Name of the Hook
@ -101,6 +112,75 @@ protected:
bool remote;
};
/**
* This class is general ObjectSQL Hook for allocation and removal.
* The object is looked when the hook is executed
*/
class AllocateRemoveHook : public Hook
{
protected:
AllocateRemoveHook(const string& name,
const string& cmd,
const string& args,
int hook_type,
bool remote):
Hook(name, cmd, args, hook_type, remote){};
virtual ~AllocateRemoveHook(){};
// -------------------------------------------------------------------------
// Hook methods
// -------------------------------------------------------------------------
void do_hook(void *arg);
virtual string& remote_host(PoolObjectSQL *obj, string& hostname)
{
hostname.clear();
return hostname;
};
};
/**
* This class is general ObjectSQL Allocate Hook that executes a command
* when the ObjectSQL is inserted in the database. The object is looked when
* the hook is executed
*/
class AllocateHook : public AllocateRemoveHook
{
public:
// -------------------------------------------------------------------------
// Init a hook of ALLOCATE type
// -------------------------------------------------------------------------
AllocateHook(const string& name,
const string& cmd,
const string& args,
bool remote):
AllocateRemoveHook(name, cmd, args, Hook::ALLOCATE, remote){};
virtual ~AllocateHook(){};
};
/**
* This class is general ObjectSQL Remove Hook that executes a command
* when the ObjectSQL is inserted in the database.
*/
class RemoveHook : public AllocateRemoveHook
{
public:
// -------------------------------------------------------------------------
// Init a hook of ALLOCATE type
// -------------------------------------------------------------------------
RemoveHook(const string& name,
const string& cmd,
const string& args,
bool remote):
AllocateRemoveHook(name, cmd, args, Hook::REMOVE, remote){};
virtual ~RemoveHook(){};
};
/**
* Objects that inherits from hookable will allow others to hook into it. The
* Hookable interface handles the list of hooks and provide a method to invoke

View File

@ -29,25 +29,52 @@ using namespace std;
* This class is general Host Allocate Hook that executes a command when the
* Host is inserted in the database. The Host object is looked
*/
class HostAllocateHook : public Hook
class HostAllocateHook : public AllocateHook
{
public:
// -------------------------------------------------------------------------
// Init a LOCAL hook of ALLOCATE type
// -------------------------------------------------------------------------
HostAllocateHook(const string& name,
const string& cmd,
const string& args,
bool remote):
Hook(name, cmd, args, Hook::ALLOCATE, remote){};
AllocateHook(name, cmd, args, remote){};
~HostAllocateHook(){};
virtual ~HostAllocateHook(){};
// -------------------------------------------------------------------------
// Hook methods
// -------------------------------------------------------------------------
private:
void do_hook(void *arg);
string& remote_host(PoolObjectSQL *obj, string& hostname)
{
Host * host = static_cast<Host *>(obj);
hostname = host->get_name();
return hostname;
}
};
/**
* This class is general Host Remove Hook that executes a command when the
* Host is dropped from the database. The Host object is looked
*/
class HostRemoveHook : public RemoveHook
{
public:
HostRemoveHook(const string& name,
const string& cmd,
const string& args,
bool remote):
RemoveHook(name, cmd, args, remote){};
virtual ~HostRemoveHook(){};
private:
string& remote_host(PoolObjectSQL *obj, string& hostname)
{
Host * host = static_cast<Host *>(obj);
hostname = host->get_name();
return hostname;
}
};
/**

View File

@ -41,7 +41,9 @@ public:
ImagePool(SqlDB * db,
const string& _default_type,
const string& _default_dev_prefix,
vector<const Attribute *>& restricted_attrs);
vector<const Attribute *>& restricted_attrs,
vector<const Attribute *> hook_mads,
const string& remotes_location);
~ImagePool(){};
@ -57,7 +59,7 @@ public:
* @param ds_type disk type for the image
* @param ds_data the datastore data
* @param source_img_id If the new Image is a clone, this must be the
* source Image ID. Otherwise, it must be set to -1
* source Image ID. Otherwise, it must be set to -1
* @param oid the id assigned to the Image
* @param error_str Returns the error reason, if any
* @return the oid assigned to the object,
@ -74,7 +76,7 @@ public:
const string& ds_name,
Image::DiskType ds_type,
const string& ds_data,
int source_img_id,
int source_img_id,
int * oid,
string& error_str);
@ -104,7 +106,7 @@ public:
return static_cast<Image *>(PoolSQL::get(name,uid,lock));
};
/**
/**
* Update a particular Image
* @param image pointer to Image
* @return 0 on success

View File

@ -135,6 +135,10 @@ public:
error_msg = "SQL DB error";
return -1;
}
else
{
do_hooks(objsql, Hook::REMOVE);
}
return 0;
};
@ -159,7 +163,7 @@ public:
// -------------------------------------------------------------------------
/**
* Creates a filter for those objects (oids) or objects owned by a given
* Creates a filter for those objects (oids) or objects owned by a given
* group that an user can access based on the ACL rules
* @param uid the user id
* @param gid the group id
@ -167,8 +171,8 @@ public:
* @param all returns if the user can access all objects
* @param filter the resulting filter string
*/
static void acl_filter(int uid,
int gid,
static void acl_filter(int uid,
int gid,
PoolObjectSQL::ObjectType auth_object,
bool& all,
string& filter);
@ -180,8 +184,8 @@ public:
* @param all user can access all objects
* @param filter the resulting filter string
*/
static void usr_filter(int uid,
int gid,
static void usr_filter(int uid,
int gid,
int filter_flag,
bool all,
const string& acl_str,
@ -197,6 +201,17 @@ public:
string& filter);
protected:
/**
* Register on "CREATE" and on "REMOVE" hooks for the pool. The hooks are
* meant to be executed locally by the generic AllocateHook and RemoveHook
* classes.
* @param hook_mads, array of HOOKs to be installed
* @param remotes_location, path to remotes in the front-end where the
* hooks are installed
*/
void register_hooks(vector<const Attribute *> hook_mads,
const string& remotes_location);
/**
* Gets an object from the pool (if needed the object is loaded from the
* database).
@ -223,9 +238,9 @@ protected:
*
* @return 0 on success
*/
int dump(ostringstream& oss,
int dump(ostringstream& oss,
const string& elem_name,
const char * table,
const char * table,
const string& where);
/**
@ -239,7 +254,7 @@ protected:
*/
int dump(ostringstream& oss,
const string& root_elem_name,
ostringstream& sql_query);
ostringstream& sql_query);
/* ---------------------------------------------------------------------- */
/* Interface to access the lastOID assigned by the pool */
@ -344,7 +359,7 @@ private:
* Generate an index key for the object
* @param name of the object
* @param uid owner of the object, only used if needed
*
*
* @return the key, a string
*/
virtual string key(const string& name, int uid)

View File

@ -40,7 +40,9 @@ class UserPool : public PoolSQL
public:
UserPool(SqlDB * db,
time_t __session_expiration_time);
time_t __session_expiration_time,
vector<const Attribute *> hook_mads,
const string& remotes_location);
~UserPool(){};
@ -125,8 +127,8 @@ public:
*
* @return false if authn failed, true otherwise
*/
bool authenticate(const string& session,
int& uid,
bool authenticate(const string& session,
int& uid,
int& gid,
string& uname,
string& gname);
@ -152,12 +154,12 @@ public:
};
/**
* Name for the OpenNebula core authentication process
* Name for the OpenNebula core authentication process
*/
static const char * CORE_AUTH;
/**
* Name for the OpenNebula server (delegated) authentication process
* Name for the OpenNebula server (delegated) authentication process
*/
static const char * SERVER_AUTH;
@ -217,7 +219,7 @@ private:
string& uname,
string& gname);
/**
* Function to authenticate external (not known) users
*/

View File

@ -25,31 +25,6 @@
using namespace std;
/**
* This class is general VM Allocate Hook that executes a command locally
* when the VM is inserted in the database. The VirtualMachine object is
* looked
*/
class VirtualMachineAllocateHook : public Hook
{
public:
// -------------------------------------------------------------------------
// Init a LOCAL hook of ALLOCATE type
// -------------------------------------------------------------------------
VirtualMachineAllocateHook(const string& name,
const string& cmd,
const string& args):
Hook(name, cmd, args, Hook::ALLOCATE, false){};
~VirtualMachineAllocateHook(){};
// -------------------------------------------------------------------------
// Hook methods
// -------------------------------------------------------------------------
void do_hook(void *arg);
};
/**
* This class provides basic functionality to store VM states for state Hooks.
* The state Map is shared by all the State hooks. A maintenance hook that

View File

@ -33,9 +33,11 @@ class VirtualNetworkPool : public PoolSQL
{
public:
VirtualNetworkPool(SqlDB * db,
const string& str_mac_prefix,
int default_size);
VirtualNetworkPool(SqlDB * db,
const string& str_mac_prefix,
int default_size,
vector<const Attribute *> hook_mads,
const string& remotes_location);
~VirtualNetworkPool(){};
@ -97,8 +99,8 @@ public:
* @param nic the nic attribute to be generated
* @param vid of the VM requesting the lease
* @param error_str string describing the error
* @return 0 on success,
* -1 error,
* @return 0 on success,
* -1 error,
* -2 not using the pool
*/
int nic_attribute(VectorAttribute * nic, int uid, int vid, string& error_str);
@ -171,10 +173,10 @@ private:
};
/**
* Function to get a VirtualNetwork by its name, as provided by a VM
* Function to get a VirtualNetwork by its name, as provided by a VM
* template
*/
VirtualNetwork * get_nic_by_name(VectorAttribute * nic,
VirtualNetwork * get_nic_by_name(VectorAttribute * nic,
const string& name,
int _uidi,
string& error);

View File

@ -312,7 +312,10 @@ DATASTORE_MAD = [
#*******************************************************************************
# Hook Manager Configuration
#*******************************************************************************
# The Driver (HM_MAD), used to execute the Hooks
# The Driver (HM_MAD)
# -----------------------------------------------
#
# Used to execute the Hooks:
# executable: path of the hook driver executable, can be an
# absolute path or relative to $ONE_LOCATION/lib/mads (or
# /usr/lib/one/mads/ if OpenNebula was installed in /)
@ -321,7 +324,10 @@ DATASTORE_MAD = [
# to $ONE_LOCATION/etc (or /etc/one/ if OpenNebula was installed
# in /)
#
# Virtual Machine Hooks (VM_HOOK) defined by:
# Virtual Machine Hooks (VM_HOOK)
# -------------------------------
#
# Defined by:
# name : for the hook, useful to track the hook (OPTIONAL)
# on : when the hook should be executed,
# - CREATE, when the VM is created (onevm create)
@ -337,14 +343,17 @@ DATASTORE_MAD = [
# SCRIPTS_REMOTE_DIR. It can be an absolute path that must exist
# on the target host
# arguments : for the hook. You can access to VM information with $
# - $VMID, the ID of the virtual machine
# - $ID, the ID of the virtual machine
# - $TEMPLATE, the VM template in xml and base64 encoded
# remote : values,
# - YES, The hook is executed in the host where the VM was
# allocated
# - NO, The hook is executed in the OpenNebula server (default)
#
# Host Hooks (HOST_HOOK) defined by:
# Host Hooks (HOST_HOOK)
# -------------------------------
#
# Defined by:
# name : for the hook, useful to track the hook (OPTIONAL)
# on : when the hook should be executed,
# - CREATE, when the Host is created (onehost create)
@ -356,15 +365,35 @@ DATASTORE_MAD = [
# SCRIPTS_REMOTE_DIR. It can be an absolute path that must exist
# on the target host.
# arguments : for the hook. You can use the following Host information:
# - $HID, the ID of the host
# - $ID, the ID of the host
# - $TEMPLATE, the Host template in xml and base64 encoded
# remote : values,
# - YES, The hook is executed in the host
# - NO, The hook is executed in the OpenNebula server (default)
#
# Virtual Network (VNET_HOOK)
# User (USER_HOOK)
# Group (GROUP_HOOK)
# Image (IMAGE_HOOK)
# -------------------------------
#
# These hooks are executed when one of the referring entities are created or
# removed. Each hook is defined by:
# name : for the hook, useful to track the hook (OPTIONAL)
# on : when the hook should be executed,
# - CREATE, when the vnet is created
# - REMOVE, when the vnet is removed
# command : path is relative to $ONE_LOCATION/var/remotes/hook
# (self-contained) or to /var/lib/one/remotes/hook (system-wide).
# That directory will be copied on the hosts under
# SCRIPTS_REMOTE_DIR. It can be an absolute path that must exist
# on the target host.
# arguments : for the hook. You can use the following Host information:
# - $ID, the ID of the host
# - $TEMPLATE, the vnet template in xml and base64 encoded
#-------------------------------------------------------------------------------
HM_MAD = [
executable = "one_hm" ]
#-------------------------------------------------------------------------------
#*******************************************************************************
# Fault Tolerance Hooks
@ -379,7 +408,7 @@ HM_MAD = [
# name = "error",
# on = "ERROR",
# command = "ft/host_error.rb",
# arguments = "$HID -r n",
# arguments = "$ID -r n",
# remote = "no" ]
#-------------------------------------------------------------------------------
# These two hooks can be used to automatically delete or resubmit VMs that reach
@ -394,13 +423,13 @@ HM_MAD = [
# name = "on_failure_delete",
# on = "FAILED",
# command = "/usr/bin/env onevm delete",
# arguments = "$VMID" ]
# arguments = "$ID" ]
#
#VM_HOOK = [
# name = "on_failure_resubmit",
# on = "FAILED",
# command = "/usr/bin/env onevm resubmit",
# arguments = "$VMID" ]
# arguments = "$ID" ]
#-------------------------------------------------------------------------------
#*******************************************************************************

View File

@ -37,7 +37,10 @@ const int GroupPool::USERS_ID = 1;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
GroupPool::GroupPool(SqlDB * db):PoolSQL(db, Group::table, true)
GroupPool::GroupPool(SqlDB * db,
vector<const Attribute *> hook_mads,
const string& remotes_location)
:PoolSQL(db, Group::table, true)
{
ostringstream oss;
string error_str;
@ -68,7 +71,9 @@ GroupPool::GroupPool(SqlDB * db):PoolSQL(db, Group::table, true)
set_update_lastOID(99);
}
register_hooks(hook_mads, remotes_location);
return;
error_groups:
@ -164,6 +169,10 @@ int GroupPool::drop(PoolObjectSQL * objsql, string& error_msg)
error_msg = "SQL DB error";
rc = -1;
}
else
{
do_hooks(objsql, Hook::REMOVE);
}
return rc;
}

View File

@ -22,6 +22,7 @@ lib_name='nebula_hm'
# Sources to generate the library
source_files=[
'Hook.cc',
'HookManager.cc',
'HookManagerDriver.cc'
]

View File

@ -18,69 +18,6 @@
#include "Host.h"
#include "Nebula.h"
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
static void parse_host_arguments(Host *host, string& parsed)
{
size_t found;
found = parsed.find("$HID");
if ( found !=string::npos )
{
ostringstream oss;
oss << host->get_oid();
parsed.replace(found,4,oss.str());
}
found = parsed.find("$TEMPLATE");
if ( found != string::npos )
{
string templ;
parsed.replace(found,9,host->to_xml64(templ));
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void HostAllocateHook::do_hook(void *arg)
{
Host * host;
string parsed_args = args;
host = static_cast<Host *>(arg);
if ( host == 0 )
{
return;
}
parse_host_arguments(host,parsed_args);
Nebula& ne = Nebula::instance();
HookManager * hm = ne.get_hm();
const HookManagerDriver * hmd = hm->get();
if ( hmd != 0 )
{
if ( remote == true )
{
hmd->execute(host->get_oid(),
name,
host->get_name(),
cmd,
parsed_args);
}
else
{
hmd->execute(host->get_oid(),name,cmd,parsed_args);
}
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
@ -172,7 +109,7 @@ void HostStateHook::do_hook(void *arg)
{
string parsed_args = args;
parse_host_arguments(host,parsed_args);
parse_hook_arguments(host, parsed_args);
Nebula& ne = Nebula::instance();
HookManager * hm = ne.get_hm();

View File

@ -34,8 +34,10 @@ string ImagePool::_default_dev_prefix;
ImagePool::ImagePool(SqlDB * db,
const string& __default_type,
const string& __default_dev_prefix,
vector<const Attribute *>& restricted_attrs):
PoolSQL(db, Image::table, true)
vector<const Attribute *>& restricted_attrs,
vector<const Attribute *> hook_mads,
const string& remotes_location)
:PoolSQL(db, Image::table, true)
{
ostringstream sql;
@ -52,8 +54,9 @@ ImagePool::ImagePool(SqlDB * db,
_default_type = "OS";
}
// Set restricted attributes
ImageTemplate::set_restricted_attributes(restricted_attrs);
register_hooks(hook_mads, remotes_location);
}
/* -------------------------------------------------------------------------- */
@ -104,7 +107,7 @@ int ImagePool::allocate (
img->ds_name = ds_name;
img->ds_id = ds_id;
img->disk_type = disk_type;
if ( cloning_id != -1 )
@ -116,7 +119,7 @@ int ImagePool::allocate (
// Insert the Object in the pool & Register the image in the repository
// ---------------------------------------------------------------------
*oid = PoolSQL::allocate(img, error_str);
if ( *oid != -1 )
{
Nebula& nd = Nebula::instance();
@ -190,9 +193,9 @@ static int get_disk_uid(VectorAttribute * disk, int _uid)
User * user;
Nebula& nd = Nebula::instance();
UserPool * upool = nd.get_upool();
user = upool->get(uname,true);
if ( user == 0 )
{
return -1;
@ -204,12 +207,12 @@ static int get_disk_uid(VectorAttribute * disk, int _uid)
}
else
{
uid = _uid;
uid = _uid;
}
return uid;
}
/* -------------------------------------------------------------------------- */
static int get_disk_id(const string& id_s)
@ -252,7 +255,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
if (!(source = disk->vector_value("IMAGE")).empty())
{
int uiid = get_disk_uid(disk,uid);
if ( uiid == -1)
{
ostringstream oss;
@ -261,7 +264,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
<< source << " . Set IMAGE_UNAME or IMAGE_UID of owner in DISK.";
error_str = oss.str();
return -1;
return -1;
}
img = imagem->acquire_image(source, uiid, error_str);
@ -280,7 +283,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
if ( iid == -1)
{
error_str = "Wrong ID set in IMAGE_ID";
return -1;
return -1;
}
img = imagem->acquire_image(iid, error_str);
@ -296,7 +299,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
if ( type != "SWAP" && type != "FS" )
if ( type != "SWAP" && type != "FS" )
{
error_str = "Unknown disk type " + type;
return -1;
@ -362,16 +365,16 @@ void ImagePool::authorize_disk(VectorAttribute * disk,int uid, AuthRequest * ar)
{
string source;
Image * img = 0;
PoolObjectAuth perm;
if (!(source = disk->vector_value("IMAGE")).empty())
{
int uiid = get_disk_uid(disk,uid);
if ( uiid == -1)
{
return;
return;
}
img = get(source , uiid, true);
@ -387,7 +390,7 @@ void ImagePool::authorize_disk(VectorAttribute * disk,int uid, AuthRequest * ar)
if ( iid == -1)
{
return;
return;
}
img = get(iid, true);

View File

@ -276,6 +276,11 @@ void Nebula::start()
vector<const Attribute *> vm_hooks;
vector<const Attribute *> host_hooks;
vector<const Attribute *> vnet_hooks;
vector<const Attribute *> user_hooks;
vector<const Attribute *> group_hooks;
vector<const Attribute *> image_hooks;
vector<const Attribute *> vm_restricted_attrs;
vector<const Attribute *> img_restricted_attrs;
@ -283,7 +288,11 @@ void Nebula::start()
docpool = new DocumentPool(db);
nebula_configuration->get("VM_HOOK", vm_hooks);
nebula_configuration->get("HOST_HOOK", host_hooks);
nebula_configuration->get("HOST_HOOK", host_hooks);
nebula_configuration->get("VNET_HOOK", vnet_hooks);
nebula_configuration->get("USER_HOOK", user_hooks);
nebula_configuration->get("GROUP_HOOK", group_hooks);
nebula_configuration->get("IMAGE_HOOK", image_hooks);
nebula_configuration->get("VM_RESTRICTED_ATTR", vm_restricted_attrs);
nebula_configuration->get("IMAGE_RESTRICTED_ATTR", img_restricted_attrs);
@ -291,26 +300,31 @@ void Nebula::start()
nebula_configuration->get("VM_MONITORING_EXPIRATION_TIME",vm_expiration);
nebula_configuration->get("HOST_MONITORING_EXPIRATION_TIME",host_expiration);
vmpool = new VirtualMachinePool(db,
vm_hooks,
hook_location,
vmpool = new VirtualMachinePool(db,
vm_hooks,
hook_location,
remotes_location,
vm_restricted_attrs,
vm_expiration);
hpool = new HostPool( db,
host_hooks,
hook_location,
remotes_location,
host_expiration);
hpool = new HostPool(db,
host_hooks,
hook_location,
remotes_location,
host_expiration);
nebula_configuration->get("MAC_PREFIX", mac_prefix);
nebula_configuration->get("NETWORK_SIZE", size);
vnpool = new VirtualNetworkPool(db,mac_prefix,size);
gpool = new GroupPool(db);
vnpool = new VirtualNetworkPool(db,
mac_prefix,
size,
vnet_hooks,
remotes_location);
gpool = new GroupPool(db, group_hooks, remotes_location);
nebula_configuration->get("SESSION_EXPIRATION_TIME", expiration_time);
upool = new UserPool(db, expiration_time);
upool = new UserPool(db, expiration_time, user_hooks, remotes_location);
nebula_configuration->get("DEFAULT_IMAGE_TYPE", default_image_type);
nebula_configuration->get("DEFAULT_DEVICE_PREFIX",
@ -319,7 +333,9 @@ void Nebula::start()
ipool = new ImagePool(db,
default_image_type,
default_device_prefix,
img_restricted_attrs);
img_restricted_attrs,
image_hooks,
remotes_location);
tpool = new VMTemplatePool(db);

View File

@ -36,7 +36,6 @@ env.Prepend(LIBS=[
'nebula_vmm',
'nebula_lcm',
'nebula_im',
'nebula_hm',
'nebula_rm',
'nebula_dm',
'nebula_tm',
@ -55,6 +54,7 @@ env.Prepend(LIBS=[
'nebula_vm',
'nebula_vmtemplate',
'nebula_document',
'nebula_hm',
'nebula_common',
'nebula_sql',
'nebula_log',

View File

@ -223,7 +223,7 @@ PoolObjectSQL * PoolSQL::get(
}
if ( uses_name_pool )
{
{
map<string,PoolObjectSQL *>::iterator name_index;
string okey;
@ -271,7 +271,7 @@ PoolObjectSQL * PoolSQL::get(
PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock)
{
map<string,PoolObjectSQL *>::iterator index;
PoolObjectSQL * objectsql;
int rc;
@ -381,9 +381,9 @@ void PoolSQL::update_cache_index(string& old_name,
if ( index != name_pool.end() )
{
name_pool.erase(old_key);
if ( name_pool.find(new_key) == name_pool.end())
{
{
name_pool.insert(make_pair(new_key, index->second));
}
}
@ -568,8 +568,8 @@ int PoolSQL::search(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void PoolSQL::acl_filter(int uid,
int gid,
void PoolSQL::acl_filter(int uid,
int gid,
PoolObjectSQL::ObjectType auth_object,
bool& all,
string& filter)
@ -591,12 +591,12 @@ void PoolSQL::acl_filter(int uid,
vector<int> oids;
vector<int> gids;
aclm->reverse_search(uid,
gid,
aclm->reverse_search(uid,
gid,
auth_object,
AuthRequest::USE,
all,
oids,
AuthRequest::USE,
all,
oids,
gids);
for ( it = oids.begin(); it < oids.end(); it++ )
@ -614,8 +614,8 @@ void PoolSQL::acl_filter(int uid,
/* -------------------------------------------------------------------------- */
void PoolSQL::usr_filter(int uid,
int gid,
void PoolSQL::usr_filter(int uid,
int gid,
int filter_flag,
bool all,
const string& acl_str,
@ -629,14 +629,14 @@ void PoolSQL::usr_filter(int uid,
}
else if ( filter_flag == RequestManagerPoolInfoFilter::MINE_GROUP )
{
uid_filter << " uid = " << uid
<< " OR ( gid = " << gid << " AND group_u = 1 )";
uid_filter << " uid = " << uid
<< " OR ( gid = " << gid << " AND group_u = 1 )";
}
else if ( filter_flag == RequestManagerPoolInfoFilter::ALL )
{
if (!all)
{
uid_filter << " uid = " << uid
uid_filter << " uid = " << uid
<< " OR ( gid = " << gid << " AND group_u = 1 )"
<< " OR other_u = 1"
<< acl_str;
@ -682,3 +682,65 @@ void PoolSQL::oid_filter(int start_id,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void PoolSQL::register_hooks(vector<const Attribute *> hook_mads,
const string& remotes_location)
{
const VectorAttribute * vattr;
string name;
string on;
string cmd;
string arg;
for (unsigned int i = 0 ; i < hook_mads.size() ; i++ )
{
vattr = static_cast<const VectorAttribute *>(hook_mads[i]);
name = vattr->vector_value("NAME");
on = vattr->vector_value("ON");
cmd = vattr->vector_value("COMMAND");
arg = vattr->vector_value("ARGUMENTS");
transform (on.begin(),on.end(),on.begin(),(int(*)(int))toupper);
if ( on.empty() || cmd.empty() )
{
NebulaLog::log("VM", Log::WARNING, "Empty ON or COMMAND attribute"
" in Hook, not registered!");
continue;
}
if ( name.empty() )
{
name = cmd;
}
if (cmd[0] != '/')
{
ostringstream cmd_os;
cmd_os << remotes_location << "/hooks/" << cmd;
cmd = cmd_os.str();
}
if ( on == "CREATE" )
{
AllocateHook * hook;
hook = new AllocateHook(name, cmd, arg, false);
add_hook(hook);
}
else if ( on == "REMOVE" )
{
RemoveHook * hook;
hook = new RemoveHook(name, cmd, arg, false);
add_hook(hook);
}
}
}

View File

@ -53,7 +53,9 @@ string UserPool::oneadmin_name;
/* -------------------------------------------------------------------------- */
UserPool::UserPool(SqlDB * db,
time_t __session_expiration_time):
time_t __session_expiration_time,
vector<const Attribute *> hook_mads,
const string& remotes_location):
PoolSQL(db, User::table, true)
{
int one_uid = -1;
@ -78,6 +80,8 @@ UserPool::UserPool(SqlDB * db,
_session_expiration_time = __session_expiration_time;
register_hooks(hook_mads, remotes_location);
User * oneadmin_user = get(0, true);
if (oneadmin_user != 0)
@ -115,7 +119,7 @@ UserPool::UserPool(SqlDB * db,
if (!file.good())
{
goto error_file;
}
}
getline(file,one_token);
@ -293,7 +297,7 @@ int UserPool::allocate (
*oid = PoolSQL::allocate(user, error_str);
if ( *oid < 0 )
{
{
return *oid;
}
@ -572,7 +576,7 @@ auth_failure:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool UserPool::authenticate_external(const string& username,
const string& token,
int& user_id,
@ -605,7 +609,7 @@ bool UserPool::authenticate_external(const string& username,
ar.wait();
if (ar.result != true) //User was not authenticated
{
{
goto auth_failure_driver;
}
@ -651,9 +655,9 @@ bool UserPool::authenticate_external(const string& username,
gname = GroupPool::USERS_NAME;
return true;
auth_failure_user:
oss << "Can't create user: " << error_str << ". Driver response: "
oss << "Can't create user: " << error_str << ". Driver response: "
<< ar.message;
NebulaLog::log("AuM",Log::ERROR,oss);
@ -682,9 +686,9 @@ auth_failure:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool UserPool::authenticate(const string& session,
int& user_id,
bool UserPool::authenticate(const string& session,
int& user_id,
int& group_id,
string& uname,
string& gname)

View File

@ -21,59 +21,6 @@
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
static void parse_vm_arguments(VirtualMachine *vm, string& parsed)
{
size_t found;
found = parsed.find("$VMID");
if ( found !=string::npos )
{
ostringstream oss;
oss << vm->get_oid();
parsed.replace(found,5,oss.str());
}
found = parsed.find("$TEMPLATE");
if ( found != string::npos )
{
string templ;
parsed.replace(found,9,vm->to_xml64(templ));
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void VirtualMachineAllocateHook::do_hook(void *arg)
{
VirtualMachine * vm;
string parsed_args = args;
vm = static_cast<VirtualMachine *>(arg);
if ( vm == 0 )
{
return;
}
parse_vm_arguments(vm, parsed_args);
Nebula& ne = Nebula::instance();
HookManager * hm = ne.get_hm();
const HookManagerDriver * hmd = hm->get();
if ( hmd != 0 )
{
hmd->execute(vm->get_oid(),name,cmd,parsed_args);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
map<int,VirtualMachineStateMapHook::VmStates>
VirtualMachineStateMapHook::vm_states;
@ -167,7 +114,7 @@ void VirtualMachineStateHook::do_hook(void *arg)
{
string parsed_args = args;
parse_vm_arguments(vm,parsed_args);
parse_hook_arguments(vm, parsed_args);
Nebula& ne = Nebula::instance();
HookManager * hm = ne.get_hm();

View File

@ -102,21 +102,21 @@ VirtualMachinePool::VirtualMachinePool(
if ( remote )
{
cmd_os << hook_location << "/" << cmd;
cmd_os << hook_location << "/" << cmd;
}
else
{
cmd_os << remotes_location << "/hooks/" << cmd;
}
}
cmd = cmd_os.str();
}
}
if ( on == "CREATE" )
{
VirtualMachineAllocateHook * hook;
AllocateHook * hook;
hook = new VirtualMachineAllocateHook(name,cmd,arg);
hook = new AllocateHook(name, cmd, arg, false);
add_hook(hook);
}
@ -230,7 +230,7 @@ int VirtualMachinePool::allocate (
{
vm->state = VirtualMachine::PENDING;
}
// ------------------------------------------------------------------------
// Insert the Object in the pool
// ------------------------------------------------------------------------
@ -281,9 +281,9 @@ int VirtualMachinePool::get_pending(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachinePool::dump_acct(ostringstream& oss,
const string& where,
int time_start,
int VirtualMachinePool::dump_acct(ostringstream& oss,
const string& where,
int time_start,
int time_end)
{
ostringstream cmd;

View File

@ -31,9 +31,12 @@ unsigned int VirtualNetworkPool::_default_size;
/* -------------------------------------------------------------------------- */
VirtualNetworkPool::VirtualNetworkPool(SqlDB * db,
const string& prefix,
int __default_size):
VirtualNetworkPool::VirtualNetworkPool(
SqlDB * db,
const string& prefix,
int __default_size,
vector<const Attribute *> hook_mads,
const string& remotes_location):
PoolSQL(db, VirtualNetwork::table, true)
{
istringstream iss;
@ -66,6 +69,8 @@ VirtualNetworkPool::VirtualNetworkPool(SqlDB * db,
iss >> hex >> _mac_prefix >> ws >> hex >> tmp >> ws;
_mac_prefix <<= 8;
_mac_prefix += tmp;
register_hooks(hook_mads, remotes_location);
}
/* -------------------------------------------------------------------------- */
@ -140,7 +145,7 @@ error_common:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
const string& name,
int _uid,
string& error)
@ -169,9 +174,9 @@ VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
User * user;
Nebula& nd = Nebula::instance();
UserPool * upool = nd.get_upool();
user = upool->get(uname,true);
if ( user == 0 )
{
error = "User set in NETWORK_UNAME does not exist";
@ -184,7 +189,7 @@ VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
}
else
{
uid = _uid;
uid = _uid;
}
vnet = get(name,uid,true);
@ -195,15 +200,15 @@ VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
oss << "User " << uid << " does not own a network with name: " << name
<< " . Set NETWORK_UNAME or NETWORK_UID of owner in NIC.";
error = oss.str();
error = oss.str();
}
return vnet;
}
/* -------------------------------------------------------------------------- */
VirtualNetwork * VirtualNetworkPool::get_nic_by_id(const string& id_s,
VirtualNetwork * VirtualNetworkPool::get_nic_by_id(const string& id_s,
string& error)
{
istringstream is;
@ -224,14 +229,14 @@ VirtualNetwork * VirtualNetworkPool::get_nic_by_id(const string& id_s,
ostringstream oss;
oss << "Virtual network with ID: " << id_s << " does not exist";
error = oss.str();
error = oss.str();
}
return vnet;
}
int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
int uid,
int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
int uid,
int vid,
string& error)
{
@ -249,7 +254,7 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
else //Not using a pre-defined network
{
return -2;
}
}
if (vnet == 0)
{
@ -275,8 +280,8 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualNetworkPool::authorize_nic(VectorAttribute * nic,
int uid,
void VirtualNetworkPool::authorize_nic(VectorAttribute * nic,
int uid,
AuthRequest * ar)
{
string network;
@ -300,7 +305,7 @@ void VirtualNetworkPool::authorize_nic(VectorAttribute * nic,
else //Not using a pre-defined network
{
return;
}
}
if (vnet == 0)
{