apply

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 26 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisplayConfigValidationErrors

func DisplayConfigValidationErrors(errors []error, deviceMAC string, vendorName string) bool

DisplayConfigValidationErrors displays vendor validation errors from ValidateForVendor. Returns true if there are errors that should abort the operation.

func DisplayConfigWarnings

func DisplayConfigWarnings(warnings []error, deviceMAC string) bool

DisplayConfigWarnings formats and displays configuration warnings/errors nicely. Returns true if there are critical errors that should abort the operation.

func HandleCommand

func HandleCommand(ctx context.Context, client api.Client, cfg *config.Config, args []string, apiLabel string, force bool) error

HandleCommand processes apply-related subcommands

Types

type APUpdater

type APUpdater struct {
	*BaseDeviceUpdater
	// contains filtered or unexported fields
}

APUpdater implements DeviceUpdater for Access Points

func NewAPUpdater

func NewAPUpdater() *APUpdater

NewAPUpdater creates a new AP updater

func (*APUpdater) FindDevicesInventoryStatus

func (a *APUpdater) FindDevicesInventoryStatus(client api.Client, cfg *config.Config, configuredAPs []string) ([]DeviceInventoryStatus, error)

FindDevicesInventoryStatus checks AP status in inventory and cache

func (*APUpdater) FindDevicesToUpdate

func (a *APUpdater) FindDevicesToUpdate(ctx context.Context, client api.Client, _ *config.Config, siteConfig SiteConfig, configuredAPs []string, siteID string, apiLabel string) ([]string, error)

FindDevicesToUpdate identifies APs that need configuration updates

func (*APUpdater) GetConfiguredDevices

func (a *APUpdater) GetConfiguredDevices(siteConfig SiteConfig) []string

GetConfiguredDevices extracts AP MAC addresses from site configuration

func (*APUpdater) GetDeviceConfigFromSite

func (a *APUpdater) GetDeviceConfigFromSite(siteConfig SiteConfig, mac string) (map[string]any, bool)

GetDeviceConfigFromSite extracts AP-specific config from site configuration

func (*APUpdater) UpdateDeviceConfigurations

func (a *APUpdater) UpdateDeviceConfigurations(ctx context.Context, client api.Client, cfg *config.Config, siteConfig SiteConfig, macs []string, siteID string, apiLabel string) error

UpdateDeviceConfigurations applies configuration updates to APs

type BaseDeviceUpdater

type BaseDeviceUpdater struct {
	// contains filtered or unexported fields
}

BaseDeviceUpdater provides common functionality for all device types

func NewBaseDeviceUpdater

func NewBaseDeviceUpdater(deviceType string) *BaseDeviceUpdater

NewBaseDeviceUpdater creates a new base device updater

func (*BaseDeviceUpdater) AssignDevices

func (b *BaseDeviceUpdater) AssignDevices(ctx context.Context, client api.Client, cfg *config.Config, macs []string, siteID string) error

AssignDevices assigns devices to a site

func (*BaseDeviceUpdater) ExportCurrentDeviceConfiguration

func (b *BaseDeviceUpdater) ExportCurrentDeviceConfiguration(_ context.Context, _ api.Client, mac string, _ string) (map[string]any, error)

ExportCurrentDeviceConfiguration exports current device config for backup

func (*BaseDeviceUpdater) FindDevicesToAssign

func (b *BaseDeviceUpdater) FindDevicesToAssign(_ api.Client, _ *config.Config, configuredDevices []string, siteID string) ([]string, error)

FindDevicesToAssign identifies devices that need to be assigned to the site. NOTE: This only returns devices that are in the API inventory to ensure we don't try to assign devices that aren't managed by this system.

func (*BaseDeviceUpdater) GetAssignedDevices

func (b *BaseDeviceUpdater) GetAssignedDevices(_ context.Context, _ api.Client, siteID string) ([]string, error)

GetAssignedDevices gets MAC addresses of devices assigned to a site from cache

func (*BaseDeviceUpdater) GetDeviceType

func (b *BaseDeviceUpdater) GetDeviceType() string

GetDeviceType returns the device type

func (*BaseDeviceUpdater) GetInventoryChecker

