2015-04-13 18:40:42 +00:00
|
|
|
package driverapi
|
|
|
|
|
2015-04-14 01:36:58 +00:00
|
|
|
import (
|
2015-05-14 06:23:45 +00:00
|
|
|
"net"
|
2015-04-17 15:42:23 -07:00
|
|
|
|
2015-04-20 08:44:06 -07:00
|
|
|
"github.com/docker/libnetwork/types"
|
2015-04-14 01:36:58 +00:00
|
|
|
)
|
2015-04-13 18:40:42 +00:00
|
|
|
|
2015-05-15 18:14:36 -07:00
|
|
|
// NetworkPluginEndpointType represents the Endpoint Type used by Plugin system
|
|
|
|
const NetworkPluginEndpointType = "NetworkDriver"
|
|
|
|
|
2015-04-13 18:40:42 +00:00
|
|
|
// Driver is an interface that every plugin driver needs to implement.
|
|
|
|
type Driver interface {
|
2015-04-15 05:25:42 +00:00
|
|
|
// Push driver specific config to the driver
|
2015-04-30 17:57:06 -07:00
|
|
|
Config(options map[string]interface{}) error
|
2015-04-15 05:25:42 +00:00
|
|
|
|
2015-04-13 18:40:42 +00:00
|
|
|
// CreateNetwork invokes the driver method to create a network passing
|
2015-04-15 05:25:42 +00:00
|
|
|
// the network id and network specific config. The config mechanism will
|
2015-04-13 18:40:42 +00:00
|
|
|
// eventually be replaced with labels which are yet to be introduced.
|
2015-04-30 17:57:06 -07:00
|
|
|
CreateNetwork(nid types.UUID, options map[string]interface{}) error
|
2015-04-13 18:40:42 +00:00
|
|
|
|
|
|
|
// DeleteNetwork invokes the driver method to delete network passing
|
|
|
|
// the network id.
|
2015-04-20 08:44:06 -07:00
|
|
|
DeleteNetwork(nid types.UUID) error
|
2015-04-13 18:40:42 +00:00
|
|
|
|
|
|
|
// CreateEndpoint invokes the driver method to create an endpoint
|
2015-05-14 06:23:45 +00:00
|
|
|
// passing the network id, endpoint id endpoint information and driver
|
|
|
|
// specific config. The endpoint information can be either consumed by
|
|
|
|
// the driver or populated by the driver. The config mechanism will
|
|
|
|
// eventually be replaced with labels which are yet to be introduced.
|
|
|
|
CreateEndpoint(nid, eid types.UUID, epInfo EndpointInfo, options map[string]interface{}) error
|
2015-04-13 18:40:42 +00:00
|
|
|
|
|
|
|
// DeleteEndpoint invokes the driver method to delete an endpoint
|
|
|
|
// passing the network id and endpoint id.
|
2015-04-20 08:44:06 -07:00
|
|
|
DeleteEndpoint(nid, eid types.UUID) error
|
2015-04-22 16:47:07 -07:00
|
|
|
|
2015-05-14 06:23:45 +00:00
|
|
|
// EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
|
|
|
|
EndpointOperInfo(nid, eid types.UUID) (map[string]interface{}, error)
|
2015-05-04 11:49:53 -07:00
|
|
|
|
2015-04-30 14:52:46 -07:00
|
|
|
// Join method is invoked when a Sandbox is attached to an endpoint.
|
2015-05-14 06:23:45 +00:00
|
|
|
Join(nid, eid types.UUID, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
|
2015-04-30 14:52:46 -07:00
|
|
|
|
|
|
|
// Leave method is invoked when a Sandbox detaches from an endpoint.
|
2015-05-14 06:23:45 +00:00
|
|
|
Leave(nid, eid types.UUID) error
|
2015-04-30 14:52:46 -07:00
|
|
|
|
2015-04-22 16:47:07 -07:00
|
|
|
// Type returns the the type of this driver, the network type this driver manages
|
|
|
|
Type() string
|
2015-04-17 15:42:23 -07:00
|
|
|
}
|
2015-05-03 20:29:43 +00:00
|
|
|
|
2015-05-14 06:23:45 +00:00
|
|
|
// EndpointInfo provides a go interface to fetch or populate endpoint assigned network resources.
|
|
|
|
type EndpointInfo interface {
|
|
|
|
// Interfaces returns a list of interfaces bound to the endpoint.
|
|
|
|
// If the list is not empty the driver is only expected to consume the interfaces.
|
|
|
|
// It is an error to try to add interfaces to a non-empty list.
|
|
|
|
// If the list is empty the driver is expected to populate with 0 or more interfaces.
|
|
|
|
Interfaces() []InterfaceInfo
|
|
|
|
|
|
|
|
// AddInterface is used by the driver to add an interface to the interface list.
|
|
|
|
// This method will return an error if the driver attempts to add interfaces
|
|
|
|
// if the Interfaces() method returned a non-empty list.
|
|
|
|
// ID field need only have significance within the endpoint so it can be a simple
|
|
|
|
// monotonically increasing number
|
|
|
|
AddInterface(ID int, mac net.HardwareAddr, ipv4 net.IPNet, ipv6 net.IPNet) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// InterfaceInfo provides a go interface for drivers to retrive
|
|
|
|
// network information to interface resources.
|
|
|
|
type InterfaceInfo interface {
|
|
|
|
// MacAddress returns the MAC address.
|
|
|
|
MacAddress() net.HardwareAddr
|
|
|
|
|
|
|
|
// Address returns the IPv4 address.
|
|
|
|
Address() net.IPNet
|
|
|
|
|
|
|
|
// AddressIPv6 returns the IPv6 address.
|
|
|
|
AddressIPv6() net.IPNet
|
|
|
|
|
|
|
|
// ID returns the numerical id of the interface and has significance only within
|
|
|
|
// the endpoint.
|
|
|
|
ID() int
|
|
|
|
}
|
|
|
|
|
|
|
|
// InterfaceNameInfo provides a go interface for the drivers to assign names
|
|
|
|
// to interfaces.
|
|
|
|
type InterfaceNameInfo interface {
|
2015-05-21 18:04:49 +00:00
|
|
|
// SetNames method assigns the srcName and dstPrefix for the interface.
|
|
|
|
SetNames(srcName, dstPrefix string) error
|
2015-05-14 06:23:45 +00:00
|
|
|
|
|
|
|
// ID returns the numerical id that was assigned to the interface by the driver
|
|
|
|
// CreateEndpoint.
|
|
|
|
ID() int
|
|
|
|
}
|
|
|
|
|
2015-05-03 20:29:43 +00:00
|
|
|
// JoinInfo represents a set of resources that the driver has the ability to provide during
|
|
|
|
// join time.
|
2015-05-14 06:23:45 +00:00
|
|
|
type JoinInfo interface {
|
|
|
|
// InterfaceNames returns a list of InterfaceNameInfo go interface to facilitate
|
|
|
|
// setting the names for the interfaces.
|
|
|
|
InterfaceNames() []InterfaceNameInfo
|
|
|
|
|
|
|
|
// SetGateway sets the default IPv4 gateway when a container joins the endpoint.
|
|
|
|
SetGateway(net.IP) error
|
|
|
|
|
|
|
|
// SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint.
|
|
|
|
SetGatewayIPv6(net.IP) error
|
|
|
|
|
2015-05-19 17:08:56 -07:00
|
|
|
// AddStaticRoute adds a routes to the sandbox.
|
|
|
|
// It may be used in addtion to or instead of a default gateway (as above).
|
|
|
|
AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP, interfaceID int) error
|
|
|
|
|
2015-05-14 06:23:45 +00:00
|
|
|
// SetHostsPath sets the overriding /etc/hosts path to use for the container.
|
|
|
|
SetHostsPath(string) error
|
|
|
|
|
|
|
|
// SetResolvConfPath sets the overriding /etc/resolv.conf path to use for the container.
|
|
|
|
SetResolvConfPath(string) error
|
2015-05-03 20:29:43 +00:00
|
|
|
}
|
2015-05-06 16:57:38 -07:00
|
|
|
|
|
|
|
// DriverCallback provides a Callback interface for Drivers into LibNetwork
|
|
|
|
type DriverCallback interface {
|
|
|
|
// RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
|
2015-06-06 10:21:51 -07:00
|
|
|
RegisterDriver(name string, driver Driver, capability Capability) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scope indicates the drivers scope capability
|
|
|
|
type Scope int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// LocalScope represents the driver capable of providing networking services for containers in a single host
|
|
|
|
LocalScope Scope = iota
|
|
|
|
// GlobalScope represents the driver capable of providing networking services for containers across hosts
|
|
|
|
GlobalScope
|
|
|
|
)
|
|
|
|
|
|
|
|
// Capability represents the high level capabilities of the drivers which libnetwork can make use of
|
|
|
|
type Capability struct {
|
|
|
|
Scope Scope
|
2015-05-06 16:57:38 -07:00
|
|
|
}
|