mirror of https://github.com/docker/docs.git
display all the containers that are part of a global network on inspect
update godeps Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
7291ec144c
commit
cdd42a5c6b
|
@ -131,7 +131,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/samalba/dockerclient",
|
"ImportPath": "github.com/samalba/dockerclient",
|
||||||
"Rev": "4656b1bc6cbc06b75d65983475e4809cbd53ebb5"
|
"Rev": "0197eaa42571af873532ba11499f6ccdf16a5f3a"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/samuel/go-zookeeper/zk",
|
"ImportPath": "github.com/samuel/go-zookeeper/zk",
|
||||||
|
|
|
@ -502,10 +502,12 @@ type NetworkResource struct {
|
||||||
Driver string
|
Driver string
|
||||||
IPAM IPAM
|
IPAM IPAM
|
||||||
Containers map[string]EndpointResource
|
Containers map[string]EndpointResource
|
||||||
|
Options map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
//EndpointResource contains network resources allocated and usd for a container in a network
|
// EndpointResource contains network resources allocated and used for a container in a network
|
||||||
type EndpointResource struct {
|
type EndpointResource struct {
|
||||||
|
Name string
|
||||||
EndpointID string
|
EndpointID string
|
||||||
MacAddress string
|
MacAddress string
|
||||||
IPv4Address string
|
IPv4Address string
|
||||||
|
|
|
@ -785,11 +785,8 @@ func ping(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
func proxyNetwork(c *context, w http.ResponseWriter, r *http.Request) {
|
func proxyNetwork(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
var id = mux.Vars(r)["networkid"]
|
var id = mux.Vars(r)["networkid"]
|
||||||
if network := c.cluster.Networks().Uniq().Get(id); network != nil {
|
if network := c.cluster.Networks().Uniq().Get(id); network != nil {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
// Set the network ID in the proxied URL path.
|
json.NewEncoder(w).Encode(network)
|
||||||
r.URL.Path = strings.Replace(r.URL.Path, id, network.ID, 1)
|
|
||||||
|
|
||||||
proxy(c.tlsConfig, network.Engine.Addr, w, r)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
httpError(w, fmt.Sprintf("No such network: %s", id), http.StatusNotFound)
|
httpError(w, fmt.Sprintf("No such network: %s", id), http.StatusNotFound)
|
||||||
|
@ -835,8 +832,13 @@ func proxyNetworkContainerOperation(c *context, w http.ResponseWriter, r *http.R
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cb := func(resp *http.Response) {
|
||||||
|
// force fresh networks on this engine
|
||||||
|
container.Engine.RefreshNetworks()
|
||||||
|
}
|
||||||
|
|
||||||
// request is forwarded to the container's address
|
// request is forwarded to the container's address
|
||||||
if err := proxy(c.tlsConfig, container.Engine.Addr, w, r); err != nil {
|
if err := proxyAsync(c.tlsConfig, container.Engine.Addr, w, r, cb); err != nil {
|
||||||
httpError(w, err.Error(), http.StatusNotFound)
|
httpError(w, err.Error(), http.StatusNotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,13 @@ type Networks []*Network
|
||||||
func (networks Networks) Uniq() Networks {
|
func (networks Networks) Uniq() Networks {
|
||||||
tmp := make(map[string]*Network)
|
tmp := make(map[string]*Network)
|
||||||
for _, network := range networks {
|
for _, network := range networks {
|
||||||
tmp[network.ID] = network
|
if _, ok := tmp[network.ID]; ok {
|
||||||
|
for id, endpoint := range network.Containers {
|
||||||
|
tmp[network.ID].Containers[id] = endpoint
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tmp[network.ID] = network
|
||||||
|
}
|
||||||
}
|
}
|
||||||
uniq := Networks{}
|
uniq := Networks{}
|
||||||
for _, network := range tmp {
|
for _, network := range tmp {
|
||||||
|
|
|
@ -34,3 +34,49 @@ func TestNetworksFilter(t *testing.T) {
|
||||||
assert.True(t, network.ID == "aaaaaaaaaa1" || network.ID == "ababababab")
|
assert.True(t, network.ID == "aaaaaaaaaa1" || network.ID == "ababababab")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNetworkUniq(t *testing.T) {
|
||||||
|
engine1 := &Engine{ID: "id1"}
|
||||||
|
engine2 := &Engine{ID: "id2"}
|
||||||
|
networks := Networks{
|
||||||
|
{dockerclient.NetworkResource{
|
||||||
|
ID: "global",
|
||||||
|
Name: "global",
|
||||||
|
Containers: map[string]dockerclient.EndpointResource{
|
||||||
|
"c1": {},
|
||||||
|
},
|
||||||
|
}, engine1},
|
||||||
|
{dockerclient.NetworkResource{
|
||||||
|
ID: "global",
|
||||||
|
Name: "global",
|
||||||
|
Containers: map[string]dockerclient.EndpointResource{
|
||||||
|
"c2": {},
|
||||||
|
},
|
||||||
|
}, engine2},
|
||||||
|
{dockerclient.NetworkResource{
|
||||||
|
ID: "local1",
|
||||||
|
Name: "local",
|
||||||
|
Containers: map[string]dockerclient.EndpointResource{
|
||||||
|
"c3": {},
|
||||||
|
},
|
||||||
|
}, engine1},
|
||||||
|
{dockerclient.NetworkResource{
|
||||||
|
ID: "local2",
|
||||||
|
Name: "local",
|
||||||
|
Containers: map[string]dockerclient.EndpointResource{
|
||||||
|
"c4": {},
|
||||||
|
},
|
||||||
|
}, engine2},
|
||||||
|
}
|
||||||
|
|
||||||
|
global := networks.Uniq().Get("global")
|
||||||
|
assert.NotNil(t, global)
|
||||||
|
assert.Equal(t, 2, len(global.Containers))
|
||||||
|
|
||||||
|
local1 := networks.Uniq().Get("local1")
|
||||||
|
assert.NotNil(t, local1)
|
||||||
|
assert.Equal(t, 1, len(local1.Containers))
|
||||||
|
|
||||||
|
local3 := networks.Uniq().Get("local3")
|
||||||
|
assert.Nil(t, local3)
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ function teardown() {
|
||||||
run docker_swarm network inspect bridge
|
run docker_swarm network inspect bridge
|
||||||
[ "$status" -ne 0 ]
|
[ "$status" -ne 0 ]
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
run docker_swarm network inspect node-0/bridge
|
run docker_swarm network inspect node-0/bridge
|
||||||
[[ "${output}" != *"\"Containers\": {}"* ]]
|
[[ "${output}" != *"\"Containers\": {}"* ]]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue