Documentation ¶
Index ¶
- Constants
- Variables
- func EnvOrDefaultChroot() string
- func EnvOrDefaultSnapshotExclusive() bool
- func EnvOrDefaultSnapshotPath() string
- func EnvOrDefaultSnapshotPreserve() bool
- func EnvOrDefaultSnapshotRoot() string
- func EnvOrDefaultTools() bool
- type Alerter
- type Option
- type PathOverrides
- type SnapshotOptions
Constants ¶
const (
DefaultChroot = "/"
)
Variables ¶
var (
NullAlerter = log.New(io.Discard, "", 0)
)
Functions ¶
func EnvOrDefaultChroot ¶
func EnvOrDefaultChroot() string
EnvOrDefaultChroot returns the value of the GHW_CHROOT environs variable or the default value of "/" if not set
func EnvOrDefaultSnapshotExclusive ¶
func EnvOrDefaultSnapshotExclusive() bool
EnvOrDefaultSnapshotExclusive returns the value of the GHW_SNAPSHOT_EXCLUSIVE environs variable or the default value of false if not set
func EnvOrDefaultSnapshotPath ¶
func EnvOrDefaultSnapshotPath() string
EnvOrDefaultSnapshotPath returns the value of the GHW_SNAPSHOT_PATH environs variable or the default value of "" (disable snapshot consumption) if not set
func EnvOrDefaultSnapshotPreserve ¶
func EnvOrDefaultSnapshotPreserve() bool
EnvOrDefaultSnapshotPreserve returns the value of the GHW_SNAPSHOT_PRESERVE environs variable or the default value of false if not set
func EnvOrDefaultSnapshotRoot ¶
func EnvOrDefaultSnapshotRoot() string
EnvOrDefaultSnapshotRoot returns the value of the the GHW_SNAPSHOT_ROOT environs variable or the default value of "" (self-manage the snapshot unpack directory, if relevant) if not set
func EnvOrDefaultTools ¶ added in v0.8.0
func EnvOrDefaultTools() bool
EnvOrDefaultTools return true if ghw should use external tools to augment the data collected from sysfs. Most users want to do this most of time, so this is enabled by default. Users consuming snapshots may want to opt out, thus they can set the GHW_DISABLE_TOOLS environs variable to any value to make ghw skip calling external tools even if they are available.
Types ¶
type Alerter ¶
type Alerter interface {
Printf(format string, v ...interface{})
}
Alerter emits warnings about undesirable but recoverable errors. We use a subset of a logger interface only to emit warnings, and `Warninger` sounded ugly.
func EnvOrDefaultAlerter ¶
func EnvOrDefaultAlerter() Alerter
EnvOrDefaultAlerter returns the default instance ghw will use to emit its warnings. ghw will emit warnings to stderr by default unless the environs variable GHW_DISABLE_WARNINGS is specified; in the latter case all warning will be suppressed.
type Option ¶
type Option struct { // To facilitate querying of sysfs filesystems that are bind-mounted to a // non-default root mountpoint, we allow users to set the GHW_CHROOT environ // variable to an alternate mountpoint. For instance, assume that the user of // ghw is a Golang binary being executed from an application container that has // certain host filesystems bind-mounted into the container at /host. The user // would ensure the GHW_CHROOT environ variable is set to "/host" and ghw will // build its paths from that location instead of / Chroot *string // Snapshot contains options for handling ghw snapshots Snapshot *SnapshotOptions // Alerter contains the target for ghw warnings Alerter Alerter // EnableTools optionally request ghw to not call any external program to learn // about the hardware. The default is to use such tools if available. EnableTools *bool // PathOverrides optionally allows to override the default paths ghw uses internally // to learn about the system resources. PathOverrides PathOverrides // Context may contain a pointer to a `Context` struct that is constructed // during a call to the `context.WithContext` function. Only used internally. // This is an interface to get around recursive package import issues. Context interface{} }
Option is used to represent optionally-configured settings. Each field is a pointer to some concrete value so that we can tell when something has been set or left unset.
func Merge ¶
Merge accepts one or more Options and merges them together, returning the merged Option
func WithAlerter ¶
WithAlerter sets alerting options for ghw
func WithChroot ¶
WithChroot allows to override the root directory ghw uses.
func WithDisableTools ¶ added in v0.8.0
func WithDisableTools() *Option
WithDisableTools sets enables or prohibts ghw to call external tools to discover hardware capabilities.
func WithNullAlerter ¶
func WithNullAlerter() *Option
WithNullAlerter sets No-op alerting options for ghw
func WithPathOverrides ¶ added in v0.9.0
func WithPathOverrides(overrides PathOverrides) *Option
WithPathOverrides supplies path-specific overrides for the context
func WithSnapshot ¶
func WithSnapshot(opts SnapshotOptions) *Option
WithSnapshot sets snapshot-processing options for a ghw run
type PathOverrides ¶ added in v0.9.0
PathOverrides is a map, keyed by the string name of a mount path, of override paths
type SnapshotOptions ¶
type SnapshotOptions struct { // Path allows users to specify a snapshot (captured using ghw-snapshot) to be // automatically consumed. Users need to supply the path of the snapshot, and // ghw will take care of unpacking it on a temporary directory. // Set the environment variable "GHW_SNAPSHOT_PRESERVE" to make ghw skip the cleanup // stage and keep the unpacked snapshot in the temporary directory. Path string // Root is the directory on which the snapshot must be unpacked. This allows // the users to manage their snapshot directory instead of ghw doing that on // their behalf. Relevant only if SnapshotPath is given. Root *string // Exclusive tells ghw if the given directory should be considered of exclusive // usage of ghw or not If the user provides a Root. If the flag is set, ghw will // unpack the snapshot in the given SnapshotRoot iff the directory is empty; otherwise // any existing content will be left untouched and the unpack stage will exit silently. // As additional side effect, give both this option and SnapshotRoot to make each // context try to unpack the snapshot only once. Exclusive bool }
SnapshotOptions contains options for handling of ghw snapshots