Browse code

Display `internal` flag on `network inspect`

Also adds internal network tests for bridge network

Signed-off-by: Chun Chen <ramichen@tencent.com>

Chun Chen authored on 2016/01/15 16:31:12
Showing 6 changed files
... ...
@@ -164,6 +164,7 @@ func buildNetworkResource(nw libnetwork.Network) *types.NetworkResource {
164 164
 	r.Options = nw.Info().DriverOptions()
165 165
 	r.Containers = make(map[string]types.EndpointResource)
166 166
 	buildIpamResources(r, nw)
167
+	r.Internal = nw.Info().Internal()
167 168
 
168 169
 	epl := nw.Endpoints()
169 170
 	for _, e := range epl {
... ...
@@ -105,6 +105,7 @@ This section lists each version from latest to oldest.  Each listing includes a
105 105
 [Docker Remote API v1.23](docker_remote_api_v1.23.md) documentation
106 106
 
107 107
 * `GET /containers/json` returns the state of the container, one of `created`, `restarting`, `running`, `paused`, `exited` or `dead`.
108
+* `GET /networks/(name)` now returns an `Internal` field showing whether the network is internal or not.
108 109
 
109 110
 
110 111
 ### v1.22 API changes
... ...
@@ -2963,6 +2963,7 @@ Content-Type: application/json
2963 2963
         "foo": "bar"
2964 2964
     }
2965 2965
   },
2966
+  "Internal": false,
2966 2967
   "Containers": {
2967 2968
     "19a4d5d687db25203351ed79d478946f861258f018fe384f229f2efa4b23513c": {
2968 2969
       "Name": "test",
... ...
@@ -50,6 +50,7 @@ $ sudo docker network inspect bridge
50 50
                 }
51 51
             ]
52 52
         },
53
+        "Internal": false,
53 54
         "Containers": {
54 55
             "bda12f8922785d1f160be70736f26c1e331ab8aaf8ed8d56728508f2e2fd4727": {
55 56
                 "Name": "container2",
... ...
@@ -621,6 +621,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkInspectCustomSpecified(c *check.C)
621 621
 	c.Assert(nr.IPAM.Config[0].Subnet, checker.Equals, "172.28.0.0/16")
622 622
 	c.Assert(nr.IPAM.Config[0].IPRange, checker.Equals, "172.28.5.0/24")
623 623
 	c.Assert(nr.IPAM.Config[0].Gateway, checker.Equals, "172.28.5.254")
624
+	c.Assert(nr.Internal, checker.False)
624 625
 	dockerCmd(c, "network", "rm", "br0")
625 626
 	assertNwNotAvailable(c, "test01")
626 627
 }
... ...
@@ -1387,3 +1388,19 @@ func (s *DockerSuite) TestDockerNetworkConnectFailsNoInspectChange(c *check.C) {
1387 1387
 	ns1 := inspectField(c, "bb", "NetworkSettings.Networks.bridge")
1388 1388
 	c.Assert(ns1, check.Equals, ns0)
1389 1389
 }
1390
+
1391
+func (s *DockerNetworkSuite) TestDockerNetworkInternalMode(c *check.C) {
1392
+	dockerCmd(c, "network", "create", "--driver=bridge", "--internal", "internal")
1393
+	assertNwIsAvailable(c, "internal")
1394
+	nr := getNetworkResource(c, "internal")
1395
+	c.Assert(nr.Internal, checker.True)
1396
+
1397
+	dockerCmd(c, "run", "-d", "--net=internal", "--name=first", "busybox", "top")
1398
+	c.Assert(waitRun("first"), check.IsNil)
1399
+	dockerCmd(c, "run", "-d", "--net=internal", "--name=second", "busybox", "top")
1400
+	c.Assert(waitRun("second"), check.IsNil)
1401
+	_, _, err := dockerCmdWithError("exec", "first", "ping", "-c", "1", "www.google.com")
1402
+	c.Assert(err, check.NotNil)
1403
+	_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
1404
+	c.Assert(err, check.IsNil)
1405
+}
... ...
@@ -45,6 +45,7 @@ $ sudo docker network inspect bridge
45 45
                 }
46 46
             ]
47 47
         },
48
+        "Internal": false,
48 49
         "Containers": {
49 50
             "bda12f8922785d1f160be70736f26c1e331ab8aaf8ed8d56728508f2e2fd4727": {
50 51
                 "Name": "container2",