Timezone
c.Timezone calls the API's Timezone group. The timezone of the host.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
Get(ctx, hostname) | *Response[Collection[TimezoneEntry]] | timezone:read | Get the timezone of the host. |
Update(ctx, hostname, input) | *Response[Collection[TimezoneResult]] | timezone:write | Set the timezone of the host. |
Get
func (s *TimezoneService) Get(
ctx context.Context,
hostname string,
) (*Response[Collection[TimezoneEntry]], error)
Get the timezone of the host.
Reads the IANA name of the timezone and its offset from UTC now: the zone that /etc/localtime links to, or /etc/timezone on Linux.
It sends GET /api/node/{hostname}/timezone, and needs the permission
timezone:read.
The examples of the method's definition:
A Linux host on UTC, go run timezone.go get:
resp, err := c.Timezone.Get(ctx, target)
Update
func (s *TimezoneService) Update(
ctx context.Context,
hostname string,
input TimezoneUpdateInput,
) (*Response[Collection[TimezoneResult]], error)
Set the timezone of the host.
Sets the timezone with timedatectl set-timezone. A host that already has the timezone does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.
It sends PUT /api/node/{hostname}/timezone, and needs the permission
timezone:write.
The examples of the method's definition:
Set a new timezone, go run timezone.go update:
resp, err := c.Timezone.Update(ctx, target, client.TimezoneUpdateInput{Timezone: "America/New_York"})
A host that already has the timezone, go run timezone.go update-2:
resp, err := c.Timezone.Update(ctx, target, client.TimezoneUpdateInput{Timezone: "UTC"})
Types
The fields of each type are the properties of its schema in the API's spec.
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.
TimezoneEntry
| Field | Type | Description |
|---|---|---|
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Status | 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. |
Timezone | string | The IANA name of the timezone, such as America/New_York. |
UTCOffset | string | The offset from UTC now, such as -05:00. |
TimezoneResult
| Field | Type | Description |
|---|---|---|
Changed | bool | Whether the host changed. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Status | 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. |
Timezone | string | The timezone of the host. |
TimezoneUpdateInput
| Field | Type | Description |
|---|---|---|
Timezone | string | The IANA name of the timezone, such as UTC or America/New_York. |
Example
examples/sdk/client/timezone.go
runs each example of this page. With no argument, it lists them.