Documentation ¶
Index ¶
- type Option
- type SSHCommandContext
- type SSHConnection
- func (conn *SSHConnection) DisablePagination() error
- func (conn *SSHConnection) IdentifyOSVersion() (config.OSVersion, error)
- func (conn *SSHConnection) IsAuthenticated() bool
- func (conn *SSHConnection) IsConnected() bool
- func (conn *SSHConnection) RunCommand(ctx *SSHCommandContext)
- func (conn *SSHConnection) Terminate()
- type SSHConnectionManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*SSHConnectionManager)
Option is a function called to configure the SSHConnectionManager
func WithKeepAliveInterval ¶
WithKeepAliveInterval allows specifying a keep alive interval
func WithKeepAliveTimeout ¶
WithKeepAliveTimeout allows specifying a keep alive timeout
func WithReconnectInterval ¶
WithReconnectInterval allows specifying a reconnect interval
type SSHCommandContext ¶
type SSHCommandContext struct { Command string Output chan string Errors chan error Done chan struct{} Timeout int }
SSHCommandContext provides context for running a command on the remote device. Lines received from the remote device are written to the Output chan. Errors encoutered during executing a command are written to the Erros chan. Once the command finished execution, an empty struct is written to the Done chan.
func NewSSHCommandContext ¶
func NewSSHCommandContext(command string) *SSHCommandContext
NewSSHCommandContext initializes the channels and returns a new SSHCommandContext.
func (*SSHCommandContext) IgnoreOutputs ¶
func (ctx *SSHCommandContext) IgnoreOutputs()
IgnoreOutputs ignores the outputs received from an SSHCommandContext and logs erros to the CLI.
type SSHConnection ¶
type SSHConnection struct { Device *config.DeviceConfig // contains filtered or unexported fields }
SSHConnection wraps an *ssh.Client and provides functions for executing commands on the remote device.
func (*SSHConnection) DisablePagination ¶
func (conn *SSHConnection) DisablePagination() error
DisablePagination disables the paginator on the remote end. This is required to parse the whole output of a command. Note that for `terminal length 0` certain privileges are required on the remote device.
func (*SSHConnection) IdentifyOSVersion ¶
func (conn *SSHConnection) IdentifyOSVersion() (config.OSVersion, error)
IdentifyOSVersion fingerprints the remote operating system.
func (*SSHConnection) IsAuthenticated ¶
func (conn *SSHConnection) IsAuthenticated() bool
IsAuthenticated tests if the authentication for this SSH Session has not yet expired
func (*SSHConnection) IsConnected ¶
func (conn *SSHConnection) IsConnected() bool
IsConnected returns whether the SSHConnection is still up and the remote end connected.
func (*SSHConnection) RunCommand ¶
func (conn *SSHConnection) RunCommand(ctx *SSHCommandContext)
RunCommand runs a command on the remote device. All events / outputs are received to the provided context.
func (*SSHConnection) Terminate ¶
func (conn *SSHConnection) Terminate()
Terminate terminates the SSHConnection
type SSHConnectionManager ¶
type SSHConnectionManager struct {
// contains filtered or unexported fields
}
SSHConnectionManager provides means of establishing and maintaining an SSH Connection to a remote deivce. SSH Connections are intentionally left open as long as possible, to reduce the number of logged logins as well as load on the TACACS server and the remote device.
func NewConnectionManager ¶
func NewConnectionManager(options ...Option) *SSHConnectionManager
NewConnectionManager applies the specified options and returns a new SSHConnectionManager
func (*SSHConnectionManager) GetConnection ¶
func (connMan *SSHConnectionManager) GetConnection(device *config.DeviceConfig) (*SSHConnection, error)
GetConnection returns an SSHConnection to the given device. If the connection has not yet been established (or lost), establishing a connection is attempted. In case of error nil and the error are returned.