Skip to main content

Hostname

c.Hostname calls the API's Hostname group. Get or set the hostname of target hosts.

Methods​

MethodReturnsPermissionDescription
Get(ctx, hostname)*Response[Collection[HostnameEntry]]hostname:readGet the hostname of the host.
Update(ctx, hostname, input)*Response[Collection[HostnameResult]]hostname:writeSet the hostname of the host.

Get​

func (s *HostnameService) Get(
ctx context.Context,
hostname string,
) (*Response[Collection[HostnameEntry]], error)

Get the hostname of the host.

Reads the host's name as the hostname command prints it, on Linux and on macOS. It makes no DNS lookup.

It sends GET /api/node/{hostname}/hostname, and needs the permission hostname:read.

The examples of the method's definition:

A host named web-01, go run hostname.go get:

resp, err := c.Hostname.Get(ctx, target)

Update​

func (s *HostnameService) Update(
ctx context.Context,
hostname string,
input HostnameUpdateInput,
) (*Response[Collection[HostnameResult]], error)

Set the hostname of the host.

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.

It sends PUT /api/node/{hostname}/hostname, and needs the permission hostname:write.

The examples of the method's definition:

Rename a host, go run hostname.go update:

resp, err := c.Hostname.Update(ctx, target, client.HostnameUpdateInput{Name: "web-02"})

A host that already has the name, go run hostname.go update-2:

resp, err := c.Hostname.Update(ctx, target, client.HostnameUpdateInput{Name: "web-01"})

Types​

The fields of each type are the properties of its schema in the API's spec.

HostnameEntry​

FieldTypeDescription
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
NamestringThe hostname of the host.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

HostnameResult​

FieldTypeDescription
ChangedboolWhether the host changed.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
NamestringThe hostname of the host.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

HostnameUpdateInput​

FieldTypeDescription
NamestringThe hostname to set, such as web-01.

RowStatus​

What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

A string, one of ok, failed, skipped, timeout.

Example​

examples/sdk/client/hostname.go runs each example of this page. With no argument, it lists them.