2016-01-29 20:08:11 -05:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
// Shim for the Host Network Service (HNS) to manage networking for
|
|
|
|
// Windows Server containers and Hyper-V containers. This module
|
|
|
|
// is a basic libnetwork driver that passes all the calls to HNS
|
|
|
|
// It implements the 4 networking modes supported by HNS L2Bridge,
|
|
|
|
// L2Tunnel, NAT and Transparent(DHCP)
|
|
|
|
//
|
|
|
|
// The network are stored in memory and docker daemon ensures discovering
|
|
|
|
// and loading these networks on startup
|
|
|
|
|
2015-05-26 13:46:21 -04:00
|
|
|
package windows
|
|
|
|
|
2015-09-16 07:39:46 -04:00
|
|
|
import (
|
2016-01-29 20:08:11 -05:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2016-09-19 18:48:06 -04:00
|
|
|
"strconv"
|
2016-01-29 20:08:11 -05:00
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/Microsoft/hcsshim"
|
2020-08-31 14:18:32 -04:00
|
|
|
"github.com/Microsoft/hcsshim/osversion"
|
2021-04-05 20:24:47 -04:00
|
|
|
"github.com/docker/docker/libnetwork/datastore"
|
|
|
|
"github.com/docker/docker/libnetwork/discoverapi"
|
|
|
|
"github.com/docker/docker/libnetwork/driverapi"
|
|
|
|
"github.com/docker/docker/libnetwork/netlabel"
|
|
|
|
"github.com/docker/docker/libnetwork/portmapper"
|
|
|
|
"github.com/docker/docker/libnetwork/types"
|
2017-07-26 17:18:31 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2015-09-16 07:39:46 -04:00
|
|
|
)
|
2015-05-26 13:46:21 -04:00
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
// networkConfiguration for network specific configuration
|
|
|
|
type networkConfiguration struct {
|
2018-02-05 19:55:56 -05:00
|
|
|
ID string
|
|
|
|
Type string
|
|
|
|
Name string
|
|
|
|
HnsID string
|
|
|
|
RDID string
|
|
|
|
VLAN uint
|
|
|
|
VSID uint
|
|
|
|
DNSServers string
|
|
|
|
MacPools []hcsshim.MacPool
|
|
|
|
DNSSuffix string
|
|
|
|
SourceMac string
|
|
|
|
NetworkAdapterName string
|
|
|
|
dbIndex uint64
|
|
|
|
dbExists bool
|
|
|
|
DisableGatewayDNS bool
|
|
|
|
EnableOutboundNat bool
|
|
|
|
OutboundNatExceptions []string
|
2016-01-29 20:08:11 -05:00
|
|
|
}
|
|
|
|
|
2016-02-25 18:06:16 -05:00
|
|
|
// endpointConfiguration represents the user specified configuration for the sandbox endpoint
|
2016-11-04 16:26:50 -04:00
|
|
|
type endpointOption struct {
|
|
|
|
MacAddress net.HardwareAddr
|
|
|
|
QosPolicies []types.QosPolicy
|
|
|
|
DNSServers []string
|
|
|
|
DisableDNS bool
|
|
|
|
DisableICC bool
|
|
|
|
}
|
|
|
|
|
2017-08-09 17:55:04 -04:00
|
|
|
// EndpointConnectivity stores the port bindings and exposed ports that the user has specified in epOptions.
|
|
|
|
type EndpointConnectivity struct {
|
2016-02-25 18:06:16 -05:00
|
|
|
PortBindings []types.PortBinding
|
|
|
|
ExposedPorts []types.TransportPort
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
type hnsEndpoint struct {
|
2017-10-02 19:08:59 -04:00
|
|
|
id string
|
|
|
|
nid string
|
|
|
|
profileID string
|
|
|
|
Type string
|
|
|
|
//Note: Currently, the sandboxID is the same as the containerID since windows does
|
|
|
|
//not expose the sandboxID.
|
|
|
|
//In the future, windows will support a proper sandboxID that is different
|
|
|
|
//than the containerID.
|
|
|
|
//Therefore, we are using sandboxID now, so that we won't have to change this code
|
|
|
|
//when windows properly supports a sandboxID.
|
|
|
|
sandboxID string
|
2016-11-04 16:26:50 -04:00
|
|
|
macAddress net.HardwareAddr
|
|
|
|
epOption *endpointOption // User specified parameters
|
2017-08-09 17:55:04 -04:00
|
|
|
epConnectivity *EndpointConnectivity // User specified parameters
|
2016-11-04 16:26:50 -04:00
|
|
|
portMapping []types.PortBinding // Operation port bindings
|
|
|
|
addr *net.IPNet
|
|
|
|
gateway net.IP
|
2017-05-16 17:06:43 -04:00
|
|
|
dbIndex uint64
|
|
|
|
dbExists bool
|
2016-01-29 20:08:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type hnsNetwork struct {
|
2019-04-17 13:54:10 -04:00
|
|
|
id string
|
|
|
|
created bool
|
|
|
|
config *networkConfiguration
|
|
|
|
endpoints map[string]*hnsEndpoint // key: endpoint id
|
|
|
|
driver *driver // The network's driver
|
|
|
|
portMapper *portmapper.PortMapper
|
2016-01-29 20:08:11 -05:00
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
type driver struct {
|
|
|
|
name string
|
|
|
|
networks map[string]*hnsNetwork
|
2017-05-16 17:06:43 -04:00
|
|
|
store datastore.DataStore
|
2016-01-29 20:08:11 -05:00
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
2017-05-16 17:06:43 -04:00
|
|
|
const (
|
|
|
|
errNotFound = "HNS failed with error : The object identifier does not represent a valid object. "
|
|
|
|
)
|
|
|
|
|
2017-08-09 17:55:04 -04:00
|
|
|
// IsBuiltinLocalDriver validates if network-type is a builtin local-scoped driver
|
2016-10-12 19:55:20 -04:00
|
|
|
func IsBuiltinLocalDriver(networkType string) bool {
|
2018-07-12 00:49:46 -04:00
|
|
|
if "l2bridge" == networkType || "l2tunnel" == networkType ||
|
|
|
|
"nat" == networkType || "ics" == networkType ||
|
|
|
|
"transparent" == networkType || "internal" == networkType ||
|
|
|
|
"private" == networkType {
|
2016-01-29 20:08:11 -05:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// New constructs a new bridge driver
|
|
|
|
func newDriver(networkType string) *driver {
|
|
|
|
return &driver{name: networkType, networks: map[string]*hnsNetwork{}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetInit returns an initializer for the given network type
|
|
|
|
func GetInit(networkType string) func(dc driverapi.DriverCallback, config map[string]interface{}) error {
|
|
|
|
return func(dc driverapi.DriverCallback, config map[string]interface{}) error {
|
2016-10-12 19:55:20 -04:00
|
|
|
if !IsBuiltinLocalDriver(networkType) {
|
2016-01-29 20:08:11 -05:00
|
|
|
return types.BadRequestErrorf("Network type not supported: %s", networkType)
|
|
|
|
}
|
|
|
|
|
2017-05-16 17:06:43 -04:00
|
|
|
d := newDriver(networkType)
|
|
|
|
|
|
|
|
err := d.initStore(config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return dc.RegisterDriver(networkType, d, driverapi.Capability{
|
2017-04-07 16:31:44 -04:00
|
|
|
DataScope: datastore.LocalScope,
|
|
|
|
ConnectivityScope: datastore.LocalScope,
|
2016-01-29 20:08:11 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) getNetwork(id string) (*hnsNetwork, error) {
|
|
|
|
d.Lock()
|
|
|
|
defer d.Unlock()
|
|
|
|
|
|
|
|
if nw, ok := d.networks[id]; ok {
|
|
|
|
return nw, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, types.NotFoundErrorf("network not found: %s", id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *hnsNetwork) getEndpoint(eid string) (*hnsEndpoint, error) {
|
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
|
|
|
if ep, ok := n.endpoints[eid]; ok {
|
|
|
|
return ep, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, types.NotFoundErrorf("Endpoint not found: %s", eid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) parseNetworkOptions(id string, genericOptions map[string]string) (*networkConfiguration, error) {
|
2017-05-16 17:06:43 -04:00
|
|
|
config := &networkConfiguration{Type: d.name}
|
2015-05-26 13:46:21 -04:00
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
for label, value := range genericOptions {
|
|
|
|
switch label {
|
|
|
|
case NetworkName:
|
|
|
|
config.Name = value
|
|
|
|
case HNSID:
|
|
|
|
config.HnsID = value
|
|
|
|
case RoutingDomain:
|
|
|
|
config.RDID = value
|
2016-03-16 14:07:20 -04:00
|
|
|
case Interface:
|
|
|
|
config.NetworkAdapterName = value
|
2016-09-19 18:48:06 -04:00
|
|
|
case DNSSuffix:
|
|
|
|
config.DNSSuffix = value
|
|
|
|
case DNSServers:
|
|
|
|
config.DNSServers = value
|
2017-11-21 14:35:32 -05:00
|
|
|
case DisableGatewayDNS:
|
|
|
|
b, err := strconv.ParseBool(value)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
config.DisableGatewayDNS = b
|
2017-05-18 16:38:04 -04:00
|
|
|
case MacPool:
|
|
|
|
config.MacPools = make([]hcsshim.MacPool, 0)
|
|
|
|
s := strings.Split(value, ",")
|
|
|
|
if len(s)%2 != 0 {
|
|
|
|
return nil, types.BadRequestErrorf("Invalid mac pool. You must specify both a start range and an end range")
|
|
|
|
}
|
|
|
|
for i := 0; i < len(s)-1; i += 2 {
|
|
|
|
config.MacPools = append(config.MacPools, hcsshim.MacPool{
|
|
|
|
StartMacAddress: s[i],
|
|
|
|
EndMacAddress: s[i+1],
|
|
|
|
})
|
|
|
|
}
|
2016-09-19 18:48:06 -04:00
|
|
|
case VLAN:
|
|
|
|
vlan, err := strconv.ParseUint(value, 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
config.VLAN = uint(vlan)
|
|
|
|
case VSID:
|
|
|
|
vsid, err := strconv.ParseUint(value, 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
config.VSID = uint(vsid)
|
2018-02-05 19:55:56 -05:00
|
|
|
case EnableOutboundNat:
|
2020-08-31 14:18:32 -04:00
|
|
|
if osversion.Build() <= 16236 {
|
2018-02-05 19:55:56 -05:00
|
|
|
return nil, fmt.Errorf("Invalid network option. OutboundNat is not supported on this OS version")
|
|
|
|
}
|
|
|
|
b, err := strconv.ParseBool(value)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
config.EnableOutboundNat = b
|
|
|
|
case OutboundNatExceptions:
|
|
|
|
s := strings.Split(value, ",")
|
|
|
|
config.OutboundNatExceptions = s
|
2016-01-29 20:08:11 -05:00
|
|
|
}
|
|
|
|
}
|
2015-05-26 13:46:21 -04:00
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
config.ID = id
|
|
|
|
config.Type = d.name
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *networkConfiguration) processIPAM(id string, ipamV4Data, ipamV6Data []driverapi.IPAMData) error {
|
|
|
|
if len(ipamV6Data) > 0 {
|
2016-02-23 16:44:38 -05:00
|
|
|
return types.ForbiddenErrorf("windowsshim driver doesn't support v6 subnets")
|
2016-01-29 20:08:11 -05:00
|
|
|
}
|
2015-05-26 13:46:21 -04:00
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
if len(ipamV4Data) == 0 {
|
|
|
|
return types.BadRequestErrorf("network %s requires ipv4 configuration", id)
|
2015-06-06 13:21:51 -04:00
|
|
|
}
|
2016-01-29 20:08:11 -05:00
|
|
|
|
|
|
|
return nil
|
2015-05-26 13:46:21 -04:00
|
|
|
}
|
|
|
|
|
2016-04-18 22:55:39 -04:00
|
|
|
func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
|
|
|
|
}
|
|
|
|
|
2017-03-02 02:57:37 -05:00
|
|
|
func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2019-08-07 17:28:54 -04:00
|
|
|
func (d *driver) createNetwork(config *networkConfiguration) *hnsNetwork {
|
2017-05-16 17:06:43 -04:00
|
|
|
network := &hnsNetwork{
|
2019-04-17 13:54:10 -04:00
|
|
|
id: config.ID,
|
|
|
|
endpoints: make(map[string]*hnsEndpoint),
|
|
|
|
config: config,
|
|
|
|
driver: d,
|
|
|
|
portMapper: portmapper.New(""),
|
2017-05-16 17:06:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
d.Lock()
|
|
|
|
d.networks[config.ID] = network
|
|
|
|
d.Unlock()
|
|
|
|
|
2019-08-07 17:28:54 -04:00
|
|
|
return network
|
2017-05-16 17:06:43 -04:00
|
|
|
}
|
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
// Create a new network
|
2016-04-18 22:55:39 -04:00
|
|
|
func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
|
2016-01-29 20:08:11 -05:00
|
|
|
if _, err := d.getNetwork(id); err == nil {
|
|
|
|
return types.ForbiddenErrorf("network %s exists", id)
|
|
|
|
}
|
|
|
|
|
|
|
|
genData, ok := option[netlabel.GenericData].(map[string]string)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Unknown generic data option")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse and validate the config. It should not conflict with existing networks' config
|
|
|
|
config, err := d.parseNetworkOptions(id, genData)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = config.processIPAM(id, ipV4Data, ipV6Data)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-08-07 17:28:54 -04:00
|
|
|
n := d.createNetwork(config)
|
2016-01-29 20:08:11 -05:00
|
|
|
|
|
|
|
// A non blank hnsid indicates that the network was discovered
|
|
|
|
// from HNS. No need to call HNS if this network was discovered
|
|
|
|
// from HNS
|
|
|
|
if config.HnsID == "" {
|
|
|
|
subnets := []hcsshim.Subnet{}
|
|
|
|
|
|
|
|
for _, ipData := range ipV4Data {
|
|
|
|
subnet := hcsshim.Subnet{
|
2016-03-04 14:35:11 -05:00
|
|
|
AddressPrefix: ipData.Pool.String(),
|
|
|
|
}
|
|
|
|
|
|
|
|
if ipData.Gateway != nil {
|
|
|
|
subnet.GatewayAddress = ipData.Gateway.IP.String()
|
2016-01-29 20:08:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
subnets = append(subnets, subnet)
|
|
|
|
}
|
|
|
|
|
|
|
|
network := &hcsshim.HNSNetwork{
|
2016-03-16 14:07:20 -04:00
|
|
|
Name: config.Name,
|
|
|
|
Type: d.name,
|
|
|
|
Subnets: subnets,
|
2016-09-19 18:48:06 -04:00
|
|
|
DNSServerList: config.DNSServers,
|
|
|
|
DNSSuffix: config.DNSSuffix,
|
2017-05-18 16:38:04 -04:00
|
|
|
MacPools: config.MacPools,
|
2016-09-19 18:48:06 -04:00
|
|
|
SourceMac: config.SourceMac,
|
2016-03-16 14:07:20 -04:00
|
|
|
NetworkAdapterName: config.NetworkAdapterName,
|
2016-01-29 20:08:11 -05:00
|
|
|
}
|
|
|
|
|
2016-09-19 18:48:06 -04:00
|
|
|
if config.VLAN != 0 {
|
|
|
|
vlanPolicy, err := json.Marshal(hcsshim.VlanPolicy{
|
|
|
|
Type: "VLAN",
|
|
|
|
VLAN: config.VLAN,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
network.Policies = append(network.Policies, vlanPolicy)
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.VSID != 0 {
|
|
|
|
vsidPolicy, err := json.Marshal(hcsshim.VsidPolicy{
|
|
|
|
Type: "VSID",
|
|
|
|
VSID: config.VSID,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
network.Policies = append(network.Policies, vsidPolicy)
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
if network.Name == "" {
|
|
|
|
network.Name = id
|
|
|
|
}
|
|
|
|
|
|
|
|
configurationb, err := json.Marshal(network)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
configuration := string(configurationb)
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Debugf("HNSNetwork Request =%v Address Space=%v", configuration, subnets)
|
2016-01-29 20:08:11 -05:00
|
|
|
|
|
|
|
hnsresponse, err := hcsshim.HNSNetworkRequest("POST", "", configuration)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
config.HnsID = hnsresponse.Id
|
|
|
|
genData[HNSID] = config.HnsID
|
2019-08-07 17:28:54 -04:00
|
|
|
n.created = true
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
d.DeleteNetwork(n.id)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
hnsIPv4Data := make([]driverapi.IPAMData, len(hnsresponse.Subnets))
|
|
|
|
|
|
|
|
for i, subnet := range hnsresponse.Subnets {
|
|
|
|
var gwIP, subnetIP *net.IPNet
|
|
|
|
|
|
|
|
//The gateway returned from HNS is an IPAddress.
|
|
|
|
//We need to convert it to an IPNet to use as the Gateway of driverapi.IPAMData struct
|
|
|
|
gwCIDR := subnet.GatewayAddress + "/32"
|
|
|
|
_, gwIP, err = net.ParseCIDR(gwCIDR)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
hnsIPv4Data[i].Gateway = gwIP
|
|
|
|
_, subnetIP, err = net.ParseCIDR(subnet.AddressPrefix)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
hnsIPv4Data[i].Pool = subnetIP
|
|
|
|
}
|
|
|
|
|
|
|
|
nInfo.UpdateIpamConfig(hnsIPv4Data)
|
2018-03-05 03:12:00 -05:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Delete any stale HNS endpoints for this network.
|
|
|
|
if endpoints, err := hcsshim.HNSListEndpointRequest(); err == nil {
|
|
|
|
for _, ep := range endpoints {
|
|
|
|
if ep.VirtualNetwork == config.HnsID {
|
|
|
|
logrus.Infof("Removing stale HNS endpoint %s", ep.Id)
|
|
|
|
_, err = hcsshim.HNSEndpointRequest("DELETE", ep.Id, "")
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warnf("Error removing HNS endpoint %s", ep.Id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logrus.Warnf("Error listing HNS endpoints for network %s", config.HnsID)
|
|
|
|
}
|
2016-01-29 20:08:11 -05:00
|
|
|
|
2019-08-07 17:28:54 -04:00
|
|
|
n.created = true
|
2017-06-12 14:30:30 -04:00
|
|
|
}
|
2019-08-07 17:28:54 -04:00
|
|
|
|
2017-05-16 17:06:43 -04:00
|
|
|
return d.storeUpdate(config)
|
2015-05-26 13:46:21 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 01:00:48 -04:00
|
|
|
func (d *driver) DeleteNetwork(nid string) error {
|
2016-01-29 20:08:11 -05:00
|
|
|
n, err := d.getNetwork(nid)
|
|
|
|
if err != nil {
|
|
|
|
return types.InternalMaskableErrorf("%s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
n.Lock()
|
|
|
|
config := n.config
|
|
|
|
n.Unlock()
|
|
|
|
|
2017-05-16 17:06:43 -04:00
|
|
|
if n.created {
|
|
|
|
_, err = hcsshim.HNSNetworkRequest("DELETE", config.HnsID, "")
|
|
|
|
if err != nil && err.Error() != errNotFound {
|
|
|
|
return types.ForbiddenErrorf(err.Error())
|
|
|
|
}
|
2016-01-29 20:08:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
d.Lock()
|
|
|
|
delete(d.networks, nid)
|
|
|
|
d.Unlock()
|
|
|
|
|
2017-05-16 17:06:43 -04:00
|
|
|
// delele endpoints belong to this network
|
|
|
|
for _, ep := range n.endpoints {
|
|
|
|
if err := d.storeDelete(ep); err != nil {
|
2018-07-05 16:33:01 -04:00
|
|
|
logrus.Warnf("Failed to remove bridge endpoint %.7s from store: %v", ep.id, err)
|
2017-05-16 17:06:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return d.storeDelete(config)
|
2015-05-26 13:46:21 -04:00
|
|
|
}
|
|
|
|
|
2016-03-28 17:50:55 -04:00
|
|
|
func convertQosPolicies(qosPolicies []types.QosPolicy) ([]json.RawMessage, error) {
|
|
|
|
var qps []json.RawMessage
|
|
|
|
|
|
|
|
// Enumerate through the qos policies specified by the user and convert
|
|
|
|
// them into the internal structure matching the JSON blob that can be
|
|
|
|
// understood by the HCS.
|
|
|
|
for _, elem := range qosPolicies {
|
|
|
|
encodedPolicy, err := json.Marshal(hcsshim.QosPolicy{
|
2019-06-26 11:54:31 -04:00
|
|
|
Type: "QOS",
|
2016-03-28 17:50:55 -04:00
|
|
|
MaximumOutgoingBandwidthInBytes: elem.MaxEgressBandwidth,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
qps = append(qps, encodedPolicy)
|
|
|
|
}
|
|
|
|
return qps, nil
|
|
|
|
}
|
|
|
|
|
2017-07-07 02:00:01 -04:00
|
|
|
// ConvertPortBindings converts PortBindings to JSON for HNS request
|
|
|
|
func ConvertPortBindings(portBindings []types.PortBinding) ([]json.RawMessage, error) {
|
2016-01-29 20:08:11 -05:00
|
|
|
var pbs []json.RawMessage
|
|
|
|
|
|
|
|
// Enumerate through the port bindings specified by the user and convert
|
|
|
|
// them into the internal structure matching the JSON blob that can be
|
|
|
|
// understood by the HCS.
|
|
|
|
for _, elem := range portBindings {
|
|
|
|
proto := strings.ToUpper(elem.Proto.String())
|
|
|
|
if proto != "TCP" && proto != "UDP" {
|
|
|
|
return nil, fmt.Errorf("invalid protocol %s", elem.Proto.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
if elem.HostPort != elem.HostPortEnd {
|
|
|
|
return nil, fmt.Errorf("Windows does not support more than one host port in NAT settings")
|
|
|
|
}
|
|
|
|
|
2019-05-13 16:31:29 -04:00
|
|
|
if len(elem.HostIP) != 0 && !elem.HostIP.IsUnspecified() {
|
2016-01-29 20:08:11 -05:00
|
|
|
return nil, fmt.Errorf("Windows does not support host IP addresses in NAT settings")
|
|
|
|
}
|
|
|
|
|
|
|
|
encodedPolicy, err := json.Marshal(hcsshim.NatPolicy{
|
|
|
|
Type: "NAT",
|
|
|
|
ExternalPort: elem.HostPort,
|
|
|
|
InternalPort: elem.Port,
|
|
|
|
Protocol: elem.Proto.String(),
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
pbs = append(pbs, encodedPolicy)
|
|
|
|
}
|
|
|
|
return pbs, nil
|
|
|
|
}
|
|
|
|
|
2017-07-07 02:00:01 -04:00
|
|
|
// ParsePortBindingPolicies parses HNS endpoint response message to PortBindings
|
|
|
|
func ParsePortBindingPolicies(policies []json.RawMessage) ([]types.PortBinding, error) {
|
2016-02-25 18:06:16 -05:00
|
|
|
var bindings []types.PortBinding
|
|
|
|
hcsPolicy := &hcsshim.NatPolicy{}
|
|
|
|
|
|
|
|
for _, elem := range policies {
|
|
|
|
|
|
|
|
if err := json.Unmarshal([]byte(elem), &hcsPolicy); err != nil || hcsPolicy.Type != "NAT" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
binding := types.PortBinding{
|
|
|
|
HostPort: hcsPolicy.ExternalPort,
|
|
|
|
HostPortEnd: hcsPolicy.ExternalPort,
|
|
|
|
Port: hcsPolicy.InternalPort,
|
|
|
|
Proto: types.ParseProtocol(hcsPolicy.Protocol),
|
|
|
|
HostIP: net.IPv4(0, 0, 0, 0),
|
|
|
|
}
|
|
|
|
|
|
|
|
bindings = append(bindings, binding)
|
|
|
|
}
|
|
|
|
|
|
|
|
return bindings, nil
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
func parseEndpointOptions(epOptions map[string]interface{}) (*endpointOption, error) {
|
2016-02-25 18:06:16 -05:00
|
|
|
if epOptions == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
ec := &endpointOption{}
|
2016-02-25 18:06:16 -05:00
|
|
|
|
|
|
|
if opt, ok := epOptions[netlabel.MacAddress]; ok {
|
|
|
|
if mac, ok := opt.(net.HardwareAddr); ok {
|
|
|
|
ec.MacAddress = mac
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("Invalid endpoint configuration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
if opt, ok := epOptions[QosPolicies]; ok {
|
|
|
|
if policies, ok := opt.([]types.QosPolicy); ok {
|
|
|
|
ec.QosPolicies = policies
|
2016-02-25 18:06:16 -05:00
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("Invalid endpoint configuration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
if opt, ok := epOptions[netlabel.DNSServers]; ok {
|
|
|
|
if dns, ok := opt.([]string); ok {
|
|
|
|
ec.DNSServers = dns
|
2016-02-25 18:06:16 -05:00
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("Invalid endpoint configuration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
if opt, ok := epOptions[DisableICC]; ok {
|
|
|
|
if disableICC, ok := opt.(bool); ok {
|
|
|
|
ec.DisableICC = disableICC
|
2016-03-28 17:50:55 -04:00
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("Invalid endpoint configuration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
if opt, ok := epOptions[DisableDNS]; ok {
|
|
|
|
if disableDNS, ok := opt.(bool); ok {
|
|
|
|
ec.DisableDNS = disableDNS
|
2016-09-19 18:48:06 -04:00
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("Invalid endpoint configuration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:06:16 -05:00
|
|
|
return ec, nil
|
|
|
|
}
|
|
|
|
|
2017-07-07 02:00:01 -04:00
|
|
|
// ParseEndpointConnectivity parses options passed to CreateEndpoint, specifically port bindings, and store in a endpointConnectivity object.
|
2017-08-09 17:55:04 -04:00
|
|
|
func ParseEndpointConnectivity(epOptions map[string]interface{}) (*EndpointConnectivity, error) {
|
2016-11-04 16:26:50 -04:00
|
|
|
if epOptions == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-08-09 17:55:04 -04:00
|
|
|
ec := &EndpointConnectivity{}
|
2016-11-04 16:26:50 -04:00
|
|
|
|
|
|
|
if opt, ok := epOptions[netlabel.PortMap]; ok {
|
|
|
|
if bs, ok := opt.([]types.PortBinding); ok {
|
|
|
|
ec.PortBindings = bs
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("Invalid endpoint configuration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
|
|
|
|
if ports, ok := opt.([]types.TransportPort); ok {
|
|
|
|
ec.ExposedPorts = ports
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("Invalid endpoint configuration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ec, nil
|
|
|
|
}
|
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
|
2016-01-29 20:08:11 -05:00
|
|
|
n, err := d.getNetwork(nid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if endpoint id is good and retrieve corresponding endpoint
|
|
|
|
ep, err := n.getEndpoint(eid)
|
|
|
|
if err == nil && ep != nil {
|
|
|
|
return driverapi.ErrEndpointExists(eid)
|
|
|
|
}
|
|
|
|
|
|
|
|
endpointStruct := &hcsshim.HNSEndpoint{
|
|
|
|
VirtualNetwork: n.config.HnsID,
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
epOption, err := parseEndpointOptions(epOptions)
|
2017-06-12 14:30:30 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-07-07 02:00:01 -04:00
|
|
|
epConnectivity, err := ParseEndpointConnectivity(epOptions)
|
2017-06-12 14:30:30 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-25 18:06:16 -05:00
|
|
|
|
2016-03-16 14:07:20 -04:00
|
|
|
macAddress := ifInfo.MacAddress()
|
|
|
|
// Use the macaddress if it was provided
|
|
|
|
if macAddress != nil {
|
|
|
|
endpointStruct.MacAddress = strings.Replace(macAddress.String(), ":", "-", -1)
|
2016-02-25 18:06:16 -05:00
|
|
|
}
|
|
|
|
|
2019-04-17 13:54:10 -04:00
|
|
|
portMapping := epConnectivity.PortBindings
|
|
|
|
|
|
|
|
if n.config.Type == "l2bridge" || n.config.Type == "l2tunnel" {
|
|
|
|
ip := net.IPv4(0, 0, 0, 0)
|
|
|
|
if ifInfo.Address() != nil {
|
|
|
|
ip = ifInfo.Address().IP
|
|
|
|
}
|
|
|
|
|
|
|
|
portMapping, err = AllocatePorts(n.portMapper, portMapping, ip)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
ReleasePorts(n.portMapper, portMapping)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
endpointStruct.Policies, err = ConvertPortBindings(portMapping)
|
2016-03-28 17:50:55 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-25 18:06:16 -05:00
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
qosPolicies, err := convertQosPolicies(epOption.QosPolicies)
|
2016-02-25 18:06:16 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-01-29 20:08:11 -05:00
|
|
|
}
|
2016-03-28 17:50:55 -04:00
|
|
|
endpointStruct.Policies = append(endpointStruct.Policies, qosPolicies...)
|
2016-01-29 20:08:11 -05:00
|
|
|
|
2016-04-20 18:44:32 -04:00
|
|
|
if ifInfo.Address() != nil {
|
|
|
|
endpointStruct.IPAddress = ifInfo.Address().IP
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
endpointStruct.DNSServerList = strings.Join(epOption.DNSServers, ",")
|
2016-09-19 18:48:06 -04:00
|
|
|
|
2017-11-21 14:35:32 -05:00
|
|
|
// overwrite the ep DisableDNS option if DisableGatewayDNS was set to true during the network creation option
|
|
|
|
if n.config.DisableGatewayDNS {
|
|
|
|
logrus.Debugf("n.config.DisableGatewayDNS[%v] overwrites epOption.DisableDNS[%v]", n.config.DisableGatewayDNS, epOption.DisableDNS)
|
|
|
|
epOption.DisableDNS = n.config.DisableGatewayDNS
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
if n.driver.name == "nat" && !epOption.DisableDNS {
|
2017-11-21 14:35:32 -05:00
|
|
|
logrus.Debugf("endpointStruct.EnableInternalDNS =[%v]", endpointStruct.EnableInternalDNS)
|
2016-09-19 18:48:06 -04:00
|
|
|
endpointStruct.EnableInternalDNS = true
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
endpointStruct.DisableICC = epOption.DisableICC
|
|
|
|
|
2018-02-05 19:55:56 -05:00
|
|
|
// Inherit OutboundNat policy from the network
|
|
|
|
if n.config.EnableOutboundNat {
|
|
|
|
outboundNatPolicy, err := json.Marshal(hcsshim.OutboundNatPolicy{
|
|
|
|
Policy: hcsshim.Policy{Type: hcsshim.OutboundNat},
|
|
|
|
Exceptions: n.config.OutboundNatExceptions,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
endpointStruct.Policies = append(endpointStruct.Policies, outboundNatPolicy)
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
configurationb, err := json.Marshal(endpointStruct)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
hnsresponse, err := hcsshim.HNSEndpointRequest("POST", "", string(configurationb))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
mac, err := net.ParseMAC(hnsresponse.MacAddress)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO For now the ip mask is not in the info generated by HNS
|
|
|
|
endpoint := &hnsEndpoint{
|
|
|
|
id: eid,
|
2017-05-16 17:06:43 -04:00
|
|
|
nid: n.id,
|
|
|
|
Type: d.name,
|
2016-01-29 20:08:11 -05:00
|
|
|
addr: &net.IPNet{IP: hnsresponse.IPAddress, Mask: hnsresponse.IPAddress.DefaultMask()},
|
|
|
|
macAddress: mac,
|
|
|
|
}
|
2016-02-25 18:06:16 -05:00
|
|
|
|
2016-11-04 16:26:50 -04:00
|
|
|
if hnsresponse.GatewayAddress != "" {
|
|
|
|
endpoint.gateway = net.ParseIP(hnsresponse.GatewayAddress)
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
endpoint.profileID = hnsresponse.Id
|
2016-11-04 16:26:50 -04:00
|
|
|
endpoint.epConnectivity = epConnectivity
|
|
|
|
endpoint.epOption = epOption
|
2017-07-07 02:00:01 -04:00
|
|
|
endpoint.portMapping, err = ParsePortBindingPolicies(hnsresponse.Policies)
|
2016-02-25 18:06:16 -05:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
hcsshim.HNSEndpointRequest("DELETE", hnsresponse.Id, "")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
n.Lock()
|
|
|
|
n.endpoints[eid] = endpoint
|
|
|
|
n.Unlock()
|
|
|
|
|
2016-04-20 18:44:32 -04:00
|
|
|
if ifInfo.Address() == nil {
|
|
|
|
ifInfo.SetIPAddress(endpoint.addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if macAddress == nil {
|
|
|
|
ifInfo.SetMacAddress(endpoint.macAddress)
|
|
|
|
}
|
2016-01-29 20:08:11 -05:00
|
|
|
|
2017-05-16 17:06:43 -04:00
|
|
|
if err = d.storeUpdate(endpoint); err != nil {
|
2018-07-05 16:33:01 -04:00
|
|
|
logrus.Errorf("Failed to save endpoint %.7s to store: %v", endpoint.id, err)
|
2017-05-16 17:06:43 -04:00
|
|
|
}
|
|
|
|
|
2015-05-26 13:46:21 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-02 01:00:48 -04:00
|
|
|
func (d *driver) DeleteEndpoint(nid, eid string) error {
|
2016-01-29 20:08:11 -05:00
|
|
|
n, err := d.getNetwork(nid)
|
|
|
|
if err != nil {
|
|
|
|
return types.InternalMaskableErrorf("%s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ep, err := n.getEndpoint(eid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-04-17 13:54:10 -04:00
|
|
|
if n.config.Type == "l2bridge" || n.config.Type == "l2tunnel" {
|
|
|
|
ReleasePorts(n.portMapper, ep.portMapping)
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
n.Lock()
|
|
|
|
delete(n.endpoints, eid)
|
|
|
|
n.Unlock()
|
|
|
|
|
|
|
|
_, err = hcsshim.HNSEndpointRequest("DELETE", ep.profileID, "")
|
2017-05-16 17:06:43 -04:00
|
|
|
if err != nil && err.Error() != errNotFound {
|
2016-01-29 20:08:11 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-05-16 17:06:43 -04:00
|
|
|
if err := d.storeDelete(ep); err != nil {
|
2018-07-05 16:33:01 -04:00
|
|
|
logrus.Warnf("Failed to remove bridge endpoint %.7s from store: %v", ep.id, err)
|
2017-05-16 17:06:43 -04:00
|
|
|
}
|
2015-05-26 13:46:21 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-02 01:00:48 -04:00
|
|
|
func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
|
2016-01-29 20:08:11 -05:00
|
|
|
network, err := d.getNetwork(nid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:06:16 -05:00
|
|
|
ep, err := network.getEndpoint(eid)
|
2016-01-29 20:08:11 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
data := make(map[string]interface{}, 1)
|
2016-09-19 18:48:06 -04:00
|
|
|
if network.driver.name == "nat" {
|
|
|
|
data["AllowUnqualifiedDNSQuery"] = true
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:06:16 -05:00
|
|
|
data["hnsid"] = ep.profileID
|
2016-11-04 16:26:50 -04:00
|
|
|
if ep.epConnectivity.ExposedPorts != nil {
|
2016-02-25 18:06:16 -05:00
|
|
|
// Return a copy of the config data
|
2016-11-04 16:26:50 -04:00
|
|
|
epc := make([]types.TransportPort, 0, len(ep.epConnectivity.ExposedPorts))
|
|
|
|
for _, tp := range ep.epConnectivity.ExposedPorts {
|
2016-02-25 18:06:16 -05:00
|
|
|
epc = append(epc, tp.GetCopy())
|
|
|
|
}
|
|
|
|
data[netlabel.ExposedPorts] = epc
|
|
|
|
}
|
|
|
|
|
|
|
|
if ep.portMapping != nil {
|
|
|
|
// Return a copy of the operational data
|
|
|
|
pmc := make([]types.PortBinding, 0, len(ep.portMapping))
|
|
|
|
for _, pm := range ep.portMapping {
|
|
|
|
pmc = append(pmc, pm.GetCopy())
|
|
|
|
}
|
|
|
|
data[netlabel.PortMap] = pmc
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(ep.macAddress) != 0 {
|
|
|
|
data[netlabel.MacAddress] = ep.macAddress
|
|
|
|
}
|
2016-01-29 20:08:11 -05:00
|
|
|
return data, nil
|
2015-05-26 13:46:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Join method is invoked when a Sandbox is attached to an endpoint.
|
2015-07-02 01:00:48 -04:00
|
|
|
func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
|
2016-01-29 20:08:11 -05:00
|
|
|
network, err := d.getNetwork(nid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that the endpoint exists
|
2016-11-04 16:26:50 -04:00
|
|
|
endpoint, err := network.getEndpoint(eid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = jinfo.SetGateway(endpoint.gateway)
|
2016-01-29 20:08:11 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-10-02 19:08:59 -04:00
|
|
|
endpoint.sandboxID = sboxKey
|
2017-03-30 23:31:34 -04:00
|
|
|
|
2017-10-02 19:08:59 -04:00
|
|
|
err = hcsshim.HotAttachEndpoint(endpoint.sandboxID, endpoint.profileID)
|
2017-03-30 23:31:34 -04:00
|
|
|
if err != nil {
|
|
|
|
// If container doesn't exists in hcs, do not throw error for hot add/remove
|
|
|
|
if err != hcsshim.ErrComputeSystemDoesNotExist {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-01-29 20:08:11 -05:00
|
|
|
|
|
|
|
jinfo.DisableGatewayService()
|
2015-05-26 13:46:21 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Leave method is invoked when a Sandbox detaches from an endpoint.
|
2015-07-02 01:00:48 -04:00
|
|
|
func (d *driver) Leave(nid, eid string) error {
|
2016-01-29 20:08:11 -05:00
|
|
|
network, err := d.getNetwork(nid)
|
|
|
|
if err != nil {
|
|
|
|
return types.InternalMaskableErrorf("%s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that the endpoint exists
|
2017-03-30 23:31:34 -04:00
|
|
|
endpoint, err := network.getEndpoint(eid)
|
2016-01-29 20:08:11 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-10-02 19:08:59 -04:00
|
|
|
err = hcsshim.HotDetachEndpoint(endpoint.sandboxID, endpoint.profileID)
|
2017-03-30 23:31:34 -04:00
|
|
|
if err != nil {
|
|
|
|
// If container doesn't exists in hcs, do not throw error for hot add/remove
|
|
|
|
if err != hcsshim.ErrComputeSystemDoesNotExist {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2015-05-26 13:46:21 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-07 17:45:51 -05:00
|
|
|
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-26 14:54:35 -05:00
|
|
|
func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
|
2016-04-13 04:04:58 -04:00
|
|
|
return nil, types.NotImplementedErrorf("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) NetworkFree(id string) error {
|
|
|
|
return types.NotImplementedErrorf("not implemented")
|
|
|
|
}
|
|
|
|
|
2015-05-26 13:46:21 -04:00
|
|
|
func (d *driver) Type() string {
|
2016-01-29 20:08:11 -05:00
|
|
|
return d.name
|
2015-05-26 13:46:21 -04:00
|
|
|
}
|
2015-09-18 15:54:08 -04:00
|
|
|
|
2016-12-18 22:56:34 -05:00
|
|
|
func (d *driver) IsBuiltIn() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-09-18 15:54:08 -04:00
|
|
|
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
|
2016-01-28 14:54:03 -05:00
|
|
|
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
|
2015-09-18 15:54:08 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
|
2016-01-28 14:54:03 -05:00
|
|
|
func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
|
2015-09-18 15:54:08 -04:00
|
|
|
return nil
|
|
|
|
}
|