gen

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Group = endpoint.Define(
	"hostname",
	"Get or set the hostname of target hosts",
	endpoint.Area(area.Config),
	endpoint.Prefix("node/{hostname}"),
	endpoint.Uses[dispatch.Deps](),
	endpoint.Tag("hostname_operations", "Hostname", "Get or set the hostname of target hosts"),
	endpoint.CommandNotes("The [hostname behavior](../../../../../reference/behaviors/config/hostname/hostname.md) page tells where the behavior runs, what it is built on and its settings."),
	endpoint.Doc[types.RowStatus](dispatch.RowStatusDoc),
	endpoint.Get[GetRequest, HostnameGetResponse]("get").
		Handle(HandleGet).
		ID("GetNodeHostname").
		Describe("Get the hostname of the host").
		Permission("hostname:read").
		Returns("Each target host's result.").
		Explain("Reads the host's name as the hostname command prints it, on Linux and on macOS. It makes no DNS lookup.").
		Example("--target web-01", "A host named web-01").
		Result("A host named web-01, on one host:\n\n```ansi\n$ osapi client node hostname get --target web-01\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n  \x1b[38;2;10;143;176mHOSTNAME  \x1b[0m\x1b[38;2;10;143;176mSTATUS  \x1b[0m\x1b[38;2;10;143;176mNAME\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      \x1b[1mweb-01\x1b[0m\n\n  1 host: \x1b[38;2;103;234;147m1 ok\x1b[0m   \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m   \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node hostname get --target _all\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n  \x1b[38;2;10;143;176mHOSTNAME  \x1b[0m\x1b[38;2;10;143;176mSTATUS  \x1b[0m\x1b[38;2;10;143;176mNAME\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      \x1b[1mweb-01\x1b[0m\n  \x1b[1mweb-02\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      \x1b[1mweb-02\x1b[0m\n\n  3 hosts: \x1b[38;2;103;234;147m2 ok\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m   \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m   \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n  \x1b[1mmac-01\x1b[0m  \x1b[38;5;222mskipped\x1b[0m  operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n  \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n  \"results\": [\n    {\n      \"hostname\": \"web-01\",\n      \"name\": \"web-01\",\n      \"status\": \"ok\"\n    }\n  ]\n}\n```").
		Errors(endpoint.NotFound(behavior.ErrNotFound, "The host does not have what the request names, such as the object of a deploy."), endpoint.Conflict(behavior.ErrNotManaged, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotManaged), endpoint.Conflict(behavior.ErrNotInstalled, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotInstalled), endpoint.Invalid(dispatch.ErrInvalid, "The request is not valid, or the host refuses the input, such as a path that is a directory.")),
	endpoint.Put[UpdateRequest, HostnameUpdateResponse]("update").
		Handle(HandleUpdate).
		ID("PutNodeHostname").
		Describe("Set the hostname of the host").
		Permission("hostname:write").
		Returns("Each target host's result, with whether it changed.").
		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("--target web-01 --name web-02", "Rename a host").
		Example("--target web-01 --name web-01", "A host that already has the name").
		Result("Rename a host, on one host:\n\n```ansi\n$ osapi client node hostname update --target web-01 --name web-02\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n  \x1b[38;2;10;143;176mHOSTNAME  \x1b[0m\x1b[38;2;10;143;176mSTATUS   \x1b[0m\x1b[38;2;10;143;176mNAME\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mchanged\x1b[0m  \x1b[1mweb-02\x1b[0m\n\n  1 host: \x1b[38;2;103;234;147m1 changed\x1b[0m   \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m   \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node hostname update --target _all --name web-02\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n  \x1b[38;2;10;143;176mHOSTNAME  \x1b[0m\x1b[38;2;10;143;176mSTATUS   \x1b[0m\x1b[38;2;10;143;176mNAME\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mchanged\x1b[0m  \x1b[1mweb-02\x1b[0m\n  \x1b[1mweb-02\x1b[0m    \x1b[38;2;103;234;147mchanged\x1b[0m  \x1b[1mweb-02\x1b[0m\n\n  3 hosts: \x1b[38;2;103;234;147m2 changed\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m   \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m   \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n  \x1b[1mmac-01\x1b[0m  \x1b[38;5;222mskipped\x1b[0m  operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n  \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n  \"results\": [\n    {\n      \"changed\": true,\n      \"hostname\": \"web-01\",\n      \"name\": \"web-02\",\n      \"status\": \"ok\"\n    }\n  ]\n}\n```\n\nA host that already has the name, on one host:\n\n```ansi\n$ osapi client node hostname update --target web-01 --name web-01\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n  \x1b[38;2;10;143;176mHOSTNAME  \x1b[0m\x1b[38;2;10;143;176mSTATUS  \x1b[0m\x1b[38;2;10;143;176mNAME\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      \x1b[1mweb-01\x1b[0m\n\n  1 host: \x1b[38;2;103;234;147m1 ok\x1b[0m   \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m   \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node hostname update --target _all --name web-01\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n  \x1b[38;2;10;143;176mHOSTNAME  \x1b[0m\x1b[38;2;10;143;176mSTATUS  \x1b[0m\x1b[38;2;10;143;176mNAME\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      \x1b[1mweb-01\x1b[0m\n  \x1b[1mweb-02\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      \x1b[1mweb-02\x1b[0m\n\n  3 hosts: \x1b[38;2;103;234;147m2 ok\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m   \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m   \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n  \x1b[1mmac-01\x1b[0m  \x1b[38;5;222mskipped\x1b[0m  operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n  \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n  \"results\": [\n    {\n      \"changed\": false,\n      \"hostname\": \"web-01\",\n      \"name\": \"web-01\",\n      \"status\": \"ok\"\n    }\n  ]\n}\n```\n\nWith the default settings, each example does this on the host:\n\n| Example | On the host |\n| --- | --- |\n| Rename a host | runs `hostnamectl set-hostname web-02` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| A name that is not a hostname | `--name \"web 01;reboot\"` | invalid hostname |\n| A name longer than 253 characters | `--name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | invalid hostname |\n| No name |  | invalid hostname |").
		Errors(endpoint.NotFound(behavior.ErrNotFound, "The host does not have what the request names, such as the object of a deploy."), endpoint.Conflict(behavior.ErrNotManaged, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotManaged), endpoint.Conflict(behavior.ErrNotInstalled, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotInstalled), endpoint.Invalid(dispatch.ErrInvalid, "The request is not valid, or the host refuses the input, such as a path that is a directory.")),
)

