You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/04/13 18:38:10 UTC
mesos git commit: Introduced '--networks' flag to mesos-execute.
Repository: mesos
Updated Branches:
refs/heads/master d88c9f977 -> 3e4770c04
Introduced '--networks' flag to mesos-execute.
Review: https://reviews.apache.org/r/45731/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3e4770c0
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3e4770c0
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3e4770c0
Branch: refs/heads/master
Commit: 3e4770c044e26bb5aeb21ed54efe643a7dee28f2
Parents: d88c9f9
Author: Qian Zhang <zh...@cn.ibm.com>
Authored: Wed Apr 13 09:36:10 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Apr 13 09:37:49 2016 -0700
----------------------------------------------------------------------
src/cli/execute.cpp | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3e4770c0/src/cli/execute.cpp
----------------------------------------------------------------------
diff --git a/src/cli/execute.cpp b/src/cli/execute.cpp
index 7a29a38..7cbe6a4 100644
--- a/src/cli/execute.cpp
+++ b/src/cli/execute.cpp
@@ -168,6 +168,11 @@ public:
"kill_after",
"Specifies a delay after which the task is killed\n"
"(e.g., 10secs, 2mins, etc).");
+
+ add(&networks,
+ "networks",
+ "Comma-separated list of networks that the container will join,\n"
+ "e.g., `net1,net2`.");
}
Option<string> master;
@@ -186,6 +191,7 @@ public:
string containerizer;
string role;
Option<Duration> kill_after;
+ Option<string> networks;
};
@@ -204,7 +210,8 @@ public:
const Option<string>& _appcImage,
const Option<string>& _dockerImage,
const string& _containerizer,
- const Option<Duration>& _killAfter)
+ const Option<Duration>& _killAfter,
+ const Option<string>& _networks)
: state(DISCONNECTED),
frameworkInfo(_frameworkInfo),
master(_master),
@@ -218,6 +225,7 @@ public:
dockerImage(_dockerImage),
containerizer(_containerizer),
killAfter(_killAfter),
+ networks(_networks),
launched(false) {}
virtual ~CommandScheduler() {}
@@ -296,8 +304,6 @@ protected:
EXIT(EXIT_FAILURE)
<< "Failed to parse resources '" << resources << "': "
<< TASK_RESOURCES.error();
-
- return;
}
foreach (const Offer& offer, offers) {
@@ -543,6 +549,13 @@ private:
image->mutable_appc()->CopyFrom(appc);
}
+ if (networks.isSome() && !networks->empty()) {
+ foreach (const string& network,
+ strings::tokenize(networks.get(), ",")) {
+ containerInfo.add_network_infos()->set_name(network);
+ }
+ }
+
return containerInfo;
} else if (containerizer == "docker") {
// 'docker' containerizer only supports 'docker' images.
@@ -553,6 +566,18 @@ private:
containerInfo.set_type(ContainerInfo::DOCKER);
containerInfo.mutable_docker()->set_image(dockerImage.get());
+ if (networks.isSome() && !networks->empty()) {
+ vector<string> tokens = strings::tokenize(networks.get(), ",");
+ if (tokens.size() > 1) {
+ EXIT(EXIT_FAILURE)
+ << "'Docker' containerizer can only support a single network";
+ } else {
+ containerInfo.mutable_docker()->set_network(
+ ContainerInfo::DockerInfo::USER);
+ containerInfo.add_network_infos()->set_name(tokens.front());
+ }
+ }
+
return containerInfo;
}
@@ -571,7 +596,7 @@ private:
const Option<string> dockerImage;
const string containerizer;
const Option<Duration> killAfter;
-
+ const Option<string> networks;
bool launched;
Owned<Mesos> mesos;
};
@@ -728,7 +753,8 @@ int main(int argc, char** argv)
appcImage,
dockerImage,
flags.containerizer,
- flags.kill_after));
+ flags.kill_after,
+ flags.networks));
process::spawn(scheduler.get());
process::wait(scheduler.get());