dev

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package dev provides access to multiple devices.

Index

Constants

View Source
const (
	BS = 'H' - '@' // BS backspace
	CR = '\r'      // CR carriage return
	LF = '\n'      // LF linefeed
)

Some constants.

Variables

This section is empty.

Functions

func CreateDevice

func CreateDevice(tab *DeviceTable, logger hasPrintf, modelName, id, hostPort, transports, user, pass, enable string, debug bool, change *conf.Change) error

CreateDevice creates a new device in the device table.

func DeviceFullPath

func DeviceFullPath(repository, id, file string) string

DeviceFullPath get the full file path for a device repository.

func DeviceFullPrefix

func DeviceFullPrefix(repository, id string) string

DeviceFullPrefix gets the full path prefix for a device repository.

func ErrlogPath

func ErrlogPath(pathPrefix, id string) string

ErrlogPath builds the full pathname for errlog file.

func RegisterModels

func RegisterModels(logger hasPrintf, t *DeviceTable)

RegisterModels adds known device models.

func Scan

func Scan(tab DeviceUpdater, devices []*Device, logger hasPrintf, opt *conf.AppConfig, reqChan chan FetchRequest) (int, int, int)

Scan scans the list of devices dispatching backup requests to the Spawner thru the request channel reqChan.

func Spawner

func Spawner(tab DeviceUpdater, logger hasPrintf, reqChan chan FetchRequest, repository, logPathPrefix string, options *conf.Options, ft *FilterTable)

Spawner launches new goroutines to fetch requests received on channel reqChan.

func UpdateLastSuccess

func UpdateLastSuccess(tab *DeviceTable, logger hasPrintf, repository string)

UpdateLastSuccess loads device last success from filesystem.

Types

type Device

type Device struct {
	conf.DevConfig
	// contains filtered or unexported fields
}

Device is an specific device.

func ClearDeviceStatus

func ClearDeviceStatus(tab DeviceUpdater, devID string, logger hasPrintf, holdtime time.Duration) (*Device, error)

ClearDeviceStatus forgets about last success (expire holdtime). Otherwise holdtime could prevent immediate backup.

func NewDevice

func NewDevice(logger hasPrintf, mod *Model, id, hostPort, transports, loginUser, loginPassword, enablePassword string, debug bool) *Device

NewDevice creates a new device.

func NewDeviceFromConf

func NewDeviceFromConf(tab *DeviceTable, logger hasPrintf, cfg *conf.DevConfig) (*Device, error)

NewDeviceFromConf creates a new device from a DevConfig.

func (*Device) DeviceDir

func (d *Device) DeviceDir(repository string) string

DeviceDir gets the directory used as device repository.

func (*Device) DevicePathPrefix

func (d *Device) DevicePathPrefix(devDir string) string

DevicePathPrefix gets the full path prefix for a device repository.

func (*Device) Fetch

func (d *Device) Fetch(tab DeviceUpdater, logger hasPrintf, resultCh chan FetchResult, delay time.Duration, repository, logPathPrefix string, opt *conf.AppConfig, ft *FilterTable)

Fetch captures a configuration for a device. Fetch runs in a per-device goroutine.

func (*Device) Holdtime

func (d *Device) Holdtime(now time.Time, holdtime time.Duration) time.Duration

Holdtime informs the devices' remaining holdtime.

func (*Device) LastElapsed

func (d *Device) LastElapsed() time.Duration

LastElapsed gets the elapsed time for the last backup attempt.

func (*Device) LastStatus

func (d *Device) LastStatus() bool

LastStatus gets a status string for last configuration backup.

func (*Device) LastSuccess

func (d *Device) LastSuccess() time.Time

LastSuccess informs the timestamp for the last successful backup.

func (*Device) LastTry

func (d *Device) LastTry() time.Time

LastTry provides the timestamp for the last backup attempt.

func (*Device) Model

func (d *Device) Model() string

Model gets the model name.

func (*Device) Printf

func (d *Device) Printf(format string, v ...interface{})

Printf formats device-specific messages into logs.

func (*Device) Username

func (d *Device) Username() string

Username gets the username for login into a device.

type DeviceTable

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

DeviceTable is goroutine concurrency-safe list of devices. Data is fully copied when either entering or leaving DeviceTable. Data is not shared with pointers.

func NewDeviceTable

func NewDeviceTable() *DeviceTable

NewDeviceTable creates a device table.

func (*DeviceTable) DeleteDevice

func (t *DeviceTable) DeleteDevice(id string)

DeleteDevice sets a device as deleted in the device table.

func (*DeviceTable) FindDeviceFreeID

func (t *DeviceTable) FindDeviceFreeID(prefix string) string

FindDeviceFreeID finds an ID available for a new device.

func (*DeviceTable) GetDevice

func (t *DeviceTable) GetDevice(id string) (*Device, error)

GetDevice finds a device in the device table.

func (*DeviceTable) GetModel

func (t *DeviceTable) GetModel(modelName string) (*Model, error)

GetModel looks up a model in the device table.

func (*DeviceTable) ListDevices

func (t *DeviceTable) ListDevices() []*Device

ListDevices gets the list of devices.

func (*DeviceTable) ListModels

func (t *DeviceTable) ListModels() []string

ListModels gets the list of models.

func (*DeviceTable) PurgeDevice

func (t *DeviceTable) PurgeDevice(id string)

PurgeDevice actually removes a device from the device table.

func (*DeviceTable) SetDevice

func (t *DeviceTable) SetDevice(d *Device) error

SetDevice adds a device into the device table.

func (*DeviceTable) SetModel

func (t *DeviceTable) SetModel(m *Model, logger hasPrintf) error

SetModel adds a model to the device table.

func (*DeviceTable) UpdateDevice

func (t *DeviceTable) UpdateDevice(d *Device) error

UpdateDevice updates device info in the device table.

type DeviceUpdater

type DeviceUpdater interface {
	GetDevice(id string) (*Device, error)
	UpdateDevice(d *Device) error
}

DeviceUpdater is helper interface for a device store which can provide and update device information.

type FetchRequest

type FetchRequest struct {
	ID        string           // fetch this device
	ReplyChan chan FetchResult // reply on this channel
}

FetchRequest is a request for fetching a device configuration.

type FetchResult

type FetchResult struct {
	Model       string
	DevID       string
	DevHostPort string
	Transport   string
	Msg         string    // result error message
	Code        int       // result error code
	Begin       time.Time // begin timestamp
	End         time.Time // end timestamp
}

FetchResult reports the result for fetching a device configuration.

type FilterFunc

type FilterFunc func(hasPrintf, bool, *FilterTable, []byte, int) []byte

FilterFunc is a helper function type for line filters.

type FilterTable

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

FilterTable stores line filters for custom line-by-line processing of configuration.

func NewFilterTable

func NewFilterTable(logger hasPrintf) *FilterTable

NewFilterTable creates a filter table.

type Model

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

Model provides default attributes for model of devices.

Jump to

Keyboard shortcuts

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