Documentation
¶
Index ¶
- Constants
- Variables
- func JoinEventInputs(events []*channel.SendInteractiveEvent) string
- func NewChannel(t *transport.Transport, options ...Option) (*channel.Channel, error)
- type Driver
- func (d *Driver) Close() error
- func (d *Driver) FormatLogMessage(level, msg string) string
- func (d *Driver) FullSendCommand(c string, failedWhenContains []string, stripPrompt, eager bool, ...) (*Response, error)
- func (d *Driver) FullSendCommands(c []string, failedWhenContains []string, stripPrompt, stopOnFailed, eager bool, ...) (*MultiResponse, error)
- func (d *Driver) FullSendInteractive(events []*channel.SendInteractiveEvent, ...) (*Response, error)
- func (d *Driver) GetPrompt() (string, error)
- func (d *Driver) Open() error
- func (d *Driver) ParseSendOptions(o []SendOption) *SendOptions
- func (d *Driver) ReadWithCallbacks(callbacks []*ReadCallback, input string, timeout, readDelay time.Duration) error
- func (d *Driver) SendCommand(c string, o ...SendOption) (*Response, error)
- func (d *Driver) SendCommands(c []string, o ...SendOption) (*MultiResponse, error)
- func (d *Driver) SendCommandsFromFile(f string, o ...SendOption) (*MultiResponse, error)
- func (d *Driver) SendInteractive(events []*channel.SendInteractiveEvent, o ...SendOption) (*Response, error)
- type MultiOperationError
- type MultiResponse
- type OperationError
- type Option
- func WithAuthBypass(bypass bool) Option
- func WithAuthPassword(password string) Option
- func WithAuthPrivateKey(privateKey string, privateKeyPassphrase ...string) Option
- func WithAuthSecondary(secondary string) Option
- func WithAuthStrictKey(stricktKey bool) Option
- func WithAuthUsername(username string) Option
- func WithChannelAuthPassphrasePattern(p *regexp.Regexp) Option
- func WithChannelAuthPasswordPattern(p *regexp.Regexp) Option
- func WithChannelAuthUsernamePattern(p *regexp.Regexp) Option
- func WithChannelLog(log io.Writer) Option
- func WithCommsPromptPattern(pattern string) Option
- func WithCommsReturnChar(char string) Option
- func WithDefaultDesiredPriv(defaultDesiredPriv string) Option
- func WithFailedWhenContains(failedWhenContains []string) Option
- func WithNetconfServerEcho(echo bool) Option
- func WithPort(port int) Option
- func WithPrivilegeLevels(privilegeLevels map[string]*PrivilegeLevel) Option
- func WithSSHConfigFile(sshConfigFile string) Option
- func WithSSHKnownHostsFile(sshKnownHostsFile string) Option
- func WithTimeoutOps(timeout time.Duration) Option
- func WithTimeoutSocket(timeout time.Duration) Option
- func WithTimeoutTransport(timeout time.Duration) Option
- func WithTransportPtySize(w, h int) Option
- func WithTransportType(transportType string) Option
- type PrivilegeLevel
- type ReadCallback
- type ReadCallbackOption
- func WithCallbackCaseInsensitive(i bool) ReadCallbackOption
- func WithCallbackComplete(complete bool) ReadCallbackOption
- func WithCallbackContains(contains string) ReadCallbackOption
- func WithCallbackContainsRe(contains string) ReadCallbackOption
- func WithCallbackMultiline(m bool) ReadCallbackOption
- func WithCallbackName(name string) ReadCallbackOption
- func WithCallbackNextReadDelay(t time.Duration) ReadCallbackOption
- func WithCallbackNextTimeout(t time.Duration) ReadCallbackOption
- func WithCallbackNotContains(notContains string) ReadCallbackOption
- func WithCallbackOnlyOnce(o bool) ReadCallbackOption
- func WithCallbackResetOutput(reset bool) ReadCallbackOption
- type Response
- type SendOption
- func WithDesiredPrivilegeLevel(privilegeLevel string) SendOption
- func WithInteractionCompletePatterns(interactionCompletePatterns []string) SendOption
- func WithSendEager(eager bool) SendOption
- func WithSendFailedWhenContains(failedWhenContains []string) SendOption
- func WithSendStopOnFailed(stopOnFailed bool) SendOption
- func WithSendStripPrompt(stripPrompt bool) SendOption
- func WithSendTimeoutOps(timeoutOps time.Duration) SendOption
- type SendOptions
Constants ¶
const ( // DefaultSendOptionsStripPrompt default to stripping prompt. DefaultSendOptionsStripPrompt = true // DefaultSendOptionsStopOnFailed default to *not* stopping on failures. DefaultSendOptionsStopOnFailed = false // DefaultSendOptionsTimeoutOps default to relying on the drivers timeout ops attribute. DefaultSendOptionsTimeoutOps = -1.0 // DefaultSendOptionsEager default to *not* eager mode. DefaultSendOptionsEager = false )
Variables ¶
var ErrCallbackAlreadyTriggered = errors.New("callback set to 'OnlyOnce', but already triggered")
var ErrCallbackTimeout = errors.New("callback timeout")
var ErrFailedOpeningTemplate = errors.New("failed opening provided path to textfsm template")
ErrFailedOpeningTemplate error for failure to open a textfsm template.
var ErrFailedParsingTemplate = errors.New("failed parsing textfsm template")
ErrFailedParsingTemplate error for failure of parsing a textfsm template.
var ErrIgnoredOption = errors.New("option ignored, for different instance type")
var ErrMustSetContains = errors.New("must set Contains or ContainsRe")
Functions ¶
func JoinEventInputs ¶
func JoinEventInputs(events []*channel.SendInteractiveEvent) string
JoinEventInputs convenience function to join inputs from a `SendInteractive` method.
Types ¶
type Driver ¶
type Driver struct { Host string AuthUsername string AuthPassword string AuthSecondary string AuthPrivateKey string AuthPrivateKeyPassphrase string AuthStrictKey bool AuthBypass bool SSHConfigFile string SSHKnownHostsFile string TransportType string Transport *transport.Transport Channel *channel.Channel FailedWhenContains []string PrivilegeLevels map[string]*PrivilegeLevel DefaultDesiredPriv string NetconfEcho *bool }
Driver primary/base driver struct.
func NewDriver ¶
NewDriver create a new instance of `Driver`, accepts a host and variadic of options to modify the driver behavior.
func (*Driver) FormatLogMessage ¶
FormatLogMessage formats log message payload, adding contextual info about the host.
func (*Driver) FullSendCommand ¶
func (d *Driver) FullSendCommand( c string, failedWhenContains []string, stripPrompt, eager bool, timeoutOps time.Duration, ) (*Response, error)
FullSendCommand same as `SendCommand` but requiring explicit options.
func (*Driver) FullSendCommands ¶
func (d *Driver) FullSendCommands( c []string, failedWhenContains []string, stripPrompt, stopOnFailed, eager bool, timeoutOps time.Duration, ) (*MultiResponse, error)
FullSendCommands same as `SendCommands` but requiring explicit options.
func (*Driver) FullSendInteractive ¶
func (d *Driver) FullSendInteractive( events []*channel.SendInteractiveEvent, interactionCompletePatterns, failedWhenContains []string, timeoutOps time.Duration, joinedEventInputs string, ) (*Response, error)
FullSendInteractive same as `SendInteractive` but requiring explicit options.
func (*Driver) ParseSendOptions ¶
func (d *Driver) ParseSendOptions( o []SendOption, ) *SendOptions
ParseSendOptions convenience function to parse and set defaults for `SendOption`s.
func (*Driver) ReadWithCallbacks ¶ added in v0.1.2
func (*Driver) SendCommand ¶
func (d *Driver) SendCommand(c string, o ...SendOption) (*Response, error)
SendCommand send a command to a device, accepts a string command and variadic of `SendOption`s.
func (*Driver) SendCommands ¶
func (d *Driver) SendCommands( c []string, o ...SendOption, ) (*MultiResponse, error)
SendCommands send commands to a device, accepts a string command and variadic of `SendOption`s.
func (*Driver) SendCommandsFromFile ¶
func (d *Driver) SendCommandsFromFile( f string, o ...SendOption, ) (*MultiResponse, error)
SendCommandsFromFile send commands from a file to a device, accepts a string command and variadic of `SendOption`s.
func (*Driver) SendInteractive ¶
func (d *Driver) SendInteractive( events []*channel.SendInteractiveEvent, o ...SendOption, ) (*Response, error)
SendInteractive send interactive commands to a device, accepts a slice of `SendInteractiveEvent` and variadic of `SendOption`s.
type MultiOperationError ¶
type MultiOperationError struct {
Operations []*OperationError
}
func (*MultiOperationError) Error ¶
func (e *MultiOperationError) Error() string
type MultiResponse ¶
type MultiResponse struct { Host string StartTime time.Time EndTime time.Time ElapsedTime float64 Responses []*Response Failed error }
MultiResponse defines a response object for plural operations -- contains a slice of `Responses` for each operation.
func NewMultiResponse ¶
func NewMultiResponse(host string) *MultiResponse
NewMultiResponse creates a new MultiResponse object.
func (*MultiResponse) AppendResponse ¶
func (mr *MultiResponse) AppendResponse(r *Response)
AppendResponse appends a response to the `Responses` attribute of the MultiResponse object.
func (*MultiResponse) JoinedResult ¶
func (mr *MultiResponse) JoinedResult() string
JoinedResult is a convenience method to print out a single unified/joined result -- this is basically all the channel output for each individual response in the MultiResponse joined by newline characters.
type OperationError ¶
OperationError is an error object returned when a scrapli operation completes "successfully" -- as in does not have an EOF/timeout or otherwise unrecoverable error -- but contains output in the device's response indicating that an input was bad/invalid or device failed to process it at that time.
func (*OperationError) Error ¶
func (e *OperationError) Error() string
Error returns an error string for the OperationError object.
type Option ¶
type Option func(interface{}) error
Option function to set driver options.
func WithAuthBypass ¶
WithAuthBypass provide bool indicating if auth should be "bypassed" -- only applicable for system and telnet transports.
func WithAuthPassword ¶
WithAuthPassword provide a string password to use for driver authentication.
func WithAuthPrivateKey ¶
WithAuthPrivateKey provide a string path to a private key to use for driver authentication, optionally provide a string to use for passphrase for given private key.
func WithAuthSecondary ¶
WithAuthSecondary provide a string "secondary" (or "enable") password to use for driver authentication. Only applicable for "network" level drivers.
func WithAuthStrictKey ¶
WithAuthStrictKey provide bool indicating if strict key checking should be enforced.
func WithAuthUsername ¶
WithAuthUsername provide a string username to use for driver authentication.
func WithChannelAuthPassphrasePattern ¶ added in v0.1.3
WithChannelAuthPassphrasePattern overrides the default in channel username regexp.
func WithChannelAuthPasswordPattern ¶ added in v0.1.3
WithChannelAuthPasswordPattern overrides the default in channel password regexp.
func WithChannelAuthUsernamePattern ¶ added in v0.1.3
WithChannelAuthUsernamePattern overrides the default in channel username regexp.
func WithChannelLog ¶
WithChannelLog provide an io.Writer object to write channel log data to.
func WithCommsPromptPattern ¶
WithCommsPromptPattern provide string regex pattern to use for prompt pattern, typically not necessary if using a network level driver.
func WithCommsReturnChar ¶
WithCommsReturnChar provide string to use as the return character, typically can be left default.
func WithDefaultDesiredPriv ¶
WithDefaultDesiredPriv provide custom default preferred privilege level to use -- only applicable to network drivers.
func WithFailedWhenContains ¶
WithFailedWhenContains provide a custom slice of strings to use to check if an output is failed -- only applicable to network drivers.
func WithNetconfServerEcho ¶
WithNetconfServerEcho provide custom default preferred privilege level to use -- only applicable for netconf.
func WithPrivilegeLevels ¶
func WithPrivilegeLevels(privilegeLevels map[string]*PrivilegeLevel) Option
WithPrivilegeLevels provide custom privilege levels to use -- only applicable to network drivers.
func WithSSHConfigFile ¶
WithSSHConfigFile provide string path to ssh config file.
func WithSSHKnownHostsFile ¶
WithSSHKnownHostsFile provide string path to ssh known hosts file.
func WithTimeoutOps ¶
WithTimeoutOps provide duration to use for "operation" timeout.
func WithTimeoutSocket ¶
WithTimeoutSocket provide duration to use for socket timeout.
func WithTimeoutTransport ¶
WithTimeoutTransport provide duration to use for transport timeout.
func WithTransportPtySize ¶
WithTransportPtySize provide pty width/height to use.
func WithTransportType ¶
WithTransportType provide string name of type of transport to use.
type PrivilegeLevel ¶
type PrivilegeLevel struct { Pattern string PatternRe *regexp.Regexp PatternNotContains []string Name string PreviousPriv string Deescalate string Escalate string EscalateAuth bool EscalatePrompt string }
PrivilegeLevel struct defining a single privilege level -- used only for "network" level drivers.
type ReadCallback ¶ added in v0.1.2
type ReadCallback struct { Callback func(*Driver, string) error Contains string NotContains string ContainsRe string CaseInsensitive bool MultiLine bool // ResetOutput bool indicating if the output should be reset or not after callback execution. ResetOutput bool // OnlyOnce bool indicating if this callback should be executed only one time. OnlyOnce bool // NextTimout timeout value to use for the subsequent read loop - ignored if Complete is true. NextTimeout time.Duration // NextReadDelay is time to use for sleeps between reads for hte subsequent read loop. NextReadDelay time.Duration Complete bool Name string // contains filtered or unexported fields }
func NewReadCallback ¶ added in v0.1.2
func NewReadCallback( callback func(*Driver, string) error, options ...ReadCallbackOption, ) (*ReadCallback, error)
type ReadCallbackOption ¶ added in v0.1.2
type ReadCallbackOption func(callback *ReadCallback) error
func WithCallbackCaseInsensitive ¶ added in v0.1.2
func WithCallbackCaseInsensitive(i bool) ReadCallbackOption
func WithCallbackComplete ¶ added in v0.1.2
func WithCallbackComplete(complete bool) ReadCallbackOption
func WithCallbackContains ¶ added in v0.1.2
func WithCallbackContains(contains string) ReadCallbackOption
func WithCallbackContainsRe ¶ added in v0.1.2
func WithCallbackContainsRe(contains string) ReadCallbackOption
func WithCallbackMultiline ¶ added in v0.1.2
func WithCallbackMultiline(m bool) ReadCallbackOption
func WithCallbackName ¶ added in v0.1.2
func WithCallbackName(name string) ReadCallbackOption
func WithCallbackNextReadDelay ¶ added in v0.1.2
func WithCallbackNextReadDelay(t time.Duration) ReadCallbackOption
func WithCallbackNextTimeout ¶ added in v0.1.2
func WithCallbackNextTimeout(t time.Duration) ReadCallbackOption
func WithCallbackNotContains ¶ added in v0.1.2
func WithCallbackNotContains(notContains string) ReadCallbackOption
func WithCallbackOnlyOnce ¶ added in v0.1.2
func WithCallbackOnlyOnce(o bool) ReadCallbackOption
func WithCallbackResetOutput ¶ added in v0.1.2
func WithCallbackResetOutput(reset bool) ReadCallbackOption
type Response ¶
type Response struct { Host string Port int ChannelInput string RawResult []byte Result string StartTime time.Time EndTime time.Time ElapsedTime float64 FailedWhenContains []string // Failed returns an error if any of the `FailedWhenContains` substrings are seen in the output // returned from the device. This error indicates that the operation has completed successfully, // but that an input was bad/invalid or device failed to process it at that time Failed error }
Response is a response object that gets returned from scrapli send operations.
func NewResponse ¶
func NewResponse( host string, port int, channelInput string, failedWhenContains []string, ) *Response
NewResponse creates a new response object.
func (*Response) FormatLogMessage ¶
FormatLogMessage formats log message payload, adding contextual info about the host.
func (*Response) TextFsmParse ¶
TextFsmParse parses recorded output w/ a provided textfsm template. the argument is interpreted as URL or filesystem path, for example: response.TextFsmParse("http://example.com/textfsm.template") or response.TextFsmParse("./local/textfsm.template").
type SendOption ¶
type SendOption func(*SendOptions)
SendOption func to set send options.
func WithDesiredPrivilegeLevel ¶
func WithDesiredPrivilegeLevel(privilegeLevel string) SendOption
WithDesiredPrivilegeLevel provide a desired privilege level for the send operation to work in.
func WithInteractionCompletePatterns ¶
func WithInteractionCompletePatterns(interactionCompletePatterns []string) SendOption
WithInteractionCompletePatterns provide a list of patterns which, when seen, indicate a `SendInteractive` "session" is complete. Only used for `SendInteractive`, otherwise ignored.
func WithSendEager ¶
func WithSendEager(eager bool) SendOption
WithSendEager bool indicating if send operation should operate in `eager` mode -- generally only used for netconf operations.
func WithSendFailedWhenContains ¶
func WithSendFailedWhenContains(failedWhenContains []string) SendOption
WithSendFailedWhenContains slice of strings that overrides the drivers `FailedWhenContains` list for a given send operation.
func WithSendStopOnFailed ¶
func WithSendStopOnFailed(stopOnFailed bool) SendOption
WithSendStopOnFailed bool indicating if multi command/config operations should stop at first sign of failure (based on FailedWhenContains list).
func WithSendStripPrompt ¶
func WithSendStripPrompt(stripPrompt bool) SendOption
WithSendStripPrompt bool indicating if you would like the hostname/device prompt stripped out of output from a send operation.
func WithSendTimeoutOps ¶
func WithSendTimeoutOps(timeoutOps time.Duration) SendOption
WithSendTimeoutOps duration to use for timeout of a given send operation.