Documentation ¶
Index ¶
- Variables
- func StartOperation(pa Interface) *portAllocationOperation
- type ErrNotInRange
- type Interface
- type PortAllocator
- func (r *PortAllocator) Allocate(port int) error
- func (r *PortAllocator) AllocateNext() (int, error)
- func (r *PortAllocator) ForEach(fn func(int))
- func (r *PortAllocator) Free() int
- func (r *PortAllocator) Has(port int) bool
- func (r *PortAllocator) Release(port int) error
- func (r *PortAllocator) Restore(pr net.PortRange, data []byte) error
- func (r *PortAllocator) Snapshot(dst *api.RangeAllocation) error
- func (r *PortAllocator) Used() int
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func StartOperation ¶
func StartOperation(pa Interface) *portAllocationOperation
Creates a portAllocationOperation, tracking a set of allocations & releases
Types ¶
type ErrNotInRange ¶
type ErrNotInRange struct {
ValidPorts string
}
func (*ErrNotInRange) Error ¶
func (e *ErrNotInRange) Error() string
type Interface ¶
type Interface interface { Allocate(int) error AllocateNext() (int, error) Release(int) error ForEach(func(int)) }
Interface manages the allocation of ports out of a range. Interface should be threadsafe.
type PortAllocator ¶
type PortAllocator struct {
// contains filtered or unexported fields
}
func NewFromSnapshot ¶ added in v1.5.5
func NewFromSnapshot(snap *api.RangeAllocation) (*PortAllocator, error)
NewFromSnapshot allocates a PortAllocator and initializes it from a snapshot.
func NewPortAllocator ¶
func NewPortAllocator(pr net.PortRange) *PortAllocator
Helper that wraps NewAllocatorCIDRRange, for creating a range backed by an in-memory store.
func NewPortAllocatorCustom ¶
func NewPortAllocatorCustom(pr net.PortRange, allocatorFactory allocator.AllocatorFactory) *PortAllocator
NewPortAllocatorCustom creates a PortAllocator over a net.PortRange, calling allocatorFactory to construct the backing store.
func (*PortAllocator) Allocate ¶
func (r *PortAllocator) Allocate(port int) error
Allocate attempts to reserve the provided port. ErrNotInRange or ErrAllocated will be returned if the port is not valid for this range or has already been reserved. ErrFull will be returned if there are no ports left.
func (*PortAllocator) AllocateNext ¶
func (r *PortAllocator) AllocateNext() (int, error)
AllocateNext reserves one of the ports from the pool. ErrFull may be returned if there are no ports left.
func (*PortAllocator) ForEach ¶ added in v1.5.5
func (r *PortAllocator) ForEach(fn func(int))
ForEach calls the provided function for each allocated port.
func (*PortAllocator) Free ¶
func (r *PortAllocator) Free() int
Free returns the count of port left in the range.
func (*PortAllocator) Has ¶
func (r *PortAllocator) Has(port int) bool
Has returns true if the provided port is already allocated and a call to Allocate(port) would fail with ErrAllocated.
func (*PortAllocator) Release ¶
func (r *PortAllocator) Release(port int) error
Release releases the port back to the pool. Releasing an unallocated port or a port out of the range is a no-op and returns no error.
func (*PortAllocator) Restore ¶
func (r *PortAllocator) Restore(pr net.PortRange, data []byte) error
Restore restores the pool to the previously captured state. ErrMismatchedNetwork is returned if the provided port range doesn't exactly match the previous range.
func (*PortAllocator) Snapshot ¶
func (r *PortAllocator) Snapshot(dst *api.RangeAllocation) error
Snapshot saves the current state of the pool.
func (*PortAllocator) Used ¶ added in v1.5.5
func (r *PortAllocator) Used() int
Used returns the count of ports used in the range.