|
@@ -24,41 +24,6 @@ import (
|
|
"github.com/docker/docker/pkg/stringid"
|
|
"github.com/docker/docker/pkg/stringid"
|
|
)
|
|
)
|
|
|
|
|
|
-// A Network represents a logical connectivity zone that containers may
|
|
|
|
-// join using the Link method. A Network is managed by a specific driver.
|
|
|
|
-type Network interface {
|
|
|
|
- // Name returns a user chosen name for this network.
|
|
|
|
- Name() string
|
|
|
|
-
|
|
|
|
- // ID returns a system generated id for this network.
|
|
|
|
- ID() string
|
|
|
|
-
|
|
|
|
- // Type returns the type of network, which corresponds to its managing driver.
|
|
|
|
- Type() string
|
|
|
|
-
|
|
|
|
- // CreateEndpoint creates a new endpoint to this network symbolically identified by the
|
|
|
|
- // specified unique name. The options parameter carries driver specific options.
|
|
|
|
- CreateEndpoint(name string, options ...EndpointOption) (*Endpoint, error)
|
|
|
|
-
|
|
|
|
- // Delete the network.
|
|
|
|
- Delete(options ...NetworkDeleteOption) error
|
|
|
|
-
|
|
|
|
- // Endpoints returns the list of Endpoint(s) in this network.
|
|
|
|
- Endpoints() []*Endpoint
|
|
|
|
-
|
|
|
|
- // WalkEndpoints uses the provided function to walk the Endpoints.
|
|
|
|
- WalkEndpoints(walker EndpointWalker)
|
|
|
|
-
|
|
|
|
- // EndpointByName returns the Endpoint which has the passed name. If not found, the error ErrNoSuchEndpoint is returned.
|
|
|
|
- EndpointByName(name string) (*Endpoint, error)
|
|
|
|
-
|
|
|
|
- // EndpointByID returns the Endpoint which has the passed id. If not found, the error ErrNoSuchEndpoint is returned.
|
|
|
|
- EndpointByID(id string) (*Endpoint, error)
|
|
|
|
-
|
|
|
|
- // Info returns certain operational data belonging to this network.
|
|
|
|
- Info() NetworkInfo
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// NetworkInfo returns some configuration and operational information about the network
|
|
// NetworkInfo returns some configuration and operational information about the network
|
|
type NetworkInfo interface {
|
|
type NetworkInfo interface {
|
|
IpamConfig() (string, map[string]string, []*IpamConf, []*IpamConf)
|
|
IpamConfig() (string, map[string]string, []*IpamConf, []*IpamConf)
|
|
@@ -199,7 +164,9 @@ func (i *IpamInfo) UnmarshalJSON(data []byte) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-type network struct {
|
|
|
|
|
|
+// Network represents a logical connectivity zone that containers may
|
|
|
|
+// join using the Link method. A network is managed by a specific driver.
|
|
|
|
+type Network struct {
|
|
ctrlr *Controller
|
|
ctrlr *Controller
|
|
name string
|
|
name string
|
|
networkType string
|
|
networkType string
|
|
@@ -243,45 +210,48 @@ const (
|
|
loadBalancerModeDefault = loadBalancerModeNAT
|
|
loadBalancerModeDefault = loadBalancerModeNAT
|
|
)
|
|
)
|
|
|
|
|
|
-func (n *network) Name() string {
|
|
|
|
|
|
+// Name returns a user chosen name for this network.
|
|
|
|
+func (n *Network) Name() string {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.name
|
|
return n.name
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ID() string {
|
|
|
|
|
|
+// ID returns a system generated id for this network.
|
|
|
|
+func (n *Network) ID() string {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.id
|
|
return n.id
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Created() time.Time {
|
|
|
|
|
|
+func (n *Network) Created() time.Time {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.created
|
|
return n.created
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Type() string {
|
|
|
|
|
|
+// Type returns the type of network, which corresponds to its managing driver.
|
|
|
|
+func (n *Network) Type() string {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.networkType
|
|
return n.networkType
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Key() []string {
|
|
|
|
|
|
+func (n *Network) Key() []string {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
return []string{datastore.NetworkKeyPrefix, n.id}
|
|
return []string{datastore.NetworkKeyPrefix, n.id}
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) KeyPrefix() []string {
|
|
|
|
|
|
+func (n *Network) KeyPrefix() []string {
|
|
return []string{datastore.NetworkKeyPrefix}
|
|
return []string{datastore.NetworkKeyPrefix}
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Value() []byte {
|
|
|
|
|
|
+func (n *Network) Value() []byte {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
b, err := json.Marshal(n)
|
|
b, err := json.Marshal(n)
|
|
@@ -291,40 +261,40 @@ func (n *network) Value() []byte {
|
|
return b
|
|
return b
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) SetValue(value []byte) error {
|
|
|
|
|
|
+func (n *Network) SetValue(value []byte) error {
|
|
return json.Unmarshal(value, n)
|
|
return json.Unmarshal(value, n)
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Index() uint64 {
|
|
|
|
|
|
+func (n *Network) Index() uint64 {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
return n.dbIndex
|
|
return n.dbIndex
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) SetIndex(index uint64) {
|
|
|
|
|
|
+func (n *Network) SetIndex(index uint64) {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
n.dbIndex = index
|
|
n.dbIndex = index
|
|
n.dbExists = true
|
|
n.dbExists = true
|
|
n.mu.Unlock()
|
|
n.mu.Unlock()
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Exists() bool {
|
|
|
|
|
|
+func (n *Network) Exists() bool {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
return n.dbExists
|
|
return n.dbExists
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Skip() bool {
|
|
|
|
|
|
+func (n *Network) Skip() bool {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
return !n.persist
|
|
return !n.persist
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) New() datastore.KVObject {
|
|
|
|
|
|
+func (n *Network) New() datastore.KVObject {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
- return &network{
|
|
|
|
|
|
+ return &Network{
|
|
ctrlr: n.ctrlr,
|
|
ctrlr: n.ctrlr,
|
|
drvOnce: &sync.Once{},
|
|
drvOnce: &sync.Once{},
|
|
scope: n.scope,
|
|
scope: n.scope,
|
|
@@ -369,7 +339,7 @@ func (i *IpamInfo) CopyTo(dstI *IpamInfo) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) validateConfiguration() error {
|
|
|
|
|
|
+func (n *Network) validateConfiguration() error {
|
|
if n.configOnly {
|
|
if n.configOnly {
|
|
// Only supports network specific configurations.
|
|
// Only supports network specific configurations.
|
|
// Network operator configurations are not supported.
|
|
// Network operator configurations are not supported.
|
|
@@ -417,7 +387,7 @@ func (n *network) validateConfiguration() error {
|
|
}
|
|
}
|
|
|
|
|
|
// applyConfigurationTo applies network specific configurations.
|
|
// applyConfigurationTo applies network specific configurations.
|
|
-func (n *network) applyConfigurationTo(to *network) error {
|
|
|
|
|
|
+func (n *Network) applyConfigurationTo(to *Network) error {
|
|
to.enableIPv6 = n.enableIPv6
|
|
to.enableIPv6 = n.enableIPv6
|
|
if len(n.labels) > 0 {
|
|
if len(n.labels) > 0 {
|
|
to.labels = make(map[string]string, len(n.labels))
|
|
to.labels = make(map[string]string, len(n.labels))
|
|
@@ -455,11 +425,11 @@ func (n *network) applyConfigurationTo(to *network) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) CopyTo(o datastore.KVObject) error {
|
|
|
|
|
|
+func (n *Network) CopyTo(o datastore.KVObject) error {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
- dstN := o.(*network)
|
|
|
|
|
|
+ dstN := o.(*Network)
|
|
dstN.name = n.name
|
|
dstN.name = n.name
|
|
dstN.id = n.id
|
|
dstN.id = n.id
|
|
dstN.created = n.created
|
|
dstN.created = n.created
|
|
@@ -537,7 +507,7 @@ func (n *network) CopyTo(o datastore.KVObject) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) DataScope() string {
|
|
|
|
|
|
+func (n *Network) DataScope() string {
|
|
s := n.Scope()
|
|
s := n.Scope()
|
|
// All swarm scope networks have local datascope
|
|
// All swarm scope networks have local datascope
|
|
if s == datastore.SwarmScope {
|
|
if s == datastore.SwarmScope {
|
|
@@ -546,7 +516,7 @@ func (n *network) DataScope() string {
|
|
return s
|
|
return s
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) getEpCnt() *endpointCnt {
|
|
|
|
|
|
+func (n *Network) getEpCnt() *endpointCnt {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
@@ -554,7 +524,7 @@ func (n *network) getEpCnt() *endpointCnt {
|
|
}
|
|
}
|
|
|
|
|
|
// TODO : Can be made much more generic with the help of reflection (but has some golang limitations)
|
|
// TODO : Can be made much more generic with the help of reflection (but has some golang limitations)
|
|
-func (n *network) MarshalJSON() ([]byte, error) {
|
|
|
|
|
|
+func (n *Network) MarshalJSON() ([]byte, error) {
|
|
netMap := make(map[string]interface{})
|
|
netMap := make(map[string]interface{})
|
|
netMap["name"] = n.name
|
|
netMap["name"] = n.name
|
|
netMap["id"] = n.id
|
|
netMap["id"] = n.id
|
|
@@ -611,7 +581,7 @@ func (n *network) MarshalJSON() ([]byte, error) {
|
|
}
|
|
}
|
|
|
|
|
|
// TODO : Can be made much more generic with the help of reflection (but has some golang limitations)
|
|
// TODO : Can be made much more generic with the help of reflection (but has some golang limitations)
|
|
-func (n *network) UnmarshalJSON(b []byte) (err error) {
|
|
|
|
|
|
+func (n *Network) UnmarshalJSON(b []byte) (err error) {
|
|
var netMap map[string]interface{}
|
|
var netMap map[string]interface{}
|
|
if err := json.Unmarshal(b, &netMap); err != nil {
|
|
if err := json.Unmarshal(b, &netMap); err != nil {
|
|
return err
|
|
return err
|
|
@@ -734,12 +704,12 @@ func (n *network) UnmarshalJSON(b []byte) (err error) {
|
|
// NetworkOption is an option setter function type used to pass various options to
|
|
// NetworkOption is an option setter function type used to pass various options to
|
|
// NewNetwork method. The various setter functions of type NetworkOption are
|
|
// NewNetwork method. The various setter functions of type NetworkOption are
|
|
// provided by libnetwork, they look like NetworkOptionXXXX(...)
|
|
// provided by libnetwork, they look like NetworkOptionXXXX(...)
|
|
-type NetworkOption func(n *network)
|
|
|
|
|
|
+type NetworkOption func(n *Network)
|
|
|
|
|
|
// NetworkOptionGeneric function returns an option setter for a Generic option defined
|
|
// NetworkOptionGeneric function returns an option setter for a Generic option defined
|
|
// in a Dictionary of Key-Value pair
|
|
// in a Dictionary of Key-Value pair
|
|
func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption {
|
|
func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
if n.generic == nil {
|
|
if n.generic == nil {
|
|
n.generic = make(map[string]interface{})
|
|
n.generic = make(map[string]interface{})
|
|
}
|
|
}
|
|
@@ -758,21 +728,21 @@ func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption {
|
|
// NetworkOptionIngress returns an option setter to indicate if a network is
|
|
// NetworkOptionIngress returns an option setter to indicate if a network is
|
|
// an ingress network.
|
|
// an ingress network.
|
|
func NetworkOptionIngress(ingress bool) NetworkOption {
|
|
func NetworkOptionIngress(ingress bool) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.ingress = ingress
|
|
n.ingress = ingress
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// NetworkOptionPersist returns an option setter to set persistence policy for a network
|
|
// NetworkOptionPersist returns an option setter to set persistence policy for a network
|
|
func NetworkOptionPersist(persist bool) NetworkOption {
|
|
func NetworkOptionPersist(persist bool) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.persist = persist
|
|
n.persist = persist
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// NetworkOptionEnableIPv6 returns an option setter to explicitly configure IPv6
|
|
// NetworkOptionEnableIPv6 returns an option setter to explicitly configure IPv6
|
|
func NetworkOptionEnableIPv6(enableIPv6 bool) NetworkOption {
|
|
func NetworkOptionEnableIPv6(enableIPv6 bool) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
if n.generic == nil {
|
|
if n.generic == nil {
|
|
n.generic = make(map[string]interface{})
|
|
n.generic = make(map[string]interface{})
|
|
}
|
|
}
|
|
@@ -784,7 +754,7 @@ func NetworkOptionEnableIPv6(enableIPv6 bool) NetworkOption {
|
|
// NetworkOptionInternalNetwork returns an option setter to config the network
|
|
// NetworkOptionInternalNetwork returns an option setter to config the network
|
|
// to be internal which disables default gateway service
|
|
// to be internal which disables default gateway service
|
|
func NetworkOptionInternalNetwork() NetworkOption {
|
|
func NetworkOptionInternalNetwork() NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
if n.generic == nil {
|
|
if n.generic == nil {
|
|
n.generic = make(map[string]interface{})
|
|
n.generic = make(map[string]interface{})
|
|
}
|
|
}
|
|
@@ -795,7 +765,7 @@ func NetworkOptionInternalNetwork() NetworkOption {
|
|
|
|
|
|
// NetworkOptionAttachable returns an option setter to set attachable for a network
|
|
// NetworkOptionAttachable returns an option setter to set attachable for a network
|
|
func NetworkOptionAttachable(attachable bool) NetworkOption {
|
|
func NetworkOptionAttachable(attachable bool) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.attachable = attachable
|
|
n.attachable = attachable
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -803,14 +773,14 @@ func NetworkOptionAttachable(attachable bool) NetworkOption {
|
|
// NetworkOptionScope returns an option setter to overwrite the network's scope.
|
|
// NetworkOptionScope returns an option setter to overwrite the network's scope.
|
|
// By default the network's scope is set to the network driver's datascope.
|
|
// By default the network's scope is set to the network driver's datascope.
|
|
func NetworkOptionScope(scope string) NetworkOption {
|
|
func NetworkOptionScope(scope string) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.scope = scope
|
|
n.scope = scope
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// NetworkOptionIpam function returns an option setter for the ipam configuration for this network
|
|
// NetworkOptionIpam function returns an option setter for the ipam configuration for this network
|
|
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf, opts map[string]string) NetworkOption {
|
|
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf, opts map[string]string) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
if ipamDriver != "" {
|
|
if ipamDriver != "" {
|
|
n.ipamType = ipamDriver
|
|
n.ipamType = ipamDriver
|
|
if ipamDriver == ipamapi.DefaultIPAM {
|
|
if ipamDriver == ipamapi.DefaultIPAM {
|
|
@@ -826,14 +796,14 @@ func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ip
|
|
|
|
|
|
// NetworkOptionLBEndpoint function returns an option setter for the configuration of the load balancer endpoint for this network
|
|
// NetworkOptionLBEndpoint function returns an option setter for the configuration of the load balancer endpoint for this network
|
|
func NetworkOptionLBEndpoint(ip net.IP) NetworkOption {
|
|
func NetworkOptionLBEndpoint(ip net.IP) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.loadBalancerIP = ip
|
|
n.loadBalancerIP = ip
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// NetworkOptionDriverOpts function returns an option setter for any driver parameter described by a map
|
|
// NetworkOptionDriverOpts function returns an option setter for any driver parameter described by a map
|
|
func NetworkOptionDriverOpts(opts map[string]string) NetworkOption {
|
|
func NetworkOptionDriverOpts(opts map[string]string) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
if n.generic == nil {
|
|
if n.generic == nil {
|
|
n.generic = make(map[string]interface{})
|
|
n.generic = make(map[string]interface{})
|
|
}
|
|
}
|
|
@@ -847,14 +817,14 @@ func NetworkOptionDriverOpts(opts map[string]string) NetworkOption {
|
|
|
|
|
|
// NetworkOptionLabels function returns an option setter for labels specific to a network
|
|
// NetworkOptionLabels function returns an option setter for labels specific to a network
|
|
func NetworkOptionLabels(labels map[string]string) NetworkOption {
|
|
func NetworkOptionLabels(labels map[string]string) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.labels = labels
|
|
n.labels = labels
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// NetworkOptionDynamic function returns an option setter for dynamic option for a network
|
|
// NetworkOptionDynamic function returns an option setter for dynamic option for a network
|
|
func NetworkOptionDynamic() NetworkOption {
|
|
func NetworkOptionDynamic() NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.dynamic = true
|
|
n.dynamic = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -864,7 +834,7 @@ func NetworkOptionDynamic() NetworkOption {
|
|
// to a container as combination of fixed-cidr-v6 + mac-address
|
|
// to a container as combination of fixed-cidr-v6 + mac-address
|
|
// TODO: Remove this option setter once we support endpoint ipam options
|
|
// TODO: Remove this option setter once we support endpoint ipam options
|
|
func NetworkOptionDeferIPv6Alloc(enable bool) NetworkOption {
|
|
func NetworkOptionDeferIPv6Alloc(enable bool) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.postIPv6 = enable
|
|
n.postIPv6 = enable
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -873,7 +843,7 @@ func NetworkOptionDeferIPv6Alloc(enable bool) NetworkOption {
|
|
// a configuration only network. It serves as a configuration
|
|
// a configuration only network. It serves as a configuration
|
|
// for other networks.
|
|
// for other networks.
|
|
func NetworkOptionConfigOnly() NetworkOption {
|
|
func NetworkOptionConfigOnly() NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.configOnly = true
|
|
n.configOnly = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -881,12 +851,12 @@ func NetworkOptionConfigOnly() NetworkOption {
|
|
// NetworkOptionConfigFrom tells controller to pick the
|
|
// NetworkOptionConfigFrom tells controller to pick the
|
|
// network configuration from a configuration only network
|
|
// network configuration from a configuration only network
|
|
func NetworkOptionConfigFrom(name string) NetworkOption {
|
|
func NetworkOptionConfigFrom(name string) NetworkOption {
|
|
- return func(n *network) {
|
|
|
|
|
|
+ return func(n *Network) {
|
|
n.configFrom = name
|
|
n.configFrom = name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) processOptions(options ...NetworkOption) {
|
|
|
|
|
|
+func (n *Network) processOptions(options ...NetworkOption) {
|
|
for _, opt := range options {
|
|
for _, opt := range options {
|
|
if opt != nil {
|
|
if opt != nil {
|
|
opt(n)
|
|
opt(n)
|
|
@@ -899,10 +869,10 @@ type networkDeleteParams struct {
|
|
}
|
|
}
|
|
|
|
|
|
// NetworkDeleteOption is a type for optional parameters to pass to the
|
|
// NetworkDeleteOption is a type for optional parameters to pass to the
|
|
-// network.Delete() function.
|
|
|
|
|
|
+// Network.Delete() function.
|
|
type NetworkDeleteOption func(p *networkDeleteParams)
|
|
type NetworkDeleteOption func(p *networkDeleteParams)
|
|
|
|
|
|
-// NetworkDeleteOptionRemoveLB informs a network.Delete() operation that should
|
|
|
|
|
|
+// NetworkDeleteOptionRemoveLB informs a Network.Delete() operation that should
|
|
// remove the load balancer endpoint for this network. Note that the Delete()
|
|
// remove the load balancer endpoint for this network. Note that the Delete()
|
|
// method will automatically remove a load balancing endpoint for most networks
|
|
// method will automatically remove a load balancing endpoint for most networks
|
|
// when the network is otherwise empty. However, this does not occur for some
|
|
// when the network is otherwise empty. However, this does not occur for some
|
|
@@ -916,7 +886,7 @@ func NetworkDeleteOptionRemoveLB(p *networkDeleteParams) {
|
|
p.rmLBEndpoint = true
|
|
p.rmLBEndpoint = true
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) resolveDriver(name string, load bool) (driverapi.Driver, driverapi.Capability, error) {
|
|
|
|
|
|
+func (n *Network) resolveDriver(name string, load bool) (driverapi.Driver, driverapi.Capability, error) {
|
|
c := n.getController()
|
|
c := n.getController()
|
|
|
|
|
|
// Check if a driver for the specified network type is available
|
|
// Check if a driver for the specified network type is available
|
|
@@ -941,7 +911,7 @@ func (n *network) resolveDriver(name string, load bool) (driverapi.Driver, drive
|
|
return d, cap, nil
|
|
return d, cap, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) driverIsMultihost() bool {
|
|
|
|
|
|
+func (n *Network) driverIsMultihost() bool {
|
|
_, cap, err := n.resolveDriver(n.networkType, true)
|
|
_, cap, err := n.resolveDriver(n.networkType, true)
|
|
if err != nil {
|
|
if err != nil {
|
|
return false
|
|
return false
|
|
@@ -949,7 +919,7 @@ func (n *network) driverIsMultihost() bool {
|
|
return cap.ConnectivityScope == datastore.GlobalScope
|
|
return cap.ConnectivityScope == datastore.GlobalScope
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) driver(load bool) (driverapi.Driver, error) {
|
|
|
|
|
|
+func (n *Network) driver(load bool) (driverapi.Driver, error) {
|
|
d, cap, err := n.resolveDriver(n.networkType, load)
|
|
d, cap, err := n.resolveDriver(n.networkType, load)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
@@ -969,7 +939,8 @@ func (n *network) driver(load bool) (driverapi.Driver, error) {
|
|
return d, nil
|
|
return d, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Delete(options ...NetworkDeleteOption) error {
|
|
|
|
|
|
+// Delete the network.
|
|
|
|
+func (n *Network) Delete(options ...NetworkDeleteOption) error {
|
|
var params networkDeleteParams
|
|
var params networkDeleteParams
|
|
for _, opt := range options {
|
|
for _, opt := range options {
|
|
opt(¶ms)
|
|
opt(¶ms)
|
|
@@ -985,7 +956,7 @@ func (n *network) Delete(options ...NetworkDeleteOption) error {
|
|
// remove load balancer and network if endpoint count == 1
|
|
// remove load balancer and network if endpoint count == 1
|
|
// - controller.networkCleanup() -- (true, true)
|
|
// - controller.networkCleanup() -- (true, true)
|
|
// remove the network no matter what
|
|
// remove the network no matter what
|
|
-func (n *network) delete(force bool, rmLBEndpoint bool) error {
|
|
|
|
|
|
+func (n *Network) delete(force bool, rmLBEndpoint bool) error {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
c := n.ctrlr
|
|
c := n.ctrlr
|
|
name := n.name
|
|
name := n.name
|
|
@@ -1093,7 +1064,7 @@ func (n *network) delete(force bool, rmLBEndpoint bool) error {
|
|
|
|
|
|
removeFromStore:
|
|
removeFromStore:
|
|
// deleteFromStore performs an atomic delete operation and the
|
|
// deleteFromStore performs an atomic delete operation and the
|
|
- // network.epCnt will help prevent any possible
|
|
|
|
|
|
+ // Network.epCnt will help prevent any possible
|
|
// race between endpoint join and network delete
|
|
// race between endpoint join and network delete
|
|
if err = c.deleteFromStore(n.getEpCnt()); err != nil {
|
|
if err = c.deleteFromStore(n.getEpCnt()); err != nil {
|
|
if !force {
|
|
if !force {
|
|
@@ -1109,10 +1080,10 @@ removeFromStore:
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) deleteNetwork() error {
|
|
|
|
|
|
+func (n *Network) deleteNetwork() error {
|
|
d, err := n.driver(true)
|
|
d, err := n.driver(true)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return fmt.Errorf("failed deleting network: %v", err)
|
|
|
|
|
|
+ return fmt.Errorf("failed deleting Network: %v", err)
|
|
}
|
|
}
|
|
|
|
|
|
if err := d.DeleteNetwork(n.ID()); err != nil {
|
|
if err := d.DeleteNetwork(n.ID()); err != nil {
|
|
@@ -1132,7 +1103,7 @@ func (n *network) deleteNetwork() error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) addEndpoint(ep *Endpoint) error {
|
|
|
|
|
|
+func (n *Network) addEndpoint(ep *Endpoint) error {
|
|
d, err := n.driver(true)
|
|
d, err := n.driver(true)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("failed to add endpoint: %v", err)
|
|
return fmt.Errorf("failed to add endpoint: %v", err)
|
|
@@ -1147,7 +1118,9 @@ func (n *network) addEndpoint(ep *Endpoint) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) CreateEndpoint(name string, options ...EndpointOption) (*Endpoint, error) {
|
|
|
|
|
|
+// CreateEndpoint creates a new endpoint to this network symbolically identified by the
|
|
|
|
+// specified unique name. The options parameter carries driver specific options.
|
|
|
|
+func (n *Network) CreateEndpoint(name string, options ...EndpointOption) (*Endpoint, error) {
|
|
var err error
|
|
var err error
|
|
if strings.TrimSpace(name) == "" {
|
|
if strings.TrimSpace(name) == "" {
|
|
return nil, ErrInvalidName(name)
|
|
return nil, ErrInvalidName(name)
|
|
@@ -1167,7 +1140,7 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (*Endpo
|
|
return n.createEndpoint(name, options...)
|
|
return n.createEndpoint(name, options...)
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) createEndpoint(name string, options ...EndpointOption) (*Endpoint, error) {
|
|
|
|
|
|
+func (n *Network) createEndpoint(name string, options ...EndpointOption) (*Endpoint, error) {
|
|
var err error
|
|
var err error
|
|
|
|
|
|
ep := &Endpoint{name: name, generic: make(map[string]interface{}), iface: &endpointInterface{}}
|
|
ep := &Endpoint{name: name, generic: make(map[string]interface{}), iface: &endpointInterface{}}
|
|
@@ -1265,7 +1238,8 @@ func (n *network) createEndpoint(name string, options ...EndpointOption) (*Endpo
|
|
return ep, nil
|
|
return ep, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Endpoints() []*Endpoint {
|
|
|
|
|
|
+// Endpoints returns the list of Endpoint(s) in this network.
|
|
|
|
+func (n *Network) Endpoints() []*Endpoint {
|
|
endpoints, err := n.getEndpointsFromStore()
|
|
endpoints, err := n.getEndpointsFromStore()
|
|
if err != nil {
|
|
if err != nil {
|
|
log.G(context.TODO()).Error(err)
|
|
log.G(context.TODO()).Error(err)
|
|
@@ -1273,7 +1247,8 @@ func (n *network) Endpoints() []*Endpoint {
|
|
return endpoints
|
|
return endpoints
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) WalkEndpoints(walker EndpointWalker) {
|
|
|
|
|
|
+// WalkEndpoints uses the provided function to walk the Endpoints.
|
|
|
|
+func (n *Network) WalkEndpoints(walker EndpointWalker) {
|
|
for _, e := range n.Endpoints() {
|
|
for _, e := range n.Endpoints() {
|
|
if walker(e) {
|
|
if walker(e) {
|
|
return
|
|
return
|
|
@@ -1281,7 +1256,9 @@ func (n *network) WalkEndpoints(walker EndpointWalker) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) EndpointByName(name string) (*Endpoint, error) {
|
|
|
|
|
|
+// EndpointByName returns the Endpoint which has the passed name. If not found,
|
|
|
|
+// the error ErrNoSuchEndpoint is returned.
|
|
|
|
+func (n *Network) EndpointByName(name string) (*Endpoint, error) {
|
|
if name == "" {
|
|
if name == "" {
|
|
return nil, ErrInvalidName(name)
|
|
return nil, ErrInvalidName(name)
|
|
}
|
|
}
|
|
@@ -1304,7 +1281,9 @@ func (n *network) EndpointByName(name string) (*Endpoint, error) {
|
|
return e, nil
|
|
return e, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) EndpointByID(id string) (*Endpoint, error) {
|
|
|
|
|
|
+// EndpointByID returns the Endpoint which has the passed id. If not found,
|
|
|
|
+// the error ErrNoSuchEndpoint is returned.
|
|
|
|
+func (n *Network) EndpointByID(id string) (*Endpoint, error) {
|
|
if id == "" {
|
|
if id == "" {
|
|
return nil, ErrInvalidID(id)
|
|
return nil, ErrInvalidID(id)
|
|
}
|
|
}
|
|
@@ -1317,7 +1296,7 @@ func (n *network) EndpointByID(id string) (*Endpoint, error) {
|
|
return ep, nil
|
|
return ep, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) updateSvcRecord(ep *Endpoint, localEps []*Endpoint, isAdd bool) {
|
|
|
|
|
|
+func (n *Network) updateSvcRecord(ep *Endpoint, localEps []*Endpoint, isAdd bool) {
|
|
var ipv6 net.IP
|
|
var ipv6 net.IP
|
|
epName := ep.Name()
|
|
epName := ep.Name()
|
|
if iface := ep.Iface(); iface != nil && iface.Address() != nil {
|
|
if iface := ep.Iface(); iface != nil && iface.Address() != nil {
|
|
@@ -1393,7 +1372,7 @@ func delNameToIP(svcMap *setmatrix.SetMatrix[svcMapEntry], name, serviceID strin
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) addSvcRecords(eID, name, serviceID string, epIP, epIPv6 net.IP, ipMapUpdate bool, method string) {
|
|
|
|
|
|
+func (n *Network) addSvcRecords(eID, name, serviceID string, epIP, epIPv6 net.IP, ipMapUpdate bool, method string) {
|
|
// Do not add service names for ingress network as this is a
|
|
// Do not add service names for ingress network as this is a
|
|
// routing only network
|
|
// routing only network
|
|
if n.ingress {
|
|
if n.ingress {
|
|
@@ -1425,7 +1404,7 @@ func (n *network) addSvcRecords(eID, name, serviceID string, epIP, epIPv6 net.IP
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) deleteSvcRecords(eID, name, serviceID string, epIP net.IP, epIPv6 net.IP, ipMapUpdate bool, method string) {
|
|
|
|
|
|
+func (n *Network) deleteSvcRecords(eID, name, serviceID string, epIP net.IP, epIPv6 net.IP, ipMapUpdate bool, method string) {
|
|
// Do not delete service names from ingress network as this is a
|
|
// Do not delete service names from ingress network as this is a
|
|
// routing only network
|
|
// routing only network
|
|
if n.ingress {
|
|
if n.ingress {
|
|
@@ -1458,7 +1437,7 @@ func (n *network) deleteSvcRecords(eID, name, serviceID string, epIP net.IP, epI
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) getSvcRecords(ep *Endpoint) []etchosts.Record {
|
|
|
|
|
|
+func (n *Network) getSvcRecords(ep *Endpoint) []etchosts.Record {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
@@ -1503,13 +1482,13 @@ func (n *network) getSvcRecords(ep *Endpoint) []etchosts.Record {
|
|
return recs
|
|
return recs
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) getController() *Controller {
|
|
|
|
|
|
+func (n *Network) getController() *Controller {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
return n.ctrlr
|
|
return n.ctrlr
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ipamAllocate() error {
|
|
|
|
|
|
+func (n *Network) ipamAllocate() error {
|
|
if n.hasSpecialDriver() {
|
|
if n.hasSpecialDriver() {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -1544,7 +1523,7 @@ func (n *network) ipamAllocate() error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) requestPoolHelper(ipam ipamapi.Ipam, addressSpace, preferredPool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
|
|
|
|
|
|
+func (n *Network) requestPoolHelper(ipam ipamapi.Ipam, addressSpace, preferredPool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
|
|
for {
|
|
for {
|
|
poolID, pool, meta, err := ipam.RequestPool(addressSpace, preferredPool, subPool, options, v6)
|
|
poolID, pool, meta, err := ipam.RequestPool(addressSpace, preferredPool, subPool, options, v6)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -1585,7 +1564,7 @@ func (n *network) requestPoolHelper(ipam ipamapi.Ipam, addressSpace, preferredPo
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
|
|
|
|
|
|
+func (n *Network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
|
|
var (
|
|
var (
|
|
cfgList *[]*IpamConf
|
|
cfgList *[]*IpamConf
|
|
infoList *[]*IpamInfo
|
|
infoList *[]*IpamInfo
|
|
@@ -1673,7 +1652,7 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ipamRelease() {
|
|
|
|
|
|
+func (n *Network) ipamRelease() {
|
|
if n.hasSpecialDriver() {
|
|
if n.hasSpecialDriver() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -1686,7 +1665,7 @@ func (n *network) ipamRelease() {
|
|
n.ipamReleaseVersion(6, ipam)
|
|
n.ipamReleaseVersion(6, ipam)
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ipamReleaseVersion(ipVer int, ipam ipamapi.Ipam) {
|
|
|
|
|
|
+func (n *Network) ipamReleaseVersion(ipVer int, ipam ipamapi.Ipam) {
|
|
var infoList *[]*IpamInfo
|
|
var infoList *[]*IpamInfo
|
|
|
|
|
|
switch ipVer {
|
|
switch ipVer {
|
|
@@ -1728,7 +1707,7 @@ func (n *network) ipamReleaseVersion(ipVer int, ipam ipamapi.Ipam) {
|
|
*infoList = nil
|
|
*infoList = nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) getIPInfo(ipVer int) []*IpamInfo {
|
|
|
|
|
|
+func (n *Network) getIPInfo(ipVer int) []*IpamInfo {
|
|
var info []*IpamInfo
|
|
var info []*IpamInfo
|
|
switch ipVer {
|
|
switch ipVer {
|
|
case 4:
|
|
case 4:
|
|
@@ -1745,7 +1724,7 @@ func (n *network) getIPInfo(ipVer int) []*IpamInfo {
|
|
return l
|
|
return l
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) getIPData(ipVer int) []driverapi.IPAMData {
|
|
|
|
|
|
+func (n *Network) getIPData(ipVer int) []driverapi.IPAMData {
|
|
var info []*IpamInfo
|
|
var info []*IpamInfo
|
|
switch ipVer {
|
|
switch ipVer {
|
|
case 4:
|
|
case 4:
|
|
@@ -1764,7 +1743,7 @@ func (n *network) getIPData(ipVer int) []driverapi.IPAMData {
|
|
return l
|
|
return l
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) deriveAddressSpace() (string, error) {
|
|
|
|
|
|
+func (n *Network) deriveAddressSpace() (string, error) {
|
|
ipam, _ := n.getController().ipamRegistry.IPAM(n.ipamType)
|
|
ipam, _ := n.getController().ipamRegistry.IPAM(n.ipamType)
|
|
if ipam == nil {
|
|
if ipam == nil {
|
|
return "", types.NotFoundErrorf("failed to get default address space: unknown ipam type %q", n.ipamType)
|
|
return "", types.NotFoundErrorf("failed to get default address space: unknown ipam type %q", n.ipamType)
|
|
@@ -1779,11 +1758,12 @@ func (n *network) deriveAddressSpace() (string, error) {
|
|
return local, nil
|
|
return local, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Info() NetworkInfo {
|
|
|
|
|
|
+// Info returns certain operational data belonging to this network.
|
|
|
|
+func (n *Network) Info() NetworkInfo {
|
|
return n
|
|
return n
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Peers() []networkdb.PeerInfo {
|
|
|
|
|
|
+func (n *Network) Peers() []networkdb.PeerInfo {
|
|
if !n.Dynamic() {
|
|
if !n.Dynamic() {
|
|
return []networkdb.PeerInfo{}
|
|
return []networkdb.PeerInfo{}
|
|
}
|
|
}
|
|
@@ -1796,7 +1776,7 @@ func (n *network) Peers() []networkdb.PeerInfo {
|
|
return agent.networkDB.Peers(n.ID())
|
|
return agent.networkDB.Peers(n.ID())
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) DriverOptions() map[string]string {
|
|
|
|
|
|
+func (n *Network) DriverOptions() map[string]string {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
if n.generic != nil {
|
|
if n.generic != nil {
|
|
@@ -1807,13 +1787,13 @@ func (n *network) DriverOptions() map[string]string {
|
|
return map[string]string{}
|
|
return map[string]string{}
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Scope() string {
|
|
|
|
|
|
+func (n *Network) Scope() string {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
return n.scope
|
|
return n.scope
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) IpamConfig() (string, map[string]string, []*IpamConf, []*IpamConf) {
|
|
|
|
|
|
+func (n *Network) IpamConfig() (string, map[string]string, []*IpamConf, []*IpamConf) {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
@@ -1839,7 +1819,7 @@ func (n *network) IpamConfig() (string, map[string]string, []*IpamConf, []*IpamC
|
|
return n.ipamType, n.ipamOptions, v4L, v6L
|
|
return n.ipamType, n.ipamOptions, v4L, v6L
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) IpamInfo() ([]*IpamInfo, []*IpamInfo) {
|
|
|
|
|
|
+func (n *Network) IpamInfo() ([]*IpamInfo, []*IpamInfo) {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
@@ -1865,56 +1845,56 @@ func (n *network) IpamInfo() ([]*IpamInfo, []*IpamInfo) {
|
|
return v4Info, v6Info
|
|
return v4Info, v6Info
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Internal() bool {
|
|
|
|
|
|
+func (n *Network) Internal() bool {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.internal
|
|
return n.internal
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Attachable() bool {
|
|
|
|
|
|
+func (n *Network) Attachable() bool {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.attachable
|
|
return n.attachable
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Ingress() bool {
|
|
|
|
|
|
+func (n *Network) Ingress() bool {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.ingress
|
|
return n.ingress
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Dynamic() bool {
|
|
|
|
|
|
+func (n *Network) Dynamic() bool {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.dynamic
|
|
return n.dynamic
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) IPv6Enabled() bool {
|
|
|
|
|
|
+func (n *Network) IPv6Enabled() bool {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.enableIPv6
|
|
return n.enableIPv6
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ConfigFrom() string {
|
|
|
|
|
|
+func (n *Network) ConfigFrom() string {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.configFrom
|
|
return n.configFrom
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ConfigOnly() bool {
|
|
|
|
|
|
+func (n *Network) ConfigOnly() bool {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
return n.configOnly
|
|
return n.configOnly
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) Labels() map[string]string {
|
|
|
|
|
|
+func (n *Network) Labels() map[string]string {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
defer n.mu.Unlock()
|
|
defer n.mu.Unlock()
|
|
|
|
|
|
@@ -1926,7 +1906,7 @@ func (n *network) Labels() map[string]string {
|
|
return lbls
|
|
return lbls
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) TableEventRegister(tableName string, objType driverapi.ObjectType) error {
|
|
|
|
|
|
+func (n *Network) TableEventRegister(tableName string, objType driverapi.ObjectType) error {
|
|
if !driverapi.IsValidType(objType) {
|
|
if !driverapi.IsValidType(objType) {
|
|
return fmt.Errorf("invalid object type %v in registering table, %s", objType, tableName)
|
|
return fmt.Errorf("invalid object type %v in registering table, %s", objType, tableName)
|
|
}
|
|
}
|
|
@@ -1941,7 +1921,7 @@ func (n *network) TableEventRegister(tableName string, objType driverapi.ObjectT
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) UpdateIpamConfig(ipV4Data []driverapi.IPAMData) {
|
|
|
|
|
|
+func (n *Network) UpdateIpamConfig(ipV4Data []driverapi.IPAMData) {
|
|
ipamV4Config := make([]*IpamConf, len(ipV4Data))
|
|
ipamV4Config := make([]*IpamConf, len(ipV4Data))
|
|
|
|
|
|
for i, data := range ipV4Data {
|
|
for i, data := range ipV4Data {
|
|
@@ -1956,16 +1936,16 @@ func (n *network) UpdateIpamConfig(ipV4Data []driverapi.IPAMData) {
|
|
n.ipamV4Config = ipamV4Config
|
|
n.ipamV4Config = ipamV4Config
|
|
}
|
|
}
|
|
|
|
|
|
-// Special drivers are ones which do not need to perform any network plumbing
|
|
|
|
-func (n *network) hasSpecialDriver() bool {
|
|
|
|
|
|
+// Special drivers are ones which do not need to perform any Network plumbing
|
|
|
|
+func (n *Network) hasSpecialDriver() bool {
|
|
return n.Type() == "host" || n.Type() == "null"
|
|
return n.Type() == "host" || n.Type() == "null"
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) hasLoadBalancerEndpoint() bool {
|
|
|
|
|
|
+func (n *Network) hasLoadBalancerEndpoint() bool {
|
|
return len(n.loadBalancerIP) != 0
|
|
return len(n.loadBalancerIP) != 0
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ResolveName(req string, ipType int) ([]net.IP, bool) {
|
|
|
|
|
|
+func (n *Network) ResolveName(req string, ipType int) ([]net.IP, bool) {
|
|
var ipv6Miss bool
|
|
var ipv6Miss bool
|
|
|
|
|
|
c := n.getController()
|
|
c := n.getController()
|
|
@@ -2009,7 +1989,7 @@ func (n *network) ResolveName(req string, ipType int) ([]net.IP, bool) {
|
|
return nil, ipv6Miss
|
|
return nil, ipv6Miss
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) HandleQueryResp(name string, ip net.IP) {
|
|
|
|
|
|
+func (n *Network) HandleQueryResp(name string, ip net.IP) {
|
|
networkID := n.ID()
|
|
networkID := n.ID()
|
|
c := n.getController()
|
|
c := n.getController()
|
|
c.mu.Lock()
|
|
c.mu.Lock()
|
|
@@ -2029,7 +2009,7 @@ func (n *network) HandleQueryResp(name string, ip net.IP) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ResolveIP(ip string) string {
|
|
|
|
|
|
+func (n *Network) ResolveIP(ip string) string {
|
|
networkID := n.ID()
|
|
networkID := n.ID()
|
|
c := n.getController()
|
|
c := n.getController()
|
|
c.mu.Lock()
|
|
c.mu.Lock()
|
|
@@ -2059,7 +2039,7 @@ func (n *network) ResolveIP(ip string) string {
|
|
return elem.name + "." + nwName
|
|
return elem.name + "." + nwName
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ResolveService(name string) ([]*net.SRV, []net.IP) {
|
|
|
|
|
|
+func (n *Network) ResolveService(name string) ([]*net.SRV, []net.IP) {
|
|
c := n.getController()
|
|
c := n.getController()
|
|
|
|
|
|
srv := []*net.SRV{}
|
|
srv := []*net.SRV{}
|
|
@@ -2114,36 +2094,33 @@ func (n *network) ResolveService(name string) ([]*net.SRV, []net.IP) {
|
|
return srv, ip
|
|
return srv, ip
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) ExecFunc(f func()) error {
|
|
|
|
|
|
+func (n *Network) ExecFunc(f func()) error {
|
|
return types.NotImplementedErrorf("ExecFunc not supported by network")
|
|
return types.NotImplementedErrorf("ExecFunc not supported by network")
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) NdotsSet() bool {
|
|
|
|
|
|
+func (n *Network) NdotsSet() bool {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
|
|
// config-only network is looked up by name
|
|
// config-only network is looked up by name
|
|
-func (c *Controller) getConfigNetwork(name string) (*network, error) {
|
|
|
|
- var n Network
|
|
|
|
-
|
|
|
|
- s := func(current Network) bool {
|
|
|
|
|
|
+func (c *Controller) getConfigNetwork(name string) (*Network, error) {
|
|
|
|
+ var n *Network
|
|
|
|
+ c.WalkNetworks(func(current *Network) bool {
|
|
if current.Info().ConfigOnly() && current.Name() == name {
|
|
if current.Info().ConfigOnly() && current.Name() == name {
|
|
n = current
|
|
n = current
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
return false
|
|
- }
|
|
|
|
-
|
|
|
|
- c.WalkNetworks(s)
|
|
|
|
|
|
+ })
|
|
|
|
|
|
if n == nil {
|
|
if n == nil {
|
|
return nil, types.NotFoundErrorf("configuration network %q not found", name)
|
|
return nil, types.NotFoundErrorf("configuration network %q not found", name)
|
|
}
|
|
}
|
|
|
|
|
|
- return n.(*network), nil
|
|
|
|
|
|
+ return n, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) lbSandboxName() string {
|
|
|
|
|
|
+func (n *Network) lbSandboxName() string {
|
|
name := "lb-" + n.name
|
|
name := "lb-" + n.name
|
|
if n.ingress {
|
|
if n.ingress {
|
|
name = n.name + "-sbox"
|
|
name = n.name + "-sbox"
|
|
@@ -2151,11 +2128,11 @@ func (n *network) lbSandboxName() string {
|
|
return name
|
|
return name
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) lbEndpointName() string {
|
|
|
|
|
|
+func (n *Network) lbEndpointName() string {
|
|
return n.name + "-endpoint"
|
|
return n.name + "-endpoint"
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) createLoadBalancerSandbox() (retErr error) {
|
|
|
|
|
|
+func (n *Network) createLoadBalancerSandbox() (retErr error) {
|
|
sandboxName := n.lbSandboxName()
|
|
sandboxName := n.lbSandboxName()
|
|
// Mark the sandbox to be a load balancer
|
|
// Mark the sandbox to be a load balancer
|
|
sbOptions := []SandboxOption{OptionLoadBalancer(n.id)}
|
|
sbOptions := []SandboxOption{OptionLoadBalancer(n.id)}
|
|
@@ -2202,7 +2179,7 @@ func (n *network) createLoadBalancerSandbox() (retErr error) {
|
|
return sb.EnableService()
|
|
return sb.EnableService()
|
|
}
|
|
}
|
|
|
|
|
|
-func (n *network) deleteLoadBalancerSandbox() error {
|
|
|
|
|
|
+func (n *Network) deleteLoadBalancerSandbox() error {
|
|
n.mu.Lock()
|
|
n.mu.Lock()
|
|
c := n.ctrlr
|
|
c := n.ctrlr
|
|
name := n.name
|
|
name := n.name
|