1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Features #539, #527, #407: Basic consistency checks for User, Cluster and VNet creation

This commit is contained in:
Carlos Martín 2011-03-21 19:01:40 +01:00
parent 96b01044db
commit 1e1cb17e3a
3 changed files with 72 additions and 42 deletions

View File

@ -57,30 +57,41 @@ ClusterPool::ClusterPool(SqlDB * db):PoolSQL(db, Cluster::table)
int ClusterPool::allocate(int * oid, string name, string& error_str)
{
Cluster * cluster;
Cluster * cluster_aux;
Cluster * cluster;
ostringstream oss;
if ( name.empty() )
{
goto error_name;
}
// Check for duplicates
cluster_aux = get(name, false);
cluster = get(name, false);
if( cluster_aux != 0 )
if( cluster != 0 )
{
ostringstream oss;
oss << "NAME is already taken by CLUSTER "
<< cluster_aux->get_oid() << ".";
error_str = oss.str();
*oid = -1;
goto error_duplicated;
}
else
{
// Build a new Cluster object
cluster = new Cluster(-1, name);
// Insert the Object in the pool
*oid = PoolSQL::allocate(cluster, error_str);
}
// Build a new Cluster object
cluster = new Cluster(-1, name);
// Insert the Object in the pool
*oid = PoolSQL::allocate(cluster, error_str);
return *oid;
error_name:
oss << "NAME cannot be empty.";
goto error_common;
error_duplicated:
oss << "NAME is already taken by CLUSTER " << cluster->get_oid() << ".";
error_common:
*oid = -1;
error_str = oss.str();
return *oid;
}

View File

@ -120,26 +120,39 @@ int UserPool::allocate (
string& error_str)
{
User * user;
ostringstream oss;
if ( username.empty() )
{
goto error_name;
}
user = get(username,false);
if ( user !=0)
if ( user !=0 )
{
ostringstream oss;
oss << "NAME is already taken by USER " << user->get_oid() << ".";
error_str = oss.str();
*oid = -1;
goto error_duplicated;
}
else
{
// Build a new User object
user = new User(-1, username, password, enabled);
// Insert the Object in the pool
*oid = PoolSQL::allocate(user, error_str);
}
// Build a new User object
user = new User(-1, username, password, enabled);
// Insert the Object in the pool
*oid = PoolSQL::allocate(user, error_str);
return *oid;
error_name:
oss << "NAME cannot be empty.";
goto error_common;
error_duplicated:
oss << "NAME is already taken by USER " << user->get_oid() << ".";
error_common:
*oid = -1;
error_str = oss.str();
return *oid;
}

View File

@ -228,9 +228,13 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
{
type = VirtualNetwork::FIXED;
}
else if ( s_type.empty() )
{
goto error_type_defined;
}
else
{
goto error_type;
goto error_wrong_type;
}
// ------------ NAME ----------------------
@ -343,32 +347,34 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
return 0;
error_type:
ose << "Wrong type in template for Virtual Network, id: ";
error_type_defined:
ose << "No TYPE in template for Virtual Network.";
goto error_common;
error_wrong_type:
ose << "Wrong type \""<< s_type <<"\" in template for Virtual Network.";
goto error_common;
error_name:
ose << "No NAME in template for Virtual Network, id: ";
ose << "No NAME in template for Virtual Network.";
goto error_common;
error_bridge:
ose << "No BRIDGE in template for Virtual Network, id: ";
ose << "No BRIDGE in template for Virtual Network.";
goto error_common;
error_update:
ose << "Can not update Virtual Network, id: ";
ose << "Can not update Virtual Network.";
goto error_common;
error_addr:
ose << "Network address is not defined, id: ";
ose << "No NETWORK_ADDRESS in template for Virtual Network.";
goto error_common;
error_null_leases:
ose << "Error getting Virtual Network leases, id: ";
ose << "Error getting Virtual Network leases.";
error_common:
ose << oid << ".";
error_str = ose.str();
NebulaLog::log("VNM", Log::ERROR, ose);
return -1;