Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DebugCount int
DebugCount is a debug verbosity counter.
Functions ¶
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.
type SSHSession ¶
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()
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 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