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(
	"image",
	"The Docker images of the host",
	endpoint.Area(area.Containers),
	endpoint.Prefix("node/{hostname}"),
	endpoint.Uses[dispatch.Deps](),
	endpoint.Tag("image_operations", "Container image", "The Docker images of the host"),
	endpoint.CommandNotes("The [image behavior](../../../../../reference/behaviors/containers/image/image.md) page tells where the behavior runs, what it is built on and its settings."),
	endpoint.Doc[types.RowStatus](dispatch.RowStatusDoc),
	endpoint.Get[ListRequest, ImageCollectionResponse]("list").
		Handle(HandleList).
		ID("GetNodeImage").
		Describe("List the images of the host").
		Permission("image:read").
		Returns("Each target host's result.").
		Explain("Reads each image through gohai's docker collector, which runs docker images. A host whose docker does not answer reports skipped.").
		Example("--target web-01", "A host with an image").
		Result("A host with an image, on one host:\n\n```ansi\n$ osapi client node image list --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;176mID            \x1b[0m\x1b[38;2;10;143;176mREPOSITORY  \x1b[0m\x1b[38;2;10;143;176mTAG   \x1b[0m\x1b[38;2;10;143;176mSIZE\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      \x1b[38;2;138;138;138m91ef0af61f39\x1b[0m  alpine      3.20  7.8MB\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 image list --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;176mID            \x1b[0m\x1b[38;2;10;143;176mREPOSITORY  \x1b[0m\x1b[38;2;10;143;176mTAG   \x1b[0m\x1b[38;2;10;143;176mSIZE\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      \x1b[38;2;138;138;138m91ef0af61f39\x1b[0m  alpine      3.20  7.8MB\n  \x1b[1mweb-02\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      \x1b[38;2;138;138;138m91ef0af61f39\x1b[0m  alpine      3.20  7.8MB\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      \"id\": \"91ef0af61f39\",\n      \"repository\": \"alpine\",\n      \"size\": \"7.8MB\",\n      \"status\": \"ok\",\n      \"tag\": \"3.20\"\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.Post[PullRequest, ImagePullResponse]("pull").
		Handle(HandlePull).
		ID("PostNodeImagePull").
		Describe("Pull an image").
		Permission("image:execute").
		Returns("Each target host's result, with whether it changed.").
		Action("pull").
		Explain("Runs docker pull, and answers the ID and the size of the image that the host has after it. A pull that gets nothing new, because the host had the image of that reference already, reports changed: false.").
		Example("--target web-01 --image alpine:3.20", "Pull an image").
		Result("Pull an image, on one host:\n\n```ansi\n$ osapi client node image pull --target web-01 --image alpine:3.20\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;176mIMAGE        \x1b[0m\x1b[38;2;10;143;176mIMAGE ID                                                                 \x1b[0m\x1b[38;2;10;143;176mSIZE\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mchanged\x1b[0m  alpine:3.20  \x1b[38;2;138;138;138msha256:91ef0af61f39ece4d6710e465df5ed6ca12112358344fd51ae6a3b886634148b\x1b[0m  3634816\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 image pull --target _all --image alpine:3.20\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;176mIMAGE        \x1b[0m\x1b[38;2;10;143;176mIMAGE ID                                                                 \x1b[0m\x1b[38;2;10;143;176mSIZE\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mchanged\x1b[0m  alpine:3.20  \x1b[38;2;138;138;138msha256:91ef0af61f39ece4d6710e465df5ed6ca12112358344fd51ae6a3b886634148b\x1b[0m  3634816\n  \x1b[1mweb-02\x1b[0m    \x1b[38;2;103;234;147mchanged\x1b[0m  alpine:3.20  \x1b[38;2;138;138;138msha256:91ef0af61f39ece4d6710e465df5ed6ca12112358344fd51ae6a3b886634148b\x1b[0m  3634816\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      \"image\": \"alpine:3.20\",\n      \"image_id\": \"sha256:91ef0af61f39ece4d6710e465df5ed6ca12112358344fd51ae6a3b886634148b\",\n      \"size\": 3634816,\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| Pull an image | runs `docker pull alpine:3.20` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| An image that is an option | `--image --all-tags` | image_ref |\n| No image |  | required |").
		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.Delete[DeleteRequest, ImageDeleteResponse]("delete").
		Handle(HandleDelete).
		ID("DeleteNodeImage").
		Describe("Remove an image").
		Permission("image:write").
		Returns("Each target host's result, with whether it changed.").
		Explain("Runs docker rmi, with -f when force is set, which removes an image that a container uses. An image that the host does not have reports changed: false.").
		Example("--target web-01 --image alpine:3.20", "Remove an image").
		Example("--target web-01 --image alpine:3.20", "An image that the host does not have").
		Result("Remove an image, on one host:\n\n```ansi\n$ osapi client node image delete --target web-01 --image alpine:3.20\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;176mIMAGE\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mchanged\x1b[0m  alpine:3.20\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 image delete --target _all --image alpine:3.20\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;176mIMAGE\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mchanged\x1b[0m  alpine:3.20\n  \x1b[1mweb-02\x1b[0m    \x1b[38;2;103;234;147mchanged\x1b[0m  alpine:3.20\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      \"image\": \"alpine:3.20\",\n      \"status\": \"ok\"\n    }\n  ]\n}\n```\n\nAn image that the host does not have, on one host:\n\n```ansi\n$ osapi client node image delete --target web-01 --image alpine:3.20\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;176mIMAGE\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      alpine:3.20\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 image delete --target _all --image alpine:3.20\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;176mIMAGE\x1b[0m\n  \x1b[1mweb-01\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      alpine:3.20\n  \x1b[1mweb-02\x1b[0m    \x1b[38;2;103;234;147mok\x1b[0m      alpine:3.20\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      \"image\": \"alpine:3.20\",\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| Remove an image | runs `docker rmi alpine:3.20` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| An image that is an option | `--image -f` | image_ref |").
		Errors(endpoint.NotFound(behavior.ErrNotFound, "The host has no image with that image."), 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 image as an endpoint group, which its spec comes from.

Functions

func Routes

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

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

Types

type DeleteRequest

type DeleteRequest struct {
	Hostname string             `` /* 182-byte string literal not displayed */
	Image    string             `doc:"The image, by its reference or its ID" in:"path" json:"image" param:"ImageImage" validate:"required,image_ref"`
	Body     ImageDeleteRequest `in:"body" validate:"required"`
}

DeleteRequest is the request of image delete: its target and its input.

type ImageCollectionResponse

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

ImageCollectionResponse is each target host's result.

func HandleList

HandleList runs image list on the target, for the endpoint server.

type ImageDeleteRequest

type ImageDeleteRequest struct {
	Force bool `doc:"Remove it also when a container uses it" json:"force,omitempty" validate:"omitempty"`
}

ImageDeleteRequest is the body of image delete.

type ImageDeleteResponse

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

ImageDeleteResponse is each target host's result.

func HandleDelete

func HandleDelete(
	ctx context.Context,
	d dispatch.Deps,
	in DeleteRequest,
) (ImageDeleteResponse, error)

HandleDelete runs image delete on the target, for the endpoint server.

type ImageEntry

type ImageEntry 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"`
	ID         *string         `doc:"The image's ID" json:"id,omitempty"`
	Repository *string         `doc:"Its repository, such as alpine" json:"repository,omitempty"`
	Tag        *string         `doc:"Its tag, such as 3.20" json:"tag,omitempty"`
	Size       *string         `doc:"Its size, as docker prints it, such as 7.8MB" json:"size,omitempty"`
	Error      *string         `doc:"Error message if the agent failed." json:"error,omitempty"`
}

ImageEntry is the result of image on one host.

type ImagePullRequest

type ImagePullRequest struct {
	Image string `doc:"The image, such as alpine:3.20" json:"image" validate:"required,image_ref"`
}

ImagePullRequest is the body of image pull.

type ImagePullResponse

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

ImagePullResponse is each target host's result.

func HandlePull

func HandlePull(
	ctx context.Context,
	d dispatch.Deps,
	in PullRequest,
) (ImagePullResponse, error)

HandlePull runs image pull on the target, for the endpoint server.

type ImagePullResult

type ImagePullResult 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"`
	Image    *string         `doc:"The image" json:"image,omitempty"`
	ImageID  *string         `doc:"The ID of the image that the host has now" json:"image_id,omitempty"`
	Size     *int64          `doc:"Its size in bytes" json:"size,omitempty"`
	Changed  *bool           `doc:"Whether the pull got a new image: false when the host had it already" json:"changed,omitempty"`
	Error    *string         `doc:"Error message if the agent failed." json:"error,omitempty"`
}

ImagePullResult is the result of image on one host.

type ImageResult

type ImageResult 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"`
	Image    *string         `doc:"The image" json:"image,omitempty"`
	Changed  *bool           `doc:"Whether the host changed" json:"changed,omitempty"`
	Error    *string         `doc:"Error message if the agent failed." json:"error,omitempty"`
}

ImageResult is the result of image on one host.

type ListRequest

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

ListRequest is the request of image list: its target and its input.

type PullRequest

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

PullRequest is the request of image pull: its target and its input.

Jump to

Keyboard shortcuts

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