2016-02-17 14:24:43 -05:00
|
|
|
// +build linux freebsd
|
2016-01-29 20:08:11 -05:00
|
|
|
|
2015-09-22 16:20:55 -04:00
|
|
|
package builtin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"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 16:20:55 -04: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 {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
2016-04-04 09:50:26 -04:00
|
|
|
|
|
|
|
ipamutils.InitNetworks()
|
|
|
|
|
2015-09-22 16:20:55 -04:00
|
|
|
a, err := ipam.NewAllocator(localDs, globalDs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ic.RegisterIpamDriver(ipamapi.DefaultIPAM, a)
|
|
|
|
}
|