Package
c.Package calls the API's Package group. The packages installed on the host.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx, hostname) | *Response[Collection[PackageInstalled]] | package:read | List the packages installed on the host. |
Create(ctx, hostname, input) | *Response[Collection[PackageResult]] | package:write | Install a package. |
Get(ctx, hostname, name) | *Response[Collection[PackageInstalled]] | package:read | Get one installed package. |
Delete(ctx, hostname, name) | *Response[Collection[PackageResult]] | package:write | Remove a package. |
List
func (s *PackageService) List(
ctx context.Context,
hostname string,
) (*Response[Collection[PackageInstalled]], error)
List the packages installed on the host.
Lists each installed package with its version: dpkg on the Debian family, rpm on the other Linux families, and Homebrew on macOS.
It sends GET /api/node/{hostname}/package, and needs the permission
package:read.
The examples of the method's definition:
A Debian host, go run package.go list:
resp, err := c.Package.List(ctx, target)
Create
func (s *PackageService) Create(
ctx context.Context,
hostname string,
input PackageCreateInput,
) (*Response[Collection[PackageResult]], error)
Install a package.
Installs the package with apt-get install, at the version when one is given. A package that is installed, at that version when one is given, does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.
It sends POST /api/node/{hostname}/package, and needs the permission
package:write.
The examples of the method's definition:
Install a package, go run package.go create:
resp, err := c.Package.Create(ctx, target, client.PackageCreateInput{Name: "tree"})
Get
func (s *PackageService) Get(
ctx context.Context,
hostname string,
name string,
) (*Response[Collection[PackageInstalled]], error)
Get one installed package.
Reads one package from the same list. A package that is not installed is not found.
It sends GET /api/node/{hostname}/package/{name}, and needs the permission
package:read.
The examples of the method's definition:
An installed package, go run package.go get:
resp, err := c.Package.Get(ctx, target, "curl")
An installed formula, go run package.go get-2:
resp, err := c.Package.Get(ctx, target, "jq")
Delete
func (s *PackageService) Delete(
ctx context.Context,
hostname string,
name string,
) (*Response[Collection[PackageResult]], error)
Remove a package.
Removes the package with apt-get remove. A package that is not installed does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.
It sends DELETE /api/node/{hostname}/package/{name}, and needs the permission
package:write.
The examples of the method's definition:
Remove a package, go run package.go delete:
resp, err := c.Package.Delete(ctx, target, "tree")
Types
The fields of each type are the properties of its schema in the API's spec.
PackageCreateInput
| Field | Type | Description |
|---|---|---|
Name | string | The package to install, such as curl. |
Version | string | The version to install, such as 8.5.0-2ubuntu10; the newest when empty. |
PackageInstalled
| Field | Type | Description |
|---|---|---|
Architecture | string | The architecture it is built for, such as amd64. |
Description | string | Its one-line summary. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Manager | string | The package database that has it: dpkg, rpm or brew. |
Name | string | The package. |
Size | int64 | Its installed 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. |
Version | string | The installed version. |
PackageResult
| 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. |
Name | string | The package. |
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/package.go
runs each example of this page. With no argument, it lists them.