ipam

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPool

func AddPool(db *gorm.DB, nsID uint, raw string) (*models.IpamNamespacePrefix, error)

func Allocate

func Allocate(db *gorm.DB, nsID, vrfID uint, raw, description string) (*models.IpamPrefix, error)

func CreateVRF

func CreateVRF(db *gorm.DB, nsID uint, name, description string) (*models.IpamVRF, error)

func DeleteNamespace

func DeleteNamespace(db *gorm.DB, id uint) error

func DeletePool

func DeletePool(db *gorm.DB, nsID, poolID uint) error

func DeletePrefix

func DeletePrefix(db *gorm.DB, nsID, prefixID uint) error

func DeleteVRF

func DeleteVRF(db *gorm.DB, nsID, vrfID uint) error

func Enabled

func Enabled(db *gorm.DB) bool

Enabled reports Settings.IpamEnabled (nil/false = off). Disabling the flag only hides the UI and 404s /api/ipam/* — it does not touch rows.

func ListPools

func ListPools(db *gorm.DB, nsID uint) ([]models.IpamNamespacePrefix, error)

func ListPrefixes

func ListPrefixes(db *gorm.DB, nsID uint) ([]models.IpamPrefix, error)

func ListVRFs

func ListVRFs(db *gorm.DB, nsID uint) ([]models.IpamVRF, error)

func ParseNodeKey

func ParseNodeKey(s string) (string, uint, error)

ParseNodeKey splits "ns:3" into ("ns", 3).

func ParsePrefix

func ParsePrefix(s string) (netip.Prefix, error)

ParsePrefix accepts a CIDR or a bare address that means "the whole family": 0.0.0.0 and 0.0.0.0/0 are IPv4-any; :: and ::/0 are IPv6-any. The result is always masked (10.1.2.3/24 → 10.1.2.0/24).

func UpdatePrefix

func UpdatePrefix(db *gorm.DB, nsID, prefixID uint, description string) (*models.IpamPrefix, error)

func UpdateVRF

func UpdateVRF(db *gorm.DB, nsID, vrfID uint, name, description string) (*models.IpamVRF, error)

Types

type NamespaceView

type NamespaceView struct {
	models.IpamNamespace
	Pools       []models.IpamNamespacePrefix `json:"pools"`
	VRFs        []models.IpamVRF             `json:"vrfs"`
	PrefixCount int64                        `json:"prefix_count"`
	PoolCount   int                          `json:"pool_count"`
	VRFCount    int                          `json:"vrf_count"`
}

NamespaceView is a namespace plus the bits the list/detail pages need without extra round-trips.

func CreateNamespace

func CreateNamespace(db *gorm.DB, name, description string) (*NamespaceView, error)

func GetNamespace

func GetNamespace(db *gorm.DB, id uint) (*NamespaceView, error)

func ListNamespaces

func ListNamespaces(db *gorm.DB) ([]NamespaceView, error)

func UpdateNamespace

func UpdateNamespace(db *gorm.DB, id uint, name, description string) (*NamespaceView, error)

type StatusError

type StatusError struct {
	Status  int
	Message string
}

StatusError is an application-level failure with an HTTP-ish status so handlers don't have to string-match error text.

func (*StatusError) Error

func (e *StatusError) Error() string

type TreeNode

type TreeNode struct {
	Key      string       `json:"key"`
	Title    string       `json:"title"`
	Lazy     bool         `json:"lazy"`
	Expanded bool         `json:"expanded,omitempty"`
	Type     string       `json:"type"`
	Data     TreeNodeData `json:"data"`
	Children []TreeNode   `json:"children,omitempty"`
}

TreeNode is one row of the prefix tree, shaped for Wunderbaum (key, title, lazy, data). Parent/children are computed from CIDR containment.

func Children

func Children(db *gorm.DB, parentKey string) ([]TreeNode, error)

Children returns the next tree level under parentKey (ns:1, vrf:2, …).

func Roots

func Roots(db *gorm.DB) ([]TreeNode, error)

Roots returns every namespace as a top-level tree node, with the first level of children already loaded so a refresh shows root prefixes and extra VRFs without an extra expand click.

func Tree

func Tree(db *gorm.DB, nsID uint, parentRaw string) ([]TreeNode, error)

type TreeNodeData

type TreeNodeData struct {
	Kind        string  `json:"kind"` // namespace | pool | vrf | allocated
	ID          uint    `json:"id"`
	NamespaceID uint    `json:"namespace_id,omitempty"`
	PoolID      uint    `json:"pool_id,omitempty"`
	PrefixID    uint    `json:"prefix_id,omitempty"`
	VRFID       uint    `json:"vrf_id,omitempty"`
	VRFName     string  `json:"vrf_name,omitempty"`
	IsDefault   bool    `json:"is_default,omitempty"`
	Family      int     `json:"family"`
	Description string  `json:"description,omitempty"`
	Used        string  `json:"used"`
	UsedFrac    float64 `json:"used_frac"`
	ChildCount  int     `json:"child_count"`
}

Jump to

Keyboard shortcuts

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