system

package
v21.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BashLibraryReservedKeyword            = "reserved_BashLibrary"
	DefaultDelayReservedKeyword           = "reserved_DefaultDelay"
	DefaultTimeoutReservedKeyword         = "reserved_DefaultTimeout"
	LongTimeoutReservedKeyword            = "reserved_LongTimeout"
	ClusterJoinTimeoutReservedKeyword     = "reserved_ClusterJoinTimeout"
	DockerImagePullTimeoutReservedKeyword = "reserved_DockerImagePullTimeout"
)

Variables

This section is empty.

Functions

func CreateTempFileFromString

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

CreateTempFileFromString creates a temporary file containing 'content'

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 BashLibraryDefinition

type BashLibraryDefinition struct {
	Content                string `json:"reserved_BashLibrary"`
	DefaultDelay           uint   `json:"reserved_DefaultDelay"`
	DefaultTimeout         string `json:"reserved_DefaultTimeout"`
	LongTimeout            string `json:"reserved_LongTimeout"`
	ClusterJoinTimeout     string `json:"reserved_ClusterJoinTimeout"`
	DockerImagePullTimeout string `json:"reserved_DockerImagePullTimeout"`
}

func BuildBashLibraryDefinition

func BuildBashLibraryDefinition(
	timings temporal.Timings,
) (*BashLibraryDefinition, fail.Error)

BuildBashLibraryDefinition generates the content of {{.reserved_BashLibrary}} and other reserved template variables

func (*BashLibraryDefinition) ToMap

func (bld *BashLibraryDefinition) ToMap() (map[string]interface{}, fail.Error)

ToMap transforms bld to a map

type SSHCommand

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

SSHCommand defines a SSH command

func (*SSHCommand) Close

func (scmd *SSHCommand) Close() fail.Error

Close is called to clean SSHCommand (close tunnel(s), remove temporary files, ...)

func (*SSHCommand) CombinedOutput

func (scmd *SSHCommand) CombinedOutput() ([]byte, fail.Error)

CombinedOutput returns the combined standard of command started output and standard error.

func (*SSHCommand) Kill

func (scmd *SSHCommand) Kill() fail.Error

Kill kills SSHCommand process.

func (*SSHCommand) Output

func (scmd *SSHCommand) Output() ([]byte, fail.Error)

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

func (*SSHCommand) RunWithTimeout

func (scmd *SSHCommand) RunWithTimeout(ctx context.Context, outs outputs.Enum, timeout time.Duration) (int, string, string, fail.Error)

RunWithTimeout ... returns:

  • retcode int
  • stdout string
  • stderr string
  • xerr fail.Error . *fail.ErrNotAvailable if remote SSH is not available . *fail.ErrTimeout if 'timeout' is reached

Note: if you want to RunWithTimeout in a loop, you MUST create the scmd inside the loop, otherwise

you risk to call twice os/exec.Wait, which may panic

FIXME: maybe we should move this method inside sshconfig directly with systematically created scmd...

func (*SSHCommand) Start

func (scmd *SSHCommand) Start() fail.Error

Start starts the specified command but does not wait for it to complete. The Wait method will wait for completion and return the exit code.

func (*SSHCommand) Wait

func (scmd *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 does not release resources associated with the cmd; SSHCommand.Close() must be called for that. !!!WARNING!!!: the error returned is NOT USING fail.Error because we may NEED TO CAST the error to recover return code

type SSHConfig

type SSHConfig struct {
	Hostname               string     `json:"hostname"`
	IPAddress              string     `json:"ip_address"`
	Port                   int        `json:"port"`
	User                   string     `json:"user"`
	PrivateKey             string     `json:"private_key"`
	LocalPort              int        `json:"-"`
	GatewayConfig          *SSHConfig `json:"primary_gateway_config,omitempty"`
	SecondaryGatewayConfig *SSHConfig `json:"secondary_gateway_config,omitempty"`
}

SSHConfig helper to manage ssh session

func (*SSHConfig) Clone added in v21.11.1

func (sconf *SSHConfig) Clone() *SSHConfig

Clone clones the SSHConfig

func (*SSHConfig) CopyWithTimeout

func (sconf *SSHConfig) CopyWithTimeout(
	ctx context.Context, remotePath, localPath string, isUpload bool, timeout time.Duration,
) (int, string, string, fail.Error)

CopyWithTimeout copies a file/directory from/to local to/from remote, and fails after 'timeout'

func (*SSHConfig) CreateTunneling

func (sconf *SSHConfig) CreateTunneling() (_ SSHTunnels, _ *SSHConfig, ferr fail.Error)

CreateTunneling ...

func (*SSHConfig) Enter

func (sconf *SSHConfig) Enter(username, shell string) (ferr fail.Error)

Enter to interactive shell, aka 'safescale ssh connect'

func (*SSHConfig) IsNull

func (sconf *SSHConfig) IsNull() bool

IsNull tells if the instance is a null value

func (*SSHConfig) NewCommand

func (sconf *SSHConfig) NewCommand(ctx context.Context, cmdString string) (*SSHCommand, fail.Error)

NewCommand returns the cmd struct to execute runCmdString remotely

func (*SSHConfig) NewSudoCommand

func (sconf *SSHConfig) NewSudoCommand(ctx context.Context, cmdString string) (*SSHCommand, fail.Error)

NewSudoCommand returns the cmd struct to execute runCmdString remotely. NewCommand is executed with sudo

func (*SSHConfig) WaitServerReady

func (sconf *SSHConfig) WaitServerReady(ctx context.Context, phase string, timeout time.Duration) (out string, ferr fail.Error)

WaitServerReady waits until the SSH server is ready

type SSHTunnel

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

SSHTunnel a SSH tunnel

func (*SSHTunnel) Close

func (stun *SSHTunnel) Close() fail.Error

Close closes ssh tunnel

type SSHTunnels

type SSHTunnels []*SSHTunnel

func (SSHTunnels) Close

func (tunnels SSHTunnels) Close() fail.Error

Close closes all the tunnels

Directories

Path Synopsis
nfs

Jump to

Keyboard shortcuts

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