ssh

package
v1.8.8 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ssh contains abstractions which manage SSH connections for the user, allowing for faster and easier remote execution

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {

	// MultiRun provides an easy shorthand for multiple calls to sshExec
	MultiRun(commands ...string) ([]string, error)

	// FastMultiRun speeds up remote execution by chaining commands together
	FastMultiRun(commands ...string) (string, error)

	// Run executes a given command on the connected remote machine.
	Run(command string) (string, error)

	// KeepTryRun attempts to run a command successfully multiple times. It will
	// keep trying until it reaches the max amount of tries or it is successful once.
	KeepTryRun(command string) (string, error)

	// DockerExec executes a command inside of a node
	DockerExec(node Node, command string) (string, error)

	// DockerCp copies a file on a remote machine from source to the dest in the node
	DockerCp(node Node, source string, dest string) error

	// KeepTryDockerExec is like KeepTryRun for nodes
	KeepTryDockerExec(node Node, command string) (string, error)

	// KeepTryDockerExecAll is like KeepTryRun for nodes, but can handle more than one command.
	// Executes the given commands in order.
	KeepTryDockerExecAll(node Node, commands ...string) ([]string, error)

	// DockerExecd runs the given command, and then returns immediately.
	// This function will not return the output of the command.
	// This is useful if you are starting a persistent process inside a container
	DockerExecd(node Node, command string) (string, error)

	// DockerExecdit runs the given command, and then returns immediately.
	// This function will not return the output of the command.
	// This is useful if you are starting a persistent process inside a container.
	// Also flags the session as interactive and sets up a virtual tty.
	DockerExecdit(node Node, command string) (string, error)

	// DockerExecdLog will cause the stdout and stderr of the command to be stored in the logs.
	// Should only be used for the blockchain process.
	DockerExecdLog(node Node, command string) error

	// DockerExecdLogAppend will cause the stdout and stderr of the command to be stored in the logs.
	// Should only be used for the blockchain process. Will append to existing logs.
	DockerExecdLogAppend(node Node, command string) error

	// DockerRead will read a file on a node, if lines > -1 then
	// it will return the last `lines` lines of the file
	DockerRead(node Node, file string, lines int) (string, error)

	// DockerMultiExec will run all of the given commands strung together with && on
	// the given node.
	DockerMultiExec(node Node, commands []string) (string, error)

	// KTDockerMultiExec is like DockerMultiExec, except it keeps attempting the command after
	// failure
	KTDockerMultiExec(node Node, commands []string) (string, error)

	// Scp is a wrapper for the scp command. Can be used to copy
	// a file over to a remote machine.
	Scp(src string, dest string) error

	// Close cleans up the resources used by sshClient object
	Close()
}

Client maintains a persistent connect with a server, allowing commands to be run on that server. This object is thread safe.

func GetTestClient added in v1.8.3

func GetTestClient(responses []string) Client

GetTestClient gets an ssh client which is only suitable for testing, and will return the given respones in order. Once they are exhausted, it will then give errors

func NewClient

func NewClient(host string, serverID int) (Client, error)

NewClient creates an instance of Client, with a connection to the host server given.

type Node added in v1.7.1

type Node interface {
	GetID() string
	GetAbsoluteNumber() int
	GetIP() string
	GetRelativeNumber() int
	GetServerID() int
	GetTestNetID() string
	GetNodeName() string
}

Node represents the interface which all nodes must follow.

type Session

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

Session is a simple wrapper for golang's ssh.Session, which decrements a semaphore on destruction.

func NewSession

func NewSession(sess *ssh.Session, sem *semaphore.Weighted) *Session

NewSession creates a new session from a native library ssh session and a semaphore

func (Session) Close

func (session Session) Close()

Close closes the internal ssh session and decrements the semaphore

func (Session) Get

func (session Session) Get() *ssh.Session

Get returns the internal native library ssh session

Jump to

Keyboard shortcuts

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