host

package
v0.0.0-...-8513156 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package host provides system host information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Darwin

type Darwin struct {
	provider.FactsAware

	InfoFn     func() (*host.InfoStat, error)
	HostnameFn func() (string, error)
	NumCPUFn   func() int
	StatFn     func(name string) (os.FileInfo, error)
	LookPathFn func(file string) (string, error)
}

Darwin implements the Host interface for Darwin (macOS).

func NewDarwinProvider

func NewDarwinProvider() *Darwin

NewDarwinProvider factory to create a new Darwin instance.

func (*Darwin) GetArchitecture

func (d *Darwin) GetArchitecture() (string, error)

GetArchitecture retrieves the system CPU architecture (e.g., x86_64, arm64). It uses gopsutil's KernelArch field which returns the native architecture as reported by `uname -m`.

func (*Darwin) GetCPUCount

func (d *Darwin) GetCPUCount() (int, error)

GetCPUCount retrieves the number of logical CPUs available to the process. It uses runtime.NumCPU under the hood.

func (*Darwin) GetFQDN

func (d *Darwin) GetFQDN() (string, error)

GetFQDN retrieves the fully qualified domain name of the system. It returns the hostname as reported by the operating system.

func (*Darwin) GetHostname

func (d *Darwin) GetHostname() (string, error)

GetHostname retrieves the hostname of the system. It returns the hostname as a string, and an error if something goes wrong.

func (*Darwin) GetKernelVersion

func (d *Darwin) GetKernelVersion() (string, error)

GetKernelVersion retrieves the running kernel version string. It uses gopsutil's KernelVersion field.

func (*Darwin) GetOSInfo

func (d *Darwin) GetOSInfo() (*Result, error)

GetOSInfo retrieves information about the operating system, including the distribution name and version. It returns the

func (*Darwin) GetPackageManager

func (d *Darwin) GetPackageManager() (string, error)

GetPackageManager detects the system's package manager. On macOS, it checks for brew.

func (*Darwin) GetServiceManager

func (d *Darwin) GetServiceManager() (string, error)

GetServiceManager detects the system's service manager. On macOS, launchd is always the service manager.

func (*Darwin) GetUptime

func (d *Darwin) GetUptime() (time.Duration, error)

GetUptime retrieves the system uptime. It returns the uptime as a time.Duration, and an error if something goes wrong.

func (*Darwin) UpdateHostname

func (d *Darwin) UpdateHostname(
	_ string,
) (*UpdateHostnameResult, error)

UpdateHostname returns ErrUnsupported on Darwin. Darwin is a development platform only; mutations are not supported.

type Debian

type Debian struct {
	provider.FactsAware

	InfoFn     func() (*host.InfoStat, error)
	HostnameFn func() (string, error)
	NumCPUFn   func() int
	StatFn     func(name string) (os.FileInfo, error)
	LookPathFn func(file string) (string, error)
	// contains filtered or unexported fields
}

Debian implements the Mem interface for Debian.

func NewDebianProvider

func NewDebianProvider(
	execManager iexec.Manager,
) *Debian

NewDebianProvider factory to create a new Debian instance.

func (*Debian) GetArchitecture

func (u *Debian) GetArchitecture() (string, error)

GetArchitecture retrieves the system CPU architecture (e.g., x86_64, arm64). It uses gopsutil's KernelArch field which returns the native architecture as reported by `uname -m`.

func (*Debian) GetCPUCount

func (u *Debian) GetCPUCount() (int, error)

GetCPUCount retrieves the number of logical CPUs available to the process. It uses runtime.NumCPU under the hood.

func (*Debian) GetFQDN

func (u *Debian) GetFQDN() (string, error)

GetFQDN retrieves the fully qualified domain name of the system. It returns the hostname as reported by the operating system.

func (*Debian) GetHostname

func (u *Debian) GetHostname() (string, error)

GetHostname retrieves the hostname of the system. It returns the hostname as a string, and an error if something goes wrong.

func (*Debian) GetKernelVersion

func (u *Debian) GetKernelVersion() (string, error)

GetKernelVersion retrieves the running kernel version string. It uses gopsutil's KernelVersion field.

func (*Debian) GetOSInfo

func (u *Debian) GetOSInfo() (*Result, error)

GetOSInfo retrieves information about the operating system, including the distribution name and version. It returns the

func (*Debian) GetPackageManager

func (u *Debian) GetPackageManager() (string, error)

GetPackageManager detects the system's package manager by checking for known executables in order of preference: apt, dnf, yum.

func (*Debian) GetServiceManager

func (u *Debian) GetServiceManager() (string, error)

GetServiceManager detects the system's service manager. It checks for the presence of /run/systemd/system to detect systemd.

func (*Debian) GetUptime

func (u *Debian) GetUptime() (time.Duration, error)

GetUptime retrieves the system uptime. It returns the uptime as a time.Duration, and an error if something goes wrong.

func (*Debian) UpdateHostname

