Image
c.Image calls the API's Image group. The Docker images of the host.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx, hostname) | *Response[Collection[ImageEntry]] | image:read | List the images of the host. |
Pull(ctx, hostname, input) | *Response[Collection[ImagePullResult]] | image:execute | Pull an image. |
Delete(ctx, hostname, input) | *Response[Collection[ImageResult]] | image:write | Remove an image. |
List
func (s *ImageService) List(
ctx context.Context,
hostname string,
) (*Response[Collection[ImageEntry]], error)
List the images of the host.
Reads each image through gohai's docker collector, which runs docker images. A host whose docker does not answer reports skipped.
It sends GET /api/node/{hostname}/image, and needs the permission
image:read.
The examples of the method's definition:
A host with an image, go run image.go list:
resp, err := c.Image.List(ctx, target)
Pull
func (s *ImageService) Pull(
ctx context.Context,
hostname string,
input ImagePullInput,
) (*Response[Collection[ImagePullResult]], error)
Pull an image.
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.
It sends POST /api/node/{hostname}/image/pull, and needs the permission
image:execute.
The examples of the method's definition:
Pull an image, go run image.go pull:
resp, err := c.Image.Pull(ctx, target, client.ImagePullInput{Image: "alpine:3.20"})
Delete
func (s *ImageService) Delete(
ctx context.Context,
hostname string,
input ImageDeleteInput,
) (*Response[Collection[ImageResult]], error)
Remove an image.
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.
It sends DELETE /api/node/{hostname}/image/{image}, and needs the permission
image:write.
The examples of the method's definition:
Remove an image, go run image.go delete:
resp, err := c.Image.Delete(ctx, target, client.ImageDeleteInput{Image: "alpine:3.20"})
Types
The fields of each type are the properties of its schema in the API's spec.
ImageDeleteInput
| Field | Type | Description |
|---|---|---|
Image | string | The image of the path. The image, by its reference or its ID. |
Force | bool | Remove it also when a container uses it. |
ImageEntry
| Field | Type | Description |
|---|---|---|
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
ID | string | The image's ID. |
Repository | string | Its repository, such as alpine. |
Size | string | Its size, as docker prints it, such as 7.8MB. |
Status | 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. |
Tag | string | Its tag, such as 3.20. |
ImagePullInput
| Field | Type | Description |
|---|---|---|
Image | string | The image, such as alpine:3.20. |
ImagePullResult
| Field | Type | Description |
|---|---|---|
Changed | bool | Whether the pull got a new image: false when the host had it already. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Image | string | The image. |
ImageID | string | The ID of the image that the host has now. |
Size | int64 | Its size in bytes. |
Status | 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. |
ImageResult
| Field | Type | Description |
|---|---|---|
Changed | bool | Whether the host changed. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Image | string | The image. |
Status | 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. |
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/image.go
runs each example of this page. With no argument, it lists them.