Feature #1112: Restrict image creation on system DS. Create new default DS

This commit is contained in:
Carlos Martín committed 2012-02-22 12:19:47 +01:00
1 parent 8f34895576
commit 546b6c8a4e
7 files changed
+102 -21

No files matched your search

+36 -7
View File
@@ -29,12 +29,17 @@
const string DatastorePool::SYSTEM_DS_NAME = "system";
const int DatastorePool::SYSTEM_DS_ID = 0;
const string DatastorePool::DEFAULT_DS_NAME = "default";
const int DatastorePool::DEFAULT_DS_ID = 1;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
DatastorePool::DatastorePool(SqlDB * db,
const string& base_path,
const string& type):
const string& system_base_path,
const string& system_type,
const string& default_base_path,
const string& default_type):
PoolSQL(db, Datastore::table)
{
ostringstream oss;
@@ -44,14 +49,38 @@ DatastorePool::DatastorePool(SqlDB * db,
{
int rc;
Datastore * ds;
DatastoreTemplate * ds_tmpl;
// Build the default datastore
// Build the default datastores
oss << "NAME = " << SYSTEM_DS_NAME << endl
<< "BASE_PATH = " << base_path << endl
<< "TYPE = " << type;
oss << "NAME = " << SYSTEM_DS_NAME << endl
<< "BASE_PATH = " << system_base_path << endl
<< "TYPE = " << system_type;
DatastoreTemplate * ds_tmpl = new DatastoreTemplate;
ds_tmpl = new DatastoreTemplate;
rc = ds_tmpl->parse_str_or_xml(oss.str(), error_str);
if( rc < 0 )
{
goto error_bootstrap;
}
ds = new Datastore(-1, ds_tmpl);
rc = PoolSQL::allocate(ds, error_str);
if( rc < 0 )
{
goto error_bootstrap;
}
oss.str("");
oss << "NAME = " << DEFAULT_DS_NAME << endl
<< "BASE_PATH = " << default_base_path << endl
<< "TYPE = " << default_type;
ds_tmpl = new DatastoreTemplate;
rc = ds_tmpl->parse_str_or_xml(oss.str(), error_str);
if( rc < 0 )
+19 -6
View File
@@ -276,8 +276,12 @@ void Nebula::start()
time_t expiration_time;
vector<const Attribute *> system_ds;
string ds_base_path;
string ds_type;
string system_ds_base_path;
string system_ds_type;
vector<const Attribute *> default_ds;
string default_ds_base_path;
string default_ds_type;
vector<const Attribute *> vm_hooks;
vector<const Attribute *> host_hooks;
@@ -319,13 +323,22 @@ void Nebula::start()
nebula_configuration->get("SYSTEM_DS", system_ds);
const VectorAttribute * ds_conf =
const VectorAttribute * ds_conf =
static_cast<const VectorAttribute *>(system_ds[0]);
ds_base_path = ds_conf->vector_value("BASE_PATH");
ds_type = ds_conf->vector_value("TYPE");
system_ds_base_path = ds_conf->vector_value("BASE_PATH");
system_ds_type = ds_conf->vector_value("TYPE");
dspool = new DatastorePool(db, ds_base_path, ds_type);
nebula_configuration->get("DEFAULT_DS", default_ds);
ds_conf = static_cast<const VectorAttribute *>(default_ds[0]);
default_ds_base_path = ds_conf->vector_value("BASE_PATH");
default_ds_type = ds_conf->vector_value("TYPE");
dspool = new DatastorePool(db,
system_ds_base_path, system_ds_type,
default_ds_base_path, default_ds_type);
}
catch (exception&)
{
+9 -1
View File
@@ -189,11 +189,19 @@ void OpenNebulaTemplate::set_conf_default()
//SYSTEM_DS
vvalue.clear();
vvalue.insert(make_pair("BASE_PATH","/var/lib/one/system_ds"));
vvalue.insert(make_pair("TYPE","shared"));
vvalue.insert(make_pair("TYPE","fs"));
vattribute = new VectorAttribute("SYSTEM_DS",vvalue);
conf_default.insert(make_pair(vattribute->name(),vattribute));
//DEFAULT_DS
vvalue.clear();
vvalue.insert(make_pair("BASE_PATH","/var/lib/one/images"));
vvalue.insert(make_pair("TYPE","fs"));
vattribute = new VectorAttribute("DEFAULT_DS",vvalue);
conf_default.insert(make_pair(vattribute->name(),vattribute));
//DEFAULT_IMAGE_TYPE
value = "OS";
+13 -1
View File
@@ -189,7 +189,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
ImageTemplate * tmpl = new ImageTemplate;
Datastore * ds;
// ------------------------- Prase image template --------------------------
// ------------------------- Parse image template --------------------------
rc = tmpl->parse_str_or_xml(str_tmpl, error_str);
@@ -203,6 +203,18 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
// ------------------------- Check Datastore exists ------------------------
if ( ds_id == DatastorePool::SYSTEM_DS_ID )
{
ostringstream oss;
oss << "New Images cannot be allocated in the system "
<< object_name(PoolObjectSQL::DATASTORE) << " [" << ds_id << "].";
failure_response(INTERNAL, allocate_error(oss.str()), att);
delete tmpl;
return;
}
if ((ds = dspool->get(ds_id,true)) == 0 )
{
failure_response(NO_EXISTS,