mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-26 06:50:09 +03:00
feature #3987: DS inherited attributes logic moved to the DatastorePool class
This commit is contained in:
parent
18bce6b094
commit
dd882538eb
@ -26,7 +26,7 @@ using namespace std;
|
||||
class DatastorePool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
DatastorePool(SqlDB * db);
|
||||
DatastorePool(SqlDB * db, const vector<const Attribute *>& _inherit_attrs);
|
||||
|
||||
~DatastorePool(){};
|
||||
|
||||
@ -189,7 +189,20 @@ public:
|
||||
return PoolSQL::list(oids, Datastore::table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the disk the datastore inherit attributes and conf values
|
||||
* @param ds_id of the datastore to use
|
||||
* @para disk vector attribute for the disk
|
||||
*
|
||||
* @return -1 if the DS does not exists
|
||||
*/
|
||||
int disk_attribute(int ds_id, VectorAttribute * disk);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Datastore attributes to be inherited into the VM disk
|
||||
*/
|
||||
vector<string> inherit_attrs;
|
||||
|
||||
/**
|
||||
* Factory method to produce objects
|
||||
|
@ -48,8 +48,7 @@ public:
|
||||
vector<const Attribute *>& restricted_attrs,
|
||||
vector<const Attribute *> hook_mads,
|
||||
const string& remotes_location,
|
||||
const vector<const Attribute *>& _inherit_image_attrs,
|
||||
const vector<const Attribute *>& _inherit_datastore_attrs);
|
||||
const vector<const Attribute *>& _inherit_image_attrs);
|
||||
|
||||
~ImagePool(){};
|
||||
|
||||
@ -248,12 +247,7 @@ private:
|
||||
/**
|
||||
* Image attributes to be inherited into the VM disk
|
||||
*/
|
||||
vector<string> inherit_image_attrs;
|
||||
|
||||
/**
|
||||
* Datastore attributes to be inherited into the VM disk
|
||||
*/
|
||||
vector<string> inherit_datastore_attrs;
|
||||
vector<string> inherit_attrs;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Pool Attributes
|
||||
|
@ -38,12 +38,24 @@ const int DatastorePool::FILE_DS_ID = 2;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
DatastorePool::DatastorePool(SqlDB * db):
|
||||
PoolSQL(db, Datastore::table, true, true)
|
||||
DatastorePool::DatastorePool(
|
||||
SqlDB * db,
|
||||
const vector<const Attribute *>& _inherit_attrs) :
|
||||
PoolSQL(db, Datastore::table, true, true)
|
||||
|
||||
{
|
||||
ostringstream oss;
|
||||
string error_str;
|
||||
|
||||
vector<const Attribute *>::const_iterator it;
|
||||
|
||||
for (it = _inherit_attrs.begin(); it != _inherit_attrs.end(); it++)
|
||||
{
|
||||
const SingleAttribute* sattr = static_cast<const SingleAttribute *>(*it);
|
||||
|
||||
inherit_attrs.push_back(sattr->value());
|
||||
}
|
||||
|
||||
if (get_lastOID() == -1) //lastOID is set in PoolSQL::init_cb
|
||||
{
|
||||
DatastoreTemplate * ds_tmpl;
|
||||
@ -261,3 +273,20 @@ int DatastorePool::drop(PoolObjectSQL * objsql, string& error_msg)
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int DatastorePool::disk_attribute(int ds_id, VectorAttribute * disk)
|
||||
{
|
||||
Datastore * ds = get(ds_id, true);
|
||||
|
||||
if (ds == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds->disk_attribute(disk, inherit_attrs);
|
||||
|
||||
ds->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,7 @@ ImagePool::ImagePool(
|
||||
vector<const Attribute *>& restricted_attrs,
|
||||
vector<const Attribute *> hook_mads,
|
||||
const string& remotes_location,
|
||||
const vector<const Attribute *>& _inherit_image_attrs,
|
||||
const vector<const Attribute *>& _inherit_datastore_attrs)
|
||||
const vector<const Attribute *>& _inherit_attrs)
|
||||
:PoolSQL(db, Image::table, true, true)
|
||||
{
|
||||
// Init static defaults
|
||||
@ -54,18 +53,11 @@ ImagePool::ImagePool(
|
||||
// Init inherit attributes
|
||||
vector<const Attribute *>::const_iterator it;
|
||||
|
||||
for (it = _inherit_image_attrs.begin(); it != _inherit_image_attrs.end(); it++)
|
||||
for (it = _inherit_attrs.begin(); it != _inherit_attrs.end(); it++)
|
||||
{
|
||||
const SingleAttribute* sattr = static_cast<const SingleAttribute *>(*it);
|
||||
|
||||
inherit_image_attrs.push_back(sattr->value());
|
||||
}
|
||||
|
||||
for (it = _inherit_datastore_attrs.begin(); it != _inherit_datastore_attrs.end(); it++)
|
||||
{
|
||||
const SingleAttribute* sattr = static_cast<const SingleAttribute *>(*it);
|
||||
|
||||
inherit_datastore_attrs.push_back(sattr->value());
|
||||
inherit_attrs.push_back(sattr->value());
|
||||
}
|
||||
|
||||
// Set default type
|
||||
@ -408,7 +400,6 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
if ( img != 0 )
|
||||
{
|
||||
DatastorePool * ds_pool = nd.get_dspool();
|
||||
Datastore * ds;
|
||||
|
||||
long long size = 0;
|
||||
bool has_size = (disk->vector_value("SIZE", size) == 0);
|
||||
@ -440,7 +431,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
}
|
||||
|
||||
iid = img->get_oid();
|
||||
img->disk_attribute(disk, img_type, dev_prefix, inherit_image_attrs);
|
||||
img->disk_attribute(disk, img_type, dev_prefix, inherit_attrs);
|
||||
|
||||
image_id = img->get_oid();
|
||||
datastore_id = img->get_ds_id();
|
||||
@ -453,9 +444,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
|
||||
img->unlock();
|
||||
|
||||
ds = ds_pool->get(datastore_id, true);
|
||||
|
||||
if ( ds == 0 )
|
||||
if ( ds_pool->disk_attribute(datastore_id, disk) == -1 )
|
||||
{
|
||||
imagem->release_image(vm_id, iid, false);
|
||||
error_str = "Associated datastore for the image does not exist";
|
||||
@ -465,10 +454,6 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds->disk_attribute(disk, inherit_datastore_attrs);
|
||||
|
||||
ds->unlock();
|
||||
}
|
||||
|
||||
disk->replace("DISK_ID", disk_id);
|
||||
@ -495,7 +480,6 @@ void ImagePool::disk_attribute(
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
DatastorePool * ds_pool = nd.get_dspool();
|
||||
Datastore * ds;
|
||||
|
||||
if (!(source = disk->vector_value("IMAGE")).empty())
|
||||
{
|
||||
@ -518,20 +502,13 @@ void ImagePool::disk_attribute(
|
||||
|
||||
if ( img != 0 )
|
||||
{
|
||||
img->disk_attribute(disk, img_type, dev_prefix, inherit_image_attrs);
|
||||
img->disk_attribute(disk, img_type, dev_prefix, inherit_attrs);
|
||||
|
||||
datastore_id = img->get_ds_id();
|
||||
|
||||
img->unlock();
|
||||
|
||||
ds = ds_pool->get(datastore_id, true);
|
||||
|
||||
if ( ds != 0 )
|
||||
{
|
||||
ds->disk_attribute(disk, inherit_datastore_attrs);
|
||||
|
||||
ds->unlock();
|
||||
}
|
||||
ds_pool->disk_attribute(datastore_id, disk);
|
||||
}
|
||||
|
||||
disk->replace("DISK_ID", disk_id);
|
||||
|
@ -594,12 +594,11 @@ void Nebula::start(bool bootstrap_only)
|
||||
img_restricted_attrs,
|
||||
image_hooks,
|
||||
remotes_location,
|
||||
inherit_image_attrs,
|
||||
inherit_datastore_attrs);
|
||||
inherit_image_attrs);
|
||||
|
||||
tpool = new VMTemplatePool(db);
|
||||
|
||||
dspool = new DatastorePool(db);
|
||||
dspool = new DatastorePool(db, inherit_datastore_attrs);
|
||||
|
||||
default_user_quota.select();
|
||||
default_group_quota.select();
|
||||
|
Loading…
x
Reference in New Issue
Block a user