github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/libnetwork/ipamapi/contract.go (about) 1 // Package ipamapi specifies the contract the IPAM service (built-in or remote) needs to satisfy. 2 package ipamapi 3 4 import ( 5 "net" 6 7 "github.com/docker/docker/libnetwork/discoverapi" 8 "github.com/docker/docker/libnetwork/types" 9 "github.com/docker/docker/pkg/plugingetter" 10 ) 11 12 // IPAM plugin types 13 const ( 14 // DefaultIPAM is the name of the built-in default ipam driver 15 DefaultIPAM = "default" 16 // NullIPAM is the name of the built-in null ipam driver 17 NullIPAM = "null" 18 // PluginEndpointType represents the Endpoint Type used by Plugin system 19 PluginEndpointType = "IpamDriver" 20 // RequestAddressType represents the Address Type used when requesting an address 21 RequestAddressType = "RequestAddressType" 22 ) 23 24 // Callback provides a Callback interface for registering an IPAM instance into LibNetwork 25 type Callback interface { 26 // GetPluginGetter returns the pluginv2 getter. 27 GetPluginGetter() plugingetter.PluginGetter 28 // RegisterIpamDriver provides a way for Remote drivers to dynamically register with libnetwork 29 RegisterIpamDriver(name string, driver Ipam) error 30 // RegisterIpamDriverWithCapabilities provides a way for Remote drivers to dynamically register with libnetwork and specify capabilities 31 RegisterIpamDriverWithCapabilities(name string, driver Ipam, capability *Capability) error 32 } 33 34 // Well-known errors returned by IPAM 35 var ( 36 ErrIpamInternalError = types.InternalErrorf("IPAM Internal Error") 37 ErrInvalidAddressSpace = types.BadRequestErrorf("Invalid Address Space") 38 ErrInvalidPool = types.BadRequestErrorf("Invalid Address Pool") 39 ErrInvalidSubPool = types.BadRequestErrorf("Invalid Address SubPool") 40 ErrInvalidRequest = types.BadRequestErrorf("Invalid Request") 41 ErrPoolNotFound = types.BadRequestErrorf("Address Pool not found") 42 ErrOverlapPool = types.ForbiddenErrorf("Address pool overlaps with existing pool on this address space") 43 ErrNoAvailablePool = types.NoServiceErrorf("No available pool") 44 ErrNoAvailableIPs = types.NoServiceErrorf("No available addresses on this pool") 45 ErrNoIPReturned = types.NoServiceErrorf("No address returned") 46 ErrIPAlreadyAllocated = types.ForbiddenErrorf("Address already in use") 47 ErrIPOutOfRange = types.BadRequestErrorf("Requested address is out of range") 48 ErrPoolOverlap = types.ForbiddenErrorf("Pool overlaps with other one on this address space") 49 ErrBadPool = types.BadRequestErrorf("Address space does not contain specified address pool") 50 ) 51 52 // Ipam represents the interface the IPAM service plugins must implement 53 // in order to allow injection/modification of IPAM database. 54 type Ipam interface { 55 discoverapi.Discover 56 57 // GetDefaultAddressSpaces returns the default local and global address spaces for this ipam 58 GetDefaultAddressSpaces() (string, string, error) 59 // RequestPool returns an address pool along with its unique id. Address space is a mandatory field 60 // which denotes a set of non-overlapping pools. pool describes the pool of addresses in CIDR notation. 61 // subpool indicates a smaller range of addresses from the pool, for now it is specified in CIDR notation. 62 // Both pool and subpool are non mandatory fields. When they are not specified, Ipam driver may choose to 63 // return a self chosen pool for this request. In such case the v6 flag needs to be set appropriately so 64 // that the driver would return the expected ip version pool. 65 RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) 66 // ReleasePool releases the address pool identified by the passed id 67 ReleasePool(poolID string) error 68 // RequestAddress request an address from the specified pool ID. Input options or required IP can be passed. 69 RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error) 70 // ReleaseAddress releases the address from the specified pool ID. 71 ReleaseAddress(string, net.IP) error 72 73 // IsBuiltIn returns true if it is a built-in driver. 74 IsBuiltIn() bool 75 } 76 77 // Capability represents the requirements and capabilities of the IPAM driver 78 type Capability struct { 79 // Whether on address request, libnetwork must 80 // specify the endpoint MAC address 81 RequiresMACAddress bool 82 // Whether of daemon start, libnetwork must replay the pool 83 // request and the address request for current local networks 84 RequiresRequestReplay bool 85 }