contract.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/discoverapi"
  6. "github.com/docker/libnetwork/types"
  7. )
  8. /********************
  9. * IPAM plugin types
  10. ********************/
  11. const (
  12. // DefaultIPAM is the name of the built-in default ipam driver
  13. DefaultIPAM = "default"
  14. // NullIPAM is the name of the built-in null ipam driver
  15. NullIPAM = "null"
  16. // PluginEndpointType represents the Endpoint Type used by Plugin system
  17. PluginEndpointType = "IpamDriver"
  18. // RequestAddressType represents the Address Type used when requesting an address
  19. RequestAddressType = "RequestAddressType"
  20. )
  21. // Callback provides a Callback interface for registering an IPAM instance into LibNetwork
  22. type Callback interface {
  23. // RegisterIpamDriver provides a way for Remote drivers to dynamically register with libnetwork
  24. RegisterIpamDriver(name string, driver Ipam) error
  25. // RegisterIpamDriverWithCapabilities provides a way for Remote drivers to dynamically register with libnetwork and specify capabilities
  26. RegisterIpamDriverWithCapabilities(name string, driver Ipam, capability *Capability) error
  27. }
  28. /**************
  29. * IPAM Errors
  30. **************/
  31. // Well-known errors returned by IPAM
  32. var (
  33. ErrIpamInternalError = types.InternalErrorf("IPAM Internal Error")
  34. ErrInvalidAddressSpace = types.BadRequestErrorf("Invalid Address Space")
  35. ErrInvalidPool = types.BadRequestErrorf("Invalid Address Pool")
  36. ErrInvalidSubPool = types.BadRequestErrorf("Invalid Address SubPool")
  37. ErrInvalidRequest = types.BadRequestErrorf("Invalid Request")
  38. ErrPoolNotFound = types.BadRequestErrorf("Address Pool not found")
  39. ErrOverlapPool = types.ForbiddenErrorf("Address pool overlaps with existing pool on this address space")
  40. ErrNoAvailablePool = types.NoServiceErrorf("No available pool")
  41. ErrNoAvailableIPs = types.NoServiceErrorf("No available addresses on this pool")
  42. ErrIPAlreadyAllocated = types.ForbiddenErrorf("Address already in use")
  43. ErrIPOutOfRange = types.BadRequestErrorf("Requested address is out of range")
  44. ErrPoolOverlap = types.ForbiddenErrorf("Pool overlaps with other one on this address space")
  45. ErrBadPool = types.BadRequestErrorf("Address space does not contain specified address pool")
  46. )
  47. /*******************************
  48. * IPAM Service Interface
  49. *******************************/
  50. // Ipam represents the interface the IPAM service plugins must implement
  51. // in order to allow injection/modification of IPAM database.
  52. type Ipam interface {
  53. discoverapi.Discover
  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. // Request 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. // Release the address from the specified pool ID
  68. ReleaseAddress(string, net.IP) error
  69. }
  70. // Capability represents the requirements and capabilities of the IPAM driver
  71. type Capability struct {
  72. RequiresMACAddress bool
  73. }