Browse Source

Enable Hot Add/Remove of Network Endpoints for Windows

Signed-off-by: Madhan Raj Mookkandy <madhanm@microsoft.com>
Madhan Raj Mookkandy 8 years ago
parent
commit
b0888450a9

+ 18 - 4
libnetwork/drivers/windows/windows.go

@@ -66,6 +66,7 @@ type hnsEndpoint struct {
 	nid            string
 	profileID      string
 	Type           string
+	containerID    string
 	macAddress     net.HardwareAddr
 	epOption       *endpointOption       // User specified parameters
 	epConnectivity *EndpointConnectivity // User specified parameters
@@ -730,7 +731,15 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
 		return err
 	}
 
-	// This is just a stub for now
+	endpoint.containerID = sboxKey
+
+	err = hcsshim.HotAttachEndpoint(endpoint.containerID, endpoint.profileID)
+	if err != nil {
+		// If container doesn't exists in hcs, do not throw error for hot add/remove
+		if err != hcsshim.ErrComputeSystemDoesNotExist {
+			return err
+		}
+	}
 
 	jinfo.DisableGatewayService()
 	return nil
@@ -744,13 +753,18 @@ func (d *driver) Leave(nid, eid string) error {
 	}
 
 	// Ensure that the endpoint exists
-	_, err = network.getEndpoint(eid)
+	endpoint, err := network.getEndpoint(eid)
 	if err != nil {
 		return err
 	}
 
-	// This is just a stub for now
-
+	err = hcsshim.HotDetachEndpoint(endpoint.containerID, endpoint.profileID)
+	if err != nil {
+		// If container doesn't exists in hcs, do not throw error for hot add/remove
+		if err != hcsshim.ErrComputeSystemDoesNotExist {
+			return err
+		}
+	}
 	return nil
 }
 

+ 1 - 6
libnetwork/osl/namespace_windows.go

@@ -5,12 +5,7 @@ import "testing"
 // GenerateKey generates a sandbox key based on the passed
 // container id.
 func GenerateKey(containerID string) string {
-	maxLen := 12
-	if len(containerID) < maxLen {
-		maxLen = len(containerID)
-	}
-
-	return containerID[:maxLen]
+	return containerID
 }
 
 // NewSandbox provides a new sandbox instance created in an os specific way

+ 0 - 7
libnetwork/sandbox.go

@@ -144,13 +144,6 @@ func (sb *sandbox) ContainerID() string {
 	return sb.containerID
 }
 
-func (sb *sandbox) Key() string {
-	if sb.config.useDefaultSandBox {
-		return osl.GenerateKey("default")
-	}
-	return osl.GenerateKey(sb.id)
-}
-
 func (sb *sandbox) Labels() map[string]interface{} {
 	sb.Lock()
 	defer sb.Unlock()

+ 12 - 0
libnetwork/sandbox_others.go

@@ -0,0 +1,12 @@
+// +build !windows
+
+package libnetwork
+
+import "github.com/docker/libnetwork/osl"
+
+func (sb *sandbox) Key() string {
+	if sb.config.useDefaultSandBox {
+		return osl.GenerateKey("default")
+	}
+	return osl.GenerateKey(sb.id)
+}

+ 12 - 0
libnetwork/sandbox_windows.go

@@ -0,0 +1,12 @@
+// +build windows
+
+package libnetwork
+
+import "github.com/docker/libnetwork/osl"
+
+func (sb *sandbox) Key() string {
+	if sb.config.useDefaultSandBox {
+		return osl.GenerateKey("default")
+	}
+	return osl.GenerateKey(sb.containerID)
+}