router

package
v0.0.0-...-cc6e817 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateDefaults

func GenerateDefaults(config *RunTimeConfig)

GenerateDefaults is setting default values for a RunTime-Configuration. It will also set all SSH-client options like password or key authentication

Types

type Router

type Router struct {
	/* Manage, scan and find the prompts */
	PromptModes        map[string]string
	PromptReplacements map[string][]string
	PromptMode         string

	/* Regular expression string for detecting the prompt */
	PromptDetect string
	/* Initial trigger strings for searching the prompt */
	PromptReadTriggers []string

	/* Ready configured prompt types */
	SSHConfigPrompt, SSHEnabledPrompt, SSHUnprivilegedPrompt string
	SSHConfigPromptPre                                       string

	/* ErrorMatches is a regex to scan for error messages in the configuration terminal */
	ErrorMatches *regexp.Regexp

	/* Command-Rewriter for general commands, e.g. 'sc:show_log => show logging' */
	CommandRewrite map[string]string

	/* Manage the SSH connection */
	SSHConnection *ssh.Client
	SSHSession    *ssh.Session
	SSHStdinPipe  io.WriteCloser
	SSHStdoutPipe io.Reader
	SSHStdErrPipe io.Reader
	ReadMsg       string
}

Router is a struct that will be used from the inside final router object

func (*Router) Close

func (ro *Router) Close()

Close will close the SSH-session and the SSH-tcp-connection

func (*Router) DetectPrompt

func (ro *Router) DetectPrompt(rtc RunTimeConfig, prompt string) error

DetectPrompt will try to detect the initial prompt and from this information will build a map of future possible prompts, e.g. the configuration prompt.

func (*Router) GetPromptMode

func (ro *Router) GetPromptMode(rtc RunTimeConfig) error

GetPromptMode will check and set the current prompt situation

func (*Router) PasteConfiguration

func (ro *Router) PasteConfiguration(rtc RunTimeConfig, configuration io.Reader) (err error)

PasteConfiguration takes a runtimeconfiguration and a reader as argument. It will read the reader line-by-line and inject configuration statements

func (*Router) ReadTill

func (ro *Router) ReadTill(rtc RunTimeConfig, search []string) (string, error)

ReadTill is our main function for reading data from the input SSH-channel and will read from the input reader, till it finds a given string, else it will run into timeout and close the SSH channel and session

func (*Router) ReadTillConfigPrompt

func (ro *Router) ReadTillConfigPrompt(rtc RunTimeConfig) (string, error)

ReadTillConfigPrompt internal calls ReadTill, looking for the SSH configuration prompt string

func (*Router) ReadTillConfigPromptSection

func (ro *Router) ReadTillConfigPromptSection(rtc RunTimeConfig) (string, error)

ReadTillConfigPromptSection internal calls ReadTill, looking for the SSH configuration section prompt string

func (*Router) ReadTillEnabledPrompt

func (ro *Router) ReadTillEnabledPrompt(rtc RunTimeConfig) (string, error)

ReadTillEnabledPrompt internal calls ReadTill, looking for the SSH enabled prompt string

func (*Router) RunCommands

func (ro *Router) RunCommands(rtc RunTimeConfig, commands io.Reader) (err error)

RunCommands will run commands inside the devices exec- or privileged mode. Command will be read from a io.reader.

func (*Router) SetupSSH

func (ro *Router) SetupSSH(addr string, clientConfig *ssh.ClientConfig, requestPty bool) (err error)

SetupSSH will create a tcp connection and open a remote shell, optional a full pseudo terminal

func (*Router) Write

func (ro *Router) Write(rtc RunTimeConfig, command string) error
Write

takes a runtimeconfiguration and a command string and will write the command string into the SSH input stream

type RunTimeConfig

type RunTimeConfig struct {
	libhost.HostConfig
	Debug           bool
	W               io.Writer
	ConnectionAddr  string
	SSHClientConfig *ssh.ClientConfig
	Hostkey         ssh.PublicKey
}

RunTimeConfig is an init struct that can be used to setup defaults and values for a Router object

Jump to

Keyboard shortcuts

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