mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Endpoint to provide ContainerInfo
Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
parent
0912ecfc05
commit
8aaf82c5b3
3 changed files with 40 additions and 0 deletions
|
@ -46,6 +46,9 @@ type Endpoint interface {
|
|||
// DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver
|
||||
DriverInfo() (map[string]interface{}, error)
|
||||
|
||||
// ContainerInfo returns the info available at the endpoint about the attached container
|
||||
ContainerInfo() ContainerInfo
|
||||
|
||||
// Delete and detaches this endpoint from the network.
|
||||
Delete() error
|
||||
}
|
||||
|
@ -102,6 +105,14 @@ type containerInfo struct {
|
|||
sync.Mutex
|
||||
}
|
||||
|
||||
func (ci *containerInfo) ID() string {
|
||||
return ci.id
|
||||
}
|
||||
|
||||
func (ci *containerInfo) Labels() map[string]interface{} {
|
||||
return ci.config.generic
|
||||
}
|
||||
|
||||
type endpoint struct {
|
||||
name string
|
||||
id types.UUID
|
||||
|
|
|
@ -40,6 +40,14 @@ type InterfaceInfo interface {
|
|||
AddressIPv6() net.IPNet
|
||||
}
|
||||
|
||||
// ContainerInfo provides an interface to retrieve the info about the container attached to the endpoint
|
||||
type ContainerInfo interface {
|
||||
// ID returns the ID of the container
|
||||
ID() string
|
||||
// Labels returns the container's labels
|
||||
Labels() map[string]interface{}
|
||||
}
|
||||
|
||||
type endpointInterface struct {
|
||||
id int
|
||||
mac net.HardwareAddr
|
||||
|
@ -111,6 +119,18 @@ type endpointJoinInfo struct {
|
|||
StaticRoutes []*types.StaticRoute
|
||||
}
|
||||
|
||||
func (ep *endpoint) ContainerInfo() ContainerInfo {
|
||||
ep.Lock()
|
||||
ci := ep.container
|
||||
defer ep.Unlock()
|
||||
|
||||
// Need this since we return the interface
|
||||
if ci == nil {
|
||||
return nil
|
||||
}
|
||||
return ci
|
||||
}
|
||||
|
||||
func (ep *endpoint) Info() EndpointInfo {
|
||||
return ep
|
||||
}
|
||||
|
|
|
@ -1045,6 +1045,11 @@ func TestEndpointJoin(t *testing.T) {
|
|||
t.Fatalf("Expected an non-empty sandbox key for a joined endpoint. Instead found a empty sandbox key")
|
||||
}
|
||||
|
||||
// Check endpoint provided container information
|
||||
if ep1.ContainerInfo().ID() != containerID {
|
||||
t.Fatalf("Endpoint ContainerInfo returned unexpected id: %s", ep1.ContainerInfo().ID())
|
||||
}
|
||||
|
||||
// Now test the container joining another network
|
||||
n2, err := createTestNetwork(bridgeNetType, "testnetwork2",
|
||||
options.Generic{
|
||||
|
@ -1077,6 +1082,10 @@ func TestEndpointJoin(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if ep1.ContainerInfo().ID() != ep2.ContainerInfo().ID() {
|
||||
t.Fatalf("ep1 and ep2 returned different container info")
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err = ep2.Leave(containerID)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue