Fetch the default subnet from weave to use as the ipam driver 'pool'
This commit is contained in:
1 parent
ec3de1a072
commit
f87876c1c3
3 files changed
+20
-2
No files matched your search
@@ -30,6 +30,15 @@ func (client *Client) ReleaseIP(ID string) error {
|
|||||||
return err
|
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) {
|
func parseIP(body string) (*net.IPNet, error) {
|
||||||
ip, ipnet, err := net.ParseCIDR(string(body))
|
ip, ipnet, err := net.ParseCIDR(string(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ func (alloc *Allocator) handleHTTPAllocate(dockerCli *docker.Client, w http.Resp
|
|||||||
|
|
||||||
// HandleHTTP wires up ipams HTTP endpoints to the provided mux.
|
// HandleHTTP wires up ipams HTTP endpoints to the provided mux.
|
||||||
func (alloc *Allocator) HandleHTTP(router *mux.Router, defaultSubnet address.CIDR, dockerCli *docker.Client) {
|
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) {
|
router.Methods("PUT").Path("/ip/{id}/{ip}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
ident := vars["id"]
|
ident := vars["id"]
|
||||||
|
|||||||
@@ -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) {
|
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)
|
Log.Debugln("RequestPool", addressSpace, pool, subPool, options)
|
||||||
_, cidr, _ := net.ParseCIDR("10.32.0.0/12")
|
if err := i.configureWeaveClient(); err == nil {
|
||||||
return "weavepool", cidr, nil, 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 {
|
func (i *ipam) ReleasePool(poolID string) error {
|
||||||
|
|||||||
Reference in new issue
Block a user