diff --git a/include/DatastorePool.h b/include/DatastorePool.h index 7dbf41913f..3d68f48f97 100644 --- a/include/DatastorePool.h +++ b/include/DatastorePool.h @@ -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 */ /* ---------------------------------------------------------------------- */ diff --git a/install.sh b/install.sh index 7053997a0e..30f20afa67 100755 --- a/install.sh +++ b/install.sh @@ -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" diff --git a/share/etc/oned.conf b/share/etc/oned.conf index c75a729a38..fb762b4b21 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -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" diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index 64f4470f64..d5e9644cdf 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -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 ) diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 2be815f846..f414535537 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -276,8 +276,12 @@ void Nebula::start() time_t expiration_time; vector system_ds; - string ds_base_path; - string ds_type; + string system_ds_base_path; + string system_ds_type; + + vector default_ds; + string default_ds_base_path; + string default_ds_type; vector vm_hooks; vector 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(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(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&) { diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index 22f9c729a5..96a0a89c53 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -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"; diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 79a02672d7..8ec46bc581 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -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,