Documentation ¶
Overview ¶
Package ipam is a ip address management library for ip's and prefixes (networks).
It uses either memory or postgresql database to store the ip's and prefixes. You can also bring you own Storage implementation as you need.
Example usage:
import ( "fmt" goipam "github.com/metal-stack/go-ipam" ) func main() { // create a ipamer with in memory storage ipam := goipam.New() prefix, err := ipam.NewPrefix("192.168.0.0/24") if err != nil { panic(err) } ip, err := ipam.AcquireIP(prefix) if err != nil { panic(err) } fmt.Printf("got IP: %s", ip.IP) err = ipam.ReleaseIP(ip) if err != nil { panic(err) } fmt.Printf("IP: %s released.", ip.IP) }
Index ¶
- Constants
- Variables
- func JitterDelay(_ uint, config *retry.Config) time.Duration
- func NewMemory() *memory
- func NewPostgresStorage(host, port, user, password, dbname string, sslmode SSLMode) (*sql, error)
- func NewPostgresStorageFromDsn(dsn string) (*sql, error)
- type Cleanable
- type ExtendedSQL
- func (s ExtendedSQL) CreatePrefix(prefix Prefix, tenantid string) (Prefix, error)
- func (s ExtendedSQL) DeletePrefix(prefix Prefix, tenantid string) (Prefix, error)
- func (s ExtendedSQL) ReadAllPrefixes(tenantid string) ([]Prefix, error)
- func (s ExtendedSQL) ReadPrefix(prefix string, tenantid string) (Prefix, error)
- func (s ExtendedSQL) UpdatePrefix(prefix Prefix, tenantid string) (Prefix, error)
- type IP
- type IPinUseError
- type Ipamer
- type NoIPAvailableError
- type NotFoundError
- type OptimisticLockError
- type Prefix
- type SSLMode
- type Storage
- type StorageProvider
- type Usage
Constants ¶
const ( // SSLModeAllow I don't care about security // but I will pay the overhead of encryption if the server insists on it SSLModeAllow = SSLMode("allow") // SSLModeDisable I don't care about security // and I don't want to pay the overhead of encryption. SSLModeDisable = SSLMode("disable") // SSLModePrefer I don't care about encryption // but I wish to pay the overhead of encryption if the server supports it. SSLModePrefer = SSLMode("prefer") // SSLModeRequire I want my data to be encrypted and I accept the overhead. // I trust that the network will make sure I always connect to the server I want. SSLModeRequire = SSLMode("require") // SSLModeVerifyCA I want my data encrypted and I accept the overhead. // I want to be sure that I connect to a server that I trust. SSLModeVerifyCA = SSLMode("verify-ca") // SSLModeVerifyFull I want my data encrypted and I accept the overhead. // I want to be sure that I connect to a server I trust, and that it's the one I specify. SSLModeVerifyFull = SSLMode("verify-full") )
Variables ¶
var ( // ErrNotFound is returned if prefix or cidr was not found ErrNotFound NotFoundError // ErrNoIPAvailable is returned if no IP is available anymore ErrNoIPAvailable NoIPAvailableError // ErrIpinUse is retured if IP is already aquired ErrIPinUse IPinUseError )
Functions ¶
func JitterDelay ¶
JitterDelay is a DelayType which varies delay in each iterations
func NewPostgresStorage ¶
NewPostgresStorage creates a new Storage which uses postgres.
func NewPostgresStorageFromDsn ¶ added in v1.6.4
Types ¶
type Cleanable ¶
type Cleanable interface {
// contains filtered or unexported methods
}
Cleanable interface for impls that support cleaning before each testrun
type ExtendedSQL ¶
type ExtendedSQL struct {
// contains filtered or unexported fields
}
ExtendedSQL extended sql interface
func (ExtendedSQL) CreatePrefix ¶
func (ExtendedSQL) DeletePrefix ¶
func (ExtendedSQL) ReadAllPrefixes ¶
func (ExtendedSQL) ReadPrefix ¶
type IPinUseError ¶ added in v1.6.2
type IPinUseError struct { }
IPinUseError is raised if the given IP is already in use so cannot be aquired
func (IPinUseError) Error ¶ added in v1.6.2
func (o IPinUseError) Error() string
type Ipamer ¶
type Ipamer interface { // NewPrefix create a new Prefix from a string notation. NewPrefix(cidr string, tenantid string) (*Prefix, error) // DeletePrefix delete a Prefix from a string notation. // If the Prefix is not found an NotFoundError is returned. DeletePrefix(cidr string, tenantid string) (*Prefix, error) // AcquireChildPrefix will return a Prefix with a smaller length from the given Prefix. AcquireChildPrefix(parentCidr string, length int, tenantid string) (*Prefix, error) // ReleaseChildPrefix will mark this child Prefix as available again. ReleaseChildPrefix(child *Prefix, tenantid string) error // PrefixFrom will return a known Prefix. PrefixFrom(cidr string, tenantid string) *Prefix // AcquireSpecificIP will acquire given IP and mark this IP as used, if already in use, return nil. // If specificIP is empty, the next free IP is returned. // If there is no free IP an NoIPAvailableError is returned. AcquireSpecificIP(prefixCidr, specificIP string, tenantid string) (*IP, error) // AcquireIP will return the next unused IP from this Prefix. AcquireIP(prefixCidr string, tenantid string) (*IP, error) // ReleaseIP will release the given IP for later usage and returns the updated Prefix. // If the IP is not found an NotFoundError is returned. ReleaseIP(ip *IP, tenantid string) (*Prefix, error) // ReleaseIPFromPrefix will release the given IP for later usage. // If the Prefix or the IP is not found an NotFoundError is returned. ReleaseIPFromPrefix(prefixCidr, ip string, tenantid string) error // PrefixesOverlapping will check if one ore more prefix of newPrefixes is overlapping // with one of existingPrefixes PrefixesOverlapping(existingPrefixes []string, newPrefixes []string) error }
Ipamer can be used to do IPAM stuff.
func NewWithStorage ¶
NewWithStorage allows you to create a Ipamer instance with your Storage implementation. The Storage interface must be implemented.
type NoIPAvailableError ¶
type NoIPAvailableError struct { }
NoIPAvailableError indicates that the acquire-operation could not be executed because the specified prefix has no free IP anymore.
func (NoIPAvailableError) Error ¶
func (o NoIPAvailableError) Error() string
type NotFoundError ¶
type NotFoundError struct { }
NotFoundError is raised if the given Prefix or Cidr was not found
func (NotFoundError) Error ¶
func (o NotFoundError) Error() string
type OptimisticLockError ¶
type OptimisticLockError struct {
// contains filtered or unexported fields
}
OptimisticLockError indicates that the operation could not be executed because the dataset to update has changed in the meantime. clients can decide to read the current dataset and retry the operation.
func (OptimisticLockError) Error ¶
func (o OptimisticLockError) Error() string
type Prefix ¶
type Prefix struct { Cidr string // The Cidr of this prefix ParentCidr string // if this prefix is a child this is a pointer back Ips map[string]bool // The ips contained in this prefix // contains filtered or unexported fields }
Prefix is a expression of a ip with length and forms a classless network.
type SSLMode ¶
type SSLMode string
SSLMode specifies how to configure ssl encryption to the database
type Storage ¶
type Storage interface { CreatePrefix(prefix Prefix, tenantid string) (Prefix, error) ReadPrefix(prefix string, tenantid string) (Prefix, error) ReadAllPrefixes(tenantid string) ([]Prefix, error) UpdatePrefix(prefix Prefix, tenantid string) (Prefix, error) DeletePrefix(prefix Prefix, tenantid string) (Prefix, error) }
Storage is a interface to store ipam objects.
type StorageProvider ¶
type StorageProvider struct {
// contains filtered or unexported fields
}
StorageProvider provides different storages