Browse Source

Merge pull request #898 from mavenugo/sbep

expose Endpoints API for a Sandbox
aboch 9 years ago
parent
commit
2b6143d61d
3 changed files with 21 additions and 0 deletions
  1. 4 0
      libnetwork/libnetwork_test.go
  2. 13 0
      libnetwork/sandbox.go
  3. 4 0
      libnetwork/sandbox_test.go

+ 4 - 0
libnetwork/libnetwork_test.go

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

+ 13 - 0
libnetwork/sandbox.go

@@ -47,6 +47,8 @@ type Sandbox interface {
 	// ResolveIP returns the service name for the passed in IP. IP is in reverse dotted
 	// notation; the format used for DNS PTR records
 	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
@@ -347,6 +349,17 @@ func (sb *sandbox) setupResolutionFiles() error {
 	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 {
 	sb.Lock()
 	defer sb.Unlock()

+ 4 - 0
libnetwork/sandbox_test.go

@@ -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")
 	}
 
+	if len(sbx.Endpoints()) != 3 {
+		t.Fatal("Expected 3 endpoints to be connected to the sandbox.")
+	}
+
 	if err := ep3.Leave(sbx); err != nil {
 		t.Fatal(err)
 	}