import_

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetProvider

func GetProvider() interface {
	ClearRecords()
	SetRecords(records []CsvRecord)
}

GetProvider returns the Example singleton via the registered getter.

func GetSystemProvider

func GetSystemProvider() interface {
	SetSystemRecords(data *SystemCSV)
	ClearSystemRecords()
	IsSystemImport() bool
}

GetSystemProvider returns the Example singleton for system CSV operations.

func Import

func Import(cmd *cobra.Command, args []string, inventory *devicetypes.Inventory) error

func ImportCSV

func ImportCSV(cmd *cobra.Command, args []string, inventory *devicetypes.Inventory) error

ImportCSV parses a CSV file and stores raw records on the Example provider. Auto-detects system CSV format (multi-section with Section column) vs traditional BOM CSV format. Does NOT create inventory objects; that is the responsibility of the transform phase.

func IsCableRecord

func IsCableRecord(rec CsvRecord) bool

IsCableRecord returns true if the record defines a cable connection. Exported so the provider can separate device records from cable records during import.

func IsSystemCSV

func IsSystemCSV(header []string) bool

IsSystemCSV returns true if the header row contains a "Section" column, indicating this is a system CSV rather than a traditional BOM CSV.

func SetProviderGetter

func SetProviderGetter(getter func() interface {
	ClearRecords()
	SetRecords(records []CsvRecord)
})

SetProviderGetter allows the parent package to provide access to the singleton.

func SetSystemProviderGetter

func SetSystemProviderGetter(getter func() interface {
	SetSystemRecords(data *SystemCSV)
	ClearSystemRecords()
	IsSystemImport() bool
})

SetSystemProviderGetter allows the parent package to provide system CSV access.

Types

type CsvRecord

type CsvRecord struct {
	PartNumber  string
	Description string
	Quantity    int
	ConfigGroup string // optional, e.g., "0100", "0200"
	// Cable fields (optional)
	SourceDevice string // device name for cable termination A
	SourcePort   string // interface name on source device
	DestDevice   string // device name for cable termination B
	DestPort     string // interface name on destination device
	CableType    string // e.g., "cat6", "dac-passive"
	CableLength  string // e.g., "2m", "10ft"
}

CsvRecord holds a parsed row from the CSV file. Contains only raw CSV column data; no inferred or computed fields.

func ParseCSV

func ParseCSV(filePath string) ([]CsvRecord, error)

ParseCSV reads and parses a CSV file into CsvRecord slices. Skips malformed rows with warnings.

type SystemCSV

type SystemCSV struct {
	Defaults        SystemRecord            // global _defaults row
	SectionDefaults map[string]SystemRecord // per-section defaults (e.g. device_defaults)
	Roles           []SystemRecord
	Locations       []SystemRecord
	Racks           []SystemRecord
	Devices         []SystemRecord
	Modules         []SystemRecord
	Connections     []SystemRecord
}

SystemCSV holds parsed system CSV data grouped by section.

func ParseSystemCSV

func ParseSystemCSV(filePath string) (*SystemCSV, error)

ParseSystemCSV reads a system CSV file and returns grouped records.

func (*SystemCSV) ApplyDefaults

func (s *SystemCSV) ApplyDefaults(rec SystemRecord) SystemRecord

ApplyDefaults merges defaults into a record. Fields already set on rec take precedence. Global defaults are applied first, then section-specific.

type SystemRecord

type SystemRecord struct {
	Section      string // role, rack, device, module, connection
	PartNumber   string
	Name         string
	Qty          int
	Rack         string // parent rack name (devices)
	Position     int    // U position in rack (devices)
	Face         string // front, rear (devices)
	Role         string // role name (devices)
	Status       string
	Serial       string
	Device       string // parent device name (modules)
	Bay          string // module bay (modules)
	ADevice      string // connection endpoint A device
	APort        string // connection endpoint A port
	BDevice      string // connection endpoint B device
	BPort        string // connection endpoint B port
	Color        string // cable color (connections)
	Length       string // cable length value (connections)
	LengthUnit   string // cable length unit (connections)
	Location     string // location name (racks)
	ContentTypes string // comma-separated content types (roles)
}

SystemRecord holds a parsed row from a system CSV file. The Section field determines which other fields are relevant.

Jump to

Keyboard shortcuts

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