func (b *BaseDeviceUpdater) GetInventoryChecker() *InventoryChecker

GetInventoryChecker returns the stored inventory checker

func (*BaseDeviceUpdater) SetInventoryChecker

func (b *BaseDeviceUpdater) SetInventoryChecker(checker *InventoryChecker)

SetInventoryChecker sets the inventory checker for reuse across operations

func (*BaseDeviceUpdater) UnassignDevices

func (b *BaseDeviceUpdater) UnassignDevices(ctx context.Context, client api.Client, cfg *config.Config, macs []string) error

UnassignDevices removes devices from a site

type ConfigFileStructure

type ConfigFileStructure struct {
	Version      int           `json:"version"`
	Config       ConfigWrapper `json:"config"`                  // New format with sites wrapper
	LastModified string        `json:"last_modified,omitempty"` // UTC timestamp when file was last modified
}

ConfigFileStructure represents the structure of a site config file

type ConfigWrapper

type ConfigWrapper struct {
	Sites map[string]SiteConfig `json:"sites"`
}

ConfigWrapper wraps the sites map

type ConfigurationBackup

type ConfigurationBackup struct {
	Timestamp      int64                     `json:"timestamp"`
	SiteID         string                    `json:"site_id"`
	SiteName       string                    `json:"site_name"`
	Operation      string                    `json:"operation"`
	DeviceCount    int                       `json:"device_count"`
	Devices        map[string]map[string]any `json:"devices"` // MAC -> config
	BackupFilePath string                    `json:"-"`       // Not serialized
}

ConfigurationBackup represents a backup of device configurations for rollback

type DeviceBatchLoader

type DeviceBatchLoader struct {
	// contains filtered or unexported fields
}

DeviceBatchLoader provides efficient batch device lookups for apply operations

func NewDeviceBatchLoader

func NewDeviceBatchLoader(_ context.Context, _ api.Client, siteID string, deviceType string) (*DeviceBatchLoader, error)

NewDeviceBatchLoader creates a new batch loader for a specific site and device type. Uses multi-vendor cache for device data.

func (*DeviceBatchLoader) GetAllDevices

func (d *DeviceBatchLoader) GetAllDevices() []*api.UnifiedDevice

GetAllDevices returns all devices in the batch

func (*DeviceBatchLoader) GetDeviceByMAC

func (d *DeviceBatchLoader) GetDeviceByMAC(mac string) (*api.UnifiedDevice, error)

GetDeviceByMAC retrieves a device by MAC with O(1) lookup

func (*DeviceBatchLoader) GetDeviceCount

func (d *DeviceBatchLoader) GetDeviceCount() int

GetDeviceCount returns the number of devices in the batch loader

func (*DeviceBatchLoader) HasDevice

func (d *DeviceBatchLoader) HasDevice(mac string) bool

HasDevice checks if a device exists in the batch loader

type DeviceInventoryStatus

type DeviceInventoryStatus struct {
	MAC             string
	InCache         bool
	InInventory     bool
	CurrentSiteName string
	CurrentSiteID   string
}

DeviceInventoryStatus represents the status of a device in relation to inventory and cache

type DeviceUpdater

