Explorar o código

Merge pull request #898 from mavenugo/sbep

expose Endpoints API for a Sandbox
aboch %!s(int64=9) %!d(string=hai) anos
pai
achega
2b6143d61d
Modificáronse 3 ficheiros con 21 adicións e 0 borrados
  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 ""
 	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)
 }
 }

+ 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
 	// 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()

+ 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")
 		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)
 	}
 	}