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

Merge branch 'master' of git.opennebula.org:one

This commit is contained in:
Daniel Molina 2011-07-12 21:36:41 +02:00
commit 5a48d560c4
6 changed files with 87 additions and 13 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

@ -83,13 +83,6 @@ try_library :rubygems, <<-EOT.unindent
* Follow the instructions from http://rubygems.org/pages/download
EOT
try_library :bundler, <<-EOT.unindent
bundler needed to install gems
execute this to install it:
[sudo] gem install bundler
EOT
if ARGV.include?('-h')
help

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

@ -333,15 +333,15 @@ public:
CPPUNIT_ASSERT( oid == 0 );
CPPUNIT_ASSERT( oid == rc );
// Try to allocate twice the same image, should work
// Try to allocate twice the same image, shouldn't work
rc = imp->allocate(uids[0], templates[0], &oid);
CPPUNIT_ASSERT( rc == 1 );
CPPUNIT_ASSERT( oid == 1 );
CPPUNIT_ASSERT( rc == -1 );
CPPUNIT_ASSERT( oid == -1 );
// Try again, this time with different uid. Should be allowed
rc = imp->allocate(uids[1], templates[0], &oid);
CPPUNIT_ASSERT( rc >= 0 );
CPPUNIT_ASSERT( oid == 2 );
CPPUNIT_ASSERT( 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;
}