Enable Hot Add/Remove of Network Endpoints for Windows

Signed-off-by: Madhan Raj Mookkandy <madhanm@microsoft.com>
This commit is contained in:
Madhan Raj Mookkandy 2017-03-30 20:31:34 -07:00 committed by Pradip Dhara
parent ef2e91707d
commit b0888450a9
5 changed files with 43 additions and 17 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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()

View file

@ -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)
}

View file

@ -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)
}