builtin_unix.go 984 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // +build linux freebsd solaris darwin
  2. package builtin
  3. import (
  4. "errors"
  5. "github.com/docker/libnetwork/datastore"
  6. "github.com/docker/libnetwork/ipam"
  7. "github.com/docker/libnetwork/ipamapi"
  8. "github.com/docker/libnetwork/ipamutils"
  9. )
  10. // Init registers the built-in ipam service with libnetwork
  11. func Init(ic ipamapi.Callback, l, g interface{}) error {
  12. var (
  13. ok bool
  14. localDs, globalDs datastore.DataStore
  15. )
  16. if l != nil {
  17. if localDs, ok = l.(datastore.DataStore); !ok {
  18. return errors.New("incorrect local datastore passed to built-in ipam init")
  19. }
  20. }
  21. if g != nil {
  22. if globalDs, ok = g.(datastore.DataStore); !ok {
  23. return errors.New("incorrect global datastore passed to built-in ipam init")
  24. }
  25. }
  26. ipamutils.InitNetworks()
  27. a, err := ipam.NewAllocator(localDs, globalDs)
  28. if err != nil {
  29. return err
  30. }
  31. cps := &ipamapi.Capability{RequiresRequestReplay: true}
  32. return ic.RegisterIpamDriverWithCapabilities(ipamapi.DefaultIPAM, a, cps)
  33. }