Add --ip_discovery_command to Agent. Similarly to the Master, we want to enable the Agent too to be initialized with an IP address that is "discovered" by an arbitrary script.
This is particularly useful for Mesos deployments on public (or private) clouds where DNS resolution is either limited or not feasible. Jira: MESOS-3154 Review: https://reviews.apache.org/r/37457 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/1ea9497f Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/1ea9497f Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/1ea9497f Branch: refs/heads/master Commit: 1ea9497faa0866f08e1b56529bdb559da64625f4 Parents: 6affd37 Author: Marco Massenzio <[email protected]> Authored: Fri Aug 14 10:12:25 2015 -0700 Committer: Benjamin Hindman <[email protected]> Committed: Fri Aug 14 10:13:13 2015 -0700 ---------------------------------------------------------------------- src/slave/main.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/1ea9497f/src/slave/main.cpp ---------------------------------------------------------------------- diff --git a/src/slave/main.cpp b/src/slave/main.cpp index 8008430..364dc7f 100644 --- a/src/slave/main.cpp +++ b/src/slave/main.cpp @@ -107,6 +107,16 @@ int main(int argc, char** argv) " zk://username:password@host1:port1,host2:port2,.../path\n" " file:///path/to/file (where file contains one of the above)"); + + // Optional IP discover script that will set the slave's IP. + // If set, its output is expected to be a valid parseable IP string. + Option<string> ip_discovery_command; + flags.add(&ip_discovery_command, + "ip_discovery_command", + "Optional IP discovery binary: if set, it is expected to emit\n" + "the IP address which slave will try to bind to.\n" + "Cannot be used in conjunction with --ip."); + Try<Nothing> load = flags.load("MESOS_", argc, argv); // TODO(marco): this pattern too should be abstracted away @@ -149,7 +159,20 @@ int main(int argc, char** argv) } // Initialize libprocess. - if (ip.isSome()) { + if (ip_discovery_command.isSome() && ip.isSome()) { + EXIT(EXIT_FAILURE) << flags.usage( + "Only one of --ip or --ip_discovery_command should be specified"); + } + + if (ip_discovery_command.isSome()) { + Try<string> ipAddress = os::shell(ip_discovery_command.get()); + + if (ipAddress.isError()) { + EXIT(EXIT_FAILURE) << ipAddress.error(); + } + + os::setenv("LIBPROCESS_IP", strings::trim(ipAddress.get())); + } else if (ip.isSome()) { os::setenv("LIBPROCESS_IP", ip.get()); }
