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

expose Endpoints API for a Sandbox

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2016-01-25 16:23:00 -08:00
parent 7cefc36f02
commit 7a76968485
3 changed files with 21 additions and 0 deletions

View file

@ -1221,6 +1221,10 @@ func (f *fakeSandbox) ResolveIP(ip string) string {
return "" return ""
} }
func (f *fakeSandbox) Endpoints() []libnetwork.Endpoint {
return nil
}
func TestExternalKey(t *testing.T) { func TestExternalKey(t *testing.T) {
externalKeyTest(t, false) externalKeyTest(t, false)
} }

View file

@ -47,6 +47,8 @@ type Sandbox interface {
// ResolveIP returns the service name for the passed in IP. IP is in reverse dotted // ResolveIP returns the service name for the passed in IP. IP is in reverse dotted
// notation; the format used for DNS PTR records // notation; the format used for DNS PTR records
ResolveIP(name string) string ResolveIP(name string) string
// Endpoints returns all the endpoints connected to the sandbox
Endpoints() []Endpoint
} }
// SandboxOption is an option setter function type used to pass various options to // SandboxOption is an option setter function type used to pass various options to
@ -347,6 +349,17 @@ func (sb *sandbox) setupResolutionFiles() error {
return nil return nil
} }
func (sb *sandbox) Endpoints() []Endpoint {
sb.Lock()
defer sb.Unlock()
endpoints := make([]Endpoint, len(sb.endpoints))
for i, ep := range sb.endpoints {
endpoints[i] = ep
}
return endpoints
}
func (sb *sandbox) getConnectedEndpoints() []*endpoint { func (sb *sandbox) getConnectedEndpoints() []*endpoint {
sb.Lock() sb.Lock()
defer sb.Unlock() defer sb.Unlock()

View file

@ -119,6 +119,10 @@ func TestSandboxAddMultiPrio(t *testing.T) {
t.Fatal("Expected ep3 to be at the top of the heap. But did not find ep3 at the top of the heap") t.Fatal("Expected ep3 to be at the top of the heap. But did not find ep3 at the top of the heap")
} }
if len(sbx.Endpoints()) != 3 {
t.Fatal("Expected 3 endpoints to be connected to the sandbox.")
}
if err := ep3.Leave(sbx); err != nil { if err := ep3.Leave(sbx); err != nil {
t.Fatal(err) t.Fatal(err)
} }