1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-06 12:58:18 +03:00

Bug: Image and VNet creation with an already used name reported a DB error, instead of a nice reason like Templates

This commit is contained in:
Carlos Martín 2011-07-12 19:30:00 +02:00
parent 3a7f18c912
commit 32e10726d4
4 changed files with 83 additions and 2 deletions

View File

@ -78,6 +78,20 @@ public:
return static_cast<Image *>(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
*/
Image * get(const string& name, int uid, bool lock)
{
return static_cast<Image *>(PoolSQL::get(name,uid,lock));
};
/**
* Update a particular Image
* @param image pointer to Image

View File

@ -69,6 +69,20 @@ public:
return static_cast<VirtualNetwork *>(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
*/
VirtualNetwork * get(const string& name, int uid, bool lock)
{
return static_cast<VirtualNetwork *>(PoolSQL::get(name,uid,lock));
};
//--------------------------------------------------------------------------
// Virtual Network DB access functions
//--------------------------------------------------------------------------

View File

@ -64,6 +64,7 @@ int ImagePool::allocate (
string& error_str)
{
Image * img;
Image * img_aux = 0;
string name;
ostringstream oss;
@ -77,6 +78,14 @@ int ImagePool::allocate (
goto error_name;
}
// Check for duplicates
img_aux = get(name,uid,false);
if( img_aux != 0 )
{
goto error_duplicated;
}
// ---------------------------------------------------------------------
// Insert the Object in the pool & Register the image in the repository
// ---------------------------------------------------------------------
@ -100,6 +109,13 @@ int ImagePool::allocate (
error_name:
oss << "NAME cannot be empty.";
goto error_common;
error_duplicated:
oss << "NAME is already taken by IMAGE "
<< img_aux->get_oid() << ".";
error_common:
delete img;
*oid = -1;

View File

@ -78,13 +78,50 @@ int VirtualNetworkPool::allocate (
int * oid,
string& error_str)
{
VirtualNetwork * vn;
string name;
VirtualNetwork * vn;
VirtualNetwork * vn_aux = 0;
string name;
ostringstream oss;
vn = new VirtualNetwork(uid, gid, uname, gname, vn_template);
// Check name
vn->get_template_attribute("NAME", name);
if ( name.empty() )
{
goto error_name;
}
// Check for duplicates
vn_aux = get(name,uid,false);
if( vn_aux != 0 )
{
goto error_duplicated;
}
vn = new VirtualNetwork(uid, gid, uname, gname, vn_template);
*oid = PoolSQL::allocate(vn, error_str);
return *oid;
error_name:
oss << "NAME cannot be empty.";
goto error_common;
error_duplicated:
oss << "NAME is already taken by NET "
<< vn_aux->get_oid() << ".";
error_common:
delete vn;
*oid = -1;
error_str = oss.str();
return *oid;
}