dcim

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonOverlap           = "overlap"
	ReasonOutOfBounds       = "out_of_bounds"
	ReasonImportedReadOnly  = "imported_read_only"
	ReasonStaleVersion      = "stale_version"
	ReasonUnknownDimensions = "unknown_dimensions"
	ReasonNotFound          = "not_found"
	ReasonInvalid           = "invalid"
	ReasonConflict          = "conflict"
	ReasonForbidden         = "forbidden"
)

Variables

This section is empty.

Functions

func AssertInterfacesFree

func AssertInterfacesFree(db *gorm.DB, ifaceAID, ifaceBID, exceptID uint) error

func BothNetboxInterfaces

func BothNetboxInterfaces(a, b models.Interface) bool

func CableSource

func CableSource(netboxID uint) string

func CreateCable

func CreateCable(db *gorm.DB, ifaceAID, ifaceBID uint, label string) (*models.Connection, error)

func CreateFloorPlan

func CreateFloorPlan(db *gorm.DB, siteID uint, name string, width, height, grid int) (*models.FloorPlan, error)

func CreateRack

func CreateRack(db *gorm.DB, w RackWrite) (*models.Rack, error)

func DeleteCable

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

func DeleteRack

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

func DeviceAtLocalSite

func DeviceAtLocalSite(db *gorm.DB, device models.Device, siteID uint) (bool, error)

func DeviceIDsAtLocalSite

func DeviceIDsAtLocalSite(db *gorm.DB, siteID uint) ([]uint, error)

DeviceIDsAtLocalSite returns devices associated with a local site: local SiteID match, imported NetBox site mapping, or a placement in a rack at that site.

func DisplayUnit

func DisplayUnit(rackHeightU, startUnit, offsetU int, numbering string) int

DisplayUnit returns the labelled U number for a 1U slot whose bottom is offsetU whole units from the rack bottom.

func GetCable

func GetCable(db *gorm.DB, id uint) (*models.Connection, error)

func GetRack

func GetRack(db *gorm.DB, id uint) (*models.Rack, error)

func GraphScopeKey

func GraphScopeKey(q GraphQuery) string

func IntervalsOverlap

func IntervalsOverlap(aStart, aEnd, bStart, bEnd int) bool

func Is

func Is(err error, reason string) bool

func ListFloorPlans

func ListFloorPlans(db *gorm.DB, siteID uint) ([]models.FloorPlan, error)

func LoadCableEnds

func LoadCableEnds(db *gorm.DB, ifaceAID, ifaceBID uint) (models.Interface, models.Interface, error)

func LocalSiteIDsForDevice

func LocalSiteIDsForDevice(db *gorm.DB, device models.Device) ([]uint, error)

LocalSiteIDsForDevice returns local sites.id values that this device belongs to. Device.SiteID is a local sites.id for Factum-created devices and a NetBox site id for imported devices — the two sequences are not interchangeable.

func OccupancyPercent

func OccupancyPercent(occupied []Occupied, rackTicks int) int

func OccupiesFace

func OccupiesFace(face string, fullDepth bool, queryFace string) bool

func OffsetFromNetboxPosition

func OffsetFromNetboxPosition(rackHeightU int, numbering string, startUnit int, positionU, heightU float64) int

OffsetFromNetboxPosition converts a NetBox position (lowest-numbered U) into ticks from the bottom of the rack.

func OutOfRack

func OutOfRack(offsetTicks, heightTicks, rackTicks int) bool

func Place

func Place(db *gorm.DB, req PlaceRequest) (*models.DevicePlacement, error)

Place mounts or moves a local device. Imported placements cannot be changed.

func PlacementInterval

func PlacementInterval(offsetTicks, heightTicks int) (start, end int)

func ReasonOf

func ReasonOf(err error) string

func RenameFloorPlan

func RenameFloorPlan(db *gorm.DB, id uint, name string) (*models.FloorPlan, error)

func SetCableNetboxID

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

