1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-25 23:21:29 +03:00

Merge branch 'feature-1112' of git.opennebula.org:one into feature-1112

This commit is contained in:
Ruben S. Montero 2012-03-01 19:13:39 +01:00
commit 8988ba734c
8 changed files with 94 additions and 39 deletions

View File

@ -123,7 +123,10 @@ private:
// *************************************************************************
Datastore(
int id,
int uid,
int gid,
const string& uname,
const string& gname,
DatastoreTemplate* ds_template,
int cluster_id,
const string& cluster_name);

View File

@ -61,6 +61,10 @@ public:
/**
* Allocates a new Datastore, writing it in the pool database. No memory is
* allocated for the object.
* @param uid the user id of the Datastore owner
* @param gid the id of the group this object is assigned to
* @param uname name of the user
* @param gname name of the group
* @param ds_template Datastore definition template
* @param oid the id assigned to the Datastore
* @param cluster_id the id of the cluster this Datastore will belong to
@ -69,7 +73,12 @@ public:
*
* @return the oid assigned to the object, -1 in case of failure
*/
int allocate(DatastoreTemplate * ds_template,
int allocate(
int uid,
int gid,
const string& uname,
const string& gname,
DatastoreTemplate * ds_template,
int * oid,
int cluster_id,
const string& cluster_name,
@ -163,7 +172,7 @@ private:
*/
PoolObjectSQL * create()
{
return new Datastore(-1, 0, -1, "");
return new Datastore(-1,-1,"","", 0, -1, "");
};
};

View File

@ -176,6 +176,16 @@ public:
*/
static const char * SERVER_NAME;
/**
* Name of the oneadmin user
*/
static string oneadmin_name;
/**
* Identifier for the oneadmin user
*/
static const int ONEADMIN_ID;
private:
//--------------------------------------------------------------------------
// Configuration Attributes for Users

View File

@ -66,6 +66,9 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper
CLIHelper.print_header(str_h1 % "DATASTORE #{datastore['ID']} INFORMATION")
puts str % ["ID", datastore.id.to_s]
puts str % ["NAME", datastore.name]
puts str % ["USER", datastore['UNAME']]
puts str % ["GROUP", datastore['GNAME']]
puts str % ["TYPE", datastore['TYPE']]
puts str % ["BASE PATH",datastore['BASE_PATH']]
puts

View File

@ -34,11 +34,15 @@ const char * Datastore::db_bootstrap =
/* Datastore :: Constructor/Destructor */
/* ************************************************************************ */
Datastore::Datastore(int id,
Datastore::Datastore(
int uid,
int gid,
const string& uname,
const string& gname,
DatastoreTemplate* ds_template,
int cluster_id,
const string& cluster_name):
PoolObjectSQL(id,DATASTORE,"",-1,-1,"","",table),
PoolObjectSQL(-1,DATASTORE,"",uid,gid,uname,gname,table),
ObjectCollection("IMAGES"),
Clusterable(cluster_id, cluster_name),
type(""),
@ -144,10 +148,6 @@ int Datastore::insert_replace(SqlDB *db, bool replace, string& error_str)
char * sql_name;
char * sql_xml;
// Set the owner and group to oneadmin
set_user(0, "");
set_group(GroupPool::ONEADMIN_ID, GroupPool::ONEADMIN_NAME);
// Update the Datastore
sql_name = db->escape_str(name.c_str());
@ -233,6 +233,10 @@ string& Datastore::to_xml(string& xml) const
oss <<
"<DATASTORE>" <<
"<ID>" << oid << "</ID>" <<
"<UID>" << uid << "</UID>" <<
"<GID>" << gid << "</GID>" <<
"<UNAME>" << uname << "</UNAME>" <<
"<GNAME>" << gname << "</GNAME>" <<
"<NAME>" << name << "</NAME>" <<
"<TYPE>" << type << "</TYPE>" <<
"<TM_MAD>" << tm_mad << "</TM_MAD>" <<
@ -261,6 +265,10 @@ int Datastore::from_xml(const string& xml)
// Get class base attributes
rc += xpath(oid, "/DATASTORE/ID", -1);
rc += xpath(uid, "/DATASTORE/UID", -1);
rc += xpath(gid, "/DATASTORE/GID", -1);
rc += xpath(uname, "/DATASTORE/UNAME", "not_found");
rc += xpath(gname, "/DATASTORE/GNAME", "not_found");
rc += xpath(name, "/DATASTORE/NAME", "not_found");
rc += xpath(type, "/DATASTORE/TYPE", "not_found");
rc += xpath(tm_mad, "/DATASTORE/TM_MAD", "not_found");
@ -269,10 +277,6 @@ int Datastore::from_xml(const string& xml)
rc += xpath(cluster_id, "/DATASTORE/CLUSTER_ID", -1);
rc += xpath(cluster, "/DATASTORE/CLUSTER", "not_found");
// Set the owner and group to oneadmin
set_user(0, "");
set_group(GroupPool::ONEADMIN_ID, GroupPool::ONEADMIN_NAME);
// Get associated classes
ObjectXML::get_nodes("/DATASTORE/IMAGES", content);

View File

@ -67,7 +67,11 @@ DatastorePool::DatastorePool(SqlDB * db):
goto error_bootstrap;
}
allocate(ds_tmpl,
allocate(UserPool::ONEADMIN_ID,
GroupPool::ONEADMIN_ID,
UserPool::oneadmin_name,
GroupPool::ONEADMIN_NAME,
ds_tmpl,
&system_id,
ClusterPool::DEFAULT_CLUSTER_ID,
ClusterPool::DEFAULT_CLUSTER_NAME,
@ -95,7 +99,11 @@ DatastorePool::DatastorePool(SqlDB * db):
goto error_bootstrap;
}
allocate(ds_tmpl,
allocate(UserPool::ONEADMIN_ID,
GroupPool::ONEADMIN_ID,
UserPool::oneadmin_name,
GroupPool::ONEADMIN_NAME,
ds_tmpl,
&default_id,
ClusterPool::DEFAULT_CLUSTER_ID,
ClusterPool::DEFAULT_CLUSTER_NAME,
@ -145,7 +153,12 @@ error_bootstrap:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int DatastorePool::allocate(DatastoreTemplate * ds_template,
int DatastorePool::allocate(
int uid,
int gid,
const string& uname,
const string& gname,
DatastoreTemplate * ds_template,
int * oid,
int cluster_id,
const string& cluster_name,
@ -156,7 +169,8 @@ int DatastorePool::allocate(DatastoreTemplate * ds_template,
string name;
ostringstream oss;
ds = new Datastore(-1, ds_template, cluster_id, cluster_name);
ds = new Datastore(uid, gid, uname, gname,
ds_template, cluster_id, cluster_name);
// -------------------------------------------------------------------------
// Check name & duplicates

View File

@ -467,7 +467,8 @@ int DatastoreAllocate::pool_allocate(
DatastoreTemplate * ds_tmpl = static_cast<DatastoreTemplate *>(tmpl);
return dspool->allocate(ds_tmpl, &id, cluster_id, cluster_name, error_str);
return dspool->allocate(att.uid, att.gid, att.uname, att.gname,
ds_tmpl, &id, cluster_id, cluster_name, error_str);
}
/* -------------------------------------------------------------------------- */

View File

@ -40,11 +40,15 @@ const char * UserPool::DEFAULT_AUTH = "default";
const char * UserPool::SERVER_NAME = "serveradmin";
const int UserPool::ONEADMIN_ID = 0;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
time_t UserPool::_session_expiration_time;
string UserPool::oneadmin_name;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -74,8 +78,13 @@ UserPool::UserPool(SqlDB * db,
_session_expiration_time = __session_expiration_time;
if (get(0,false) != 0)
User * oneadmin_user = get(0, true);
if (oneadmin_user != 0)
{
oneadmin_name = oneadmin_user->get_name();
oneadmin_user->unlock();
return;
}
@ -122,6 +131,8 @@ UserPool::UserPool(SqlDB * db,
goto error_token;
}
oneadmin_name = one_name;
if ( one_name == SERVER_NAME )
{
goto error_one_name;