builtin_windows.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // +build windows
  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. windowsipam "github.com/docker/libnetwork/ipams/windowsipam"
  10. )
  11. // InitDockerDefault registers the built-in ipam service with libnetwork
  12. func InitDockerDefault(ic ipamapi.Callback, l, g interface{}) error {
  13. var (
  14. ok bool
  15. localDs, globalDs datastore.DataStore
  16. )
  17. if l != nil {
  18. if localDs, ok = l.(datastore.DataStore); !ok {
  19. return errors.New("incorrect local datastore passed to built-in ipam init")
  20. }
  21. }
  22. if g != nil {
  23. if globalDs, ok = g.(datastore.DataStore); !ok {
  24. return errors.New("incorrect global datastore passed to built-in ipam init")
  25. }
  26. }
  27. ipamutils.InitNetworks()
  28. a, err := ipam.NewAllocator(localDs, globalDs)
  29. if err != nil {
  30. return err
  31. }
  32. cps := &ipamapi.Capability{RequiresRequestReplay: true}
  33. return ic.RegisterIpamDriverWithCapabilities(ipamapi.DefaultIPAM, a, cps)
  34. }
  35. // Init registers the built-in ipam service with libnetwork
  36. func Init(ic ipamapi.Callback, l, g interface{}) error {
  37. initFunc := windowsipam.GetInit(windowsipam.DefaultIPAM)
  38. err := InitDockerDefault(ic, l, g)
  39. if err != nil {
  40. return err
  41. }
  42. return initFunc(ic, l, g)
  43. }