VsmStatus Client::vsm_create_zone(const char* id, const char* tname) noexcept
{
assert(id);
- if (tname) {
- mStatus = Status(VSMCLIENT_OTHER_ERROR, "Named template isn't implemented");
- return vsm_get_status();
- }
+ const char* template_name = tname ? tname : "default";
- GVariant* args_in = g_variant_new("(s)", id);
+ GVariant* args_in = g_variant_new("(ss)", id, template_name);
return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_ZONE, args_in);
}
*
* @param[in] client vasum-server's client
* @param[in] id zone id
- * @param[in] tname template name, NULL for default
+ * @param[in] tname template name, NULL is equivalent to "default"
* @return status of this function call
*/
VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname);
"zoneConfigs" : [],
"zonesPath" : "${DATA_DIR}/.zones",
"zoneImagePath" : "",
- "zoneTemplatePath" : "/etc/vasum/templates/template.conf",
+ "zoneTemplateDir" : "/etc/vasum/templates/",
"zoneNewConfigPrefix" : "/var/lib/vasum",
"runMountPointPrefix" : "/var/run/zones",
"defaultId" : "",
if (methodName == api::host::METHOD_CREATE_ZONE) {
const gchar* id = NULL;
- g_variant_get(parameters, "(&s)", &id);
+ const gchar* templateName = NULL;
+ g_variant_get(parameters, "(&s&s)", &id, &templateName);
if (mCreateZoneCallback){
- mCreateZoneCallback(id, result);
+ mCreateZoneCallback(id, templateName, result);
}
return;
}
dbus::MethodResultBuilder::Pointer result
)> SetActiveZoneCallback;
typedef std::function<void(const std::string& id,
+ const std::string& templateName,
dbus::MethodResultBuilder::Pointer result
)> CreateZoneCallback;
typedef std::function<void(const std::string& id,
" </method>"
" <method name='" + METHOD_CREATE_ZONE + "'>"
" <arg type='s' name='id' direction='in'/>"
+ " <arg type='s' name='templateName' direction='in'/>"
" </method>"
" <method name='" + METHOD_DESTROY_ZONE + "'>"
" <arg type='s' name='id' direction='in'/>"
)
};
+struct ZoneDynamicConfig {
+ //TODO a place for zone dynamic config (other than provisioning which has its own struct)
+ CONFIG_REGISTER_EMPTY
+};
} // namespace vasum
mRootPath = (zonePath / fs::path("rootfs")).string();
const std::string dbPrefix = DB_PREFIX + mAdmin->getId();
+ config::loadFromKVStoreWithJsonFile(dbPath, zoneConfigPath, mDynamicConfig, dbPrefix);
mProvision.reset(new ZoneProvision(mRootPath, zoneConfigPath, dbPath, dbPrefix, mConfig.validLinkPrefixes));
}
private:
utils::Worker::Pointer mWorker;
ZoneConfig mConfig;
+ ZoneDynamicConfig mDynamicConfig;
std::vector<boost::regex> mPermittedToSend;
std::vector<boost::regex> mPermittedToRecv;
std::unique_ptr<ZoneConnectionTransport> mConnectionTransport;
std::string zoneImagePath;
/**
- * A path where template configuration files for new zones reside
+ * A dir where template configuration files for new zones reside
*/
- std::string zoneTemplatePath;
+ std::string zoneTemplateDir;
/**
* Prefix added to a path for new zone configuration files
dbPath,
zonesPath,
zoneImagePath,
- zoneTemplatePath,
+ zoneTemplateDir,
zoneNewConfigPrefix,
lxcTemplatePrefix,
availableVTs,
this, _1, _2));
mHostConnection.setCreateZoneCallback(bind(&ZonesManager::handleCreateZoneCall,
- this, _1, _2));
+ this, _1, _2, _3));
mHostConnection.setDestroyZoneCallback(bind(&ZonesManager::handleDestroyZoneCall,
this, _1, _2));
}
void ZonesManager::handleCreateZoneCall(const std::string& id,
+ const std::string& templateName,
dbus::MethodResultBuilder::Pointer result)
{
if (id.empty()) {
return true;
};
+ std::string zoneTemplatePath = utils::createFilePath(mConfig.zoneTemplateDir,
+ templateName + ".conf");
+
try {
- LOGI("Generating config from " << mConfig.zoneTemplatePath << " to " << newConfigPath);
- generateNewConfig(id, mConfig.zoneTemplatePath, newConfigPath);
+ LOGI("Generating config from " << zoneTemplatePath << " to " << newConfigPath);
+ generateNewConfig(id, zoneTemplatePath, newConfigPath);
} catch (VasumException& e) {
LOGE("Generate config failed: " << e.what());
void handleSetActiveZoneCall(const std::string& id,
dbus::MethodResultBuilder::Pointer result);
void handleCreateZoneCall(const std::string& id,
+ const std::string& templateName,
dbus::MethodResultBuilder::Pointer result);
void handleDestroyZoneCall(const std::string& id,
dbus::MethodResultBuilder::Pointer result);
"defaultId" : "ut-zones-manager-console1-dbus",
"zonesPath" : "/tmp/ut-zones",
"zoneImagePath" : "",
- "zoneTemplatePath" : "no_need_for_templates_in_this_test",
+ "zoneTemplateDir" : "no_need_for_templates_in_this_test",
"zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/client/ut-client/",
"runMountPointPrefix" : "",
"lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@",
${CMAKE_BINARY_DIR}/ut-zones-manager/zones/console3-dbus.conf @ONLY)
FILE(GLOB manager_zone_CONF_GEN ${CMAKE_BINARY_DIR}/ut-zones-manager/zones/*.conf)
-CONFIGURE_FILE(ut-zones-manager/templates/template.conf.in
- ${CMAKE_BINARY_DIR}/ut-zones-manager/templates/template.conf @ONLY)
+CONFIGURE_FILE(ut-zones-manager/templates/default.conf.in
+ ${CMAKE_BINARY_DIR}/ut-zones-manager/templates/default.conf @ONLY)
FILE(GLOB manager_zone_TEMPLATE_GEN ${CMAKE_BINARY_DIR}/ut-zones-manager/templates/*.conf)
"zoneConfigs" : ["zones/zone1.conf", "missing/file/path/missing.conf", "zones/zone3.conf"],
"zonesPath" : "/tmp/ut-zones",
"zoneImagePath" : "",
- "zoneTemplatePath" : "no_need_for_templates_in_this_test",
+ "zoneTemplateDir" : "no_need_for_templates_in_this_test",
"zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-server/",
"runMountPointPrefix" : "",
"defaultId" : "ut-server-zone1",
"zoneConfigs" : ["zones/zone1.conf", "zones/zone2.conf", "zones/zone3.conf"],
"zonesPath" : "/tmp/ut-zones",
"zoneImagePath" : "",
- "zoneTemplatePath" : "no_need_for_templates_in_this_test",
+ "zoneTemplateDir" : "no_need_for_templates_in_this_test",
"zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-server/",
"runMountPointPrefix" : "",
"defaultId" : "ut-server-zone1",
"defaultId" : "ut-zones-manager-console1",
"zonesPath" : "/tmp/ut-zones",
"zoneImagePath" : "",
- "zoneTemplatePath" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/template.conf",
+ "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/",
"zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/",
"lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@",
"availableVTs" : [],
"defaultId" : "",
"zonesPath" : "/tmp/ut-zones",
"zoneImagePath" : "",
- "zoneTemplatePath" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/template.conf",
+ "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/",
"zoneNewConfigPrefix" : "/tmp/ut-zones/generated-configs/",
"runMountPointPrefix" : "",
"lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@",
"defaultId" : "ut-zones-manager-console1",
"zonesPath" : "/tmp/ut-zones",
"zoneImagePath" : "",
- "zoneTemplatePath" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/template.conf",
+ "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/",
"zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/",
"lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@",
"availableVTs" : [],
"defaultId" : "ut-zones-manager-console1-dbus",
"zonesPath" : "/tmp/ut-zones",
"zoneImagePath" : "",
- "zoneTemplatePath" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/template.conf",
+ "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/",
"zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/",
"runMountPointPrefix" : "",
"lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@",
"Line 2\n";
const std::string NON_EXISTANT_ZONE_ID = "NON_EXISTANT_ZONE_ID";
const std::string ZONES_PATH = "/tmp/ut-zones"; // the same as in daemon.conf
+const std::string TEMPLATE_NAME = "default";
/**
* Currently there is no way to propagate an error from async call
}
void callAsyncMethodCreateZone(const std::string& id,
+ const std::string& templateName,
const VoidResultCallback& result)
{
auto asyncResult = [result](dbus::AsyncMethodCallResult& asyncMethodCallResult) {
};
assert(isHost());
- GVariant* parameters = g_variant_new("(s)", id.c_str());
+ GVariant* parameters = g_variant_new("(ss)", id.c_str(), templateName.c_str());
mClient->callMethodAsync(api::host::BUS_NAME,
api::host::OBJECT_PATH,
api::host::INTERFACE,
DbusAccessory dbus(DbusAccessory::HOST_ID);
// create zone1
- dbus.callAsyncMethodCreateZone(zone1, resultCallback);
+ dbus.callAsyncMethodCreateZone(zone1, TEMPLATE_NAME, resultCallback);
BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT));
// create zone2
- dbus.callAsyncMethodCreateZone(zone2, resultCallback);
+ dbus.callAsyncMethodCreateZone(zone2, TEMPLATE_NAME, resultCallback);
BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT));
// create zone3
- dbus.callAsyncMethodCreateZone(zone3, resultCallback);
+ dbus.callAsyncMethodCreateZone(zone3, TEMPLATE_NAME, resultCallback);
BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT));
cm.startAll();
{
ZonesManager cm(EMPTY_DBUS_CONFIG_PATH);
DbusAccessory dbus(DbusAccessory::HOST_ID);
- dbus.callAsyncMethodCreateZone(zone, resultCallback);
+ dbus.callAsyncMethodCreateZone(zone, TEMPLATE_NAME, resultCallback);
BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT));
}