Browse code

Fixing network inspect for swarm

Signed-off-by: Abhinandan Prativadi <abhi@docker.com>

Abhinandan Prativadi authored on 2018/05/12 06:37:01
Showing 2 changed files
... ...
@@ -140,13 +140,13 @@ func swarmPortConfigToAPIPortConfig(portConfig *swarmapi.PortConfig) types.PortC
140 140
 func BasicNetworkFromGRPC(n swarmapi.Network) basictypes.NetworkResource {
141 141
 	spec := n.Spec
142 142
 	var ipam networktypes.IPAM
143
-	if spec.IPAM != nil {
144
-		if spec.IPAM.Driver != nil {
145
-			ipam.Driver = spec.IPAM.Driver.Name
146
-			ipam.Options = spec.IPAM.Driver.Options
143
+	if n.IPAM != nil {
144
+		if n.IPAM.Driver != nil {
145
+			ipam.Driver = n.IPAM.Driver.Name
146
+			ipam.Options = n.IPAM.Driver.Options
147 147
 		}
148
-		ipam.Config = make([]networktypes.IPAMConfig, 0, len(spec.IPAM.Configs))
149
-		for _, ic := range spec.IPAM.Configs {
148
+		ipam.Config = make([]networktypes.IPAMConfig, 0, len(n.IPAM.Configs))
149
+		for _, ic := range n.IPAM.Configs {
150 150
 			ipamConfig := networktypes.IPAMConfig{
151 151
 				Subnet:     ic.Subnet,
152 152
 				IPRange:    ic.Range,
... ...
@@ -162,9 +162,19 @@ func noTasks(client client.ServiceAPIClient) func(log poll.LogT) poll.Result {
162 162
 // Check to see if Service and Tasks info are part of the inspect verbose response
163 163
 func validNetworkVerbose(network types.NetworkResource, service string, instances uint64) bool {
164 164
 	if service, ok := network.Services[service]; ok {
165
-		if len(service.Tasks) == int(instances) {
166
-			return true
165
+		if len(service.Tasks) != int(instances) {
166
+			return false
167 167
 		}
168 168
 	}
169
-	return false
169
+
170
+	if network.IPAM.Config == nil {
171
+		return false
172
+	}
173
+
174
+	for _, cfg := range network.IPAM.Config {
175
+		if cfg.Gateway == "" || cfg.Subnet == "" {
176
+			return false
177
+		}
178
+	}
179
+	return true
170 180
 }