contract.go 4.4 KB

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