Documentation ¶
Index ¶
- Constants
- Variables
- func AddAlias(namespace, alias string, vlan int) error
- func Allocate(namespace, s string) (int, bool, error)
- func Blacklist(vlan int)
- func Delete(namespace, alias string)
- func GetAliases(prefix string) []string
- func GetBlacklist() []int
- func GetRanges() map[string]Range
- func GetVLAN(namespace, alias string) (int, error)
- func ParseVLAN(namespace, s string) (int, error)
- func PrintVLAN(namespace string, vlan int) string
- func SetRange(prefix string, min, max int) error
- func Tabular(namespace string) [][]string
- type Alias
- type Range
- type VLANs
- func (v *VLANs) AddAlias(namespace, alias string, vlan int) error
- func (v *VLANs) Allocate(namespace, alias string) (int, bool, error)
- func (v *VLANs) Blacklist(vlan int)
- func (v *VLANs) Delete(namespace, prefix string)
- func (v *VLANs) GetAlias(vlan int) (Alias, error)
- func (v *VLANs) GetAliases(prefix string) []string
- func (v *VLANs) GetBlacklist() []int
- func (v *VLANs) GetRanges() map[string]Range
- func (v *VLANs) GetVLAN(namespace, alias string) (int, error)
- func (v *VLANs) ParseVLAN(namespace, s string) (int, error)
- func (v *VLANs) PrintVLAN(namespace string, vlan int) string
- func (v *VLANs) SetRange(namespace string, min, max int) error
- func (v *VLANs) Tabular(namespace string) [][]string
Constants ¶
const AliasSep = "//"
AliasSep separates namespace from VLAN alias
const BlacklistedVLAN = "BLACKLISTED"
BlacklistedVLAN is used to track manually reserved VLANs
const DisconnectedVLAN = "DISCONNECTED"
DisconnectedVLAN always resolves to VLAN -1
const VLANStart, VLANEnd = 101, 4096
VLANStart and VLANEnd are the default ranges for VLAN allocation
Variables ¶
var Default = NewVLANs()
var ErrOutOfVLANs = errors.New("out of VLANs")
var ErrUnallocated = errors.New("unallocated")
Functions ¶
func GetAliases ¶
func GetBlacklist ¶
func GetBlacklist() []int
Types ¶
type Alias ¶
func ParseAlias ¶
type VLANs ¶
VLANs stores the state for the VLANs that we've allocated so far
func (*VLANs) Allocate ¶
Allocate looks up the VLAN for the provided alias. If one has not already been assigned, it will allocate the next available VLAN. Returns the VLAN and flag for whether the alias was created or not.
func (*VLANs) Blacklist ¶
Blacklist marks a VLAN as manually configured which removes it from the allocation pool. For instance, if a user runs `vm config net 100`, VLAN 100 would be marked as blacklisted.
func (*VLANs) Delete ¶
Delete allocation for aliases matching a given namespace. Also clears any ranges set for the given namespace if the prefix is empty.
func (*VLANs) GetAlias ¶
GetAlias returns the alias for a given VLAN or ErrUnallocated. Note that previously Blacklisted VLANs will return the const BlacklistedVLAN.
func (*VLANs) GetAliases ¶
GetAliases returns a list of aliases with the given prefix.
func (*VLANs) GetBlacklist ¶
GetBlacklist returns a list of VLANs that have been blacklisted.
func (*VLANs) ParseVLAN ¶
ParseVLAN parses s and returns a VLAN. If s can be parsed as an integer, the resulting integer is returned. If s matches an existing alias, that VLAN is returned. Otherwise, returns ErrUnallocated.
func (*VLANs) PrintVLAN ¶
PrintVLAN prints the alias for the VLAN, if one is set. Will trim off the namespace prefix if it matches the currently active namespace.