Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Group = endpoint.Define( "timezone", "The timezone of the host", endpoint.Area(area.Config), endpoint.Prefix("node/{hostname}"), endpoint.Uses[dispatch.Deps](), endpoint.Tag("timezone_operations", "Timezone", "The timezone of the host"), endpoint.CommandNotes("The [timezone behavior](../../../../../reference/behaviors/config/timezone/timezone.md) page tells where the behavior runs, what it is built on and its settings."), endpoint.Doc[types.RowStatus](dispatch.RowStatusDoc), endpoint.Get[GetRequest, TimezoneGetResponse]("get"). Handle(HandleGet). ID("GetNodeTimezone"). Describe("Get the timezone of the host"). Permission("timezone:read"). Returns("Each target host's result."). Explain("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."). Example("--target web-01", "A Linux host on UTC"). Example("--target web-01", "A Mac on UTC"). Result("A Linux host on UTC, on one host:\n\n```ansi\n$ osapi client node timezone 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;176mTIMEZONE \x1b[0m\x1b[38;2;10;143;176mUTC OFFSET\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m UTC +00:00\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 timezone 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;176mTIMEZONE \x1b[0m\x1b[38;2;10;143;176mUTC OFFSET\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m UTC +00:00\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m UTC +00:00\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 \"status\": \"ok\",\n \"timezone\": \"UTC\",\n \"utc_offset\": \"+00:00\"\n }\n ]\n}\n```\n\nA Mac on UTC, on one host:\n\n```ansi\n$ osapi client node timezone 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;176mTIMEZONE \x1b[0m\x1b[38;2;10;143;176mUTC OFFSET\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m UTC +00:00\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 timezone 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;176mTIMEZONE \x1b[0m\x1b[38;2;10;143;176mUTC OFFSET\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m UTC +00:00\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m UTC +00:00\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 \"status\": \"ok\",\n \"timezone\": \"UTC\",\n \"utc_offset\": \"+00:00\"\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, TimezoneUpdateResponse]("update"). Handle(HandleUpdate). ID("PutNodeTimezone"). Describe("Set the timezone of the host"). Permission("timezone:write"). Returns("Each target host's result, with whether it changed."). Explain("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."). Example("--target web-01 --timezone America/New_York", "Set a new timezone"). Example("--target web-01 --timezone UTC", "A host that already has the timezone"). Result("Set a new timezone, on one host:\n\n```ansi\n$ osapi client node timezone update --target web-01 --timezone America/New_York\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;176mTIMEZONE\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m America/New_York\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 timezone update --target _all --timezone America/New_York\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;176mTIMEZONE\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m America/New_York\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m America/New_York\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 \"status\": \"ok\",\n \"timezone\": \"America/New_York\"\n }\n ]\n}\n```\n\nA host that already has the timezone, on one host:\n\n```ansi\n$ osapi client node timezone update --target web-01 --timezone UTC\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;176mTIMEZONE\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m UTC\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 timezone update --target _all --timezone UTC\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;176mTIMEZONE\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m UTC\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m UTC\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 \"status\": \"ok\",\n \"timezone\": \"UTC\"\n }\n ]\n}\n```\n\nWith the default settings, each example does this on the host:\n\n| Example | On the host |\n| --- | --- |\n| Set a new timezone | runs `timedatectl set-timezone America/New_York` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| A name that is not a timezone | `--timezone ../../etc/passwd` | not a valid timezone name |\n| A name that starts with a dash | `--timezone -UTC` | not a valid timezone name |\n| A name longer than 64 characters | `--timezone aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | timezone |"). 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 timezone as an endpoint group, which its spec comes from.
Functions ¶
Types ¶
type GetRequest ¶
type GetRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
}
GetRequest is the request of timezone get: its target and its input.
type TimezoneEntry ¶
type TimezoneEntry 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"`
Timezone *string `doc:"The IANA name of the timezone, such as America/New_York" json:"timezone,omitempty"`
UTCOffset *string `doc:"The offset from UTC now, such as -05:00" json:"utc_offset,omitempty"`
Error *string `doc:"Error message if the agent failed." json:"error,omitempty"`
}
TimezoneEntry is the result of timezone on one host.
type TimezoneGetResponse ¶
type TimezoneGetResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []TimezoneEntry `json:"results"`
}
TimezoneGetResponse is each target host's result.
func HandleGet ¶
func HandleGet( ctx context.Context, d dispatch.Deps, in GetRequest, ) (TimezoneGetResponse, error)
HandleGet runs timezone get on the target, for the endpoint server.
type TimezoneResult ¶
type TimezoneResult 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"`
Timezone *string `doc:"The timezone of the host" json:"timezone,omitempty"`
Changed *bool `doc:"Whether the host changed" json:"changed,omitempty"`
Error *string `doc:"Error message if the agent failed." json:"error,omitempty"`
}
TimezoneResult is the result of timezone on one host.
type TimezoneUpdateRequest ¶
type TimezoneUpdateRequest struct {
Timezone string `doc:"The IANA name of the timezone, such as UTC or America/New_York" json:"timezone" validate:"required,max=64,timezone_name"`
}
TimezoneUpdateRequest is the body of timezone update.
type TimezoneUpdateResponse ¶
type TimezoneUpdateResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []TimezoneResult `json:"results"`
}
TimezoneUpdateResponse is each target host's result.
func HandleUpdate ¶
func HandleUpdate( ctx context.Context, d dispatch.Deps, in UpdateRequest, ) (TimezoneUpdateResponse, error)
HandleUpdate runs timezone update on the target, for the endpoint server.
type UpdateRequest ¶
type UpdateRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
Body TimezoneUpdateRequest `in:"body" validate:"required"`
}
UpdateRequest is the request of timezone update: its target and its input.