#include <cassert>
#include <climits>
+#include <thread>
+#include <chrono>
namespace vasum {
-namespace {
-
-// TODO: this should be in zone's configuration file
-const int SHUTDOWN_WAIT = 10;
-
-} // namespace
-
const std::uint64_t DEFAULT_CPU_SHARES = 1024;
const std::uint64_t DEFAULT_VCPU_PERIOD_MS = 100000;
ZoneAdmin::ZoneAdmin(const std::string& zoneId,
const std::string& zonesPath,
- const std::string& lxcTemplatePrefix,
+ const std::string& zoneTemplatePrefix,
const ZoneConfig& config,
const ZoneDynamicConfig& dynamicConfig)
: mConfig(config),
+ mDynamicConfig(dynamicConfig),
mZone(zonesPath, zoneId),
mId(zoneId),
mDetachOnExit(false),
if (!mZone.isDefined()) {
- const std::string lxcTemplate = utils::getAbsolutePath(config.lxcTemplate,
- lxcTemplatePrefix);
- LOGI(mId << ": Creating zone from template: " << lxcTemplate);
+ const std::string zoneTemplate = utils::getAbsolutePath(config.zoneTemplate,
+ zoneTemplatePrefix);
+ LOGI(mId << ": Creating zone from template: " << zoneTemplate);
utils::CStringArrayBuilder args;
if (!dynamicConfig.ipv4Gateway.empty()) {
args.add("--ipv4-gateway");
args.add("--vt");
args.add(vt.c_str());
}
- if (!mZone.create(lxcTemplate, args.c_array())) {
+ if (!mZone.create(zoneTemplate, args.c_array())) {
throw ZoneOperationException("Could not create zone");
}
}
throw ZoneOperationException("Could not start zone");
}
+ // Wait until the full platform launch with graphical stack.
+ // VT should be activated by a graphical stack.
+ // If we do it with 'zoneToFocus.activateVT' before starting the graphical stack,
+ // graphical stack initialization failed and we finally switch to the black screen.
+ // Skip waiting when graphical stack is not running (unit tests).
+ if (mDynamicConfig.vt > 0) {
+ // TODO, timeout is a temporary solution
+ std::this_thread::sleep_for(std::chrono::milliseconds(4000));
+ }
+
LOGD(mId << ": Started");
}
return;
}
- if (!mZone.shutdown(SHUTDOWN_WAIT)) {
+ if (!mZone.shutdown(mConfig.shutdownTimeout)) {
// force stop
if (!mZone.stop()) {
throw ZoneOperationException("Could not stop zone");
netdev::movePhys(mZone.getInitPid(), devId);
}
+void ZoneAdmin::destroyNetdev(const std::string& devId)
+{
+ netdev::destroyNetdev(devId, mZone.getInitPid());
+}
+
+void ZoneAdmin::setNetdevAttrs(const std::string& netdev, const NetdevAttrs& attrs)
+{
+ netdev::setAttrs(mZone.getInitPid(), netdev, attrs);
+}
+
+ZoneAdmin::NetdevAttrs ZoneAdmin::getNetdevAttrs(const std::string& netdev)
+{
+ return netdev::getAttrs(mZone.getInitPid(), netdev);
+}
+
+std::vector<std::string> ZoneAdmin::getNetdevList()
+{
+ return netdev::listNetdev(mZone.getInitPid());
+}
+
+void ZoneAdmin::deleteNetdevIpAddress(const std::string& netdev, const std::string& ip)
+{
+ netdev::deleteIpAddress(mZone.getInitPid(), netdev, ip);
+}
+
} // namespace vasum