contract.go 4.3 KB

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