Skip to main content

Package

c.Package calls the API's Package group. The packages installed on the host.

Methods​

MethodReturnsPermissionDescription
List(ctx, hostname)*Response[Collection[PackageInstalled]]package:readList the packages installed on the host.
Create(ctx, hostname, input)*Response[Collection[PackageResult]]package:writeInstall a package.
Get(ctx, hostname, name)*Response[Collection[PackageInstalled]]package:readGet one installed package.
Delete(ctx, hostname, name)*Response[Collection[PackageResult]]package:writeRemove 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​

FieldTypeDescription
NamestringThe package to install, such as curl.
VersionstringThe version to install, such as 8.5.0-2ubuntu10; the newest when empty.

PackageInstalled​

FieldTypeDescription
ArchitecturestringThe architecture it is built for, such as amd64.
DescriptionstringIts one-line summary.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
ManagerstringThe package database that has it: dpkg, rpm or brew.
NamestringThe package.
Sizeint64Its installed size in bytes.
StatusRowStatusWhat 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.
VersionstringThe installed version.

PackageResult​

FieldTypeDescription
ChangedboolWhether the host changed.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
NamestringThe package.
StatusRowStatusWhat 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.