mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
B #4850: Invoke federation master when creating users from the driver callbacks
This commit is contained in:
parent
690f930464
commit
9d90f12602
@ -131,11 +131,15 @@ void Client::call(const std::string &method, const std::string format,
|
||||
|
||||
std::string::const_iterator i;
|
||||
|
||||
std::string sval;
|
||||
int ival;
|
||||
bool bval;
|
||||
std::string sval;
|
||||
int ival;
|
||||
bool bval;
|
||||
|
||||
std::set<int> * vval;
|
||||
std::set<int>::iterator it;
|
||||
|
||||
const char* pval;
|
||||
vector<xmlrpc_c::value> x_vval;
|
||||
|
||||
xmlrpc_c::paramList plist;
|
||||
|
||||
@ -164,6 +168,18 @@ void Client::call(const std::string &method, const std::string format,
|
||||
plist.add(xmlrpc_c::value_boolean(bval));
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
vval = static_cast<std::set<int> *>(va_arg(args,
|
||||
std::set<int> *));
|
||||
|
||||
for (it = vval->begin(); it != vval->end(); ++it)
|
||||
{
|
||||
x_vval.push_back(xmlrpc_c::value_int(*it));
|
||||
}
|
||||
|
||||
plist.add(xmlrpc_c::value_array(x_vval));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -225,6 +225,86 @@ error_common:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static int master_allocate(const string& uname, const string& passwd,
|
||||
const string& driver, const set<int>& gids, string& error_str)
|
||||
{
|
||||
Client * client = Client::client();
|
||||
|
||||
xmlrpc_c::value result;
|
||||
vector<xmlrpc_c::value> values;
|
||||
|
||||
std::ostringstream oss("Cannot allocate user at federation master: ",
|
||||
std::ios::ate);
|
||||
try
|
||||
{
|
||||
client->call("one.user.allocate", "sssI", &result, uname.c_str(),
|
||||
passwd.c_str(), driver.c_str(), &gids);
|
||||
}
|
||||
catch (exception const& e)
|
||||
{
|
||||
oss << e.what();
|
||||
error_str = oss.str();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
values = xmlrpc_c::value_array(result).vectorValueValue();
|
||||
|
||||
if ( xmlrpc_c::value_boolean(values[0]) == false )
|
||||
{
|
||||
std::string error_xml = xmlrpc_c::value_string(values[1]);
|
||||
|
||||
oss << error_xml;
|
||||
error_str = oss.str();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int oid = xmlrpc_c::value_int(values[1]);
|
||||
|
||||
return oid;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static int master_chgrp(int user_id, int group_id, string& error_str)
|
||||
{
|
||||
Client * client = Client::client();
|
||||
|
||||
xmlrpc_c::value result;
|
||||
vector<xmlrpc_c::value> values;
|
||||
|
||||
std::ostringstream oss("Cannot change user group at federation master: ",
|
||||
std::ios::ate);
|
||||
try
|
||||
{
|
||||
client->call("one.user.chgrp", "ii", &result, user_id, group_id);
|
||||
}
|
||||
catch (exception const& e)
|
||||
{
|
||||
oss << e.what();
|
||||
error_str = oss.str();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
values = xmlrpc_c::value_array(result).vectorValueValue();
|
||||
|
||||
if ( xmlrpc_c::value_boolean(values[0]) == false )
|
||||
{
|
||||
std::string error_xml = xmlrpc_c::value_string(values[1]);
|
||||
|
||||
oss << error_xml;
|
||||
error_str = oss.str();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int UserPool::allocate (
|
||||
int * oid,
|
||||
const string& uname,
|
||||
@ -249,11 +329,20 @@ int UserPool::allocate (
|
||||
|
||||
if (nd.is_federation_slave())
|
||||
{
|
||||
NebulaLog::log("ONE",Log::ERROR,
|
||||
"UserPool::allocate called, but this "
|
||||
"OpenNebula is a federation slave");
|
||||
*oid = master_allocate(uname, password, auth, gids, error_str);
|
||||
|
||||
return -1;
|
||||
if ( *oid < 0 )
|
||||
{
|
||||
NebulaLog::log("ONE", Log::ERROR, error_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( master_chgrp(*oid, gid, error_str) == -1 )
|
||||
{
|
||||
NebulaLog::log("ONE", Log::ERROR, error_str);
|
||||
}
|
||||
|
||||
return *oid;
|
||||
}
|
||||
|
||||
// Check username and password
|
||||
|
Loading…
x
Reference in New Issue
Block a user