contract.go 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Package ipamapi specifies the contract the IPAM service (built-in or remote) needs to satisfy.
  2. package ipamapi
  3. import (
  4. "net"
  5. "github.com/docker/docker/libnetwork/types"
  6. )
  7. // IPAM plugin types
  8. const (
  9. // DefaultIPAM is the name of the built-in default ipam driver
  10. DefaultIPAM = "default"
  11. // NullIPAM is the name of the built-in null ipam driver
  12. NullIPAM = "null"
  13. // PluginEndpointType represents the Endpoint Type used by Plugin system
  14. PluginEndpointType = "IpamDriver"
  15. // RequestAddressType represents the Address Type used when requesting an address
  16. RequestAddressType = "RequestAddressType"
  17. )
  18. // Registerer provides a callback interface for registering IPAM instances into libnetwork.
  19. type Registerer interface {
  20. // RegisterIpamDriver provides a way for drivers to dynamically register with libnetwork
  21. RegisterIpamDriver(name string, driver Ipam) error
  22. // RegisterIpamDriverWithCapabilities provides a way for drivers to dynamically register with libnetwork and specify capabilities
  23. RegisterIpamDriverWithCapabilities(name string, driver Ipam, capability *Capability) error
  24. }
  25. // Well-known errors returned by IPAM
  26. var (
  27. ErrInvalidAddressSpace = types.InvalidParameterErrorf("invalid address space")
  28. ErrInvalidPool = types.InvalidParameterErrorf("invalid address pool")
  29. ErrInvalidSubPool = types.InvalidParameterErrorf("invalid address subpool")
  30. ErrNoAvailableIPs = types.UnavailableErrorf("no available addresses on this pool")
  31. ErrNoIPReturned = types.UnavailableErrorf("no address returned")
  32. ErrIPAlreadyAllocated = types.ForbiddenErrorf("Address already in use")
  33. ErrIPOutOfRange = types.InvalidParameterErrorf("requested address is out of range")
  34. ErrPoolOverlap = types.ForbiddenErrorf("Pool overlaps with other one on this address space")
  35. ErrBadPool = types.InvalidParameterErrorf("address space does not contain specified address pool")
  36. )
  37. // Ipam represents the interface the IPAM service plugins must implement
  38. // in order to allow injection/modification of IPAM database.
  39. type Ipam interface {
  40. // GetDefaultAddressSpaces returns the default local and global address spaces for this ipam
  41. GetDefaultAddressSpaces() (string, string, error)
  42. // RequestPool returns an address pool along with its unique id. Address space is a mandatory field
  43. // which denotes a set of non-overlapping pools. requestedPool describes the pool of addresses in CIDR notation.
  44. // requestedSubPool indicates a smaller range of addresses from the pool, for now it is specified in CIDR notation.
  45. // Both requestedPool and requestedSubPool are non-mandatory fields. When they are not specified, Ipam driver may choose to
  46. // return a self chosen pool for this request. In such case the v6 flag needs to be set appropriately so
  47. // that the driver would return the expected ip version pool.
  48. RequestPool(addressSpace, requestedPool, requestedSubPool string, options map[string]string, v6 bool) (poolID string, pool *net.IPNet, meta map[string]string, err error)
  49. // ReleasePool releases the address pool identified by the passed id
  50. ReleasePool(poolID string) error
  51. // RequestAddress request an address from the specified pool ID. Input options or required IP can be passed.
  52. RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)
  53. // ReleaseAddress releases the address from the specified pool ID.
  54. ReleaseAddress(string, net.IP) error
  55. // IsBuiltIn returns true if it is a built-in driver.
  56. IsBuiltIn() bool
  57. }
  58. // Capability represents the requirements and capabilities of the IPAM driver
  59. type Capability struct {
  60. // Whether on address request, libnetwork must
  61. // specify the endpoint MAC address
  62. RequiresMACAddress bool
  63. // Whether of daemon start, libnetwork must replay the pool
  64. // request and the address request for current local networks
  65. RequiresRequestReplay bool
  66. }