func SnapMM

func SnapMM(v, grid int) int

func StatusOf

func StatusOf(err error) int

func TicksToU

func TicksToU(ticks int) float64

func UToTicks

func UToTicks(u float64) int

func Unmount

func Unmount(db *gorm.DB, deviceID uint, version int) error

func UpdateCable

func UpdateCable(db *gorm.DB, id, ifaceAID, ifaceBID uint, label string) (*models.Connection, error)

func UpdateRack

func UpdateRack(db *gorm.DB, id uint, w RackWrite) (*models.Rack, error)

func UtilizedTicks

func UtilizedTicks(occupied []Occupied, rackTicks int) int

UtilizedTicks is the union of occupied ticks on either face. A full-depth device is counted once.

func ValidateDeviceTypeResize

func ValidateDeviceTypeResize(db *gorm.DB, typeID uint, newHeight *int, newFull *bool) error

ValidateDeviceTypeResize rejects a size change that would overlap or overflow any placement of that type.

func ValidateRackHeight

func ValidateRackHeight(db *gorm.DB, rack models.Rack, newHeightU int) error

ValidateRackHeight rejects shrinking a rack over existing placements.

func WholeUBoundary

func WholeUBoundary(offsetTicks, heightTicks int) bool

Types

type DeviceBrief

type DeviceBrief struct {
	ID           uint   `json:"id"`
	Name         string `json:"name"`
	DeviceTypeID uint   `json:"device_type_id,omitempty"`
	ModelName    string `json:"model_name,omitempty"`
	VM           bool   `json:"vm"`
	Source       string `json:"source,omitempty"`
	NetboxID     uint   `json:"netbox_id,omitempty"`
	HeightTicks  *int   `json:"height_ticks"`
	FullDepth    *bool  `json:"full_depth"`
}

type ElevationDTO

type ElevationDTO struct {
	Rack        RackSummary    `json:"rack"`
	Placements  []PlacementDTO `json:"placements"`
	Unplaced    []DeviceBrief  `json:"unplaced"`
	Accessories []DeviceBrief  `json:"accessories"`
	Issues      []string       `json:"issues"`
	UnitLabels  []UnitLabel    `json:"unit_labels"`
}

func Elevation

func Elevation(db *gorm.DB, rackID uint) (*ElevationDTO, error)

type Error

type Error struct {
	Status  int
	Reason  string
	Message string
}

Error is a domain error with an HTTP status and machine-readable reason.

func (*Error) Error

func (e *Error) Error() string

type FloorLayoutWrite

type FloorLayoutWrite struct {
	Revision    int                      `json:"revision"`
	WidthMM     int                      `json:"width_mm"`
	HeightMM    int                      `json:"height_mm"`
	GridMM      int                      `json:"grid_mm"`
	Racks       []FloorPlanRackDTO       `json:"racks"`
	Annotations []FloorPlanAnnotationDTO `json:"annotations"`
}

type FloorPlanAnnotationDTO

type FloorPlanAnnotationDTO struct {
	ID       uint   `json:"id,omitempty"`
	Kind     string `json:"kind"`
	Text     string `json:"text"`
	XMM      int    `json:"x_mm"`
	YMM      int    `json:"y_mm"`
	WidthMM  int    `json:"width_mm"`
	HeightMM int    `json:"height_mm"`
	Rotation int    `json:"rotation"`
}

type FloorPlanDTO

type FloorPlanDTO struct {
	ID          uint                     `json:"id"`
	SiteID      uint                     `json:"site_id"`
	SiteName    string                   `json:"site_name,omitempty"`
	Name        string                   `json:"name"`
	WidthMM     int                      `json:"width_mm"`
	HeightMM    int                      `json:"height_mm"`
	GridMM      int                      `json:"grid_mm"`
	Revision    int                      `json:"revision"`
	Racks       []FloorPlanRackDTO       `json:"racks"`
	Annotations []FloorPlanAnnotationDTO `json:"annotations"`
	Available   []RackSummary            `json:"available_racks,omitempty"`
}

