1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-08 21:17:43 +03:00

Feature #407: Base implementation for groups.

So far groups can be managed, but resources can't be associated to a group.
Tasks done:

  * New basic onegroup command
  * RequestManager XML-RPC methods
  * New group pool
  * New GROUP authorization symbol
  * Basic GroupPool tests
  * Ruby OCA methods
This commit is contained in:
Carlos Martín 2011-05-10 18:45:15 +02:00
parent 2fc0f5b5ca
commit ae53d43789
33 changed files with 1875 additions and 9 deletions

View File

@ -58,6 +58,7 @@ main_env.Append(LIBPATH=[
cwd+'/src/sql',
cwd+'/src/host',
cwd+'/src/cluster',
cwd+'/src/group',
cwd+'/src/mad',
cwd+'/src/nebula',
cwd+'/src/pool',
@ -187,6 +188,7 @@ build_scripts=[
'src/template/SConstruct',
'src/host/SConstruct',
'src/cluster/SConstruct',
'src/group/SConstruct',
'src/mad/SConstruct',
'src/nebula/SConstruct',
'src/pool/SConstruct',
@ -233,6 +235,7 @@ if testing=='yes':
'src/common/test/SConstruct',
'src/host/test/SConstruct',
'src/cluster/test/SConstruct',
'src/group/test/SConstruct',
'src/image/test/SConstruct',
'src/lcm/test/SConstruct',
'src/pool/test/SConstruct',

View File

@ -295,7 +295,8 @@ public:
IMAGE,
USER,
CLUSTER,
TEMPLATE
TEMPLATE,
GROUP
};
/**

109
include/Group.h Normal file
View File

@ -0,0 +1,109 @@
/* ------------------------------------------------------------------------ */
/* 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 GROUP_H_
#define GROUP_H_
#include "PoolSQL.h"
using namespace std;
/**
* The Group class.
*/
class Group : public PoolObjectSQL
{
public:
/**
* Function to write a Group on an output stream
*/
friend ostream& operator<<(ostream& os, Group& group);
/**
* Function to print the Group object into a string in XML format
* @param xml the resulting XML string
* @return a reference to the generated string
*/
string& to_xml(string& xml) const;
/**
* Rebuilds the object from an xml formatted string
* @param xml_str The xml-formatted string
*
* @return 0 on success, -1 otherwise
*/
int from_xml(const string &xml_str);
private:
// -------------------------------------------------------------------------
// Friends
// -------------------------------------------------------------------------
friend class GroupPool;
// *************************************************************************
// Constructor
// *************************************************************************
Group(int id, int uid, const string& name);
virtual ~Group();
// *************************************************************************
// DataBase implementation (Private)
// *************************************************************************
static const char * db_names;
static const char * db_bootstrap;
static const char * table;
/**
* 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);
/**
* Bootstraps the database table(s) associated to the Group
*/
static void bootstrap(SqlDB * db)
{
ostringstream oss(Group::db_bootstrap);
db->exec(oss);
};
/**
* Writes the Group in the database.
* @param db pointer to the db
* @return 0 on success
*/
int insert(SqlDB *db, string& error_str);
/**
* Writes/updates the Group's data fields in the database.
* @param db pointer to the db
* @return 0 on success
*/
int update(SqlDB *db);
};
#endif /*GROUP_H_*/

133
include/GroupPool.h Normal file
View File

@ -0,0 +1,133 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2011, 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 GROUP_POOL_H_
#define GROUP_POOL_H_
#include "Group.h"
#include "SqlDB.h"
using namespace std;
class GroupPool : public PoolSQL
{
public:
GroupPool(SqlDB * db);
~GroupPool(){};
/**
* Cluster name for the default cluster
*/
static const string DEFAULT_GROUP_NAME;
/* ---------------------------------------------------------------------- */
/* Methods for DB management */
/* ---------------------------------------------------------------------- */
/**
* Allocates a new group, writting it in the pool database. No memory is
* allocated for the object.
* @param uid user id (the owner of the Object)
* @param name Group name
* @param oid the id assigned to the Group
* @param error_str Returns the error reason, if any
*
* @return the oid assigned to the object, -1 in case of failure
*/
int allocate(int uid,
string name,
int * oid,
string& error_str);
/**
* Function to get a group from the pool, if the object is not in memory
* it is loaded from the DB
* @param oid group unique id
* @param lock locks the group mutex
* @return a pointer to the group, 0 if the group could not be loaded
*/
Group * get(int oid, bool lock)
{
return static_cast<Group *>(PoolSQL::get(oid,lock));
};
/**
* Gets an object from the pool (if needed the object is loaded from the
* database).
* @param name of the object
* @param uid id of owner
* @param lock locks the object if true
*
* @return a pointer to the object, 0 in case of failure
*/
Group * get(const string& name, int uid, bool lock)
{
return static_cast<Group *>(PoolSQL::get(name,uid,lock));
};
/** Update a particular Group
* @param user pointer to Group
* @return 0 on success
*/
int update(Group * group)
{
return group->update(db);
};
/**
* Drops the Group from the data base. The object mutex SHOULD be
* locked.
* @param group a pointer to the object
* @return 0 on success.
*/
int drop(Group * group);
/**
* Bootstraps the database table(s) associated to the Group pool
*/
static void bootstrap(SqlDB * _db)
{
Group::bootstrap(_db);
};
/**
* Dumps the Group pool in XML format. A filter can be also added to the
* query
* @param oss the output stream to dump the pool contents
* @param where filter for the objects, defaults to all
*
* @return 0 on success
*/
int dump(ostringstream& oss, const string& where)
{
return PoolSQL::dump(oss, "GROUP_POOL", Group::table, where);
};
private:
/**
* Factory method to produce objects
* @return a pointer to the new object
*/
PoolObjectSQL * create()
{
return new Group(-1,-1,"");
};
};
#endif /*GROUP_POOL_H_*/

View File

@ -26,6 +26,7 @@
#include "HostPool.h"
#include "UserPool.h"
#include "VMTemplatePool.h"
#include "GroupPool.h"
#include "VirtualMachineManager.h"
#include "LifeCycleManager.h"
@ -82,6 +83,11 @@ public:
return cpool;
};
GroupPool * get_gpool()
{
return gpool;
};
VMTemplatePool * get_tpool()
{
return tpool;
@ -240,8 +246,8 @@ private:
// -----------------------------------------------------------------------
Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),vnpool(0),
upool(0),ipool(0),cpool(0),tpool(0),lcm(0),vmm(0),im(0),tm(0),dm(0),
rm(0),hm(0),authm(0),imagem(0)
upool(0),ipool(0),cpool(0),gpool(0),tpool(0),lcm(0),vmm(0),im(0),tm(0),
dm(0),rm(0),hm(0),authm(0),imagem(0)
{
const char * nl = getenv("ONE_LOCATION");
@ -306,6 +312,11 @@ private:
delete cpool;
}
if ( gpool != 0)
{
delete gpool;
}
if ( tpool != 0)
{
delete tpool;
@ -403,6 +414,7 @@ private:
UserPool * upool;
ImagePool * ipool;
ClusterPool * cpool;
GroupPool * gpool;
VMTemplatePool * tpool;
// ---------------------------------------------------------------

View File

@ -25,6 +25,7 @@
#include "ImagePool.h"
#include "ClusterPool.h"
#include "VMTemplatePool.h"
#include "GroupPool.h"
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/registry.hpp>
@ -48,11 +49,12 @@ public:
ImagePool * _ipool,
ClusterPool * _cpool,
VMTemplatePool * _tpool,
GroupPool * _gpool,
int _port,
string _xml_log_file)
:vmpool(_vmpool),hpool(_hpool),vnpool(_vnpool),upool(_upool),
ipool(_ipool),cpool(_cpool),tpool(_tpool),port(_port),socket_fd(-1),
xml_log_file(_xml_log_file)
ipool(_ipool),cpool(_cpool),tpool(_tpool),gpool(_gpool),port(_port),
socket_fd(-1),xml_log_file(_xml_log_file)
{
am.addListener(this);
};
@ -141,6 +143,11 @@ private:
*/
VMTemplatePool * tpool;
/**
* Pointer to the Group Pool, to access groups
*/
GroupPool * gpool;
/**
* Port number where the connection will be open
*/
@ -987,6 +994,113 @@ private:
};
/* ---------------------------------------------------------------------- */
/* Group Interface */
/* ---------------------------------------------------------------------- */
class GroupAllocate: public xmlrpc_c::method
{
public:
GroupAllocate(
UserPool * _upool,
GroupPool * _gpool):
upool(_upool),
gpool(_gpool)
{
_signature="A:ss";
_help="Allocates a group in the pool";
};
~GroupAllocate(){};
void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retvalP);
private:
UserPool * upool;
GroupPool * gpool;
};
/* ---------------------------------------------------------------------- */
class GroupInfo: public xmlrpc_c::method
{
public:
GroupInfo(
UserPool * _upool,
GroupPool * _gpool):
upool(_upool),
gpool(_gpool)
{
_signature="A:si";
_help="Returns group information";
};
~GroupInfo(){};
void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retvalP);
private:
UserPool * upool;
GroupPool * gpool;
};
/* ---------------------------------------------------------------------- */
class GroupDelete: public xmlrpc_c::method
{
public:
GroupDelete(
UserPool * _upool,
GroupPool * _gpool):
upool(_upool),
gpool(_gpool)
{
_signature="A:si";
_help="Deletes a group from the pool";
};
~GroupDelete(){};
void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retvalP);
private:
UserPool * upool;
GroupPool * gpool;
};
/* ---------------------------------------------------------------------- */
class GroupPoolInfo: public xmlrpc_c::method
{
public:
GroupPoolInfo(
UserPool * _upool,
GroupPool * _gpool):
upool(_upool),
gpool(_gpool)
{
_signature="A:s";
_help="Returns the group pool information";
};
~GroupPoolInfo(){};
void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retvalP);
private:
UserPool * upool;
GroupPool * gpool;
};
/* ---------------------------------------------------------------------- */
/* Virtual Network Interface */
/* ---------------------------------------------------------------------- */

