transport

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugCount int

DebugCount is a debug verbosity counter.

Functions

func Write

func Write(tx Transport, host string, data, info []string, options ...TransportOption) error

Write config to a node.

Types

type SSHKind

type SSHKind interface {
	// Start a config transaction
	ConfigStart(s *SSHTransport, transaction bool) error
	// Commit a config transaction
	ConfigCommit(s *SSHTransport) (*SSHReply, error)
	// Prompt parsing function
	//
	// This function receives string, split by the delimiter and should ensure this is a valid prompt
	// Valid prompt, strip the prompt from the result and add it to the prompt in SSHReply
	//
	// A default implementation is promptParseNoSpaces, which simply ensures there are
	// no spaces between the start of the line and the #
	PromptParse(s *SSHTransport, in *string) *SSHReply
}

SSHKind is an interface to implement kind specific methods for transactions and prompt checking.

type SSHReply

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

SSHReply is SSH reply, executed command and the prompt.

func (*SSHReply) Debug

func (r *SSHReply) Debug(node, message string, t ...interface{})

func (*SSHReply) Info

func (r *SSHReply) Info(node string) *SSHReply

func (*SSHReply) LogString

func (r *SSHReply) LogString(node string, linefeed, debug bool) string

LogString will include the entire SSHReply

Each field will be prefixed by a character.
# - command sent
| - result received
? - prompt part of the result

type SSHSession

type SSHSession struct {
	In      io.Reader
	Out     io.WriteCloser
	Session *ssh.Session
}

func NewSSHSession

func NewSSHSession(host string, sshConfig *ssh.ClientConfig) (*SSHSession, error)

NewSSHSession creates a new SSH session (Dial, open in/out pipes and start the shell) pass the authentication details in sshConfig.

func (*SSHSession) Close

func (ses *SSHSession) Close()

func (*SSHSession) Writeln

func (ses *SSHSession) Writeln(command string) (int, error)

type SSHTransport

type SSHTransport struct {

	// Contains the first read after connecting
	LoginMessage *SSHReply
	// SSH parameters used in connect
	// default: 22
	Port int

	// Keep the target for logging
	Target string

	// SSH Options
	// required!
	SSHConfig *ssh.ClientConfig

	// Character to split the incoming stream (#/$/>)
	// default: #
	PromptChar string

	// Kind specific transactions & prompt checking function
	K SSHKind
	// contains filtered or unexported fields
}

SSHTransport setting needs to be set before calling Connect() SSHTransport implements the Transport interface.

func NewSSHTransport

func NewSSHTransport(node *types.NodeConfig, options ...SSHTransportOption) (*SSHTransport, error)

func (*SSHTransport) Close

func (t *SSHTransport) Close()

Close the Session and channels Part of the Transport interface.

func (*SSHTransport) Connect

func (t *SSHTransport) Connect(host string, _ ...TransportOption) error

Connect to a host Part of the Transport interface.

func (*SSHTransport) InChannel

func (t *SSHTransport) InChannel()

InChannel creates the channel reading the SSH connection.

The first prompt is saved in LoginMessages

  • The channel read the SSH session, splits on PromptChar
  • Uses SSHKind's PromptParse to split the received data in *result* and *prompt* parts (if no valid prompt was found, prompt will simply be empty and result contain all the data)
  • Emit data.

func (*SSHTransport) Run

func (t *SSHTransport) Run(command string, timeout int) *SSHReply

Run a single command and wait for the reply.

func (*SSHTransport) Write

func (t *SSHTransport) Write(data, info *string) error

Write a config snippet (a set of commands) Session NEEDS to be configurable for other kinds Part of the Transport interface.

type SSHTransportOption

type SSHTransportOption func(*SSHTransport) error

func HostKeyCallback

func HostKeyCallback(callback ...ssh.HostKeyCallback) SSHTransportOption

HostKeyCallback adds a basic username & password to a config. Will initialize the config if required.

func WithUserNamePassword

func WithUserNamePassword(username, password string) SSHTransportOption

WithUserNamePassword adds username & password authentication.

type SrlSSHKind

type SrlSSHKind struct{}

SrlSSHKind implements SShKind.

func (*SrlSSHKind) ConfigCommit

func (*SrlSSHKind) ConfigCommit(s *SSHTransport) (*SSHReply, error)

func (*SrlSSHKind) ConfigStart

func (*SrlSSHKind) ConfigStart(s *SSHTransport, transaction bool) error

func (*SrlSSHKind) PromptParse

func (*SrlSSHKind) PromptParse(s *SSHTransport, in *string) *SSHReply

type Transport

type Transport interface {
	// Connect to the target host
	Connect(host string, options ...TransportOption) error
	// Execute some config
	Write(data *string, info *string) error
	Close()
}

type TransportOption

type TransportOption func(*Transport)

type VrSrosSSHKind

type VrSrosSSHKind struct{}

VrSrosSSHKind implements SShKind.

func (*VrSrosSSHKind) ConfigCommit

func (*VrSrosSSHKind) ConfigCommit(s *SSHTransport) (*SSHReply, error)

func (*VrSrosSSHKind) ConfigStart

func (*VrSrosSSHKind) ConfigStart(s *SSHTransport, transaction bool) error

func (*VrSrosSSHKind) PromptParse

func (*VrSrosSSHKind) PromptParse(s *SSHTransport, in *string) *SSHReply

Jump to

Keyboard shortcuts

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