mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bmah...@apache.org
Subject [04/24] mesos git commit: Fixed parsing network ip address with docker.
Date Mon, 25 Apr 2016 21:15:20 GMT
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/95dae310
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/95dae310
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/95dae310

Branch: refs/heads/0.28.x
Commit: 95dae310486eaa10a125b32b0cf9e55e2b626001
Parents: b709724
Author: Timothy Chen <tnachen@apache.org>
Authored: Mon Mar 7 23:40:55 2016 -0800
Committer: Vinod Kone <vinodkone@gmail.com>
Committed: Fri Mar 11 13:45:35 2016 -0500

----------------------------------------------------------------------
 src/docker/docker.cpp | 55 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 44 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/95dae310/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);


Mime
View raw message