contract.go 3.8 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/libnetwork/types"
  6. )
  7. /********************
  8. * IPAM plugin types
  9. ********************/
  10. const (
  11. // DefaultIPAM is the name of the built-in default ipam driver
  12. DefaultIPAM = "default"
  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. // Callback provides a Callback interface for registering an IPAM instance into LibNetwork
  19. type Callback interface {
  20. // RegisterIpamDriver provides a way for Remote drivers to dynamically register with libnetwork
  21. RegisterIpamDriver(name string, driver Ipam) error
  22. // RegisterIpamDriverWithCapabilities provides a way for Remote drivers to dynamically register with libnetwork and specify cpaabilities
  23. RegisterIpamDriverWithCapabilities(name string, driver Ipam, capability *Capability) error
  24. }
  25. /**************
  26. * IPAM Errors
  27. **************/
  28. // Weel-known errors returned by IPAM
  29. var (
  30. ErrIpamInternalError = types.InternalErrorf("IPAM Internal Error")
  31. ErrInvalidAddressSpace = types.BadRequestErrorf("Invalid Address Space")
  32. ErrInvalidPool = types.BadRequestErrorf("Invalid Address Pool")
  33. ErrInvalidSubPool = types.BadRequestErrorf("Invalid Address SubPool")
  34. ErrInvalidRequest = types.BadRequestErrorf("Invalid Request")
  35. ErrPoolNotFound = types.BadRequestErrorf("Address Pool not found")
  36. ErrOverlapPool = types.ForbiddenErrorf("Address pool overlaps with existing pool on this address space")
  37. ErrNoAvailablePool = types.NoServiceErrorf("No available pool")
  38. ErrNoAvailableIPs = types.NoServiceErrorf("No available addresses on this pool")
  39. ErrIPAlreadyAllocated = types.ForbiddenErrorf("Address already in use")
  40. ErrIPOutOfRange = types.BadRequestErrorf("Requested address is out of range")
  41. ErrPoolOverlap = types.ForbiddenErrorf("Pool overlaps with other one on this address space")
  42. ErrBadPool = types.BadRequestErrorf("Address space does not contain specified address pool")
  43. )
  44. /*******************************
  45. * IPAM Service Interface
  46. *******************************/
  47. // Ipam represents the interface the IPAM service plugins must implement
  48. // in order to allow injection/modification of IPAM database.
  49. type Ipam interface {
  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. // Request address from the specified pool ID. Input options or preferred IP can be passed.
  62. RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)
  63. // Release the address from the specified pool ID
  64. ReleaseAddress(string, net.IP) error
  65. }
  66. // Capability represents the requirements and capabilities of the IPAM driver
  67. type Capability struct {
  68. RequiresMACAddress bool
  69. }