device

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_TIMEOUT_READ = time.Second * 5

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device interface {
	Sanitize([]byte) string                                            // sanitizes output from switches
	RegexInit() *regexp.Regexp                                         // identifies the start of a connection
	RegexCmd() *regexp.Regexp                                          // identifies the start of the next prompt and the output of the current command
	Initialize(context.Context) error                                  // run any commands necessary to start the connection
	DisablePaging(context.Context) error                               // stop the switch from taking breaks in between long outputs
	Cmd(context.Context, time.Duration, string) (*DeviceResult, error) // Run a command and receive the output/switch error as a result
	FlushFor(context.Context, time.Duration) error                     // flush the read data for a period of time (useful if the last command timed out)
}

type DeviceConnection

type DeviceConnection interface {
	Start(context.Context) error
	Stop() error
	FlushFor(context.Context, time.Duration) error
	ReadUntilFunc(context.Context, time.Duration, DeviceInputCondition) ([]byte, error)
	ReadUntilMatch(context.Context, time.Duration, *regexp.Regexp) ([]byte, error)
	ReadFor(context.Context, time.Duration) ([]byte, error)
	Send([]byte) error
}

func NewDeviceConnection

func NewDeviceConnection(stdin io.WriteCloser, stdout io.Reader) DeviceConnection

create a new device connection from a reader/writer combo

func SimpleConnectionFromSSH added in v0.1.1

func SimpleConnectionFromSSH(host string, port uint16, config *ssh.ClientConfig) (DeviceConnection, func(), error)

type DeviceInputCondition

type DeviceInputCondition func([]byte) bool

type DeviceResult

type DeviceResult struct {
	Command string
	Output  string
}

type DeviceSettings

type DeviceSettings struct {
	Connection  DeviceConnection
	TimeoutRead time.Duration
}

type DeviceSwitch added in v0.1.1

type DeviceSwitch interface {
	// Initialize(context.Context) error                  // initialize the connection if needed
	Device
	GetRunningConfig(context.Context) (string, error)  // get the current configuration
	GetLogs(context.Context) (string, error)           // get the current configuration
	GetVersion(context.Context) ([]string, error)      // get the current running software version
	GetVersionROM(context.Context) ([]string, error)   // get the current ROM version (if different from GetVersion)
	GetCPU(context.Context) (int, error)               // get CPU utilization percentage
	GetRAM(context.Context) (int, error)               // get RAM utilization percentage
	GetUptime(context.Context) (string, error)         // get the current uptime
	GetSysname(context.Context) (string, error)        // get the system's name
	GetSerialNumber(context.Context) ([]string, error) // get all serial numbers (if stacked, return multiple)
	GetModelNumber(context.Context) ([]string, error)  // get the model/part number
	GetModelName(context.Context) ([]string, error)    // Get the full model name
}

Typical operations that all switches should be able to support

Jump to

Keyboard shortcuts

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