func (manager *IPManager) Get(ip string) (string, error) {
	kvPair, err := manager.client.Get(ip)
	if err != nil && err != store.ErrKeyNotFound {
		return "", errors.Wrapf(err, "get ipstore: failed to get %v from db", kvPair)
	}
	if err == store.ErrKeyNotFound {
		return "", nil
	}
	return string(kvPair.Value), nil
}
Get returns the id by which the ip was used and return empty if the key not exists
package ipstore
import (
	"math/big"
	"net"
	"time"
	"github.com/docker/libkv/store"
	"github.com/docker/libkv/store/boltdb"
	"github.com/pkg/errors"
)
const (
	MaxMask = 30
	IPPrefix = "1"
)
type IPManager struct {
	client      store.Store
	subnet      net.IPNet
	lastKnownIP net.IP
}
type Config struct {
	DB                string
	PersistConnection bool
	Bucket            string
	ConnectionTimeout time.Duration
}
type IPAllocator interface {
	GetAvailableIP(string) (string, error)
	Get(string) (string, error)
	Assign(string, string) error
	Update(string, string) error
	Release(string) error
	ReleaseByID(string) (string, error)
	Exists(string) (bool, error)
	SetLastKnownIP(net.IP)
	Close()
}
func NewIPAllocator(options *Config, subnet net.IPNet) (IPAllocator, error) {
	config := &store.Config{
		PersistConnection: options.PersistConnection,
		ConnectionTimeout: options.ConnectionTimeout,
		Bucket:            options.Bucket,
	}
	client, err := boltdb.New([]string{options.DB}, config)
	if err != nil {
		return nil, err
	}
	return &IPManager{
		client:      client,
		subnet:      subnet,
		lastKnownIP: subnet.IP.Mask(subnet.Mask),
	}, nil
}
func (manager *IPManager) SetLastKnownIP(ip net.IP) {
	manager.lastKnownIP = ip
}
func (manager *IPManager) GetAvailableIP(id string) (string, error) {
	var err error
	nextIP := manager.lastKnownIP
	for {
		nextIP, err = NextIP(nextIP, manager.subnet)
		if err != nil {
			return "", err
		}
		err = manager.Assign(nextIP.String(), id)
		if err != nil && err != store.ErrKeyExists {
			return "", errors.Wrapf(err, "ipstore get ip: failed to assign ip in ipam")
		} else if err == store.ErrKeyExists {
		} else {
			manager.lastKnownIP = nextIP
			return nextIP.String(), nil
		}
		if nextIP.Equal(manager.lastKnownIP) {
			return "", errors.New("getAvailableIP ipstore: failed to find available ip addresses in the subnet")
		}
	}
}