1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/libnetwork/ipams/builtin/builtin_unix.go
Alessandro Boch 651f6ea0fa Avoid persisting ipam data if it can be reconstructed
- Also restore older behavior where overlap check is not run
  when preferred pool is specified. Got broken by recent changes

Signed-off-by: Alessandro Boch <aboch@docker.com>
2016-05-12 10:27:10 -07:00

43 lines
981 B
Go

// +build linux freebsd solaris darwin
package builtin
import (
"fmt"
"github.com/docker/libnetwork/datastore"
"github.com/docker/libnetwork/ipam"
"github.com/docker/libnetwork/ipamapi"
"github.com/docker/libnetwork/ipamutils"
)
// Init registers the built-in ipam service with libnetwork
func Init(ic ipamapi.Callback, l, g interface{}) error {
var (
ok bool
localDs, globalDs datastore.DataStore
)
if l != nil {
if localDs, ok = l.(datastore.DataStore); !ok {
return fmt.Errorf("incorrect local datastore passed to built-in ipam init")
}
}
if g != nil {
if globalDs, ok = g.(datastore.DataStore); !ok {
return fmt.Errorf("incorrect global datastore passed to built-in ipam init")
}
}
ipamutils.InitNetworks()
a, err := ipam.NewAllocator(localDs, globalDs)
if err != nil {
return err
}
cps := &ipamapi.Capability{RequiresRequestReplay: true}
return ic.RegisterIpamDriverWithCapabilities(ipamapi.DefaultIPAM, a, cps)
}