Documentation
¶
Index ¶
- func CIDRAddressCount(cidr string) (*big.Int, error)
- func CIDRAddressCountFitsInt64(cidr string) bool
- func CIDRAddressCountInt64(cidr string) int64
- func CIDRAddressCountString(cidr string) string
- func Contains(supernet string, cidr string) (bool, error)
- func IsCIDRAvailable(supernet string, cidr string) (bool, error)
- func NextAvailableCIDR(supernet string, prefixLength int) (string, error)
- func NextAvailableCIDRWithAllocations(supernet string, prefixLength int, allocatedCIDRs []string) (string, error)
- func Overlaps(cidr1 string, cidr2 string) (bool, error)
- func ValidateCIDR(cidr string) bool
- type Allocation
- type Block
- type Environment
- type Pool
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CIDRAddressCount ¶
CIDRAddressCount returns the number of addresses in the CIDR (2^(bits-prefix)) for both IPv4 and IPv6. Caller can use the result for display or comparison.
func CIDRAddressCountFitsInt64 ¶
CIDRAddressCountFitsInt64 reports whether the CIDR's address count fits in int64.
func CIDRAddressCountInt64 ¶
CIDRAddressCountInt64 returns the address count as int64 when it fits; otherwise 0. Used for backward-compat storage (total_ips) when value fits in BIGINT.
func CIDRAddressCountString ¶
CIDRAddressCountString returns the address count as a decimal string for API/display. Returns "0" on parse error so callers can still display something safe.
func IsCIDRAvailable ¶
IsCIDRAvailable checks if the specified CIDR block is available within the given supernet.
func NextAvailableCIDR ¶
NextAvailableCIDR finds the next available CIDR block within the given supernet. It attempts best-effort bin-packing to minimize fragmentation of the supernet.
func NextAvailableCIDRWithAllocations ¶
func NextAvailableCIDRWithAllocations(supernet string, prefixLength int, allocatedCIDRs []string) (string, error)
NextAvailableCIDRWithAllocations returns a suggested CIDR of the given prefix length within the supernet, considering existing allocations (IPv4 only). It bin-packs: first tries to fill a gap between allocations; if no gap fits, returns the next available CIDR after the last allocation. If allocatedCIDRs is empty, delegates to NextAvailableCIDR.
func ValidateCIDR ¶
ValidateCIDR checks if the provided CIDR block is valid.
Types ¶
type Allocation ¶
type Allocation struct {
Id uuid.UUID `json:"id"`
Name string `json:"name"`
Block Block `json:"block"`
}
Allocation represents an allocation of a network block.
type Block ¶
type Block struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
CIDR string `json:"cidr"`
Usage Usage `json:"usage"`
Children []Block `json:"children,omitempty"`
EnvironmentID uuid.UUID `json:"environment_id,omitempty"`
OrganizationID uuid.UUID `json:"organization_id,omitempty"` // for orphan blocks; blocks in envs get org via environment
PoolID *uuid.UUID `json:"pool_id,omitempty"` // optional; block CIDR must be contained in pool's CIDR
}
Block represents a network block with a CIDR notation. When EnvironmentID is nil (orphan block), OrganizationID scopes the block to that organization. PoolID optionally links the block to an environment pool; the block's CIDR must be contained in the pool's CIDR.
type Environment ¶
type Environment struct {
Id uuid.UUID `json:"id"`
Name string `json:"name"`
OrganizationID uuid.UUID `json:"organization_id"`
Block []Block `json:"block"`
}
Environment represents a network environment. It containers a supernet block.
type Pool ¶
type Pool struct {
ID uuid.UUID `json:"id"`
OrganizationID uuid.UUID `json:"organization_id"`
EnvironmentID uuid.UUID `json:"environment_id"`
Name string `json:"name"`
CIDR string `json:"cidr"`
}
Pool is a range of CIDRs that network blocks in an environment can draw from. Pools are scoped to an organization (via environment). Hierarchy: Organization -> Environment -> Pool(s) -> Network blocks -> Allocations