null.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Package null implements the null ipam driver. Null ipam driver satisfies ipamapi contract,
  2. // but does not effectively reserve/allocate any address pool or address
  3. package null
  4. import (
  5. "fmt"
  6. "net"
  7. "github.com/docker/libnetwork/discoverapi"
  8. "github.com/docker/libnetwork/ipamapi"
  9. "github.com/docker/libnetwork/types"
  10. )
  11. var (
  12. defaultAS = "null"
  13. defaultPool, _ = types.ParseCIDR("0.0.0.0/0")
  14. defaultPoolID = fmt.Sprintf("%s/%s", defaultAS, defaultPool.String())
  15. )
  16. type allocator struct{}
  17. func (a *allocator) GetDefaultAddressSpaces() (string, string, error) {
  18. return defaultAS, defaultAS, nil
  19. }
  20. func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
  21. if addressSpace != defaultAS {
  22. return "", nil, nil, types.BadRequestErrorf("unknown address space: %s", addressSpace)
  23. }
  24. if pool != "" {
  25. return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address pool requests")
  26. }
  27. if subPool != "" {
  28. return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address subpool requests")
  29. }
  30. if v6 {
  31. return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle IPv6 address pool pool requests")
  32. }
  33. return defaultPoolID, defaultPool, nil, nil
  34. }
  35. func (a *allocator) ReleasePool(poolID string) error {
  36. return nil
  37. }
  38. func (a *allocator) RequestAddress(poolID string, ip net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) {
  39. if poolID != defaultPoolID {
  40. return nil, nil, types.BadRequestErrorf("unknown pool id: %s", poolID)
  41. }
  42. return nil, nil, nil
  43. }
  44. func (a *allocator) ReleaseAddress(poolID string, ip net.IP) error {
  45. if poolID != defaultPoolID {
  46. return types.BadRequestErrorf("unknown pool id: %s", poolID)
  47. }
  48. return nil
  49. }
  50. func (a *allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
  51. return nil
  52. }
  53. func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
  54. return nil
  55. }
  56. func (a *allocator) IsBuiltIn() bool {
  57. return true
  58. }
  59. // Init registers a remote ipam when its plugin is activated
  60. func Init(ic ipamapi.Callback, l, g interface{}) error {
  61. return ic.RegisterIpamDriver(ipamapi.NullIPAM, &allocator{})
  62. }