View File

@ -45,7 +45,8 @@ protected:
NebulaTest():mysql(false), need_host_pool(false), need_vm_pool(false),
need_vnet_pool(false), need_image_pool(false),
need_user_pool(false), need_cluster_pool(false),
need_template_pool(false),need_vmm(false),
need_template_pool(false), need_group_pool(false),
need_vmm(false),
need_im(false), need_tm(false),
need_lcm(false), need_dm(false),
need_rm(false), need_hm(false),
@ -66,6 +67,7 @@ public:
bool need_user_pool;
bool need_cluster_pool;
bool need_template_pool;
bool need_group_pool;
bool need_vmm;
bool need_im;
@ -104,6 +106,8 @@ public:
virtual VMTemplatePool* create_tpool(SqlDB* db);
virtual GroupPool* create_gpool(SqlDB* db);
// ------------------------------------------------------------------------
// Managers
// ------------------------------------------------------------------------
@ -134,6 +138,7 @@ public:
ImagePool * ipool,
ClusterPool * cpool,
VMTemplatePool * tpool,
GroupPool * gpool,
string log_file);
virtual HookManager* create_hm(VirtualMachinePool * vmpool);

View File

@ -365,6 +365,7 @@ BIN_FILES="src/nebula/oned \
src/cli/oneimage \
src/cli/onecluster \
src/cli/onetemplate \
src/cli/onegroup \
share/scripts/one \
src/authm_mad/oneauth"
@ -411,6 +412,8 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \
src/oca/ruby/OpenNebula/ClusterPool.rb \
src/oca/ruby/OpenNebula/Template.rb \
src/oca/ruby/OpenNebula/TemplatePool.rb \
src/oca/ruby/OpenNebula/Group.rb \
src/oca/ruby/OpenNebula/GroupPool.rb \
src/oca/ruby/OpenNebula/XMLUtils.rb"
@ -733,7 +736,8 @@ CLI_BIN_FILES="src/cli/onevm \
src/cli/oneuser \
src/cli/oneimage \
src/cli/onecluster \
src/cli/onetemplate"
src/cli/onetemplate \
src/cli/onegroup"
#-----------------------------------------------------------------------------
# Sunstone files
@ -843,6 +847,7 @@ MAN_FILES="share/man/oneauth.8.gz \
share/man/onevm.8.gz \
share/man/onevnet.8.gz \
share/man/onetemplate.8.gz \
share/man/onegroup.8.gz \
share/man/econe-describe-images.8.gz \
share/man/econe-describe-instances.8.gz \
share/man/econe-register.8.gz \

