system

package
v19.10.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 28 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateKeyPair

func CreateKeyPair() (publicKeyBytes []byte, privateKeyBytes []byte, err error)

CreateKeyPair creates a key pair

func CreateTempFileFromString

func CreateTempFileFromString(content string, filemode os.FileMode) (*os.File, error)

CreateTempFileFromString creates a temporary file containing 'content'

func ExtractRetCode

func ExtractRetCode(err error) (string, int, error)

ExtractRetCode extracts info from the error

func GetBashLibrary

func GetBashLibrary() (string, error)

GetBashLibrary generates the content of {{.reserved_BashLibrary}}

func IsSCPRetryable

func IsSCPRetryable(code int) bool

IsSCPRetryable tells if the retcode of a scp command may be retried

func IsSSHRetryable

func IsSSHRetryable(code int) bool

IsSSHRetryable tells if the retcode of a ssh command may be retried

func SCPErrorString

func SCPErrorString(retcode int) string

SCPErrorString returns if possible the string corresponding to SCP execution

func SSHErrorString

func SSHErrorString(retcode int) string

SSHErrorString returns if possible the string corresponding to SSH execution

Types

type SSHCommand

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

SSHCommand defines a SSH command

func (*SSHCommand) CombinedOutput

func (sc *SSHCommand) CombinedOutput() ([]byte, error)

CombinedOutput runs the command and returns its combined standard output and standard error.

func (*SSHCommand) Display

func (sc *SSHCommand) Display() string

Display ...

func (*SSHCommand) Kill

func (sc *SSHCommand) Kill() error

Kill kills SSHCommand process and releases any resources associated with the SSHCommand.

func (*SSHCommand) Output

func (sc *SSHCommand) Output() ([]byte, error)

Output runs the command and returns its standard output. Any returned error will usually be of type *ExitError. If c.Stderr was nil, Output populates ExitError.Stderr.

func (*SSHCommand) Run

func (sc *SSHCommand) Run(t concurrency.Task) (int, string, string, error)

Run starts the specified command and waits for it to complete.

The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status.

If the command starts but does not complete successfully, the error is of type *ExitError. Other error types may be returned for other situations.

func (*SSHCommand) RunWithTimeout

func (sc *SSHCommand) RunWithTimeout(t concurrency.Task, timeout time.Duration) (int, string, string, error)

RunWithTimeout ...

func (*SSHCommand) Start

func (sc *SSHCommand) Start() error

Start starts the specified command but does not wait for it to complete.

The Wait method will return the exit code and release associated resources once the command exits.

func (*SSHCommand) StderrPipe

func (sc *SSHCommand) StderrPipe() (io.ReadCloser, error)

StderrPipe returns a pipe that will be connected to the command's standard error when the command starts. Wait will close the pipe after seeing the command exit, so most callers need not close the pipe themselves; however, an implication is that it is incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to use Run when using StderrPipe.

func (*SSHCommand) StdinPipe

func (sc *SSHCommand) StdinPipe() (io.WriteCloser, error)

StdinPipe returns a pipe that will be connected to the command's standard input when the command starts. The pipe will be closed automatically after Wait sees the command exit. A caller need only call Close to force the pipe to close sooner. For example, if the command being run will not exit until standard input is closed, the caller must close the pipe.

func (*SSHCommand) StdoutPipe

func (sc *SSHCommand) StdoutPipe() (io.ReadCloser, error)

StdoutPipe returns a pipe that will be connected to the command's standard output when the command starts. Wait will close the pipe after seeing the command exit, so most callers need not close the pipe themselves; however, an implication is that it is incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to call Run when using StdoutPipe.

func (*SSHCommand) Wait

func (sc *SSHCommand) Wait() error

Wait waits for the command to exit and waits for any copying to stdin or copying from stdout or stderr to complete. The command must have been started by Start. The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status. If the command fails to run or doesn't complete successfully, the error is of type *ExitError. Other error types may be returned for I/O problems. Wait also waits for the I/O loop copying from c.Stdin into the process's standard input to complete. Wait releases any resources associated with the cmd.

type SSHConfig

type SSHConfig struct {
	User          string
	Host          string
	PrivateKey    string
	Port          int
	LocalPort     int
	GatewayConfig *SSHConfig
	// contains filtered or unexported fields
}

SSHConfig helper to manage ssh session

func (*SSHConfig) Command

func (ssh *SSHConfig) Command(cmdString string) (*SSHCommand, error)

Command returns the cmd struct to execute cmdString remotely

func (*SSHConfig) CommandContext

func (ssh *SSHConfig) CommandContext(ctx context.Context, cmdString string) (*SSHCommand, error)

CommandContext is like Command but includes a context.

The provided context is used to kill the process (by calling os.Process.Kill) if the context becomes done before the command completes on its own.

func (*SSHConfig) Copy

func (ssh *SSHConfig) Copy(remotePath, localPath string, isUpload bool) (int, string, string, error)

Copy copies a file/directory from/to local to/from remote

func (*SSHConfig) CreateTunneling

func (ssh *SSHConfig) CreateTunneling() ([]*SSHTunnel, *SSHConfig, error)

CreateTunneling ...

func (*SSHConfig) Enter

func (ssh *SSHConfig) Enter() error

Enter Enter to interactive shell

func (*SSHConfig) Exec

func (ssh *SSHConfig) Exec(cmdString string) error

Exec executes the cmd using ssh

func (*SSHConfig) SudoCommand

func (ssh *SSHConfig) SudoCommand(cmdString string) (*SSHCommand, error)

SudoCommand returns the cmd struct to execute cmdString remotely. Command is executed with sudo

func (*SSHConfig) WaitServerReady

func (ssh *SSHConfig) WaitServerReady(phase string, timeout time.Duration) (out string, err error)

WaitServerReady waits until the SSH server is ready the 'timeout' parameter is in minutes

type SSHTunnel

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

SSHTunnel a SSH tunnel

func (*SSHTunnel) Close

func (tunnel *SSHTunnel) Close() error

Close closes ssh tunnel

Directories

Path Synopsis
nfs

Jump to

Keyboard shortcuts

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