Documentation
¶
Overview ¶
Package host provides system host information.
Index ¶
- type Darwin
- func (d *Darwin) GetArchitecture() (string, error)
- func (d *Darwin) GetCPUCount() (int, error)
- func (d *Darwin) GetFQDN() (string, error)
- func (d *Darwin) GetHostname() (string, error)
- func (d *Darwin) GetKernelVersion() (string, error)
- func (d *Darwin) GetOSInfo() (*Result, error)
- func (d *Darwin) GetPackageManager() (string, error)
- func (d *Darwin) GetServiceManager() (string, error)
- func (d *Darwin) GetUptime() (time.Duration, error)
- func (d *Darwin) UpdateHostname(_ string) (*UpdateHostnameResult, error)
- type Debian
- func (u *Debian) GetArchitecture() (string, error)
- func (u *Debian) GetCPUCount() (int, error)
- func (u *Debian) GetFQDN() (string, error)
- func (u *Debian) GetHostname() (string, error)
- func (u *Debian) GetKernelVersion() (string, error)
- func (u *Debian) GetOSInfo() (*Result, error)
- func (u *Debian) GetPackageManager() (string, error)
- func (u *Debian) GetServiceManager() (string, error)
- func (u *Debian) GetUptime() (time.Duration, error)
- func (u *Debian) UpdateHostname(name string) (*UpdateHostnameResult, error)
- type DebianDocker
- type ExecNotFoundError
- type Linux
- func (l *Linux) GetArchitecture() (string, error)
- func (l *Linux) GetCPUCount() (int, error)
- func (l *Linux) GetFQDN() (string, error)
- func (dls *Linux) GetHostname() (string, error)
- func (l *Linux) GetKernelVersion() (string, error)
- func (l *Linux) GetOSInfo() (*Result, error)
- func (l *Linux) GetPackageManager() (string, error)
- func (l *Linux) GetServiceManager() (string, error)
- func (l *Linux) GetUptime() (time.Duration, error)
- func (l *Linux) UpdateHostname(_ string) (*UpdateHostnameResult, error)
- type Provider
- type Result
- type UpdateHostnameResult
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 ¶
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 ¶
GetCPUCount retrieves the number of logical CPUs available to the process. It uses runtime.NumCPU under the hood.
func (*Darwin) GetFQDN ¶
GetFQDN retrieves the fully qualified domain name of the system. It returns the hostname as reported by the operating system.
func (*Darwin) GetHostname ¶
GetHostname retrieves the hostname of the system. It returns the hostname as a string, and an error if something goes wrong.
func (*Darwin) GetKernelVersion ¶
GetKernelVersion retrieves the running kernel version string. It uses gopsutil's KernelVersion field.
func (*Darwin) GetOSInfo ¶
GetOSInfo retrieves information about the operating system, including the distribution name and version. It returns the
func (*Darwin) GetPackageManager ¶
GetPackageManager detects the system's package manager. On macOS, it checks for brew.
func (*Darwin) GetServiceManager ¶
GetServiceManager detects the system's service manager. On macOS, launchd is always the service manager.
func (*Darwin) GetUptime ¶
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 ¶
NewDebianProvider factory to create a new Debian instance.
func (*Debian) GetArchitecture ¶
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 ¶
GetCPUCount retrieves the number of logical CPUs available to the process. It uses runtime.NumCPU under the hood.
func (*Debian) GetFQDN ¶
GetFQDN retrieves the fully qualified domain name of the system. It returns the hostname as reported by the operating system.
func (*Debian) GetHostname ¶
GetHostname retrieves the hostname of the system. It returns the hostname as a string, and an error if something goes wrong.
func (*Debian) GetKernelVersion ¶
GetKernelVersion retrieves the running kernel version string. It uses gopsutil's KernelVersion field.
func (*Debian) GetOSInfo ¶
GetOSInfo retrieves information about the operating system, including the distribution name and version. It returns the
func (*Debian) GetPackageManager ¶
GetPackageManager detects the system's package manager by checking for known executables in order of preference: apt, dnf, yum.
func (*Debian) GetServiceManager ¶
GetServiceManager detects the system's service manager. It checks for the presence of /run/systemd/system to detect systemd.
func (*Debian) GetUptime ¶
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 ¶
GetArchitecture retrieves the system CPU architecture. It returns an error because it is not implemented for LinuxProvider.
func (*Linux) GetCPUCount ¶
GetCPUCount retrieves the number of logical CPUs available. It returns an error because it is not implemented for LinuxProvider.
func (*Linux) GetFQDN ¶
GetFQDN retrieves the fully qualified domain name of the system. It returns an error because it is not implemented for LinuxProvider.
func (*Linux) GetHostname ¶
GetHostname retrieves the hostname of the system. It returns the hostname as a string, and an error if something goes wrong.
func (*Linux) GetKernelVersion ¶
GetKernelVersion retrieves the running kernel version string. It returns an error because it is not implemented for LinuxProvider.
func (*Linux) GetOSInfo ¶
GetOSInfo retrieves information about the operating system, including the distribution name and version. It returns the
func (*Linux) GetPackageManager ¶
GetPackageManager detects the system's package manager. It returns an error because it is not implemented for LinuxProvider.
func (*Linux) GetServiceManager ¶
GetServiceManager detects the system's service manager. It returns an error because it is not implemented for LinuxProvider.
func (*Linux) GetUptime ¶
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.
Source Files
¶
- darwin.go
- darwin_get_architecture.go
- darwin_get_cpu_count.go
- darwin_get_fqdn.go
- darwin_get_hostname.go
- darwin_get_kernel_version.go
- darwin_get_os_info.go
- darwin_get_package_manager.go
- darwin_get_service_manager.go
- darwin_get_uptime.go
- darwin_update_hostname.go
- debian.go
- debian_docker.go
- debian_docker_update_hostname.go
- debian_get_architecture.go
- debian_get_cpu_count.go
- debian_get_fqdn.go
- debian_get_hostname.go
- debian_get_kernel_version.go
- debian_get_os_info.go
- debian_get_package_manager.go
- debian_get_service_manager.go
- debian_get_uptime.go
- debian_update_hostname.go
- linux.go
- linux_get_architecture.go
- linux_get_cpu_count.go
- linux_get_fqdn.go
- linux_get_hostname.go
- linux_get_kernel_version.go
- linux_get_os_info.go
- linux_get_package_manager.go
- linux_get_service_manager.go
- linux_get_uptime.go
- linux_update_hostname.go
- types.go