Browse code

Show peer nodes in network inspect for swarm overlay networks

Signed-off-by: Santhosh Manohar <santhosh@docker.com>

Santhosh Manohar authored on 2016/11/05 04:27:36
Showing 5 changed files
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"github.com/docker/docker/api/types/filters"
12 12
 	"github.com/docker/docker/api/types/network"
13 13
 	"github.com/docker/libnetwork"
14
+	"github.com/docker/libnetwork/networkdb"
14 15
 )
15 16
 
16 17
 func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
... ...
@@ -177,6 +178,11 @@ func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.Netwo
177 177
 	r.Internal = info.Internal()
178 178
 	r.Labels = info.Labels()
179 179
 
180
+	peers := info.Peers()
181
+	if len(peers) != 0 {
182
+		r.Peers = buildPeerInfoResources(peers)
183
+	}
184
+
180 185
 	epl := nw.Endpoints()
181 186
 	for _, e := range epl {
182 187
 		ei := e.Info()
... ...
@@ -195,6 +201,17 @@ func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.Netwo
195 195
 	return r
196 196
 }
197 197
 
198
+func buildPeerInfoResources(peers []networkdb.PeerInfo) []network.PeerInfo {
199
+	peerInfo := make([]network.PeerInfo, 0, len(peers))
200
+	for _, peer := range peers {
201
+		peerInfo = append(peerInfo, network.PeerInfo{
202
+			Name: peer.Name,
203
+			IP:   peer.IP,
204
+		})
205
+	}
206
+	return peerInfo
207
+}
208
+
198 209
 func buildIpamResources(r *types.NetworkResource, nwInfo libnetwork.NetworkInfo) {
199 210
 	id, opts, ipv4conf, ipv6conf := nwInfo.IpamConfig()
200 211
 
... ...
@@ -28,6 +28,12 @@ type EndpointIPAMConfig struct {
28 28
 	LinkLocalIPs []string `json:",omitempty"`
29 29
 }
30 30
 
31
+// PeerInfo represents one peer of a overlay network
32
+type PeerInfo struct {
33
+	Name string
34
+	IP   string
35
+}
36
+
31 37
 // EndpointSettings stores the network endpoint details
32 38
 type EndpointSettings struct {
33 39
 	// Configurations
... ...
@@ -395,6 +395,7 @@ type NetworkResource struct {
395 395
 	Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
396 396
 	Options    map[string]string           // Options holds the network specific options to use for when creating the network
397 397
 	Labels     map[string]string           // Labels holds metadata specific to the network being created
398
+	Peers      []network.PeerInfo          `json:",omitempty"` // List of peer nodes for an overlay network
398 399
 }
399 400
 
400 401
 // EndpointResource contains network resources allocated and used for a container in a network
... ...
@@ -171,6 +171,7 @@ This section lists each version from latest to oldest.  Each listing includes a
171 171
 * The `HostConfig` field now includes `CpuCount` that represents the number of CPUs available for execution by the container. Windows daemon only.
172 172
 * `POST /services/create` and `POST /services/(id or name)/update` now accept the `TTY` parameter, which allocate a pseudo-TTY in container.
173 173
 * `POST /services/create` and `POST /services/(id or name)/update` now accept the `DNSConfig` parameter, which specifies DNS related configurations in resolver configuration file (resolv.conf) through `Nameservers`, `Search`, and `Options`.
174
+* `GET /networks/(id or name)` now includes IP and name of all peers nodes for swarm mode overlay networks.
174 175
 
175 176
 ### v1.24 API changes
176 177
 
... ...
@@ -124,6 +124,63 @@ $ docker network inspect simple-network
124 124
 ]
125 125
 ```
126 126
 
127
+For swarm mode overlay networks `network inspect` also shows the IP address and node name 
128
+of the peers. Peers are the nodes in the swarm cluster which have at least one task attached 
129
+to the network. Node name is of the format `<hostname>-<unique ID>`.
130
+
131
+```bash
132
+$ docker network inspect ingress
133
+[
134
+    {
135
+        "Name": "ingress",
136
+        "Id": "j0izitrut30h975vk4m1u5kk3",
137
+        "Created": "2016-11-08T06:49:59.803387552Z",
138
+        "Scope": "swarm",
139
+        "Driver": "overlay",
140
+        "EnableIPv6": false,
141
+        "IPAM": {
142
+            "Driver": "default",
143
+            "Options": null,
144
+            "Config": [
145
+                {
146
+                    "Subnet": "10.255.0.0/16",
147
+                    "Gateway": "10.255.0.1"
148
+                }
149
+            ]
150
+        },
151
+        "Internal": false,
152
+        "Attachable": false,
153
+        "Containers": {
154
+            "ingress-sbox": {
155
+                "Name": "ingress-endpoint",
156
+                "EndpointID": "40e002d27b7e5d75f60bc72199d8cae3344e1896abec5eddae9743755fe09115",
157
+                "MacAddress": "02:42:0a:ff:00:03",
158
+                "IPv4Address": "10.255.0.3/16",
159
+                "IPv6Address": ""
160
+            }
161
+        },
162
+        "Options": {
163
+            "com.docker.network.driver.overlay.vxlanid_list": "256"
164
+        },
165
+        "Labels": {},
166
+        "Peers": [
167
+            {
168
+                "Name": "net-1-1d22adfe4d5c",
169
+                "IP": "192.168.33.11"
170
+            },
171
+            {
172
+                "Name": "net-2-d55d838b34af",
173
+                "IP": "192.168.33.12"
174
+            },
175
+            {
176
+                "Name": "net-3-8473f8140bd9",
177
+                "IP": "192.168.33.13"
178
+            }
179
+        ]
180
+    }
181
+]
182
+```
183
+
127 184
 ## Related information
128 185
 
129 186
 * [network disconnect ](network_disconnect.md)