sshclient

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package sshclient contains the interface to speak to bare metal servers with ssh.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCommandExitedWithoutExitSignal means the ssh command exited unplanned.
	ErrCommandExitedWithoutExitSignal = errors.New("wait: remote command exited without exit status or exit signal")
	// ErrCommandExitedWithStatusOne means the ssh command exited with sttatus 1.
	ErrCommandExitedWithStatusOne = errors.New("Process exited with status 1") //nolint:stylecheck // this is used to check ssh errors

	// ErrConnectionRefused means the ssh connection was refused.
	ErrConnectionRefused = errors.New("connect: connection refused")
	// ErrAuthenticationFailed means ssh was unable to authenticate.
	ErrAuthenticationFailed = errors.New("ssh: unable to authenticate")
	// ErrEmptyStdOut means that StdOut equals empty string.
	ErrEmptyStdOut = errors.New("unexpected empty output in stdout")
	// ErrTimeout means that there is a timeout error.
	ErrTimeout = errors.New("i/o timeout")
	// ErrCheckDiskBrokenDisk means that a disk seams broken.
	ErrCheckDiskBrokenDisk = errors.New("CheckDisk failed")
)
View Source
var (

	// ErrInvalidWWN indicates that a WWN has an invalid syntax.
	ErrInvalidWWN = fmt.Errorf("WWN does not match regex %q", isValidWWNRegex.String())
)

Functions

func IsAuthenticationFailedError

func IsAuthenticationFailedError(err error) bool

IsAuthenticationFailedError checks whether the ssh error is an authentication failed error.

func IsCommandExitedWithoutExitSignalError

func IsCommandExitedWithoutExitSignalError(err error) bool

IsCommandExitedWithoutExitSignalError checks whether the ssh error is an unplanned exit error.

func IsConnectionRefusedError

func IsConnectionRefusedError(err error) bool

IsConnectionRefusedError checks whether the ssh error is a connection refused error.

func IsTimeoutError

func IsTimeoutError(err error) bool

IsTimeoutError checks whether the ssh error is an unplanned exit error.

Types

type Client

type Client interface {
	GetHostName() Output
	GetHardwareDetailsRAM() Output
	GetHardwareDetailsNics() Output
	GetHardwareDetailsStorage() Output
	GetHardwareDetailsCPUArch() Output
	GetHardwareDetailsCPUModel() Output
	GetHardwareDetailsCPUClockGigahertz() Output
	GetHardwareDetailsCPUFlags() Output
	GetHardwareDetailsCPUThreads() Output
	GetHardwareDetailsCPUCores() Output
	GetHardwareDetailsDebug() Output
	GetInstallImageState() (InstallImageState, error)
	GetResultOfInstallImage() (string, error)
	GetCloudInitOutput() Output
	CreateAutoSetup(data string) Output
	DownloadImage(path, url string) Output
	CreatePostInstallScript(data string) Output
	ExecuteInstallImage(hasPostInstallScript bool) Output
	Reboot() Output
	CloudInitStatus() Output
	CheckCloudInitLogsForSigTerm() Output
	CleanCloudInitLogs() Output
	CleanCloudInitInstances() Output
	ResetKubeadm() Output
	UntarTGZ() Output
	DetectLinuxOnAnotherDisk(sliceOfWwns []string) Output

	// Erase filesystem, raid and partition-table signatures.
	// String "all" will wipe all disks.
	WipeDisk(ctx context.Context, sliceOfWwns []string) (string, error)

	// CheckDisk checks the given disks via smartctl.
	// ErrCheckDiskBrokenDisk gets returned, if a disk is broken.
	CheckDisk(ctx context.Context, sliceOfWwns []string) (info string, err error)
}

Client is the interface defining all functions necessary to talk to a bare metal server via SSH.

type Credentials

type Credentials struct {
	Name       string
	PublicKey  string
	PrivateKey string
}

Credentials defines the credentials for SSH calls specified in a secret.

func CredentialsFromSecret

func CredentialsFromSecret(secret *corev1.Secret, secretRef infrav1.SSHSecretRef) Credentials

CredentialsFromSecret generates the credentials object from a secret and a secretRef.

func (Credentials) Validate

func (creds Credentials) Validate() error

Validate returns an error if the ssh credentials are invalid.

type Factory

type Factory interface {
	NewClient(Input) Client
}

Factory is the interface for creating new Client objects.

func NewFactory

func NewFactory() Factory

NewFactory creates a new factory for SSH clients.

type Input

type Input struct {
	IP         string
	PrivateKey string
	Port       int
}

Input defines an SSH input.

type InstallImageState

type InstallImageState string

InstallImageState defines three states of the process.

const (
	// InstallImageStateNotStartedYet means the process has not started yet.
	InstallImageStateNotStartedYet InstallImageState = "not-started-yet"
	// InstallImageStateRunning means the process is still running.
	InstallImageStateRunning InstallImageState = "running"
	// InstallImageStateFinished has finished.
	InstallImageStateFinished InstallImageState = "finished"
)

type Output

type Output struct {
	StdOut string
	StdErr string
	Err    error
}

Output defines the SSH output.

func (Output) ExitStatus

func (o Output) ExitStatus() (int, error)

ExitStatus returns the exit status of the remote shell command. There are three case: First case: Remote command finished with exit 0: 0, nil. Second case: Remote command finished with non zero: N, nil. Third case: Remote command was not called successfully (like host not reachable): 0, err.

func (Output) String

func (o Output) String() string

Jump to

Keyboard shortcuts

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