external

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContainerRestartPolicyDefault       = ""
	ContainerRestartPolicyAlways        = "always"
	ContainerRestartPolicyUnlessStopped = "unless-stopped"
)

Container restart policy defines

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockDevice added in v0.3.0

type BlockDevice struct {
	Name     string        `json:"name"`
	Label    string        `json:"label"`
	Size     int64         `json:"size"`
	Serial   string        `json:"serial"`
	Children []BlockDevice `json:"children,omitempty"`
}

BlockDevice represents a block device on the system, including its name, label, size, serial number, and any child devices.

type Command

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

Command define command

func NewCommand

func NewCommand(cmdName string, args ...any) *Command

NewCommand inits a new command

func (*Command) AppendArgs

func (cmd *Command) AppendArgs(args ...any)

AppendArgs append new args to current args

func (*Command) Command

func (cmd *Command) Command() string

Command gets the command

func (*Command) Exec

func (cmd *Command) Exec(ctx context.Context) (out string, err error)

Exec execute the command

func (*Command) String

func (cmd *Command) String() string

func (*Command) SudoExec

func (cmd *Command) SudoExec(ctx context.Context) (out string, err error)

SudoExec execute the command

type DiskInterface

type DiskInterface interface {
	GetNvmeDisks() ([]string, error)
	ListBlockDevices(ctx context.Context) ([]BlockDevice, error)
}

DiskInterface provides interface about disk.

type DockerInterface

type DockerInterface interface {
	GetContainer(string) string
	Run(ctx context.Context, args *RunArgs) (out string, err error)
	Cp(ctx context.Context, src, container, containerPath string) error
	Rm(ctx context.Context, name string, force bool) (out string, err error)
	Exec(context.Context, string, string, ...string) (out string, err error)
	Load(ctx context.Context, path string) (out string, err error)
	Tag(ctx context.Context, src, dst string) error
}

DockerInterface provides interface about docker.

type FSInterface

type FSInterface interface {
	MkdirTemp(context.Context, string, string) (string, error)
	MkTempFile(context.Context, string) (string, error)
	MkdirAll(context.Context, string) error
	RemoveAll(context.Context, string) error
	ReadFile(context.Context, string) (string, error)
	WriteFile(string, []byte, os.FileMode) error
	DownloadFile(string, string) error
	ReadRemoteFile(string) (string, error)
	IsNotExist(string) (bool, error)
	Sha256sum(context.Context, string) (string, error)
	Tar(srcPaths []string, basePath, dstPath string, needGzip bool) error
	ExtractTar(ctx context.Context, srcPath, dstDir string) error
}

FSInterface provides interface about local fs, this is not implemented for remote runner.

type LocalRunner

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

LocalRunner implements RunInterface by running command on local host.

func NewLocalRunner

func NewLocalRunner(cfg *LocalRunnerCfg) *LocalRunner

NewLocalRunner creates a local runner.

func (*LocalRunner) Exec

func (r *LocalRunner) Exec(ctx context.Context, cmd string, args ...string) (string, error)

Exec executes a command with sudo

func (*LocalRunner) NonSudoExec

func (r *LocalRunner) NonSudoExec(ctx context.Context, command string, args ...string) (string, error)

NonSudoExec executes a command.

func (*LocalRunner) Scp

func (r *LocalRunner) Scp(ctx context.Context, local, remote string) error

Scp copy local file or dir to remote host.

func (*LocalRunner) Stat added in v0.3.0

func (r *LocalRunner) Stat(path string) (os.FileInfo, error)

Stat run stat on path.

type LocalRunnerCfg

type LocalRunnerCfg struct {
	Logger         log.Interface
	MaxExitTimeout *time.Duration
	User           string
	Password       string
}

LocalRunnerCfg defines configurations of a local runner.

type Manager

type Manager struct {
	Runner RunnerInterface

	Os     OsInterface
	Net    NetInterface
	Docker DockerInterface
	Disk   DiskInterface
	FS     FSInterface
}

Manager provides a way to use all external interfaces

func NewManager

func NewManager(runner RunnerInterface, logger log.Interface) (em *Manager)

NewManager create a new external manager

func NewRemoteRunnerManager

func NewRemoteRunnerManager(node *config.Node, logger log.Interface) (*Manager, error)

NewRemoteRunnerManager create a new remote runner manager

type NetInterface

type NetInterface interface {
	GetRdmaLinks() ([]string, error)
}

NetInterface provides interface about network.

type NewManagerFunc

type NewManagerFunc func() *Manager

NewManagerFunc type of new manager func.

type OsInterface added in v0.3.0

type OsInterface interface {
	RandomString(length int) string
	Sleep(time.Duration)
}

OsInterface provides interface about os.

type PublishArgs

type PublishArgs struct {
	HostAddress   *string
	HostPort      int
	ContainerPort int
	Protocol      *string
}

PublishArgs defines args for publishing a container port.

type RemoteRunner

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

RemoteRunner implements RunInterface by running command on a remote host.

func NewRemoteRunner

func NewRemoteRunner(cfg *RemoteRunnerCfg) (*RemoteRunner, error)

NewRemoteRunner creates a remote runner.

func (*RemoteRunner) Close

func (r *RemoteRunner) Close()

Close closes the runner.

func (*RemoteRunner) Exec

func (r *RemoteRunner) Exec(ctx context.Context, command string, args ...string) (string, error)

Exec executes a command with sudo.

func (*RemoteRunner) NonSudoExec

func (r *RemoteRunner) NonSudoExec(ctx context.Context, command string, args ...string) (string, error)

NonSudoExec executes a command.

func (*RemoteRunner) Scp

func (r *RemoteRunner) Scp(ctx context.Context, local, remote string) error

Scp copy local file or dir to remote host.

func (*RemoteRunner) Stat added in v0.3.0

func (r *RemoteRunner) Stat(path string) (os.FileInfo, error)

Stat run stat on path

type RemoteRunnerCfg

type RemoteRunnerCfg struct {
	Username   string
	Password   *string
	TargetHost string
	TargetPort int
	PrivateKey *string
	Logger     log.Interface
	Timeout    time.Duration
}

RemoteRunnerCfg defines configurations of a remote runner.

type RunArgs

type RunArgs struct {
	Image         string
	HostNetwork   bool
	Entrypoint    *string
	Rm            *bool
	Command       []string
	Privileged    *bool
	Ulimits       map[string]string
	Name          *string
	Detach        *bool
	Publish       []*PublishArgs
	Volumes       []*VolumeArgs
	Envs          map[string]string
	RestartPolicy string
}

RunArgs defines args for docker run command.

type RunError

type RunError interface {
	ExitCode() int
	Error() string
	ExitCodeEquals(syscall.Errno) bool
	ExitCodeIn(...syscall.Errno) bool
}

RunError is the wrapper of os.exec error, it export error code

func NewRunError

func NewRunError(code int, msg string) (err RunError)

NewRunError is used to get the RunError

type RunnerInterface

type RunnerInterface interface {
	NonSudoExec(ctx context.Context, command string, args ...string) (string, error)
	Exec(ctx context.Context, command string, args ...string) (string, error)

	Scp(ctx context.Context, local, remote string) error
	Stat(path string) (os.FileInfo, error)
}

RunnerInterface is the interface for running command.

type VolumeArgs

type VolumeArgs struct {
	Source string
	Target string
	Rshare *bool
}

VolumeArgs defines args for binding a volume.

Jump to

Keyboard shortcuts

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