diff --git a/libnetwork/drivers/windows/windows.go b/libnetwork/drivers/windows/windows.go index 0b15b2aa4905fd99d24b4d06a87e29676ad16fd4..0a4d9b96662e039b83a5ed82a44a31025282ddd9 100644 --- a/libnetwork/drivers/windows/windows.go +++ b/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 } diff --git a/libnetwork/osl/namespace_windows.go b/libnetwork/osl/namespace_windows.go index bfdca30bcbb89252b513bd9e3c5f45b6688f84b9..49503c00ffd23e39c16360897565eb3f9fa32d94 100644 --- a/libnetwork/osl/namespace_windows.go +++ b/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 diff --git a/libnetwork/sandbox.go b/libnetwork/sandbox.go index 315195ebb87babf99bb844f9b69d6bb963174c2b..db0ffb0d1d70b12cb58c51257352547f73cd0943 100644 --- a/libnetwork/sandbox.go +++ b/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() diff --git a/libnetwork/sandbox_others.go b/libnetwork/sandbox_others.go new file mode 100644 index 0000000000000000000000000000000000000000..89232415deb9f84c618ddbfd2b2db173e02bd062 --- /dev/null +++ b/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) +} diff --git a/libnetwork/sandbox_windows.go b/libnetwork/sandbox_windows.go new file mode 100644 index 0000000000000000000000000000000000000000..e2ce30e6756d4fabbe7520d04e17be5eee780390 --- /dev/null +++ b/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) +}