func (u *Debian) UpdateHostname(
	name string,
) (*UpdateHostnameResult, error)

UpdateHostname sets the system hostname using hostnamectl. It checks the current hostname first and returns Changed: false if the hostname is already set to the requested value.

type DebianDocker

type DebianDocker struct {
	Debian
}

DebianDocker implements the Host Provider interface for Debian-family systems running inside Docker containers. It delegates all read operations to an embedded Debian provider. Mutations return ErrUnsupported because hostname is managed by the container runtime.

func NewDebianDockerProvider

func NewDebianDockerProvider() *DebianDocker

NewDebianDockerProvider factory to create a new DebianDocker instance.

func (*DebianDocker) UpdateHostname

func (d *DebianDocker) UpdateHostname(
	_ string,
) (*UpdateHostnameResult, error)

UpdateHostname returns ErrUnsupported for container environments. Hostname in containers is managed by the container runtime.

type ExecNotFoundError

type ExecNotFoundError struct {
	Name string
}

ExecNotFoundError wraps exec.ErrNotFound for testability.

func (*ExecNotFoundError) Error

func (e *ExecNotFoundError) Error() string

Error implements the error interface.

type Linux

type Linux struct {
	provider.FactsAware
}

Linux implements the Load interface for Linux.

func NewLinuxProvider

func NewLinuxProvider() *Linux

NewLinuxProvider factory to create a new Linux instance.

func (*Linux) GetArchitecture

func (l *Linux) GetArchitecture() (string, error)

GetArchitecture retrieves the system CPU architecture. It returns an error because it is not implemented for LinuxProvider.

func (*Linux) GetCPUCount

func (l *Linux) GetCPUCount() (int, error)

GetCPUCount retrieves the number of logical CPUs available. It returns an error because it is not implemented for LinuxProvider.

func (*Linux) GetFQDN

func (l *Linux) GetFQDN() (string, error)

GetFQDN retrieves the fully qualified domain name of the system. It returns an error because it is not implemented for LinuxProvider.

func (*Linux) GetHostname

func (dls *Linux) GetHostname() (string, error)

GetHostname retrieves the hostname of the system. It returns the hostname as a string, and an error if something goes wrong.

func (*Linux) GetKernelVersion

func (l *Linux) GetKernelVersion() (string, error)

GetKernelVersion retrieves the running kernel version string. It returns an error because it is not implemented for LinuxProvider.

func (*Linux) GetOSInfo

func (l *Linux) GetOSInfo() (*Result, error)

GetOSInfo retrieves information about the operating system, including the distribution name and version. It returns the

func (*Linux) GetPackageManager

func (l *Linux) GetPackageManager() (string, error)

GetPackageManager detects the system's package manager. It returns an error because it is not implemented for LinuxProvider.

func (*Linux) GetServiceManager

func (l *Linux) GetServiceManager() (string, error)

GetServiceManager detects the system's service manager. It returns an error because it is not implemented for LinuxProvider.

func (*Linux) GetUptime

func (l *Linux) GetUptime() (time.Duration, error)

GetUptime retrieves the system uptime. It returns the uptime as a time.Duration, and an error if something goes wrong.

func (*Linux) UpdateHostname

func (l *Linux) UpdateHostname(
	_ string,
) (*UpdateHostnameResult, error)

UpdateHostname returns ErrUnsupported on generic Linux.

type Provider

type Provider interface {
	// GetUptime retrieves the system uptime.
	GetUptime() (time.Duration, error)
	// GetHostname retrieves the hostname of the system.
	GetHostname() (string, error)
	// GetOSInfo retrieves information about the operating system, including the
	// distribution name and version.
	GetOSInfo() (*Result, error)
	// GetArchitecture retrieves the system CPU architecture (e.g., x86_64, arm64).
	GetArchitecture() (string, error)
	// GetKernelVersion retrieves the running kernel version string.
	GetKernelVersion() (string, error)
	// GetFQDN retrieves the fully qualified domain name of the system.
	GetFQDN() (string, error)
	// GetCPUCount retrieves the number of logical CPUs available.
	GetCPUCount() (int, error)
	// GetServiceManager detects the system's service manager (e.g., systemd).
	GetServiceManager() (string, error)
	// GetPackageManager detects the system's package manager (e.g., apt, dnf, yum).
	GetPackageManager() (string, error)
	// UpdateHostname sets the system hostname.
	UpdateHostname(name string) (*UpdateHostnameResult, error)
}

Provider implements the methods to interact with various Host components.

type Result

type Result struct {
	// The name of the Linux distribution (e.g., Debian, CentOS).
	Distribution string
	// The version of the Linux distribution (e.g., 20.04, 8.3).
	Version string
	// Changed indicates whether system state was modified.
	Changed bool `json:"changed"`
}

Result represents the operating system information.

type UpdateHostnameResult

type UpdateHostnameResult struct {
	// Changed indicates whether the hostname was actually modified.
	Changed bool `json:"changed"`
}

UpdateHostnameResult represents the outcome of a hostname set operation.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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