View File

@ -18,7 +18,8 @@ TESTS="$TWD_DIR/vnm/test \
$TWD_DIR/um/test \
$TWD_DIR/lcm/test \
$TWD_DIR/pool/test \
$TWD_DIR/vm_template/test"
$TWD_DIR/vm_template/test \
$TWD_DIR/group/test"
#-------------------------------------------------------------------------------
# COMMAND LINE PARSING

View File

@ -87,6 +87,7 @@ void AuthRequest::add_auth(Object ob,
case USER: oss << "USER:" ; break;
case CLUSTER: oss << "CLUSTER:" ; break;
case TEMPLATE: oss << "TEMPLATE:" ; break;
case GROUP: oss << "GROUP:" ; break;
}
if (op == CREATE || op == INSTANTIATE) //encode the ob_id, it is a template

View File

@ -321,6 +321,10 @@ def get_template_id(name)
get_entity_id(name, OpenNebula::TemplatePool)
end
def get_group_id(name)
get_entity_id(name, OpenNebula::GroupPool)
end
def str_running_time(data)
stime=Time.at(data["STIME"].to_i)
if data["ETIME"]=="0"

186
src/cli/onegroup Executable file
View File

@ -0,0 +1,186 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, 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. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
require 'OpenNebula'
require 'client_utilities'
require 'command_parse'
ShowTableUP={
:id => {
:name => "ID",
:desc => "ONE identifier for group",
:size => 4,
:proc => lambda {|d,e|
d.id
}
},
:uid => {
:name => "OWNER",
:desc => "Owner of the group",
:size => 5,
:proc => lambda {|d,e|
d.uid
}
},
:name => {
:name => "NAME",
:desc => "Name of the group",
:size => 16,
:proc => lambda {|d,e|
d.name
}
},
:default => [:id, :uid, :name]
}
class UPShow
def initialize
@grouppool=OpenNebula::GroupPool.new(get_one_client)
@table=ShowTable.new(ShowTableUP)
end
def header_up_small
scr_bold
scr_underline
print @table.header_str
scr_restore
puts ""
end
def list_short(options=nil)
res=@grouppool.info
if options
@table.columns=options[:columns] if options[:columns]
end
if OpenNebula.is_error?(res)
result=res
else
result=res
header_up_small
puts @table.data_str(@grouppool, options)
result
end
end
end
class OneUPParse < CommandParse
COMMANDS_HELP=<<-EOT
Description:
This command enables the OpenNebula administrator to manage groups.
Commands:
* create (Creates a new group)
onegroup create groupname
* delete (Removes a group)
onegroup delete <id>
* list (Lists all the groups in the pool)
onegroup list
EOT
def text_commands
COMMANDS_HELP
end
def text_command_name
"onegroup"
end
def list_options
table=ShowTable.new(ShowTableUP)
table.print_help
end
end
oneup_opts=OneUPParse.new([:list, :xml])
oneup_opts.parse(ARGV)
ops=oneup_opts.options
result=[false, "Unknown error"]
command=ARGV.shift
case command
when "create"
check_parameters("create", 1)
group=OpenNebula::Group.new(OpenNebula::Group.build_xml, get_one_client)
result=group.allocate(ARGV[0])
if is_successful?(result)
puts "ID: " + group.id.to_s if ops[:verbose]
exit 0
end
when "delete"
check_parameters("delete", 1)
args=expand_args(ARGV)
args.each do |param|
group_id=get_group_id(param)
group=OpenNebula::Group.new(
OpenNebula::Group.build_xml(group_id), get_one_client)
result=group.delete
if !OpenNebula.is_error?(result)
puts "Group deleted" if ops[:verbose]
break
end
end
when "list"
if !ops[:xml]
uplist=UPShow.new
ops[:columns]=ops[:list] if ops[:list]
result=uplist.list_short(ops)
else
grouppool=OpenNebula::GroupPool.new(get_one_client)
grouppool.info
puts grouppool.to_xml(true)
end
else
oneup_opts.print_help
exit -1
end
if OpenNebula.is_error?(result)
puts "Error: " + result.message
exit -1
end

