contract.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Package ipamapi specifies the contract the IPAM service (built-in or remote) needs to satisfy.
  2. package ipamapi
  3. import (
  4. "errors"
  5. "net"
  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 = "IPAM"
  15. )
  16. // Callback provides a Callback interface for registering an IPAM instance into LibNetwork
  17. type Callback interface {
  18. // RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a ipam instance
  19. RegisterIpamDriver(name string, driver Ipam) error
  20. }
  21. /**************
  22. * IPAM Errors
  23. **************/
  24. // Weel-known errors returned by IPAM
  25. var (
  26. ErrInvalidIpamService = errors.New("Invalid IPAM Service")
  27. ErrInvalidIpamConfigService = errors.New("Invalid IPAM Config Service")
  28. ErrIpamNotAvailable = errors.New("IPAM Service not available")
  29. ErrIpamInternalError = errors.New("IPAM Internal Error")
  30. ErrInvalidAddressSpace = errors.New("Invalid Address Space")
  31. ErrInvalidPool = errors.New("Invalid Address Pool")
  32. ErrInvalidSubPool = errors.New("Invalid Address SubPool")
  33. ErrInvalidRequest = errors.New("Invalid Request")
  34. ErrPoolNotFound = errors.New("Address Pool not found")
  35. ErrOverlapPool = errors.New("Address pool overlaps with existing pool on this address space")
  36. ErrNoAvailablePool = errors.New("No available pool")
  37. ErrNoAvailableIPs = errors.New("No available addresses on this pool")
  38. ErrIPAlreadyAllocated = errors.New("Address already in use")
  39. ErrIPOutOfRange = errors.New("Requested address is out of range")
  40. ErrPoolOverlap = errors.New("Pool overlaps with other one on this address space")
  41. ErrBadPool = errors.New("Address space does not contain specified address pool")
  42. )
  43. /*******************************
  44. * IPAM Service Interface
  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. // GetDefaultAddressSpaces returns the default local and global address spaces for this ipam
  50. GetDefaultAddressSpaces() (string, string, error)
  51. // RequestPool returns an address pool along with its unique id. Address space is a mandatory field
  52. // which denotes a set of non-overlapping pools. pool describes the pool of addrresses in CIDR notation.
  53. // subpool indicates a smaller range of addresses from the pool, for now it is specified in CIDR notation.
  54. // Both pool and subpool are non mandatory fields. When they are not specified, Ipam driver may choose to
  55. // return a self chosen pool for this request. In such case the v6 flag needs to be set appropriately so
  56. // that the driver would return the expected ip version pool.
  57. RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error)
  58. // ReleasePool releases the address pool identified by the passed id
  59. ReleasePool(poolID string) error
  60. // Request address from the specified pool ID. Input options or preferred IP can be passed.
  61. RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)
  62. // Release the address from the specified pool ID
  63. ReleaseAddress(string, net.IP) error
  64. }