func GetFloorPlan

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

func SaveFloorLayout

func SaveFloorLayout(db *gorm.DB, id uint, w FloorLayoutWrite) (*FloorPlanDTO, error)

type FloorPlanRackDTO

type FloorPlanRackDTO struct {
	ID       uint        `json:"id,omitempty"`
	RackID   uint        `json:"rack_id"`
	XMM      int         `json:"x_mm"`
	YMM      int         `json:"y_mm"`
	Rotation int         `json:"rotation"`
	Rack     RackSummary `json:"rack"`
}

type Footprint

type Footprint struct {
	MinX, MinY, MaxX, MaxY int
}

type GraphDTO

type GraphDTO struct {
	Scope     string      `json:"scope"`
	Truncated bool        `json:"truncated"`
	Nodes     []GraphNode `json:"nodes"`
	Edges     []GraphEdge `json:"edges"`
}

func ConnectionGraph

func ConnectionGraph(db *gorm.DB, q GraphQuery) (*GraphDTO, error)

type GraphEdge

type GraphEdge struct {
	ID           uint   `json:"id"`
	Label        string `json:"label,omitempty"`
	DeviceAID    uint   `json:"device_a_id"`
	InterfaceAID uint   `json:"interface_a_id"`
	DeviceBID    uint   `json:"device_b_id"`
	InterfaceBID uint   `json:"interface_b_id"`
	Unavailable  bool   `json:"unavailable,omitempty"`
}

type GraphNode

type GraphNode struct {
	ID         uint        `json:"id"`
	Name       string      `json:"name"`
	External   bool        `json:"external,omitempty"`
	Site       string      `json:"site,omitempty"`
	RackID     uint        `json:"rack_id,omitempty"`
	Interfaces []GraphPort `json:"interfaces"`
}

type GraphPort

type GraphPort struct {
	ID   uint   `json:"id"`
	Name string `json:"name"`
}

type GraphQuery

type GraphQuery struct {
	SiteID   uint
	RackID   uint
	DeviceID uint
	Depth    int
}

type LayoutDTO

type LayoutDTO struct {
	Scope    string        `json:"scope"`
	Revision int           `json:"revision"`
	Nodes    map[string]XY `json:"nodes"`
}

func GetLayout

func GetLayout(db *gorm.DB, userID uint, scope string) (*LayoutDTO, error)

func SaveLayout

func SaveLayout(db *gorm.DB, userID uint, scope string, revision int, nodes map[string]XY) (*LayoutDTO, error)

type Occupied

type Occupied struct {
	DeviceID  uint
	Start     int
	End       int
	Front     bool
	Rear      bool
	FullDepth bool
}

Occupied is one device's occupied interval on a rack face, in ticks from the bottom of the rack. End is exclusive.

func ConflictsWith

func ConflictsWith(existing []Occupied, deviceID uint, start, end int, front, rear bool) *Occupied

func OccupancyFromPlacements

func OccupancyFromPlacements(placements []models.DevicePlacement, heightFor func(deviceID uint) int, fullDepthFor func(deviceID uint) bool) []Occupied

OccupancyFromPlacements builds occupied intervals. heightFor returns the device height in ticks (0 unknown/zero-U). fullDepthFor reports whether the device blocks both faces.

type PairCable

type PairCable struct {
	ID           uint   `json:"id"`
	Label        string `json:"label,omitempty"`
	NetboxID     uint   `json:"netbox_id,omitempty"`
	Source       string `json:"source"`
	DeviceAID    uint   `json:"device_a_id"`
	InterfaceAID uint   `json:"interface_a_id"`
	DeviceBID    uint   `json:"device_b_id"`
	InterfaceBID uint   `json:"interface_b_id"`
}

type PairDTO

type PairDTO struct {
	DeviceA PairDevice  `json:"device_a"`
	DeviceB PairDevice  `json:"device_b"`
	Cables  []PairCable `json:"cables"`
}

