Skip to main content

Power

c.Power calls the API's Power group. Reboot or shut down the host.

Methods​

MethodReturnsPermissionDescription
Reboot(ctx, hostname, input)*Response[Collection[PowerResult]]power:executeReboot the host.
Shutdown(ctx, hostname, input)*Response[Collection[PowerResult]]power:executeShut 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​

FieldTypeDescription
DelayintSeconds before the host goes down. It rounds to whole minutes, at least one.
MessagestringA message to the logged-in users first.

PowerResult​

FieldTypeDescription
Actionstringreboot or shutdown.
ChangedboolAlways true: each run changes the host.
DelayintSeconds before the host goes down.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
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.

PowerShutdownInput​

FieldTypeDescription
DelayintSeconds before the host goes down. It rounds to whole minutes, at least one.
MessagestringA 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.