Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DebugCount int
Debug count
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 }
An interface to implement kind specific methods for transactions and prompt checking
type SSHReply ¶
type SSHReply struct {
// contains filtered or unexported fields
}
The SSH reply, executed command and the prompt
type SSHSession ¶
func NewSSHSession ¶
func NewSSHSession(host string, sshConfig *ssh.ClientConfig) (*SSHSession, error)
Create a new SSH session (Dial, open in/out pipes and start the shell) pass the authntication 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, options ...TransportOption) error
Connect to a host Part of the Transport interface
func (*SSHTransport) InChannel ¶
func (t *SSHTransport) 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
Add a basic username & password to a config Will initialize the config if required
func WithUserNamePassword ¶
func WithUserNamePassword(username, password string) SSHTransportOption
Add username & password authentication
type SrlSSHKind ¶
type SrlSSHKind struct{}
implements SShKind
func (*SrlSSHKind) ConfigCommit ¶
func (sk *SrlSSHKind) ConfigCommit(s *SSHTransport) (*SSHReply, error)
func (*SrlSSHKind) ConfigStart ¶
func (sk *SrlSSHKind) ConfigStart(s *SSHTransport, transaction bool) error
func (*SrlSSHKind) PromptParse ¶
func (sk *SrlSSHKind) PromptParse(s *SSHTransport, in *string) *SSHReply
type TransportOption ¶
type TransportOption func(*Transport)
type VrSrosSSHKind ¶
type VrSrosSSHKind struct{}
implements SShKind
func (*VrSrosSSHKind) ConfigCommit ¶
func (sk *VrSrosSSHKind) ConfigCommit(s *SSHTransport) (*SSHReply, error)
func (*VrSrosSSHKind) ConfigStart ¶
func (sk *VrSrosSSHKind) ConfigStart(s *SSHTransport, transaction bool) error
func (*VrSrosSSHKind) PromptParse ¶
func (sk *VrSrosSSHKind) PromptParse(s *SSHTransport, in *string) *SSHReply