Group is hostname as an endpoint group, which its spec comes from.

Functions

func Routes

func Routes(
	s *server.Server,
) []server.Route

Routes are the hostname group's endpoints, as its definition declares them.

Types

type GetRequest

type GetRequest struct {
	Hostname string `` /* 182-byte string literal not displayed */
}

GetRequest is the request of hostname get: its target and its input.

type HostnameEntry

type HostnameEntry struct {
	Hostname string          `doc:"Hostname of the agent that produced this result." json:"hostname"`
	Status   types.RowStatus `doc:"The status of the operation for this host." json:"status"`
	Name     *string         `doc:"The hostname of the host" json:"name,omitempty"`
	Error    *string         `doc:"Error message if the agent failed." json:"error,omitempty"`
}

HostnameEntry is the result of hostname on one host.

type HostnameGetResponse

type HostnameGetResponse struct {
	JobID   string          `` /* 133-byte string literal not displayed */
	Results []HostnameEntry `json:"results"`
}

HostnameGetResponse is each target host's result.

func HandleGet

func HandleGet(
	ctx context.Context,
	d dispatch.Deps,
	in GetRequest,
) (HostnameGetResponse, error)

HandleGet runs hostname get on the target, for the endpoint server.

type HostnameResult

type HostnameResult struct {
	Hostname string          `doc:"Hostname of the agent that produced this result." json:"hostname"`
	Status   types.RowStatus `doc:"The status of the operation for this host." json:"status"`
	Name     *string         `doc:"The hostname of the host" json:"name,omitempty"`
	Changed  *bool           `doc:"Whether the host changed" json:"changed,omitempty"`
	Error    *string         `doc:"Error message if the agent failed." json:"error,omitempty"`
}

HostnameResult is the result of hostname on one host.

type HostnameUpdateRequest

type HostnameUpdateRequest struct {
	Name string `doc:"The hostname to set, such as web-01" json:"name" validate:"required,max=253,hostname"`
}

HostnameUpdateRequest is the body of hostname update.

type HostnameUpdateResponse

type HostnameUpdateResponse struct {
	JobID   string           `` /* 133-byte string literal not displayed */
	Results []HostnameResult `json:"results"`
}

HostnameUpdateResponse is each target host's result.

func HandleUpdate

func HandleUpdate(
	ctx context.Context,
	d dispatch.Deps,
	in UpdateRequest,
) (HostnameUpdateResponse, error)

HandleUpdate runs hostname update on the target, for the endpoint server.

type UpdateRequest

type UpdateRequest struct {
	Hostname string                `` /* 182-byte string literal not displayed */
	Body     HostnameUpdateRequest `in:"body" validate:"required"`
}

UpdateRequest is the request of hostname update: its target and its input.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL