contract.go 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. "github.com/docker/docker/pkg/plugingetter"
  7. )
  8. // IPAM plugin types
  9. const (
  10. // DefaultIPAM is the name of the built-in default ipam driver
  11. DefaultIPAM = "default"
  12. // NullIPAM is the name of the built-in null ipam driver
  13. NullIPAM = "null"
  14. // PluginEndpointType represents the Endpoint Type used by Plugin system
  15. PluginEndpointType = "IpamDriver"
  16. // RequestAddressType represents the Address Type used when requesting an address
  17. RequestAddressType = "RequestAddressType"
  18. )
  19. // Registerer provides a callback interface for registering IPAM instances into libnetwork.
  20. type Registerer interface {
  21. // RegisterIpamDriver provides a way for drivers to dynamically register with libnetwork
  22. RegisterIpamDriver(name string, driver Ipam) error
  23. // RegisterIpamDriverWithCapabilities provides a way for drivers to dynamically register with libnetwork and specify capabilities
  24. RegisterIpamDriverWithCapabilities(name string, driver Ipam, capability *Capability) error
  25. }
  26. // Callback is a legacy interface for registering an IPAM instance into LibNetwork.
  27. //
  28. // The narrower [Registerer] interface is preferred for new code.
  29. type Callback interface {
  30. Registerer
  31. // GetPluginGetter returns the pluginv2 getter.
  32. GetPluginGetter() plugingetter.PluginGetter
  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. // Ipam represents the interface the IPAM service plugins must implement
  52. // in order to allow injection/modification of IPAM database.
  53. type Ipam interface {
  54. // GetDefaultAddressSpaces returns the default local and global address spaces for this ipam
  55. GetDefaultAddressSpaces() (string, string, error)
  56. // RequestPool returns an address pool along with its unique id. Address space is a mandatory field
  57. // which denotes a set of non-overlapping pools. pool describes the pool of addresses in CIDR notation.
  58. // subpool indicates a smaller range of addresses from the pool, for now it is specified in CIDR notation.
  59. // Both pool and subpool are non mandatory fields. When they are not specified, Ipam driver may choose to
  60. // return a self chosen pool for this request. In such case the v6 flag needs to be set appropriately so
  61. // that the driver would return the expected ip version pool.
  62. RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error)
  63. // ReleasePool releases the address pool identified by the passed id
  64. ReleasePool(poolID string) error
  65. // RequestAddress request an address from the specified pool ID. Input options or required IP can be passed.
  66. RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)
  67. // ReleaseAddress releases the address from the specified pool ID.
  68. ReleaseAddress(string, net.IP) error
  69. // IsBuiltIn returns true if it is a built-in driver.
  70. IsBuiltIn() bool
  71. }
  72. // Capability represents the requirements and capabilities of the IPAM driver
  73. type Capability struct {
  74. // Whether on address request, libnetwork must
  75. // specify the endpoint MAC address
  76. RequiresMACAddress bool
  77. // Whether of daemon start, libnetwork must replay the pool
  78. // request and the address request for current local networks
  79. RequiresRequestReplay bool
  80. }