diff --git a/api/ipam.go b/api/ipam.go index 39da04a4..00467dc9 100644 --- a/api/ipam.go +++ b/api/ipam.go @@ -30,6 +30,15 @@ func (client *Client) ReleaseIP(ID string) error { return err } +func (client *Client) DefaultSubnet() (*net.IPNet, error) { + cidr, err := httpVerb("GET", fmt.Sprintf("%s/ipinfo/defaultsubnet", client.baseUrl), nil) + if err != nil { + return nil, err + } + _, ipnet, err := net.ParseCIDR(cidr) + return ipnet, err +} + func parseIP(body string) (*net.IPNet, error) { ip, ipnet, err := net.ParseCIDR(string(body)) if err != nil { diff --git a/ipam/http.go b/ipam/http.go index a86fbc50..eb51b87a 100644 --- a/ipam/http.go +++ b/ipam/http.go @@ -57,6 +57,10 @@ func (alloc *Allocator) handleHTTPAllocate(dockerCli *docker.Client, w http.Resp // HandleHTTP wires up ipams HTTP endpoints to the provided mux. func (alloc *Allocator) HandleHTTP(router *mux.Router, defaultSubnet address.CIDR, dockerCli *docker.Client) { + router.Methods("GET").Path("/ipinfo/defaultsubnet").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "%s", defaultSubnet) + }) + router.Methods("PUT").Path("/ip/{id}/{ip}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) ident := vars["id"] diff --git a/plugin/ipam/driver.go b/plugin/ipam/driver.go index a81de6f5..b94e302b 100644 --- a/plugin/ipam/driver.go +++ b/plugin/ipam/driver.go @@ -43,8 +43,13 @@ func (i *ipam) GetDefaultAddressSpaces() (string, string, error) { func (i *ipam) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) { Log.Debugln("RequestPool", addressSpace, pool, subPool, options) - _, cidr, _ := net.ParseCIDR("10.32.0.0/12") - return "weavepool", cidr, nil, nil + if err := i.configureWeaveClient(); err == nil { + cidr, err := i.weave.DefaultSubnet() + Log.Debugln("RequestPool returning ", cidr, err) + return "weavepool", cidr, nil, err + } else { + return "", nil, nil, err + } } func (i *ipam) ReleasePool(poolID string) error {