Documentation ¶
Overview ¶
Package dev provides access to multiple devices.
Index ¶
- Constants
- func CreateDevice(tab *DeviceTable, logger hasPrintf, ...) error
- func DeviceFullPath(repository, id, file string) string
- func DeviceFullPrefix(repository, id string) string
- func ErrlogPath(pathPrefix, id string) string
- func RegisterModels(logger hasPrintf, t *DeviceTable)
- func Scan(tab DeviceUpdater, devices []*Device, logger hasPrintf, opt *conf.AppConfig, ...) (int, int, int)
- func Spawner(tab DeviceUpdater, logger hasPrintf, reqChan chan FetchRequest, ...)
- func UpdateLastSuccess(tab *DeviceTable, logger hasPrintf, repository string)
- type Device
- func (d *Device) DeviceDir(repository string) string
- func (d *Device) DevicePathPrefix(devDir string) string
- func (d *Device) Fetch(tab DeviceUpdater, logger hasPrintf, resultCh chan FetchResult, ...)
- func (d *Device) Holdtime(now time.Time, holdtime time.Duration) time.Duration
- func (d *Device) LastElapsed() time.Duration
- func (d *Device) LastStatus() bool
- func (d *Device) LastSuccess() time.Time
- func (d *Device) LastTry() time.Time
- func (d *Device) Model() string
- func (d *Device) Printf(format string, v ...interface{})
- func (d *Device) Username() string
- type DeviceTable
- func (t *DeviceTable) DeleteDevice(id string)
- func (t *DeviceTable) FindDeviceFreeID(prefix string) string
- func (t *DeviceTable) GetDevice(id string) (*Device, error)
- func (t *DeviceTable) GetModel(modelName string) (*Model, error)
- func (t *DeviceTable) ListDevices() []*Device
- func (t *DeviceTable) ListModels() []string
- func (t *DeviceTable) PurgeDevice(id string)
- func (t *DeviceTable) SetDevice(d *Device) error
- func (t *DeviceTable) SetModel(m *Model, logger hasPrintf) error
- func (t *DeviceTable) UpdateDevice(d *Device) error
- type DeviceUpdater
- type FetchRequest
- type FetchResult
- type FilterFunc
- type FilterTable
- type Model
Constants ¶
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 ¶
DeviceFullPath get the full file path for a device repository.
func DeviceFullPrefix ¶
DeviceFullPrefix gets the full path prefix for a device repository.
func ErrlogPath ¶
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 ¶
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) DevicePathPrefix ¶
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) LastElapsed ¶
LastElapsed gets the elapsed time for the last backup attempt.
func (*Device) LastStatus ¶
LastStatus gets a status string for last configuration backup.
func (*Device) LastSuccess ¶
LastSuccess informs the timestamp for the last successful backup.
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 (*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.