Fetch the default subnet from weave to use as the ipam driver 'pool'

This commit is contained in:
Bryan Boreham committed 2015-12-08 16:59:34 +00:00
1 parent ec3de1a072
commit f87876c1c3
3 files changed
+20 -2

No files matched your search

+9
View File
@@ -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 {
+4
View File
@@ -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"]
+7 -2
View File
@@ -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 {