Skip to main content

NodeFile

c.NodeFile calls the API's NodeFile group. Files of the object store, deployed to the host.

Methods​

MethodReturnsPermissionDescription
Get(ctx, hostname, path)*Response[Collection[FileStatus]]file:readShow whether a deployed file holds what osapi wrote.
Update(ctx, hostname, input)*Response[Collection[FileUpdateResult]]file:writeDeploy an object of the object store to a path.
Delete(ctx, hostname, input)*Response[Collection[FileDeleteResult]]file:writeRemove a file that osapi deployed.

Get​

func (s *NodeFileService) Get(
ctx context.Context,
hostname string,
path string,
) (*Response[Collection[FileStatus]], error)

Show whether a deployed file holds what osapi wrote.

Compares the file on the host with the record that osapi keeps of what it deployed: in-sync when they agree, drifted when something changed the file, missing when osapi deployed the file and it is gone, and unmanaged when osapi did not deploy the path or undeployed it. A path that is a directory is refused.

It sends GET /api/node/{hostname}/file, and needs the permission file:read.

The examples of the method's definition:

A deployed file, go run node_file.go get:

resp, err := c.NodeFile.Get(ctx, target, "/etc/osapi/file-example.conf")

Update​

func (s *NodeFileService) Update(
ctx context.Context,
hostname string,
input NodeFileUpdateInput,
) (*Response[Collection[FileUpdateResult]], error)

Deploy an object of the object store to a path.

Writes the object at the path with its mode and ownership, and keeps a record of it. A template object, or content_type template, is rendered first with .Facts, .Vars and .Hostname. The record keeps the SHA-256 of the object as it was read. A file that holds the content, mode and owner already, from the same object, does not change and reports changed: false. osapi client file stale list compares the object now with that SHA-256, so it shows the deployments whose object changed since.

It sends PUT /api/node/{hostname}/file, and needs the permission file:write.

The examples of the method's definition:

Deploy a file, go run node_file.go update:

resp, err := c.NodeFile.Update(ctx, target, client.NodeFileUpdateInput{
ObjectName: "example.conf",
Path: "/etc/osapi/file-example.conf",
})

Render a template, go run node_file.go update-2:

resp, err := c.NodeFile.Update(ctx, target, client.NodeFileUpdateInput{
ObjectName: "example.conf.tmpl",
Path: "/etc/osapi/file-example.conf",
Vars: map[string]string{"port": "8080"},
})

Delete​

func (s *NodeFileService) Delete(
ctx context.Context,
hostname string,
input NodeFileDeleteInput,
) (*Response[Collection[FileDeleteResult]], error)

Remove a file that osapi deployed.

Removes the file and keeps its record, marked undeployed, so status reports unmanaged. A path that osapi did not deploy, or deleted already, does not change and reports changed: false. The object stays in the object store.

It sends DELETE /api/node/{hostname}/file, and needs the permission file:write.

The examples of the method's definition:

Remove a deployed file, go run node_file.go delete:

resp, err := c.NodeFile.Delete(ctx, target, client.NodeFileDeleteInput{Path: "/etc/osapi/file-example.conf"})

Types​

The fields of each type are the properties of its schema in the API's spec.

ContentType​

ContentType is how a deploy treats a file: raw writes its bytes as they are; template renders it with Go text/template and the agent's facts.

A string, one of raw, template.

FileDeleteResult​

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

FileStatus​

FieldTypeDescription
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
PathstringAbsolute path of the file.
SHA256stringSHA-256 of the file on the host, when it is there.
Statestringin-sync, drifted, missing or unmanaged.
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.

FileUpdateResult​

FieldTypeDescription
ChangedboolWhether the host changed.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
PathstringAbsolute path of the file.
SHA256stringSHA-256 of the content that the file holds.
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.

NodeFileDeleteInput​

FieldTypeDescription
PathstringAbsolute path of the file on the host.

NodeFileUpdateInput​

FieldTypeDescription
ContentTypeContentTypeContentType is how a deploy treats a file: raw writes its bytes as they are; template renders it with Go text/template and the agent's facts.
GroupstringGroup that owns the file; left as written when empty.
ModestringPermissions in octal, such as 0644; when empty, a file keeps its mode and a new file gets 0644.
ObjectNamestringThe object of the object store, from osapi client file list.
OwnerstringUser that owns the file; left as written when empty.
PathstringAbsolute path of the file on the host.
Varsmap[string]stringVariables of a template, as .Vars, each as key=value.

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/node_file.go runs each example of this page. With no argument, it lists them.