Get or set the hostname of target hosts. osapi behavior get --name hostname
and osapi behavior method get show the same.
Behavior
| |
|---|
| Name | hostname |
| Description | Get or set the hostname of target hosts |
| Placement | node |
| Internal | no |
| API | yes |
| CLI | yes |
| Next | no |
| Platforms | linux, darwin |
| Sudo | none |
| Runs | hostname |
| Writes | none |
| Keeps state | no |
| Uses | none |
| Used by | status |
Methods (2)
| NAME | VERB | HTTP | ROUTE | PERMISSION | DESCRIPTION |
|---|
| get | read | GET | /api/node/{hostname}/hostname | hostname:read | Get the hostname of the host |
| update | write | PUT | /api/node/{hostname}/hostname | hostname:write | Set the hostname of the host |
Types (2)
| NAME | INPUT | OUTPUT |
|---|
| get | GetInput | Entry { name } |
| update | UpdateInput { name* } | Result { name, changed } |
Settings (0)
None. Declare them with behavior.Config.
Telemetry
| |
|---|
| Span | behavior.hostname.<method> |
| Child spans | exec hostnamectl, exec hostname |
| Metrics | osapi_behavior_calls_total, osapi_behavior_duration_seconds, osapi_behavior_changes_total |
| Attributes | osapi.behavior.name, osapi.behavior.method, osapi.behavior.verb, osapi.behavior.outcome, osapi.behavior.changed |
| Recorded inputs | name (update) |
Method get
| |
|---|
| Name | get |
| Verb | read |
| Description | Get the hostname of the host |
| Detail | Reads the host's name as the hostname command prints it, on Linux and on macOS. It makes no DNS lookup. |
| HTTP | GET |
| Route | /api/node/{hostname}/hostname |
| Permission | hostname:read |
| Command | osapi client node hostname get |
| Input type | GetInput |
| Output type | Entry |
None. The method takes no input; its command needs only --target.
Output (1)
| FIELD | TYPE | DESCRIPTION |
|---|
| name | string | The hostname of the host |
Examples (1)
| EXAMPLE | INPUT | OUTPUT |
|---|
| A host named web-01 | (none) | name=web-01 |
Method update
| |
|---|
| Name | update |
| Verb | write |
| Description | Set the hostname of the host |
| Detail | 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. |
| HTTP | PUT |
| Route | /api/node/{hostname}/hostname |
| Permission | hostname:write |
| Command | osapi client node hostname update |
| Input type | UpdateInput |
| Output type | Result |
| FIELD | TYPE | REQUIRED | CONSTRAINTS | DESCRIPTION |
|---|
| name | string | yes | format hostname, max length 253 | The hostname to set, such as web-01 |
Output (2)
| FIELD | TYPE | DESCRIPTION |
|---|
| name | string | The hostname of the host |
| changed | boolean | Whether the host changed |
Examples (2)
| EXAMPLE | INPUT | OUTPUT |
|---|
| Rename a host | name=web-02 | name=web-02, changed=true |
| A host that already has the name | name=web-01 | name=web-01, changed=false |