first working version
This commit is contained in:
parent
372915e24d
commit
6da132106f
18 changed files with 519 additions and 96 deletions
|
|
@ -46,12 +46,12 @@ func (a *Alloc) cidr(ip net.IP) string {
|
|||
func (a *Alloc) AllocIP(ctx context.Context, name string) (addr string, err error) {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
for _, cidr := range a.pool {
|
||||
c := ipaddr.NewCursor([]ipaddr.Prefix{*ipaddr.NewPrefix(cidr)})
|
||||
for _, p := range a.pool {
|
||||
c := ipaddr.NewCursor([]ipaddr.Prefix{*ipaddr.NewPrefix(p)})
|
||||
for pos := c.First(); pos != nil; pos = c.Next() {
|
||||
cidr := a.cidr(pos.IP)
|
||||
if !a.db.IPExists(cidr) {
|
||||
err = a.db.SetIP(cidr, name)
|
||||
err = a.db.SetIPName(cidr, name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -70,11 +70,11 @@ func (a *Alloc) FreeIP(ctx context.Context, name string) (err error) {
|
|||
if name == "" {
|
||||
return
|
||||
}
|
||||
ip, err := a.db.GetName(name)
|
||||
ip, err := a.db.GetIP(name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return a.db.DeleteIP(ip, name)
|
||||
return a.db.DeleteIPName(ip, name)
|
||||
}
|
||||
|
||||
func parseRange(cidrs []string) (nets []*net.IPNet, err error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue