system

package
v0.0.0-...-8fd811e Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VirtualSystemHyperV    = "HyperV"
	VirtualSystemVMWare    = "VMware"
	VirtualSystemKVM       = "KVM"
	VirtualSystemXen       = "Xen"
	VirtualSystemRoleGuest = "guest"
	VirtualSystemRoleHost  = "host"
)
View Source
const DefaultDirMode = os.FileMode(0700)
View Source
const DefaultFileMode = os.FileMode(0540)
View Source
const UnknownValue = "unknown"

Variables

This section is empty.

Functions

func CreateScriptFile

func CreateScriptFile(scriptDir, scriptContent string, interpreter Interpreter, enc *encoding.Encoder) (filePath string, err error)

func GetGidByName

func GetGidByName(group string) (gid uint32, err error)

func GetScriptExtensionOS

func GetScriptExtensionOS(interpreter Interpreter) string

func GetUIDByName

func GetUIDByName(name string) (uid uint32, err error)

func HasShebangLine

func HasShebangLine(script string) bool

HasShebangLine is just for making code more readable

func IsPortOpen

func IsPortOpen(hostPort string, timeout time.Duration) (bool, error)

IsPortOpen returns (true, nil) if a given TCP port is open on a given host. (false, err) - otherwise or if timeout is reached. 'hostPort' is in format <host>:<port>

func PercentIOWait

func PercentIOWait(lastCall *LastCallCPU) ([]float64, error)

PercentIOWait calculates the percentage of io-wait combined for all CPU's. The current cpu times are compared against cpu times from the last call.

func ValidateScriptDir

func ValidateScriptDir(scriptDir string) error

func ValidateScriptDirOS

func ValidateScriptDirOS(scriptDirSysInfo os.FileInfo, scriptDir string) error

Types

type CPUInfo

type CPUInfo struct {
	CPUs     []cpu.InfoStat
	NumCores int
}

type CmdExecutor

type CmdExecutor interface {
	New(ctx context.Context, execCtx *CmdExecutorContext) *exec.Cmd
	Start(cmd *exec.Cmd) error
	Wait(cmd *exec.Cmd) error
}

type CmdExecutorContext

type CmdExecutorContext struct {
	Interpreter Interpreter
	Command     string
	WorkingDir  string
	IsSudo      bool
	HasShebang  bool
}

type CmdExecutorImpl

type CmdExecutorImpl struct {
	*logger.Logger
}

func NewCmdExecutor

func NewCmdExecutor(l *logger.Logger) *CmdExecutorImpl

func (*CmdExecutorImpl) New

func (e *CmdExecutorImpl) New(ctx context.Context, execCtx *CmdExecutorContext) *exec.Cmd

func (*CmdExecutorImpl) Start

func (e *CmdExecutorImpl) Start(cmd *exec.Cmd) error

func (*CmdExecutorImpl) Wait

func (e *CmdExecutorImpl) Wait(cmd *exec.Cmd) error

type Interpreter

type Interpreter struct {
	InterpreterNameFromInput string
	InterpreterAliases       map[string]string
}

func (Interpreter) Get

func (i Interpreter) Get() string

func (Interpreter) GetDefault

func (i Interpreter) GetDefault() string

func (Interpreter) Matches

func (i Interpreter) Matches(search string, exact bool) bool

type LastCallCPU

type LastCallCPU struct {
	sync.Mutex
	// contains filtered or unexported fields
}

type MockSystemInfo

type MockSystemInfo struct {
	ReturnHostname                string
	ReturnHostnameError           error
	ReturnHostInfo                *host.InfoStat
	ReturnHostInfoError           error
	ReturnCPUInfo                 CPUInfo
	ReturnCPUInfoError            error
	ReturnCPUPercent              float64
	ReturnCPUPercentError         error
	ReturnCPUPercentIOWait        float64
	ReturnCPUPercentIOWaitError   error
	ReturnMemoryStat              *mem.VirtualMemoryStat
	ReturnMemoryError             error
	ReturnUname                   string
	ReturnUnameError              error
	ReturnInterfaceAddrs          []net.Addr
	ReturnInterfaceAddrsError     error
	ReturnGoArch                  string
	ReturnSystemTime              time.Time
	ReturnVirtualizationInfoError error
}

func (*MockSystemInfo) CPUInfo

func (s *MockSystemInfo) CPUInfo(ctx context.Context) (CPUInfo, error)

func (*MockSystemInfo) CPUPercent

func (s *MockSystemInfo) CPUPercent(ctx context.Context) (float64, error)

func (*MockSystemInfo) CPUPercentIOWait

func (s *MockSystemInfo) CPUPercentIOWait(ctx context.Context) (float64, error)

func (*MockSystemInfo) GoArch

func (s *MockSystemInfo) GoArch() string

func (*MockSystemInfo) HostInfo

func (s *MockSystemInfo) HostInfo(ctx context.Context) (*host.InfoStat, error)

func (*MockSystemInfo) Hostname

func (s *MockSystemInfo) Hostname() (string, error)

func (*MockSystemInfo) InterfaceAddrs

func (s *MockSystemInfo) InterfaceAddrs() ([]net.Addr, error)

func (*MockSystemInfo) MemoryStats

func (s *MockSystemInfo) MemoryStats(ctx context.Context) (*mem.VirtualMemoryStat, error)

func (*MockSystemInfo) SystemTime

func (s *MockSystemInfo) SystemTime() time.Time

func (*MockSystemInfo) Uname

func (s *MockSystemInfo) Uname(ctx context.Context) (string, error)

func (*MockSystemInfo) VirtualizationInfo

func (s *MockSystemInfo) VirtualizationInfo(ctx context.Context) (virtSystem, virtRole string, err error)

type ShellEncoding

type ShellEncoding struct {
	InputEncoding  encoding.Encoding
	OutputEncoding encoding.Encoding
}

func DetectConsoleEncoding

func DetectConsoleEncoding(ctx context.Context, interpreter Interpreter) (*ShellEncoding, error)

DetectConsoleEncoding returns encoding that interpreter is using. Returns nil, if it's UTF-8

func (*ShellEncoding) GetInputEncoder

func (e *ShellEncoding) GetInputEncoder() *encoding.Encoder

func (*ShellEncoding) GetOutputDecoder

func (e *ShellEncoding) GetOutputDecoder() *encoding.Decoder

func (*ShellEncoding) String

func (e *ShellEncoding) String() string

type SysInfo

type SysInfo interface {
	Hostname() (string, error)
	HostInfo(context.Context) (*host.InfoStat, error)
	CPUInfo(ctx context.Context) (CPUInfo, error)
	CPUPercent(ctx context.Context) (float64, error)
	CPUPercentIOWait(ctx context.Context) (float64, error)
	MemoryStats(context.Context) (*mem.VirtualMemoryStat, error)
	Uname(context.Context) (string, error)
	InterfaceAddrs() ([]net.Addr, error)
	GoArch() string
	SystemTime() time.Time
	VirtualizationInfo(ctx context.Context) (virtSystem, virtRole string, err error)
}

func NewSystemInfo

func NewSystemInfo(cmdExec CmdExecutor) SysInfo

type SysUserLookup

type SysUserLookup interface {
	GetUIDByName(user string) (uid uint32, err error)
	GetGidByName(group string) (gid uint32, err error)
	GetCurrentUserAndGroup() (*user.User, *user.Group, error)
}

type SysUserProvider

type SysUserProvider struct{}

func (SysUserProvider) GetCurrentUserAndGroup

func (sup SysUserProvider) GetCurrentUserAndGroup() (*user.User, *user.Group, error)

func (SysUserProvider) GetGidByName

func (sup SysUserProvider) GetGidByName(group string) (gid uint32, err error)

func (SysUserProvider) GetUIDByName

func (sup SysUserProvider) GetUIDByName(user string) (uid uint32, err error)

Jump to

Keyboard shortcuts

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