Documentation
¶
Overview ¶
Package hostname is the hostname behavior: the name of the host, and on Debian, setting it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Behavior = behavior.Register(behavior.Define( "hostname", "Get or set the hostname of target hosts", behavior.Node, behavior.API, behavior.Area(area.Config), behavior.CLI, behavior.Platform(behavior.PlatformLinux, newLinux), behavior.Platform(behavior.PlatformDarwin, newDarwin), behavior.Runs("hostname"), behavior.Read("get", Get). Describe("Get the hostname of the host"). Explain("Reads the host's name as the hostname command prints it, on Linux and "+ "on macOS. It makes no DNS lookup."). Example("A host named web-01", GetInput{}, Entry{Name: "web-01"}, behavior.Prints("hostname", "web-01\n"), behavior.Prints("hostname -s", "web-01\n"), ), behavior.Write("update", Update). On(behavior.PlatformDebian). Sudo("hostnamectl"). Describe("Set the hostname of the host"). Explain("Sets the static hostname with hostnamectl set-hostname, which keeps it "+ "after a reboot. A host that already has the name does not change and "+ "reports changed: false. It runs on the Debian family only, and elsewhere "+ "reports skipped. In a container the runtime owns the hostname, so there "+ "it also reports skipped."). Example("Rename a host", UpdateInput{Name: "web-02"}, Result{Name: "web-02", Changed: true}, append( named("web-01"), behavior.PrintsAfter( "hostnamectl set-hostname web-02", "hostnamectl hostname", "web-02\n", ), behavior.Ran("hostnamectl", "set-hostname", "web-02"), behavior.Reads(GetInput{}, Entry{Name: "web-02"}), )..., ). Example("A host that already has the name", UpdateInput{Name: "web-01"}, Result{Name: "web-01"}, append(named("web-01"), behavior.Reads(GetInput{}, Entry{Name: "web-01"}), )..., ). Fails("A name that is not a hostname", UpdateInput{Name: "web 01;reboot"}, "invalid hostname"). Fails("A name longer than 253 characters", UpdateInput{Name: strings.Repeat("a", 254)}, "invalid hostname"). Fails("No name", UpdateInput{}, "invalid hostname"), ))
Behavior is the hostname definition.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Name string `json:"name" doc:"The hostname of the host"`
}
Entry is the host's name.
type Provider ¶
type Provider interface {
// Hostname is the kernel's hostname.
Hostname(ctx context.Context) (string, error)
// SetHostname sets the static hostname, and reports whether it changed.
SetHostname(ctx context.Context, name string) (bool, error)
}
Provider is what each platform implements.
type Result ¶
type Result struct {
Name string `json:"name" doc:"The hostname of the host"`
Changed bool `json:"changed" doc:"Whether the host changed"`
}
Result is the name after an update, and whether the host changed.
type UpdateInput ¶
type UpdateInput struct {
Name string `json:"name" validate:"required,max=253,hostname" doc:"The hostname to set, such as web-01" telemetry:"attr"`
}
UpdateInput is the name to set.