type DeviceUpdater interface {
	// GetDeviceType returns the device type (ap, switch, gateway)
	GetDeviceType() string

	// GetConfiguredDevices extracts device MAC addresses from site configuration
	GetConfiguredDevices(siteConfig SiteConfig) []string

	// GetAssignedDevices gets MAC addresses of devices assigned to a site from cache
	GetAssignedDevices(ctx context.Context, client api.Client, siteID string) ([]string, error)

	// FindDevicesInventoryStatus checks device status in inventory and cache
	FindDevicesInventoryStatus(client api.Client, cfg *config.Config, configuredDevices []string) ([]DeviceInventoryStatus, error)

	// UnassignDevices removes devices from a site
	UnassignDevices(ctx context.Context, client api.Client, cfg *config.Config, macs []string) error

	// AssignDevices assigns devices to a site
	AssignDevices(ctx context.Context, client api.Client, cfg *config.Config, macs []string, siteID string) error

	// FindDevicesToAssign identifies devices that need to be assigned to the site
	FindDevicesToAssign(client api.Client, cfg *config.Config, configuredDevices []string, siteID string) ([]string, error)

	// FindDevicesToUpdate identifies devices that need configuration updates
	FindDevicesToUpdate(ctx context.Context, client api.Client, cfg *config.Config, siteConfig SiteConfig, configuredDevices []string, siteID string, apiLabel string) ([]string, error)

	// UpdateDeviceConfigurations applies configuration updates to devices
	UpdateDeviceConfigurations(ctx context.Context, client api.Client, cfg *config.Config, siteConfig SiteConfig, macs []string, siteID string, apiLabel string) error

	// GetDeviceConfigFromSite extracts device-specific config from site configuration
	GetDeviceConfigFromSite(siteConfig SiteConfig, mac string) (map[string]any, bool)

	// ExportCurrentDeviceConfiguration exports current device config for backup
	ExportCurrentDeviceConfiguration(ctx context.Context, client api.Client, mac string, siteID string) (map[string]any, error)

	// SetInventoryChecker sets the inventory checker for reuse across operations
	SetInventoryChecker(checker *InventoryChecker)

	// GetInventoryChecker returns the stored inventory checker
	GetInventoryChecker() *InventoryChecker
}

DeviceUpdater defines the interface for device update operations

type FileHashCache

type FileHashCache struct {
	Hashes map[string]FileHashInfo `json:"hashes"`
}

FileHashCache stores file hashes and modification times for change detection

type FileHashInfo

type FileHashInfo struct {
	Hash    string    `json:"hash"`
	ModTime time.Time `json:"mod_time"`
}

FileHashInfo stores hash and modification time for a file

type GatewayUpdater

type GatewayUpdater struct {
	*BaseDeviceUpdater
	// contains filtered or unexported fields
}

GatewayUpdater implements DeviceUpdater for Gateways (WAN Edge devices)

func NewGatewayUpdater

func NewGatewayUpdater() *GatewayUpdater

NewGatewayUpdater creates a new Gateway updater

func (*GatewayUpdater) FindDevicesInventoryStatus

func (g *GatewayUpdater) FindDevicesInventoryStatus(client api.Client, cfg *config.Config, configuredGateways []string) ([]DeviceInventoryStatus, error)

FindDevicesInventoryStatus checks Gateway status in inventory and cache

func (*GatewayUpdater) FindDevicesToUpdate

func (g *GatewayUpdater) FindDevicesToUpdate(ctx context.Context, client api.Client, _ *config.Config, siteConfig SiteConfig, configuredGateways []string, siteID string, apiLabel string) ([]string, error)

FindDevicesToUpdate identifies Gateways that need configuration updates

func (*GatewayUpdater) GetConfiguredDevices

func (g *GatewayUpdater) GetConfiguredDevices(siteConfig SiteConfig) []string

GetConfiguredDevices extracts Gateway MAC addresses from site configuration

func (*GatewayUpdater) GetDeviceConfigFromSite

func (g *GatewayUpdater) GetDeviceConfigFromSite(siteConfig SiteConfig, mac string) (map[string]any, bool)

GetDeviceConfigFromSite extracts Gateway-specific config from site configuration

func (*GatewayUpdater) UpdateDeviceConfigurations

func (g *GatewayUpdater) UpdateDeviceConfigurations(ctx context.Context, client api.Client, cfg *config.Config, siteConfig SiteConfig, macs []string, siteID string, apiLabel string) error

UpdateDeviceConfigurations applies configuration updates to Gateways

type InventoryChecker

type InventoryChecker struct {
	// contains filtered or unexported fields
}

InventoryChecker provides methods to verify devices are in inventory before operations

func NewInventoryChecker

func NewInventoryChecker(_ context.Context, client api.Client, cfg *config.Config, deviceType string) (*InventoryChecker, error)

NewInventoryChecker creates an inventory checker for the specified device type. Uses multi-vendor cache for inventory data.

func (*InventoryChecker) FilterByInventory

func (ic *InventoryChecker) FilterByInventory(macs []string) []string

FilterByInventory filters a list of MACs to only include those in inventory