View File

@ -40,6 +40,7 @@ env.Prepend(LIBS=[
'nebula_template',
'nebula_vm',
'nebula_vmtemplate',
'nebula_group',
'nebula_vnm',
'nebula_image',
'nebula_pool',

189
src/group/Group.cc Normal file
View File

@ -0,0 +1,189 @@
/* ------------------------------------------------------------------------ */
/* 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 <limits.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include "Group.h"
const char * Group::table = "group_pool";
const char * Group::db_names = "oid, name, body, uid";
const char * Group::db_bootstrap = "CREATE TABLE IF NOT EXISTS group_pool ("
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, "
"UNIQUE(name))";
/* ************************************************************************ */
/* Group :: Constructor/Destructor */
/* ************************************************************************ */
Group::Group(int id, int uid, const string& name):
PoolObjectSQL(id,name,uid,table){};
Group::~Group(){};
/* ************************************************************************ */
/* Group :: Database Access Functions */
/* ************************************************************************ */
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Group::insert(SqlDB *db, string& error_str)
{
int rc;
rc = insert_replace(db, false);
if ( rc != 0 )
{
error_str = "Error inserting Group in DB.";
}
return rc;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Group::update(SqlDB *db)
{
int rc;
rc = insert_replace(db, true);
return rc;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Group::insert_replace(SqlDB *db, bool replace)
{
ostringstream oss;
int rc;
string xml_body;
char * sql_name;
char * sql_xml;
// Update the Group
sql_name = db->escape_str(name.c_str());
if ( sql_name == 0 )
{
goto error_name;
}
sql_xml = db->escape_str(to_xml(xml_body).c_str());
if ( sql_xml == 0 )
{
goto error_body;
}
if(replace)
{
oss << "REPLACE";
}
else
{
oss << "INSERT";
}
// Construct the SQL statement to Insert or Replace
oss <<" INTO "<<table <<" ("<< db_names <<") VALUES ("
<< oid << ","
<< "'" << sql_name << "',"
<< "'" << sql_xml << "',"
<< uid << ")";
rc = db->exec(oss);
db->free_str(sql_name);
db->free_str(sql_xml);
return rc;
error_body:
db->free_str(sql_name);
error_name:
return -1;
}
/* ************************************************************************ */
/* Group :: Misc */
/* ************************************************************************ */
ostream& operator<<(ostream& os, Group& group)
{
string group_str;
os << group.to_xml(group_str);
return os;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
string& Group::to_xml(string& xml) const
{
ostringstream oss;
oss <<
"<GROUP>" <<
"<ID>" << oid << "</ID>" <<
"<UID>" << uid << "</UID>" <<
"<NAME>" << name << "</NAME>" <<
"</GROUP>";
xml = oss.str();
return xml;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Group::from_xml(const string& xml)
{
int rc = 0;
// Initialize the internal XML object
update_from_str(xml);
// Get class base attributes
rc += xpath(oid, "/GROUP/ID", -1);
rc += xpath(uid, "/GROUP/UID", -1);
rc += xpath(name,"/GROUP/NAME", "not_found");
if (rc != 0)
{
return -1;
}
return 0;
}

118
src/group/GroupPool.cc Normal file
View File

@ -0,0 +1,118 @@
/* -------------------------------------------------------------------------- */
/* 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 "GroupPool.h"
#include "Nebula.h"
#include "NebulaLog.h"
#include <stdexcept>
const string GroupPool::DEFAULT_GROUP_NAME = "default";
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
GroupPool::GroupPool(SqlDB * db):PoolSQL(db, Group::table)
{
// lastOID is set in PoolSQL::init_cb
if (get_lastOID() == -1)
{
int rc;
Group * group;
string error_str;
// Build a new Group object
group = new Group(0, 0, GroupPool::DEFAULT_GROUP_NAME);
// Insert the Object in the pool
rc = PoolSQL::allocate(group, error_str);
if(rc != 0)
{
ostringstream oss;
oss << "Error trying to create default group: " << error_str;
NebulaLog::log("GROUP",Log::ERROR,oss);
throw runtime_error(oss.str());
}
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int GroupPool::allocate(int uid, string name, int * oid, string& error_str)
{
Group * group;
ostringstream oss;
if ( name.empty() )
{
goto error_name;
}
// Check for duplicates
group = get(name, uid, false);
if( group != 0 )
{
goto error_duplicated;
}
// Build a new Group object
group = new Group(-1, uid, name);
// Insert the Object in the pool
*oid = PoolSQL::allocate(group, error_str);
return *oid;
error_name:
oss << "NAME cannot be empty.";
goto error_common;
error_duplicated:
oss << "NAME is already taken by GROUP " << group->get_oid() << ".";
error_common:
*oid = -1;
error_str = oss.str();
return *oid;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int GroupPool::drop(Group * group)
{
int rc;
// Return error if group is 'default'
if( group->get_oid() == 0 )
{
NebulaLog::log("GROUP",Log::WARNING,
"Default group cannot be deleted.");
return -1;
}
rc = group->drop(db);
return rc;
}

30
src/group/SConstruct Normal file
View File

@ -0,0 +1,30 @@
# SConstruct for src/group
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
Import('env')
lib_name='nebula_group'
# Sources to generate the library
source_files=[
'GroupPool.cc',
'Group.cc'
]
# Build library
env.StaticLibrary(lib_name, source_files)

View File

@ -0,0 +1,233 @@
/* -------------------------------------------------------------------------- */
/* 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 <string>
#include <iostream>
#include <stdlib.h>
#include "GroupPool.h"
#include "PoolTest.h"
using namespace std;
const int uids[] = {0,1,2};
const string names[] = {"First name", "Second name"};
const string xmls[] =
{
"<GROUP><ID>1</ID><UID>0</UID><NAME>First name</NAME></GROUP>",
"<GROUP><ID>2</ID><UID>1</UID><NAME>Second name</NAME></GROUP>"
};
const string group_xml_dump =
"<GROUP_POOL><GROUP><ID>0</ID><UID>0</UID><NAME>default</NAME></GROUP><GROUP><ID>1</ID><UID>5</UID><NAME>group_a</NAME></GROUP><GROUP><ID>3</ID><UID>5</UID><NAME>group_c</NAME></GROUP><GROUP><ID>4</ID><UID>5</UID><NAME>group_d</NAME></GROUP></GROUP_POOL>";
/* ************************************************************************* */
/* ************************************************************************* */
#include "NebulaTest.h"
class NebulaTestGroup: public NebulaTest
{
public:
NebulaTestGroup():NebulaTest()
{
NebulaTest::the_tester = this;
need_group_pool= true;
}
};
class GroupPoolTest : public PoolTest
{
CPPUNIT_TEST_SUITE (GroupPoolTest);
// Not all tests from PoolTest can be used. Because
// of the initial default group added to the DB, the
// oid_assignment would fail.
CPPUNIT_TEST (get_from_cache);
CPPUNIT_TEST (get_from_db);
CPPUNIT_TEST (wrong_get);
CPPUNIT_TEST (drop_and_get);
CPPUNIT_TEST (duplicates);
CPPUNIT_TEST (dump);
CPPUNIT_TEST_SUITE_END ();
protected:
NebulaTestGroup * tester;
GroupPool * gpool;
void bootstrap(SqlDB* db)
{
// setUp overwritten
};
PoolSQL* create_pool(SqlDB* db)
{
// setUp overwritten
return gpool;
};
int allocate(int index)
{
int oid;
string err;
return gpool->allocate(uids[index], names[index], &oid, err);
};
void check(int index, PoolObjectSQL* obj)
{
Group * group = static_cast<Group *>(obj);
CPPUNIT_ASSERT( obj != 0 );
string xml_str = "";
string name = group->get_name();
CPPUNIT_ASSERT( name == names[index] );
// Get the xml
group->to_xml(xml_str);
// A little help for debugging
/*
if( xml_str != xmls[index] )
{
cout << endl << xml_str << endl << "========"
<< endl << xmls[index];
}
//*/
CPPUNIT_ASSERT( xml_str == xmls[index]);
};
private:
public:
GroupPoolTest()
{
xmlInitParser();
};
~GroupPoolTest()
{
xmlCleanupParser();
};
void setUp()
{
create_db();
tester = new NebulaTestGroup();
Nebula& neb = Nebula::instance();
neb.start();
gpool = neb.get_gpool();
pool = gpool;
};
void tearDown()
{
delete_db();
delete tester;
};
/* ********************************************************************* */
/* ********************************************************************* */
void duplicates()
{
int rc, oid;
string err;
GroupPool * gpool = static_cast<GroupPool*>(pool);
// Allocate a group
rc = gpool->allocate(uids[0], names[0], &oid, err);
CPPUNIT_ASSERT( oid == 1 );
CPPUNIT_ASSERT( oid == rc );
// Try to allocate twice the same group, should fail
rc = gpool->allocate(uids[0], names[0], &oid, err);
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( oid == rc );
// Try again, this time with different uid. Should fail, groups can't
// repeat names
rc = gpool->allocate(uids[1], names[0], &oid, err);
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( oid == rc );
}
/* ********************************************************************* */
void dump()
{
Group * group;
int oid, rc;
ostringstream oss;
string err;
// Allocate some groups
rc = gpool->allocate(5, "group_a", &oid, err);
CPPUNIT_ASSERT( rc == 1 );
rc = gpool->allocate(5, "group_b", &oid, err);
CPPUNIT_ASSERT( rc == 2 );
rc = gpool->allocate(5, "group_c", &oid, err);
CPPUNIT_ASSERT( rc == 3 );
rc = gpool->allocate(5, "group_d", &oid, err);
CPPUNIT_ASSERT( rc == 4 );
// Drop one of them
group = gpool->get(2, false);
CPPUNIT_ASSERT( group != 0 );
rc = gpool->drop(group);
CPPUNIT_ASSERT( rc == 0 );
// dump the pool
rc = gpool->dump(oss,"");
/*
if( oss.str() != group_xml_dump )
{
cout << endl << oss.str() << endl << "========"
<< endl << group_xml_dump;
}
//*/
CPPUNIT_ASSERT( oss.str() == group_xml_dump );
}
};
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char ** argv)
{
return PoolTest::main(argc, argv, GroupPoolTest::suite());
}

57
src/group/test/SConstruct Normal file
View File

@ -0,0 +1,57 @@
# --------------------------------------------------------------------------
# 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.
# --------------------------------------------------------------------------
Import('env')
env.Prepend(LIBS=[
'nebula_cluster',
'nebula_host',
'nebula_pool',
'nebula_template',
'nebula_xml',
'nebula_log',
'nebula_common',
'nebula_sql',
### TODO: delete not needed
'nebula_core_test',
'nebula_host',
'nebula_cluster',
'nebula_xml',
'nebula_vmm',
'nebula_im',
'nebula_rm',
'nebula_tm',
'nebula_um',
'nebula_mad',
'nebula_template',
'nebula_vm',
'nebula_vmtemplate',
'nebula_group',
'nebula_vnm',
'nebula_image',
'nebula_pool',
'nebula_hm',
'nebula_authm',
'nebula_common',
'nebula_lcm',
'nebula_dm',
'nebula_sql',
'nebula_log',
'crypto'
])
env.Program('test','GroupPoolTest.cc')

View File

@ -32,6 +32,7 @@ env.Prepend(LIBS=[
'nebula_template',
'nebula_vm',
'nebula_vmtemplate',
'nebula_group',
'nebula_vnm',
'nebula_image',
'nebula_pool',

View File

@ -31,6 +31,7 @@ env.Prepend(LIBS=[
'nebula_template',
'nebula_vm',
'nebula_vmtemplate',
'nebula_group',
'nebula_vnm',
'nebula_image',
'nebula_pool',

View File

@ -235,6 +235,7 @@ void Nebula::start()
UserPool::bootstrap(db);
ImagePool::bootstrap(db);
ClusterPool::bootstrap(db);
GroupPool::bootstrap(db);
VMTemplatePool::bootstrap(db);
}
catch (exception&)
@ -275,6 +276,8 @@ void Nebula::start()
cpool = new ClusterPool(db);
gpool = new GroupPool(db);
tpool = new VMTemplatePool(db);
}
catch (exception&)
@ -443,6 +446,7 @@ void Nebula::start()
ipool,
cpool,
tpool,
gpool,
rm_port,
log_location + "one_xmlrpc.log");
}

View File

@ -41,6 +41,7 @@ env.Prepend(LIBS=[
'nebula_dm',
'nebula_tm',
'nebula_um',
'nebula_group',
'nebula_authm',
'nebula_mad',
'nebula_template',

View File

@ -39,6 +39,8 @@ require 'OpenNebula/Cluster'
require 'OpenNebula/ClusterPool'
require 'OpenNebula/Template'
require 'OpenNebula/TemplatePool'
require 'OpenNebula/Group'
require 'OpenNebula/GroupPool'
module OpenNebula

View File

@ -0,0 +1,87 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, 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 'OpenNebula/Pool'
module OpenNebula
class Group < PoolElement
# ---------------------------------------------------------------------
# Constants and Class Methods
# ---------------------------------------------------------------------
GROUP_METHODS = {
:info => "group.info",
:allocate => "group.allocate",
:delete => "group.delete",
}
# Creates a Group description with just its identifier
# this method should be used to create plain Group objects.
# +id+ the id of the user
#
# Example:
# group = Group.new(Group.build_xml(3),rpc_client)
#
def Group.build_xml(pe_id=nil)
if pe_id
group_xml = "<GROUP><ID>#{pe_id}</ID></GROUP>"
else
group_xml = "<GROUP></GROUP>"
end
XMLElement.build_xml(group_xml,'GROUP')
end
# ---------------------------------------------------------------------
# Class constructor
# ---------------------------------------------------------------------
def initialize(xml, client)
super(xml,client)
@client = client
end
# ---------------------------------------------------------------------
# XML-RPC Methods for the Group Object
# ---------------------------------------------------------------------
# Retrieves the information of the given Group.
def info()
super(GROUP_METHODS[:info], 'GROUP')
end
# Allocates a new Group in OpenNebula
#
# +groupname+ A string containing the name of the Group.
def allocate(groupname)
super(GROUP_METHODS[:allocate], groupname)
end
# Deletes the Group
def delete()
super(GROUP_METHODS[:delete])
end
# ---------------------------------------------------------------------
# Helpers to get information
# ---------------------------------------------------------------------
# Returns the owner (numeric value)
def uid
self['UID'].to_i
end
end
end

View File

@ -0,0 +1,52 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, 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 'OpenNebula/Pool'
module OpenNebula
class GroupPool < Pool
# ---------------------------------------------------------------------
# Constants and Class attribute accessors
# ---------------------------------------------------------------------
GROUP_POOL_METHODS = {
:info => "grouppool.info"
}
# ---------------------------------------------------------------------
# Class constructor & Pool Methods
# ---------------------------------------------------------------------
# +client+ a Client object that represents a XML-RPC connection
def initialize(client)
super('GROUP_POOL','GROUP',client)
end
# Factory method to create User objects
def factory(element_xml)
OpenNebula::Group.new(element_xml,@client)
end
# ---------------------------------------------------------------------
# XML-RPC Methods for the User Object
# ---------------------------------------------------------------------
# Retrieves all the Groups in the pool.
def info()
super(GROUP_POOL_METHODS[:info])
end
end
end

View File

@ -288,6 +288,18 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr clusterpool_info(new
RequestManager::ClusterPoolInfo(upool,cpool));
xmlrpc_c::methodPtr group_allocate(new
RequestManager::GroupAllocate(upool,gpool));
xmlrpc_c::methodPtr group_info(new
RequestManager::GroupInfo(upool,gpool));
xmlrpc_c::methodPtr group_delete(new
RequestManager::GroupDelete(upool,gpool));
xmlrpc_c::methodPtr grouppool_info(new
RequestManager::GroupPoolInfo(upool,gpool));
xmlrpc_c::methodPtr vn_allocate(new
RequestManager::VirtualNetworkAllocate(vnpool,upool));
@ -392,6 +404,14 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.clusterpool.info", clusterpool_info);
/* Group related methods */
RequestManagerRegistry.addMethod("one.group.allocate", group_allocate);
RequestManagerRegistry.addMethod("one.group.info", group_info);
RequestManagerRegistry.addMethod("one.group.delete", group_delete);
RequestManagerRegistry.addMethod("one.grouppool.info", grouppool_info);
/* Network related methods*/
RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate);

View File

@ -0,0 +1,122 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2011, 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 "RequestManager.h"
#include "NebulaLog.h"
#include "AuthManager.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestManager::GroupAllocate::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
string session;
string error_str;
string name;
int id;
const string method_name = "GroupAllocate";
int rc, uid;
ostringstream oss;
/* -- RPC specific vars -- */
vector<xmlrpc_c::value> arrayData;
xmlrpc_c::value_array * arrayresult;
NebulaLog::log("ReM",Log::DEBUG,"GroupAllocate method invoked");
// Get the parameters
session = xmlrpc_c::value_string(paramList.getString(0));
name = xmlrpc_c::value_string(paramList.getString(1));
//Authenticate the user
uid = GroupAllocate::upool->authenticate(session);
if ( uid == -1 )
{
goto error_authenticate;
}
//Authorize the operation
if ( uid != 0 ) // uid == 0 means oneadmin
{
AuthRequest ar(uid);
ar.add_auth(AuthRequest::GROUP,
-1,
AuthRequest::CREATE,
uid,
false);
if (UserPool::authorize(ar) == -1)
{
goto error_authorize;
}
}
// Perform the allocation in the pool
rc = GroupAllocate::gpool->allocate(uid, name, &id, error_str);
if ( rc == -1 )
{
goto error_allocate;
}
// All nice, return the new id to client
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
arrayData.push_back(xmlrpc_c::value_int(id));
arrayresult = new xmlrpc_c::value_array(arrayData);
// Copy arrayresult into retval mem space
*retval = *arrayresult;
// and get rid of the original
delete arrayresult;
return;
error_authenticate:
oss.str(authenticate_error(method_name));
goto error_common;
error_authorize:
oss.str(authorization_error(method_name, "CREATE", "GROUP", uid, -1));
goto error_common;
error_allocate:
oss << action_error(method_name, "CREATE", "GROUP", -2, 0);
oss << " " << error_str;
goto error_common;
error_common:
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
NebulaLog::log("ReM",Log::ERROR,oss);
xmlrpc_c::value_array arrayresult_error(arrayData);
*retval = arrayresult_error;
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -0,0 +1,144 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2011, 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 "RequestManager.h"
#include "NebulaLog.h"
#include "AuthManager.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestManager::GroupDelete::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
string session;
int id;
Group * group;
ostringstream oss;
int rc;
int owner;
const string method_name = "GroupDelete";
/* -- RPC specific vars -- */
vector<xmlrpc_c::value> arrayData;
xmlrpc_c::value_array * arrayresult;
NebulaLog::log("ReM",Log::DEBUG,"GroupDelete method invoked");
// Get the parameters
session = xmlrpc_c::value_string(paramList.getString(0));
id = xmlrpc_c::value_int (paramList.getInt(1));
//Authenticate the user
rc = GroupDelete::upool->authenticate(session);
if ( rc == -1 )
{
goto error_authenticate;
}
// Get template from the pool
group = GroupDelete::gpool->get(id,true);
if ( group == 0 )
{
goto error_get;
}
owner = group->get_uid();
group->unlock();
//Authorize the operation
if ( rc != 0 ) // rc == 0 means oneadmin
{
AuthRequest ar(rc);
ar.add_auth(AuthRequest::GROUP,
id,
AuthRequest::DELETE,
owner,
false);
if (UserPool::authorize(ar) == -1)
{
goto error_authorize;
}
}
// Perform the deletion from the pool
group = GroupDelete::gpool->get(id,true);
if ( group == 0 )
{
goto error_get;
}
rc = GroupDelete::gpool->drop(group);
group->unlock();
if ( rc != 0 )
{
goto error_delete;
}
// Return success
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
arrayresult = new xmlrpc_c::value_array(arrayData);
// Copy arrayresult into retval mem space
*retval = *arrayresult;
// and get rid of the original
delete arrayresult;
return;
error_authenticate:
oss.str(authenticate_error(method_name));
goto error_common;
error_authorize:
oss.str(authorization_error(method_name, "DELETE", "GROUP", rc, id));
goto error_common;
error_get:
oss.str(get_error(method_name, "GROUP", id));
goto error_common;
error_delete:
oss.str(action_error(method_name, "DELETE", "GROUP", id, rc));
goto error_common;
error_common:
NebulaLog::log ("Rem",Log::ERROR,oss);
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
xmlrpc_c::value_array arrayresult_error(arrayData);
*retval = arrayresult_error;
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -0,0 +1,107 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2011, 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 "RequestManager.h"
#include "NebulaLog.h"
#include "AuthManager.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestManager::GroupInfo::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
string session;
Group * group;
ostringstream oss;
int id;
int rc;
const string method_name = "GroupInfo";
/* -- RPC specific vars -- */
vector<xmlrpc_c::value> arrayData;
xmlrpc_c::value_array * arrayresult;
NebulaLog::log("ReM",Log::DEBUG,"GroupInfo method invoked");
// Get the parameters
session = xmlrpc_c::value_string(paramList.getString(0));
id = xmlrpc_c::value_int (paramList.getInt(1));
//Authenticate the user
rc = GroupInfo::upool->authenticate(session);
if ( rc == -1 )
{
goto error_authenticate;
}
// TODO: perform authorization with INFO ?
// Get the group
group = GroupInfo::gpool->get(id,true);
if ( group == 0 )
{
goto error_get;
}
oss << *group;
group->unlock();
// All nice, return the group info to the client
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
// Copy arrayresult into retval mem space
arrayresult = new xmlrpc_c::value_array(arrayData);
*retval = *arrayresult;
delete arrayresult; // and get rid of the original
return;
error_authenticate:
oss.str(authenticate_error(method_name));
goto error_common;
error_get:
oss.str(get_error(method_name, "GROUP", id));
goto error_common;
error_common:
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
NebulaLog::log("ReM",Log::ERROR,oss);
xmlrpc_c::value_array arrayresult_error(arrayData);
*retval = arrayresult_error;
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -0,0 +1,100 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2011, 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 "RequestManager.h"
#include "NebulaLog.h"
#include "AuthManager.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestManager::GroupPoolInfo::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
string session;
ostringstream oss;
int rc;
const string method_name = "GroupPoolInfo";
/* -- RPC specific vars -- */
vector<xmlrpc_c::value> arrayData;
xmlrpc_c::value_array * arrayresult;
NebulaLog::log("ReM",Log::DEBUG,"GroupPoolInfo method invoked");
// Get the parameters
session = xmlrpc_c::value_string(paramList.getString(0));
//Authenticate the user
rc = GroupPoolInfo::upool->authenticate(session);
if ( rc == -1 )
{
goto error_authenticate;
}
// TODO: perform authorization with INFO?
// Add flags, like "groups I belong to", "groups I own"
// Dump the pool
rc = GroupPoolInfo::gpool->dump(oss, "");
if ( rc != 0 )
{
goto error_dump;
}
//All nice, return the info to the client
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
arrayresult = new xmlrpc_c::value_array(arrayData);
// Copy arrayresult into retval mem space
*retval = *arrayresult;
// and get rid of the original
delete arrayresult;
return;
error_authenticate:
oss.str(authenticate_error(method_name));
goto error_common;
error_dump:
oss.str(get_error(method_name, "GROUP", -1));
goto error_common;
error_common:
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
NebulaLog::log("ReM",Log::ERROR,oss);
xmlrpc_c::value_array arrayresult_error(arrayData);
*retval = arrayresult_error;
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -50,6 +50,10 @@ source_files=[
'RequestManagerClusterInfo.cc',
'RequestManagerClusterPoolInfo.cc',
'RequestManagerClusterRemove.cc',
'RequestManagerGroupAllocate.cc',
'RequestManagerGroupDelete.cc',
'RequestManagerGroupInfo.cc',
'RequestManagerGroupPoolInfo.cc',
'RequestManagerVirtualNetworkAllocate.cc',
'RequestManagerVirtualNetworkInfo.cc',
'RequestManagerVirtualNetworkPoolInfo.cc',

View File

@ -87,6 +87,11 @@ void Nebula::start()
delete tpool;
}
if ( gpool != 0)
{
delete gpool;
}
if ( vmm != 0)
{
delete vmm;
@ -171,6 +176,8 @@ void Nebula::start()
UserPool::bootstrap(db);
ImagePool::bootstrap(db);
ClusterPool::bootstrap(db);
VMTemplatePool::bootstrap(db);
GroupPool::bootstrap(db);
}
catch (exception&)
{
@ -222,6 +229,11 @@ void Nebula::start()
{
tpool = tester->create_tpool(db);
}
if (tester->need_group_pool)
{
gpool = tester->create_gpool(db);
}
}
catch (exception&)
{
@ -367,7 +379,7 @@ void Nebula::start()
try
{
rm = tester->create_rm(vmpool,hpool,vnpool,upool,ipool,cpool,tpool,
log_location + "one_xmlrpc.log");
gpool,log_location + "one_xmlrpc.log");
}
catch (bad_alloc&)
{

View File

@ -57,6 +57,11 @@ VMTemplatePool* NebulaTest::create_tpool(SqlDB* db)
return new VMTemplatePool(db);
}
GroupPool* NebulaTest::create_gpool(SqlDB* db)
{
return new GroupPool(db);
}
// -----------------------------------------------------------
// Managers
// -----------------------------------------------------------
@ -116,6 +121,7 @@ RequestManager* NebulaTest::create_rm(
ImagePool * ipool,
ClusterPool * cpool,
VMTemplatePool * tpool,
GroupPool * gpool,
string log_file)
{
int rm_port = 2633;
@ -127,6 +133,7 @@ RequestManager* NebulaTest::create_rm(
ipool,
cpool,
tpool,
gpool,
rm_port,
log_file);
}