PairDTO is two devices with every interface and the cables between them.

func ConnectionPair

func ConnectionPair(db *gorm.DB, aID, bID uint) (*PairDTO, error)

ConnectionPair loads two devices, every interface, and cables that terminate on those ports. aID and bID may be the same device.

type PairDevice

type PairDevice struct {
	ID         uint       `json:"id"`
	Name       string     `json:"name"`
	Site       string     `json:"site,omitempty"`
	Interfaces []PairPort `json:"interfaces"`
}
type PairLink struct {
	ID                uint   `json:"id"`
	Label             string `json:"label,omitempty"`
	NetboxID          uint   `json:"netbox_id,omitempty"`
	Source            string `json:"source"`
	PeerDeviceID      uint   `json:"peer_device_id"`
	PeerDeviceName    string `json:"peer_device_name"`
	PeerInterfaceID   uint   `json:"peer_interface_id"`
	PeerInterfaceName string `json:"peer_interface_name"`
}

PairLink is the cable occupying one interface, if any.

type PairPort

type PairPort struct {
	ID          uint      `json:"id"`
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	Type        string    `json:"type,omitempty"`
	Enabled     bool      `json:"enabled"`
	Connection  *PairLink `json:"connection,omitempty"`
}

type PlaceRequest

type PlaceRequest struct {
	DeviceID    uint
	RackID      uint
	OffsetTicks int
	Face        string
	Version     int
}

type PlacementDTO

type PlacementDTO struct {
	ID            uint    `json:"id"`
	DeviceID      uint    `json:"device_id"`
	DeviceName    string  `json:"device_name"`
	DeviceTypeID  uint    `json:"device_type_id,omitempty"`
	ModelName     string  `json:"model_name,omitempty"`
	OffsetTicks   int     `json:"offset_ticks"`
	HeightTicks   int     `json:"height_ticks"`
	HeightU       float64 `json:"height_u"`
	Face          string  `json:"face"`
	FullDepth     bool    `json:"full_depth"`
	Source        string  `json:"source"`
	Version       int     `json:"version"`
	Conflict      string  `json:"conflict,omitempty"`
	ReadOnly      bool    `json:"read_only"`
	UnknownHeight bool    `json:"unknown_height"`
	ZeroU         bool    `json:"zero_u"`
}

type RackSummary

type RackSummary struct {
	ID                uint   `json:"id"`
	SiteID            uint   `json:"site_id"`
	SiteName          string `json:"site_name,omitempty"`
	Name              string `json:"name"`
	Source            string `json:"source"`
	NetboxID          uint   `json:"netbox_id,omitempty"`
	HeightU           int    `json:"height_u"`
	WidthMM           int    `json:"width_mm"`
	DepthMM           int    `json:"depth_mm"`
	StartUnit         int    `json:"start_unit"`
	Numbering         string `json:"numbering"`
	Version           int    `json:"version"`
	DeviceCount       int    `json:"device_count"`
	OccupancyPercent  int    `json:"occupancy_percent"`
	UnknownDimensions int    `json:"unknown_dimensions"`
	HasConflict       bool   `json:"has_conflict"`
	ReadOnly          bool   `json:"read_only"`
}

func ListRacks

func ListRacks(db *gorm.DB, siteID uint) ([]RackSummary, error)

type RackWrite

type RackWrite struct {
	SiteID    uint   `json:"site_id"`
	Name      string `json:"name"`
	HeightU   int    `json:"height_u"`
	WidthMM   int    `json:"width_mm"`
	DepthMM   int    `json:"depth_mm"`
	StartUnit int    `json:"start_unit"`
	Numbering string `json:"numbering"`
	Version   int    `json:"version"`
}

type UnitLabel

type UnitLabel struct {
	OffsetU int `json:"offset_u"`
	Label   int `json:"label"`
}

type XY

type XY struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Jump to

Keyboard shortcuts

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