func (*InventoryChecker) GetInventoryItem

func (ic *InventoryChecker) GetInventoryItem(mac string) (*api.MistInventoryItem, bool)

GetInventoryItem returns the full inventory item for a device MAC. This provides O(1) lookup without additional API calls.

func (*InventoryChecker) GetSiteAssignment

func (ic *InventoryChecker) GetSiteAssignment(mac string) (siteID, siteName string, found bool)

GetSiteAssignment returns the current site assignment for a device from the cached inventory. This provides O(1) lookup without additional API calls. Returns siteID, siteName, and whether the device was found in inventory.

func (*InventoryChecker) IsInAPIInventory

func (ic *InventoryChecker) IsInAPIInventory(mac string) bool

IsInAPIInventory checks if a device MAC is in the API inventory

func (*InventoryChecker) IsInInventory

func (ic *InventoryChecker) IsInInventory(mac string) bool

IsInInventory checks if a device MAC is in BOTH API and local inventory. This is the strict check required for write operations (apply, configure, assign, unassign).

Rationale:

  • API inventory = devices that exist in the vendor account
  • Local inventory = fail-safe allowlist of devices we're allowed to modify
  • We might want to view devices in the API, but NOT write changes unless explicitly allowlisted

For read-only operations, use IsInAPIInventory() instead.

func (*InventoryChecker) IsInLocalInventory

func (ic *InventoryChecker) IsInLocalInventory(mac string) bool

IsInLocalInventory checks if a device MAC is specifically in the local inventory file

func (*InventoryChecker) LogInventoryStatus

func (ic *InventoryChecker) LogInventoryStatus(mac string)

LogInventoryStatus logs the inventory status of a device

type SiteConfig

type SiteConfig struct {
	SiteConfig map[string]any `json:"site_config"`
	Devices    struct {
		APs      map[string]map[string]any `json:"ap"`      // AP is a map of MAC -> config
		Switches map[string]map[string]any `json:"switch"`  // Switch is a map of MAC -> config
		WanEdge  map[string]map[string]any `json:"gateway"` // Gateway is a map of MAC -> config
	} `json:"devices"`
	LastModified string `json:"last_modified,omitempty"` // UTC timestamp when config was last modified
}

SiteConfig represents a site configuration in the config file

type SwitchUpdater

type SwitchUpdater struct {
	*BaseDeviceUpdater
	// contains filtered or unexported fields
}

SwitchUpdater implements DeviceUpdater for Switches

func NewSwitchUpdater

func NewSwitchUpdater() *SwitchUpdater

NewSwitchUpdater creates a new Switch updater

func (*SwitchUpdater) FindDevicesInventoryStatus

func (s *SwitchUpdater) FindDevicesInventoryStatus(client api.Client, cfg *config.Config, configuredSwitches []string) ([]DeviceInventoryStatus, error)

FindDevicesInventoryStatus checks Switch status in inventory and cache

func (*SwitchUpdater) FindDevicesToUpdate

func (s *SwitchUpdater) FindDevicesToUpdate(ctx context.Context, client api.Client, _ *config.Config, siteConfig SiteConfig, configuredSwitches []string, siteID string, apiLabel string) ([]string, error)

FindDevicesToUpdate identifies Switches that need configuration updates

func (*SwitchUpdater) GetConfiguredDevices

func (s *SwitchUpdater) GetConfiguredDevices(siteConfig SiteConfig) []string

GetConfiguredDevices extracts Switch MAC addresses from site configuration

func (*SwitchUpdater) GetDeviceConfigFromSite

func (s *SwitchUpdater) GetDeviceConfigFromSite(siteConfig SiteConfig, mac string) (map[string]any, bool)

GetDeviceConfigFromSite extracts Switch-specific config from site configuration

func (*SwitchUpdater) UpdateDeviceConfigurations

func (s *SwitchUpdater) UpdateDeviceConfigurations(ctx context.Context, client api.Client, cfg *config.Config, siteConfig SiteConfig, macs []string, siteID string, apiLabel string) error

UpdateDeviceConfigurations applies configuration updates to Switches

Jump to

Keyboard shortcuts

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