You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by tn...@apache.org on 2016/03/11 01:23:55 UTC
mesos git commit: Fixed parsing network ip address with docker.
Repository: mesos
Updated Branches:
refs/heads/master 5e50ad37a -> c65d06791
Fixed parsing network ip address with docker.
Review: https://reviews.apache.org/r/44531
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c65d0679
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c65d0679
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c65d0679
Branch: refs/heads/master
Commit: c65d06791f0f3651f5cd1f1ad9f4955f03677795
Parents: 5e50ad3
Author: Timothy Chen <tn...@apache.org>
Authored: Mon Mar 7 23:40:55 2016 -0800
Committer: Timothy Chen <tn...@apache.org>
Committed: Thu Mar 10 16:23:49 2016 -0800
----------------------------------------------------------------------
src/docker/docker.cpp | 55 ++++++++++++++++++++++++++++++++++++----------
1 file changed, 44 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/c65d0679/src/docker/docker.cpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp
index 5272870..4d35513 100755
--- a/src/docker/docker.cpp
+++ b/src/docker/docker.cpp
@@ -301,19 +301,52 @@ Try<Docker::Container> Docker::Container::create(const string& output)
bool started = startedAtValue.get().value != "0001-01-01T00:00:00Z";
- Result<JSON::String> ipAddressValue =
- json.find<JSON::String>("NetworkSettings.IPAddress");
- if (ipAddressValue.isNone()) {
- return Error("Unable to find NetworkSettings.IPAddress in container");
- } else if (ipAddressValue.isError()) {
- return Error(
- "Error finding NetworkSettings.Name in container: " +
- ipAddressValue.error());
+ Option<string> ipAddress;
+ bool findDeprecatedIP = false;
+ Result<JSON::String> networkMode =
+ json.find<JSON::String>("HostConfig.NetworkMode");
+ if (!networkMode.isSome()) {
+ // We need to fail back to the old field as Docker added NetworkMode
+ // since Docker remote API 1.15.
+ VLOG(1) << "Unable to detect HostConfig.NetworkMode, "
+ << "attempting deprecated IP field";
+ findDeprecatedIP = true;
+ } else {
+ // We currently rely on the fact that we always set --net when
+ // we shell out to docker run, and therefore the network mode
+ // matches what --net is. Without --net, the network mode would be set
+ // to 'default' and we won't be able to find the IP address as
+ // it will be in 'Networks.bridge' key.
+ string addressLocation = "NetworkSettings.Networks." +
+ networkMode->value + ".IPAddress";
+
+ Result<JSON::String> ipAddressValue =
+ json.find<JSON::String>(addressLocation);
+
+ if (!ipAddressValue.isSome()) {
+ // We also need to failback to the old field as the IP Address
+ // field location also changed since Docker remote API 1.20.
+ VLOG(1) << "Unable to detect IP Address at '" << addressLocation << "',"
+ << " attempting deprecated field";
+ findDeprecatedIP = true;
+ } else if (!ipAddressValue->value.empty()) {
+ ipAddress = ipAddressValue->value;
+ }
}
- Option<string> ipAddress;
- if (!ipAddressValue->value.empty()) {
- ipAddress = ipAddressValue->value;
+ if (findDeprecatedIP) {
+ Result<JSON::String> ipAddressValue =
+ json.find<JSON::String>("NetworkSettings.IPAddress");
+
+ if (ipAddressValue.isNone()) {
+ return Error("Unable to find NetworkSettings.IPAddress in container");
+ } else if (ipAddressValue.isError()) {
+ return Error(
+ "Error finding NetworkSettings.IPAddress in container: " +
+ ipAddressValue.error());
+ } else if (!ipAddressValue->value.empty()) {
+ ipAddress = ipAddressValue->value;
+ }
}
return Docker::Container(output, id, name, optionalPid, started, ipAddress);