builtin_unix.go 895 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // +build linux freebsd solaris
  2. package builtin
  3. import (
  4. "fmt"
  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 fmt.Errorf("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 fmt.Errorf("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. return ic.RegisterIpamDriver(ipamapi.DefaultIPAM, a)
  32. }