allocator

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoFreeAddresses is returned is there is no free IP addresses left in the pool
	ErrNoFreeAddresses = errors.New("no free addresses in the allocated range")
)

Functions

func CanonicalizeIP

func CanonicalizeIP(addr *net.IP) error

CanonicalizeIP makes sure a provided ip is in standard form

Types

type IPAllocator

type IPAllocator interface {
	// Allocate allocates IP address from the range for the container identified by ID and ifName
	Allocate(id string, ifName string, meta types.ReservationMetadata, staticIP net.IP) (*current.IPConfig, error)
}

IPAllocator is the interface of the allocate package

func NewIPAllocator

func NewIPAllocator(s *RangeSet, exclusions *RangeSet,
	poolKey string, session storePkg.Session) IPAllocator

NewIPAllocator create and initialize a new instance of IP allocator

type Range

type Range struct {
	RangeStart net.IP      `json:"rangeStart,omitempty"` // The first ip, inclusive
	RangeEnd   net.IP      `json:"rangeEnd,omitempty"`   // The last ip, inclusive
	Subnet     types.IPNet `json:"subnet"`
	Gateway    net.IP      `json:"gateway,omitempty"`
}

Range contains IP range configuration

func (*Range) Canonicalize

func (r *Range) Canonicalize() error

Canonicalize takes a given range and ensures that all information is consistent, filling out Start, End, and Gateway with sane values if missing

func (*Range) Contains

func (r *Range) Contains(addr net.IP) bool

Contains checks if a given ip is a valid, allocatable address in a given Range

func (*Range) Overlaps

func (r *Range) Overlaps(r1 *Range) bool

Overlaps returns true if there is any overlap between ranges

func (*Range) String

func (r *Range) String() string

String returns string representation of the Range

type RangeIter

type RangeIter struct {
	// contains filtered or unexported fields
}

RangeIter implements iterator over the RangeSet

func (*RangeIter) Next

func (i *RangeIter) Next() (*net.IPNet, net.IP)

Next returns the next IP, its mask, and its gateway. Returns nil if the iterator has been exhausted

func (*RangeIter) StartIP

func (i *RangeIter) StartIP() net.IP

StartIP returns start IP of the current range

type RangeSet

type RangeSet []Range

RangeSet is an alias type for list or Range objects

func (*RangeSet) Canonicalize

func (s *RangeSet) Canonicalize() error

Canonicalize ensures the RangeSet is in a standard form, and detects any invalid input. Call Range.Canonicalize() on every Range in the set

func (*RangeSet) Contains

func (s *RangeSet) Contains(addr net.IP) bool

Contains returns true if any range in this set contains an IP

func (*RangeSet) Overlaps

func (s *RangeSet) Overlaps(p1 *RangeSet) bool

Overlaps returns true if any ranges in any set overlap with this one

func (*RangeSet) RangeFor

func (s *RangeSet) RangeFor(addr net.IP) (*Range, error)

RangeFor finds the range that contains an IP, or nil if not found

func (*RangeSet) String

func (s *RangeSet) String() string

String returns string representation of the RangeSet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL