diff --git a/libnetwork/drivers/windows/windows.go b/libnetwork/drivers/windows/windows.go index 0b15b2aa49..0a4d9b9666 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 bfdca30bcb..49503c00ff 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 315195ebb8..db0ffb0d1d 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 0000000000..89232415de --- /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 0000000000..e2ce30e675 --- /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) +}