commit
c9525532ea
1 file changed
+22
-10
+22
-10
@@ -54,6 +54,21 @@ func (i *Ipam) ReleasePool(poolID string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func splitPoolID(poolID string) (subnet, iprange *net.IPNet, err error) {
|
||||||
|
parts := strings.Split(poolID, "-")
|
||||||
|
if len(parts) != 3 || parts[0] != "weave" {
|
||||||
|
err = fmt.Errorf("Unrecognized pool ID: %s", poolID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, subnet, err = net.ParseCIDR(parts[1]); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, iprange, err = net.ParseCIDR(parts[2]); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string]string) (ip *net.IPNet, _ map[string]string, err error) {
|
func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string]string) (ip *net.IPNet, _ map[string]string, err error) {
|
||||||
i.logReq("RequestAddress", poolID, address, options)
|
i.logReq("RequestAddress", poolID, address, options)
|
||||||
defer func() { i.logRes("RequestAddress", err, ip) }()
|
defer func() { i.logRes("RequestAddress", err, ip) }()
|
||||||
@@ -62,13 +77,8 @@ func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string]
|
|||||||
ip, err = i.weave.AllocateIP("_")
|
ip, err = i.weave.AllocateIP("_")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
parts := strings.Split(poolID, "-")
|
subnet, iprange, err := splitPoolID(poolID)
|
||||||
if len(parts) != 3 || parts[0] != "weave" {
|
if err != nil {
|
||||||
err = fmt.Errorf("Unrecognized pool ID: %s", poolID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var subnet, iprange *net.IPNet
|
|
||||||
if _, subnet, err = net.ParseCIDR(parts[1]); err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if address != nil { // try to claim specific address requested
|
if address != nil { // try to claim specific address requested
|
||||||
@@ -77,9 +87,6 @@ func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string]
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if _, iprange, err = net.ParseCIDR(parts[2]); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// We are lying slightly to IPAM here: the range is not a subnet
|
// We are lying slightly to IPAM here: the range is not a subnet
|
||||||
if ip, err = i.weave.AllocateIPInSubnet("_", iprange); err != nil {
|
if ip, err = i.weave.AllocateIPInSubnet("_", iprange); err != nil {
|
||||||
return
|
return
|
||||||
@@ -91,6 +98,11 @@ func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string]
|
|||||||
|
|
||||||
func (i *Ipam) ReleaseAddress(poolID string, address net.IP) error {
|
func (i *Ipam) ReleaseAddress(poolID string, address net.IP) error {
|
||||||
i.logReq("ReleaseAddress", poolID, address)
|
i.logReq("ReleaseAddress", poolID, address)
|
||||||
|
if subnet, _, err := splitPoolID(poolID); err != nil {
|
||||||
|
return err
|
||||||
|
} else if address.Equal(subnet.IP) { // is it the gateway address we faked earlier?
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return i.weave.ReleaseIPsFor(address.String())
|
return i.weave.ReleaseIPsFor(address.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user