2016-03-07 15:30:20 -08:00
|
|
|
// +build linux freebsd solaris darwin
|
2016-01-29 17:08:11 -08:00
|
|
|
|
2015-09-22 13:20:55 -07:00
|
|
|
package builtin
|
|
|
|
|
|
|
|
import (
|
2016-11-22 09:29:53 +08:00
|
|
|
"errors"
|
2015-09-22 13:20:55 -07:00
|
|
|
|
|
|
|
"github.com/docker/libnetwork/datastore"
|
|
|
|
"github.com/docker/libnetwork/ipam"
|
|
|
|
"github.com/docker/libnetwork/ipamapi"
|
2016-04-04 09:50:26 -04:00
|
|
|
"github.com/docker/libnetwork/ipamutils"
|
2015-09-22 13:20:55 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2016-11-22 09:29:53 +08:00
|
|
|
return errors.New("incorrect local datastore passed to built-in ipam init")
|
2015-09-22 13:20:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if g != nil {
|
|
|
|
if globalDs, ok = g.(datastore.DataStore); !ok {
|
2016-11-22 09:29:53 +08:00
|
|
|
return errors.New("incorrect global datastore passed to built-in ipam init")
|
2015-09-22 13:20:55 -07:00
|
|
|
}
|
|
|
|
}
|
2016-04-04 09:50:26 -04:00
|
|
|
|
|
|
|
ipamutils.InitNetworks()
|
|
|
|
|
2015-09-22 13:20:55 -07:00
|
|
|
a, err := ipam.NewAllocator(localDs, globalDs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-04-18 15:11:36 -07:00
|
|
|
cps := &ipamapi.Capability{RequiresRequestReplay: true}
|
|
|
|
|
|
|
|
return ic.RegisterIpamDriverWithCapabilities(ipamapi.DefaultIPAM, a, cps)
|
2015-09-22 13:20:55 -07:00
|
|
|
}
|