contract.go 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ErrIpamInternalError = types.InternalErrorf("IPAM Internal Error")
  28. ErrInvalidAddressSpace = types.BadRequestErrorf("Invalid Address Space")
  29. ErrInvalidPool = types.BadRequestErrorf("Invalid Address Pool")
  30. ErrInvalidSubPool = types.BadRequestErrorf("Invalid Address SubPool")
  31. ErrInvalidRequest = types.BadRequestErrorf("Invalid Request")
  32. ErrPoolNotFound = types.BadRequestErrorf("Address Pool not found")
  33. ErrOverlapPool = types.ForbiddenErrorf("Address pool overlaps with existing pool on this address space")
  34. ErrNoAvailablePool = types.NoServiceErrorf("No available pool")
  35. ErrNoAvailableIPs = types.NoServiceErrorf("No available addresses on this pool")
  36. ErrNoIPReturned = types.NoServiceErrorf("No address returned")
  37. ErrIPAlreadyAllocated = types.ForbiddenErrorf("Address already in use")
  38. ErrIPOutOfRange = types.BadRequestErrorf("Requested address is out of range")
  39. ErrPoolOverlap = types.ForbiddenErrorf("Pool overlaps with other one on this address space")
  40. ErrBadPool = types.BadRequestErrorf("Address space does not contain specified address pool")
  41. )
  42. // Ipam represents the interface the IPAM service plugins must implement
  43. // in order to allow injection/modification of IPAM database.
  44. type Ipam interface {
  45. // GetDefaultAddressSpaces returns the default local and global address spaces for this ipam
  46. GetDefaultAddressSpaces() (string, string, error)
  47. // RequestPool returns an address pool along with its unique id. Address space is a mandatory field
  48. // which denotes a set of non-overlapping pools. pool describes the pool of addresses in CIDR notation.
  49. // subpool indicates a smaller range of addresses from the pool, for now it is specified in CIDR notation.
  50. // Both pool and subpool are non mandatory fields. When they are not specified, Ipam driver may choose to
  51. // return a self chosen pool for this request. In such case the v6 flag needs to be set appropriately so
  52. // that the driver would return the expected ip version pool.
  53. RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error)
  54. // ReleasePool releases the address pool identified by the passed id
  55. ReleasePool(poolID string) error
  56. // RequestAddress request an address from the specified pool ID. Input options or required IP can be passed.
  57. RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)
  58. // ReleaseAddress releases the address from the specified pool ID.
  59. ReleaseAddress(string, net.IP) error
  60. // IsBuiltIn returns true if it is a built-in driver.
  61. IsBuiltIn() bool
  62. }
  63. // Capability represents the requirements and capabilities of the IPAM driver
  64. type Capability struct {
  65. // Whether on address request, libnetwork must
  66. // specify the endpoint MAC address
  67. RequiresMACAddress bool
  68. // Whether of daemon start, libnetwork must replay the pool
  69. // request and the address request for current local networks
  70. RequiresRequestReplay bool
  71. }