Power
c.Power calls the API's Power group. Reboot or shut down the host.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
Reboot(ctx, hostname, input) | *Response[Collection[PowerResult]] | power:execute | Reboot the host. |
Shutdown(ctx, hostname, input) | *Response[Collection[PowerResult]] | power:execute | Shut the host down. |
Reboot
func (s *PowerService) Reboot(
ctx context.Context,
hostname string,
input PowerRebootInput,
) (*Response[Collection[PowerResult]], error)
Reboot the host.
Runs shutdown -r -- +N, with N the delay in whole minutes and at least one, so the agent can answer before the host goes down. A message goes to the logged-in users. Each run changes the host.
It sends POST /api/node/{hostname}/power/reboot, and needs the permission
power:execute.
The examples of the method's definition:
In one minute, go run power.go reboot:
resp, err := c.Power.Reboot(ctx, target, client.PowerRebootInput{})
In five minutes, with a message, go run power.go reboot-2:
resp, err := c.Power.Reboot(ctx, target, client.PowerRebootInput{
Delay: 300,
Message: "maintenance",
})
Shutdown
func (s *PowerService) Shutdown(
ctx context.Context,
hostname string,
input PowerShutdownInput,
) (*Response[Collection[PowerResult]], error)
Shut the host down.
Runs shutdown -h -- +N, with N the delay in whole minutes and at least one, so the agent can answer before the host goes down. A message goes to the logged-in users. Each run changes the host.
It sends POST /api/node/{hostname}/power/shutdown, and needs the permission
power:execute.
The examples of the method's definition:
In one minute, go run power.go shutdown:
resp, err := c.Power.Shutdown(ctx, target, client.PowerShutdownInput{})
In five minutes, with a message, go run power.go shutdown-2:
resp, err := c.Power.Shutdown(ctx, target, client.PowerShutdownInput{
Delay: 300,
Message: "maintenance",
})
Types
The fields of each type are the properties of its schema in the API's spec.
PowerRebootInput
| Field | Type | Description |
|---|---|---|
Delay | int | Seconds before the host goes down. It rounds to whole minutes, at least one. |
Message | string | A message to the logged-in users first. |
PowerResult
| Field | Type | Description |
|---|---|---|
Action | string | reboot or shutdown. |
Changed | bool | Always true: each run changes the host. |
Delay | int | Seconds before the host goes down. |
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. |
PowerShutdownInput
| Field | Type | Description |
|---|---|---|
Delay | int | Seconds before the host goes down. It rounds to whole minutes, at least one. |
Message | string | A message to the logged-in users first. |
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/power.go
runs each example of this page. With no argument, it lists them.