mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 20:02:38 +09: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:
1 parent
2fc0f5b5ca
commit
ae53d43789
33 files changed
+1875
-9
No files matched your search
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Executable
+186
@@ -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
|
||||
@@ -40,6 +40,7 @@ env.Prepend(LIBS=[
|
||||
'nebula_template',
|
||||
'nebula_vm',
|
||||
'nebula_vmtemplate',
|
||||
'nebula_group',
|
||||
'nebula_vnm',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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)
|
||||
@@ -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());
|
||||
}
|
||||
@@ -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')
|
||||
@@ -32,6 +32,7 @@ env.Prepend(LIBS=[
|
||||
'nebula_template',
|
||||
'nebula_vm',
|
||||
'nebula_vmtemplate',
|
||||
'nebula_group',
|
||||
'nebula_vnm',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
|
||||
@@ -31,6 +31,7 @@ env.Prepend(LIBS=[
|
||||
'nebula_template',
|
||||
'nebula_vm',
|
||||
'nebula_vmtemplate',
|
||||
'nebula_group',
|
||||
'nebula_vnm',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ env.Prepend(LIBS=[
|
||||
'nebula_dm',
|
||||
'nebula_tm',
|
||||
'nebula_um',
|
||||
'nebula_group',
|
||||
'nebula_authm',
|
||||
'nebula_mad',
|
||||
'nebula_template',
|
||||
|
||||
@@ -39,6 +39,8 @@ require 'OpenNebula/Cluster'
|
||||
require 'OpenNebula/ClusterPool'
|
||||
require 'OpenNebula/Template'
|
||||
require 'OpenNebula/TemplatePool'
|
||||
require 'OpenNebula/Group'
|
||||
require 'OpenNebula/GroupPool'
|
||||
|
||||
module OpenNebula
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -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',
|
||||
|
||||
+13
-1
@@ -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&)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user