mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
Feature #1112: Restrict image creation on system DS. Create new default DS
This commit is contained in:
parent
8f34895576
commit
546b6c8a4e
@ -27,8 +27,10 @@ class DatastorePool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
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);
|
||||
|
||||
~DatastorePool(){};
|
||||
|
||||
@ -37,15 +39,25 @@ public:
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Default name for the oneadmin group
|
||||
* Name for the system datastore
|
||||
*/
|
||||
static const string SYSTEM_DS_NAME;
|
||||
|
||||
/**
|
||||
* Identifier for the oneadmin group
|
||||
* Identifier for the system datastore
|
||||
*/
|
||||
static const int SYSTEM_DS_ID;
|
||||
|
||||
/**
|
||||
* Name for the default datastore
|
||||
*/
|
||||
static const string DEFAULT_DS_NAME;
|
||||
|
||||
/**
|
||||
* Identifier for the default datastore
|
||||
*/
|
||||
static const int DEFAULT_DS_ID;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Methods for DB management */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@ -100,6 +100,7 @@ if [ -z "$ROOT" ] ; then
|
||||
SUNSTONE_LOCATION="$LIB_LOCATION/sunstone"
|
||||
OZONES_LOCATION="$LIB_LOCATION/ozones"
|
||||
SYSTEM_DS_LOCATION="$VAR_LOCATION/system_ds"
|
||||
DEFAULT_DS_LOCATION="$VAR_LOCATION/images"
|
||||
RUN_LOCATION="/var/run/one"
|
||||
LOCK_LOCATION="/var/lock/one"
|
||||
INCLUDE_LOCATION="/usr/include"
|
||||
@ -130,7 +131,7 @@ if [ -z "$ROOT" ] ; then
|
||||
MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \
|
||||
$INCLUDE_LOCATION $SHARE_LOCATION \
|
||||
$LOG_LOCATION $RUN_LOCATION $LOCK_LOCATION \
|
||||
$SYSTEM_DS_LOCATION $MAN_LOCATION"
|
||||
$SYSTEM_DS_LOCATION $DEFAULT_DS_LOCATION $MAN_LOCATION"
|
||||
|
||||
DELETE_DIRS="$LIB_LOCATION $ETC_LOCATION $LOG_LOCATION $VAR_LOCATION \
|
||||
$RUN_LOCATION $SHARE_DIRS"
|
||||
@ -146,6 +147,7 @@ else
|
||||
SUNSTONE_LOCATION="$LIB_LOCATION/sunstone"
|
||||
OZONES_LOCATION="$LIB_LOCATION/ozones"
|
||||
SYSTEM_DS_LOCATION="$VAR_LOCATION/system_ds"
|
||||
DEFAULT_DS_LOCATION="$VAR_LOCATION/images"
|
||||
INCLUDE_LOCATION="$ROOT/include"
|
||||
SHARE_LOCATION="$ROOT/share"
|
||||
MAN_LOCATION="$ROOT/share/man/man1"
|
||||
@ -167,7 +169,7 @@ else
|
||||
else
|
||||
MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \
|
||||
$INCLUDE_LOCATION $SHARE_LOCATION $SYSTEM_DS_LOCATION \
|
||||
$MAN_LOCATION $OZONES_LOCATION"
|
||||
$DEFAULT_DS_LOCATION $MAN_LOCATION $OZONES_LOCATION"
|
||||
|
||||
DELETE_DIRS="$MAKE_DIRS"
|
||||
|
||||
|
@ -110,6 +110,11 @@ SYSTEM_DS = [
|
||||
type = "fs"
|
||||
]
|
||||
|
||||
DEFAULT_DS = [
|
||||
base_path = "/var/lib/one/images",
|
||||
type = "fs"
|
||||
]
|
||||
|
||||
DEFAULT_IMAGE_TYPE = "OS"
|
||||
DEFAULT_DEVICE_PREFIX = "hd"
|
||||
|
||||
|
@ -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 )
|
||||
|
@ -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&)
|
||||
{
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user