1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #17615 from WeiZhang555/17404-net-inspect-name

Include container names in `network inspect`
This commit is contained in:
Alexander Morozov 2015-11-13 11:54:59 -08:00
commit a4acb1db4a
3 changed files with 43 additions and 0 deletions

View file

@ -237,6 +237,7 @@ func buildEndpointResource(e libnetwork.Endpoint) types.EndpointResource {
}
er.EndpointID = e.ID()
er.Name = e.Name()
ei := e.Info()
if ei == nil {
return er

View file

@ -362,6 +362,7 @@ type NetworkResource struct {
// EndpointResource contains network resources allocated and used for a container in a network
type EndpointResource struct {
Name string
EndpointID string
MacAddress string
IPv4Address string

View file

@ -294,6 +294,47 @@ func (s *DockerSuite) TestDockerInspectMultipleNetwork(c *check.C) {
c.Assert(out, checker.Contains, "Error: No such network: nonexistent")
}
func (s *DockerSuite) TestDockerInspectNetworkWithContainerName(c *check.C) {
dockerCmd(c, "network", "create", "brNetForInspect")
assertNwIsAvailable(c, "brNetForInspect")
defer func() {
dockerCmd(c, "network", "rm", "brNetForInspect")
assertNwNotAvailable(c, "brNetForInspect")
}()
out, _ := dockerCmd(c, "run", "-d", "--name", "testNetInspect1", "--net", "brNetForInspect", "busybox", "top")
c.Assert(waitRun("testNetInspect1"), check.IsNil)
containerID := strings.TrimSpace(out)
defer func() {
// we don't stop container by name, because we'll rename it later
dockerCmd(c, "stop", containerID)
}()
out, _ = dockerCmd(c, "network", "inspect", "brNetForInspect")
networkResources := []types.NetworkResource{}
err := json.Unmarshal([]byte(out), &networkResources)
c.Assert(err, check.IsNil)
c.Assert(networkResources, checker.HasLen, 1)
container, ok := networkResources[0].Containers[containerID]
c.Assert(ok, checker.True)
c.Assert(container.Name, checker.Equals, "testNetInspect1")
// rename container and check docker inspect output update
newName := "HappyNewName"
dockerCmd(c, "rename", "testNetInspect1", newName)
// check whether network inspect works properly
out, _ = dockerCmd(c, "network", "inspect", "brNetForInspect")
newNetRes := []types.NetworkResource{}
err = json.Unmarshal([]byte(out), &newNetRes)
c.Assert(err, check.IsNil)
c.Assert(newNetRes, checker.HasLen, 1)
container1, ok := newNetRes[0].Containers[containerID]
c.Assert(ok, checker.True)
c.Assert(container1.Name, checker.Equals, newName)
}
func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnect(c *check.C) {
dockerCmd(c, "network", "create", "test")
assertNwIsAvailable(c, "test")