mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #17538 from calavera/deprecated_bridge_interface
Fix network inspect for default networks.
This commit is contained in:
commit
33f5429786
7 changed files with 123 additions and 49 deletions
|
@ -286,6 +286,7 @@ type ContainerJSON struct {
|
||||||
// NetworkSettings exposes the network settings in the api
|
// NetworkSettings exposes the network settings in the api
|
||||||
type NetworkSettings struct {
|
type NetworkSettings struct {
|
||||||
NetworkSettingsBase
|
NetworkSettingsBase
|
||||||
|
DefaultNetworkSettings
|
||||||
Networks map[string]*network.EndpointSettings
|
Networks map[string]*network.EndpointSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,6 +303,20 @@ type NetworkSettingsBase struct {
|
||||||
SecondaryIPv6Addresses []network.Address
|
SecondaryIPv6Addresses []network.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultNetworkSettings holds network information
|
||||||
|
// during the 2 release deprecation period.
|
||||||
|
// It will be removed in Docker 1.11.
|
||||||
|
type DefaultNetworkSettings struct {
|
||||||
|
EndpointID string
|
||||||
|
Gateway string
|
||||||
|
GlobalIPv6Address string
|
||||||
|
GlobalIPv6PrefixLen int
|
||||||
|
IPAddress string
|
||||||
|
IPPrefixLen int
|
||||||
|
IPv6Gateway string
|
||||||
|
MacAddress string
|
||||||
|
}
|
||||||
|
|
||||||
// MountPoint represents a mount point configuration inside the container.
|
// MountPoint represents a mount point configuration inside the container.
|
||||||
type MountPoint struct {
|
type MountPoint struct {
|
||||||
Name string `json:",omitempty"`
|
Name string `json:",omitempty"`
|
||||||
|
|
|
@ -36,12 +36,5 @@ type StatsJSON struct {
|
||||||
// NetworkSettings is a backward compatible struct for APIs prior to 1.21
|
// NetworkSettings is a backward compatible struct for APIs prior to 1.21
|
||||||
type NetworkSettings struct {
|
type NetworkSettings struct {
|
||||||
types.NetworkSettingsBase
|
types.NetworkSettingsBase
|
||||||
EndpointID string
|
types.DefaultNetworkSettings
|
||||||
Gateway string
|
|
||||||
GlobalIPv6Address string
|
|
||||||
GlobalIPv6PrefixLen int
|
|
||||||
IPAddress string
|
|
||||||
IPPrefixLen int
|
|
||||||
IPv6Gateway string
|
|
||||||
MacAddress string
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (daemon *Daemon) ContainerInspect(name string, size bool) (*types.Container
|
||||||
|
|
||||||
mountPoints := addMountPoints(container)
|
mountPoints := addMountPoints(container)
|
||||||
networkSettings := &types.NetworkSettings{
|
networkSettings := &types.NetworkSettings{
|
||||||
types.NetworkSettingsBase{
|
NetworkSettingsBase: types.NetworkSettingsBase{
|
||||||
Bridge: container.NetworkSettings.Bridge,
|
Bridge: container.NetworkSettings.Bridge,
|
||||||
SandboxID: container.NetworkSettings.SandboxID,
|
SandboxID: container.NetworkSettings.SandboxID,
|
||||||
HairpinMode: container.NetworkSettings.HairpinMode,
|
HairpinMode: container.NetworkSettings.HairpinMode,
|
||||||
|
@ -39,7 +39,8 @@ func (daemon *Daemon) ContainerInspect(name string, size bool) (*types.Container
|
||||||
SecondaryIPAddresses: container.NetworkSettings.SecondaryIPAddresses,
|
SecondaryIPAddresses: container.NetworkSettings.SecondaryIPAddresses,
|
||||||
SecondaryIPv6Addresses: container.NetworkSettings.SecondaryIPv6Addresses,
|
SecondaryIPv6Addresses: container.NetworkSettings.SecondaryIPv6Addresses,
|
||||||
},
|
},
|
||||||
container.NetworkSettings.Networks,
|
DefaultNetworkSettings: daemon.getDefaultNetworkSettings(container.NetworkSettings.Networks),
|
||||||
|
Networks: container.NetworkSettings.Networks,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.ContainerJSON{base, mountPoints, container.Config, networkSettings}, nil
|
return &types.ContainerJSON{base, mountPoints, container.Config, networkSettings}, nil
|
||||||
|
@ -68,7 +69,7 @@ func (daemon *Daemon) ContainerInspect120(name string) (*v1p20.ContainerJSON, er
|
||||||
container.Config.ExposedPorts,
|
container.Config.ExposedPorts,
|
||||||
container.hostConfig.VolumeDriver,
|
container.hostConfig.VolumeDriver,
|
||||||
}
|
}
|
||||||
networkSettings := getBackwardsCompatibleNetworkSettings(container.NetworkSettings)
|
networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings)
|
||||||
|
|
||||||
return &v1p20.ContainerJSON{base, mountPoints, config, networkSettings}, nil
|
return &v1p20.ContainerJSON{base, mountPoints, config, networkSettings}, nil
|
||||||
}
|
}
|
||||||
|
@ -167,7 +168,7 @@ func (daemon *Daemon) VolumeInspect(name string) (*types.Volume, error) {
|
||||||
return volumeToAPIType(v), nil
|
return volumeToAPIType(v), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBackwardsCompatibleNetworkSettings(settings *network.Settings) *v1p20.NetworkSettings {
|
func (daemon *Daemon) getBackwardsCompatibleNetworkSettings(settings *network.Settings) *v1p20.NetworkSettings {
|
||||||
result := &v1p20.NetworkSettings{
|
result := &v1p20.NetworkSettings{
|
||||||
NetworkSettingsBase: types.NetworkSettingsBase{
|
NetworkSettingsBase: types.NetworkSettingsBase{
|
||||||
Bridge: settings.Bridge,
|
Bridge: settings.Bridge,
|
||||||
|
@ -180,16 +181,26 @@ func getBackwardsCompatibleNetworkSettings(settings *network.Settings) *v1p20.Ne
|
||||||
SecondaryIPAddresses: settings.SecondaryIPAddresses,
|
SecondaryIPAddresses: settings.SecondaryIPAddresses,
|
||||||
SecondaryIPv6Addresses: settings.SecondaryIPv6Addresses,
|
SecondaryIPv6Addresses: settings.SecondaryIPv6Addresses,
|
||||||
},
|
},
|
||||||
|
DefaultNetworkSettings: daemon.getDefaultNetworkSettings(settings.Networks),
|
||||||
}
|
}
|
||||||
if bridgeSettings := settings.Networks["bridge"]; bridgeSettings != nil {
|
|
||||||
result.EndpointID = bridgeSettings.EndpointID
|
|
||||||
result.Gateway = bridgeSettings.Gateway
|
|
||||||
result.GlobalIPv6Address = bridgeSettings.GlobalIPv6Address
|
|
||||||
result.GlobalIPv6PrefixLen = bridgeSettings.GlobalIPv6PrefixLen
|
|
||||||
result.IPAddress = bridgeSettings.IPAddress
|
|
||||||
result.IPPrefixLen = bridgeSettings.IPPrefixLen
|
|
||||||
result.IPv6Gateway = bridgeSettings.IPv6Gateway
|
|
||||||
result.MacAddress = bridgeSettings.MacAddress
|
|
||||||
}
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getDefaultNetworkSettings creates the deprecated structure that holds the information
|
||||||
|
// about the bridge network for a container.
|
||||||
|
func (daemon *Daemon) getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings {
|
||||||
|
var settings types.DefaultNetworkSettings
|
||||||
|
|
||||||
|
if defaultNetwork, ok := networks["bridge"]; ok {
|
||||||
|
settings.EndpointID = defaultNetwork.EndpointID
|
||||||
|
settings.Gateway = defaultNetwork.Gateway
|
||||||
|
settings.GlobalIPv6Address = defaultNetwork.GlobalIPv6Address
|
||||||
|
settings.GlobalIPv6PrefixLen = defaultNetwork.GlobalIPv6PrefixLen
|
||||||
|
settings.IPAddress = defaultNetwork.IPAddress
|
||||||
|
settings.IPPrefixLen = defaultNetwork.IPPrefixLen
|
||||||
|
settings.IPv6Gateway = defaultNetwork.IPv6Gateway
|
||||||
|
settings.MacAddress = defaultNetwork.MacAddress
|
||||||
|
}
|
||||||
|
return settings
|
||||||
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (daemon *Daemon) ContainerInspectPre120(name string) (*v1p19.ContainerJSON,
|
||||||
container.hostConfig.CPUShares,
|
container.hostConfig.CPUShares,
|
||||||
container.hostConfig.CpusetCpus,
|
container.hostConfig.CpusetCpus,
|
||||||
}
|
}
|
||||||
networkSettings := getBackwardsCompatibleNetworkSettings(container.NetworkSettings)
|
networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings)
|
||||||
|
|
||||||
return &v1p19.ContainerJSON{base, volumes, volumesRW, config, networkSettings}, nil
|
return &v1p19.ContainerJSON{base, volumes, volumesRW, config, networkSettings}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/versions/v1p20"
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/docker/docker/pkg/stringutils"
|
"github.com/docker/docker/pkg/stringutils"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
@ -23,19 +24,15 @@ func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
|
||||||
version string
|
version string
|
||||||
keys []string
|
keys []string
|
||||||
}{
|
}{
|
||||||
{"1.20", append(keysBase, "Mounts")},
|
{"v1.20", append(keysBase, "Mounts")},
|
||||||
{"1.19", append(keysBase, "Volumes", "VolumesRW")},
|
{"v1.19", append(keysBase, "Volumes", "VolumesRW")},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cs := range cases {
|
for _, cs := range cases {
|
||||||
endpoint := fmt.Sprintf("/v%s/containers/%s/json", cs.version, cleanedContainerID)
|
body := getInspectBody(c, cs.version, cleanedContainerID)
|
||||||
|
|
||||||
status, body, err := sockRequest("GET", endpoint, nil)
|
|
||||||
c.Assert(err, check.IsNil)
|
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
|
||||||
|
|
||||||
var inspectJSON map[string]interface{}
|
var inspectJSON map[string]interface{}
|
||||||
if err = json.Unmarshal(body, &inspectJSON); err != nil {
|
if err := json.Unmarshal(body, &inspectJSON); err != nil {
|
||||||
c.Fatalf("unable to unmarshal body for version %s: %v", cs.version, err)
|
c.Fatalf("unable to unmarshal body for version %s: %v", cs.version, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,15 +54,12 @@ func (s *DockerSuite) TestInspectApiContainerVolumeDriverLegacy(c *check.C) {
|
||||||
|
|
||||||
cleanedContainerID := strings.TrimSpace(out)
|
cleanedContainerID := strings.TrimSpace(out)
|
||||||
|
|
||||||
cases := []string{"1.19", "1.20"}
|
cases := []string{"v1.19", "v1.20"}
|
||||||
for _, version := range cases {
|
for _, version := range cases {
|
||||||
endpoint := fmt.Sprintf("/v%s/containers/%s/json", version, cleanedContainerID)
|
body := getInspectBody(c, version, cleanedContainerID)
|
||||||
status, body, err := sockRequest("GET", endpoint, nil)
|
|
||||||
c.Assert(err, check.IsNil)
|
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
|
||||||
|
|
||||||
var inspectJSON map[string]interface{}
|
var inspectJSON map[string]interface{}
|
||||||
if err = json.Unmarshal(body, &inspectJSON); err != nil {
|
if err := json.Unmarshal(body, &inspectJSON); err != nil {
|
||||||
c.Fatalf("unable to unmarshal body for version %s: %v", version, err)
|
c.Fatalf("unable to unmarshal body for version %s: %v", version, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,13 +79,10 @@ func (s *DockerSuite) TestInspectApiContainerVolumeDriver(c *check.C) {
|
||||||
|
|
||||||
cleanedContainerID := strings.TrimSpace(out)
|
cleanedContainerID := strings.TrimSpace(out)
|
||||||
|
|
||||||
endpoint := fmt.Sprintf("/v1.21/containers/%s/json", cleanedContainerID)
|
body := getInspectBody(c, "v1.21", cleanedContainerID)
|
||||||
status, body, err := sockRequest("GET", endpoint, nil)
|
|
||||||
c.Assert(err, check.IsNil)
|
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
|
||||||
|
|
||||||
var inspectJSON map[string]interface{}
|
var inspectJSON map[string]interface{}
|
||||||
if err = json.Unmarshal(body, &inspectJSON); err != nil {
|
if err := json.Unmarshal(body, &inspectJSON); err != nil {
|
||||||
c.Fatalf("unable to unmarshal body for version 1.21: %v", err)
|
c.Fatalf("unable to unmarshal body for version 1.21: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,15 +131,12 @@ func (s *DockerSuite) TestInspectApiEmptyFieldsInConfigPre121(c *check.C) {
|
||||||
|
|
||||||
cleanedContainerID := strings.TrimSpace(out)
|
cleanedContainerID := strings.TrimSpace(out)
|
||||||
|
|
||||||
cases := []string{"1.19", "1.20"}
|
cases := []string{"v1.19", "v1.20"}
|
||||||
for _, version := range cases {
|
for _, version := range cases {
|
||||||
endpoint := fmt.Sprintf("/v%s/containers/%s/json", version, cleanedContainerID)
|
body := getInspectBody(c, version, cleanedContainerID)
|
||||||
status, body, err := sockRequest("GET", endpoint, nil)
|
|
||||||
c.Assert(err, check.IsNil)
|
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
|
||||||
|
|
||||||
var inspectJSON map[string]interface{}
|
var inspectJSON map[string]interface{}
|
||||||
if err = json.Unmarshal(body, &inspectJSON); err != nil {
|
if err := json.Unmarshal(body, &inspectJSON); err != nil {
|
||||||
c.Fatalf("unable to unmarshal body for version %s: %v", version, err)
|
c.Fatalf("unable to unmarshal body for version %s: %v", version, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,3 +152,33 @@ func (s *DockerSuite) TestInspectApiEmptyFieldsInConfigPre121(c *check.C) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestInspectApiBridgeNetworkSettings120(c *check.C) {
|
||||||
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||||
|
|
||||||
|
cleanedContainerID := strings.TrimSpace(out)
|
||||||
|
body := getInspectBody(c, "v1.20", cleanedContainerID)
|
||||||
|
|
||||||
|
var inspectJSON v1p20.ContainerJSON
|
||||||
|
err := json.Unmarshal(body, &inspectJSON)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
settings := inspectJSON.NetworkSettings
|
||||||
|
c.Assert(settings.IPAddress, checker.Not(checker.HasLen), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestInspectApiBridgeNetworkSettings121(c *check.C) {
|
||||||
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||||
|
cleanedContainerID := strings.TrimSpace(out)
|
||||||
|
|
||||||
|
body := getInspectBody(c, "v1.21", cleanedContainerID)
|
||||||
|
|
||||||
|
var inspectJSON types.ContainerJSON
|
||||||
|
err := json.Unmarshal(body, &inspectJSON)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
settings := inspectJSON.NetworkSettings
|
||||||
|
c.Assert(settings.IPAddress, checker.Not(checker.HasLen), 0)
|
||||||
|
c.Assert(settings.Networks["bridge"], checker.Not(checker.IsNil))
|
||||||
|
c.Assert(settings.IPAddress, checker.Equals, settings.Networks["bridge"].IPAddress)
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/versions/v1p20"
|
||||||
"github.com/docker/docker/pkg/integration/checker"
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/docker/libnetwork/driverapi"
|
"github.com/docker/libnetwork/driverapi"
|
||||||
remoteapi "github.com/docker/libnetwork/drivers/remote/api"
|
remoteapi "github.com/docker/libnetwork/drivers/remote/api"
|
||||||
|
@ -641,3 +642,31 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacInspect(c *check.C) {
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(mac, checker.Equals, "a0:b1:c2:d3:e4:f5")
|
c.Assert(mac, checker.Equals, "a0:b1:c2:d3:e4:f5")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestInspectApiMultipeNetworks(c *check.C) {
|
||||||
|
dockerCmd(c, "network", "create", "mybridge1")
|
||||||
|
dockerCmd(c, "network", "create", "mybridge2")
|
||||||
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
||||||
|
id := strings.TrimSpace(out)
|
||||||
|
c.Assert(waitRun(id), check.IsNil)
|
||||||
|
|
||||||
|
dockerCmd(c, "network", "connect", "mybridge1", id)
|
||||||
|
dockerCmd(c, "network", "connect", "mybridge2", id)
|
||||||
|
|
||||||
|
body := getInspectBody(c, "v1.20", id)
|
||||||
|
var inspect120 v1p20.ContainerJSON
|
||||||
|
err := json.Unmarshal(body, &inspect120)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
versionedIP := inspect120.NetworkSettings.IPAddress
|
||||||
|
|
||||||
|
body = getInspectBody(c, "v1.21", id)
|
||||||
|
var inspect121 types.ContainerJSON
|
||||||
|
err = json.Unmarshal(body, &inspect121)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(inspect121.NetworkSettings.Networks, checker.HasLen, 3)
|
||||||
|
|
||||||
|
bridge := inspect121.NetworkSettings.Networks["bridge"]
|
||||||
|
c.Assert(bridge.IPAddress, checker.Equals, versionedIP)
|
||||||
|
c.Assert(bridge.IPAddress, checker.Equals, inspect121.NetworkSettings.IPAddress)
|
||||||
|
}
|
||||||
|
|
|
@ -1587,3 +1587,11 @@ func waitInspect(name, expr, expected string, timeout time.Duration) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getInspectBody(c *check.C, version, id string) []byte {
|
||||||
|
endpoint := fmt.Sprintf("/%s/containers/%s/json", version, id)
|
||||||
|
status, body, err := sockRequest("GET", endpoint, nil)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue