Documentation
¶
Overview ¶
Package protocol is the request format shared by the nsl CLI and the VM agent. See docs/specs/agent.md. Both ends are built from this repository, so the version detects mismatched builds and is never negotiated.
Index ¶
- Constants
- Variables
- func DecodeStrict(data []byte, dst any) error
- func Encode(r Request) (string, error)
- func ExitStatus(code, status int32) int
- func SafeHostPath(p string) bool
- func ValidAccount(s string) bool
- func ValidBuildID(s string) bool
- func ValidDigest(s string) bool
- func ValidID(s string) bool
- func ValidName(s string) bool
- func ValidUID(n int) bool
- func ValidZone(s string) bool
- type Account
- type Alias
- type Binding
- type CreateResult
- type Credential
- type Error
- type Identity
- type Image
- type Listener
- type MachineRecord
- type MachineRef
- type MachineStatus
- type Request
- type Rootfs
- type Share
- type StartResult
Constants ¶
const ( Version = 1 MachineVersion = 1 Limit = 64 << 10 AgentPath = "/usr/lib/nsl/nsl-agent" ImageShare = "/var/cache/nsl/images" // ArchiveLimit bounds an exported root filesystem, compressed or not: the // largest data disk. ArchiveLimit int64 = 4096 << 30 )
Version is the agent protocol; MachineVersion is the machine-layer protocol that the agent requires of machine images.
const ( CodeBadRequest = "bad-request" CodeProtocol = "protocol" CodeUnknownMachine = "unknown-machine" CodeMachineID = "machine-id" CodeNotRunning = "not-running" CodeBusy = "busy" CodeRefused = "refused" CodeFailed = "failed" )
Error codes from docs/specs/agent.md.
const ErrorExit = 255
ErrorExit is the agent's exit status for its own errors.
Variables ¶
var Passive = map[string]bool{"identity": true, "machines": true, "listeners": true, "display": true}
Passive operations observe or serve the VM; they are not activity for the idle monitor.
Functions ¶
func DecodeStrict ¶
DecodeStrict decodes one JSON value, rejecting duplicate keys, unknown fields and trailing data.
func ExitStatus ¶
ExitStatus maps systemd's ExecMainCode and ExecMainStatus to a shell-style status: the exit code, or 128+N for signal N.
func SafeHostPath ¶
SafeHostPath reports whether p is a clean absolute path other than / that vmspawn and mount options can carry.
func ValidAccount ¶
ValidAccount reports whether s is a POSIX account name nsl accepts.
func ValidBuildID ¶
ValidBuildID reports whether s is an image build ID.
func ValidDigest ¶
ValidDigest reports whether s is sha256: followed by 64 lowercase hex digits.
func ValidName ¶
ValidName reports whether s is a machine name: a lowercase letter, then lowercase letters, digits or interior hyphens, at most 24 characters.
Types ¶
type Binding ¶
type Binding struct {
Version int `json:"version"`
ID string `json:"id"`
Role string `json:"role"`
UID int `json:"uid"`
GID int `json:"gid"`
Machine *MachineRef `json:"machine,omitempty"`
}
Binding is the VM identity recorded on first boot and checked on every boot.
type CreateResult ¶
type CreateResult struct {
BuildID string `json:"build_id"`
}
CreateResult is the answer to create and import.
type Credential ¶
type Credential struct {
Binding
PublicKey string `json:"public_key"`
Autostart bool `json:"autostart"`
IdleTimeout int `json:"idle_timeout"`
Aliases []Alias `json:"aliases"`
}
Credential is the nsl.vm boot credential. The binding fields must match the VM's recorded binding on every boot after the first.
func (*Credential) Validate ¶
func (c *Credential) Validate() error
Validate checks a credential completely.
type Error ¶
func ParseError ¶
ParseError recovers an agent error from its stderr line, for operations whose stderr belongs to the agent rather than to a user command.
type Identity ¶
type Identity struct {
Protocol int `json:"protocol"`
VM Binding `json:"vm"`
Image json.RawMessage `json:"image"`
}
Identity is the agent's answer to the identity operation.
type Image ¶
type Image struct {
Path string `json:"path"`
Digest string `json:"digest"`
Size int64 `json:"size"`
BuildID string `json:"build_id"`
}
Image names a verified machine image in the VM's read-only image share. BuildID is empty for a local image; the agent reports the descriptor's.
type Listener ¶
type Listener struct {
Port int `json:"port"`
Address string `json:"address"`
Machine string `json:"machine"`
}
Listener is one TCP socket listening for a machine, from the listeners operation.
type MachineRecord ¶
type MachineRecord struct {
Schema int `json:"schema"`
Name string `json:"name"`
ID string `json:"id"`
Account Account `json:"account"`
BuildID string `json:"build_id"`
Created string `json:"created"`
}
MachineRecord is the VM's record of one machine, on the state subvolume.
type MachineRef ¶
type MachineStatus ¶
type MachineStatus struct {
Machine string `json:"machine"`
ID string `json:"id"`
State string `json:"state"`
Sessions int `json:"sessions"`
BuildID string `json:"build_id"`
}
MachineStatus is one entry of the machines operation.
type Request ¶
type Request struct {
Protocol int `json:"protocol"`
Op string `json:"op"`
Machine string `json:"machine,omitempty"`
ID string `json:"id,omitempty"`
Argv []string `json:"argv,omitempty"`
Directory string `json:"directory,omitempty"`
Root bool `json:"root,omitempty"`
TTY bool `json:"tty,omitempty"`
Env map[string]string `json:"env,omitempty"`
IdleTimeout *int `json:"idle_timeout,omitempty"`
Account *Account `json:"account,omitempty"`
Image *Image `json:"image,omitempty"`
Rootfs *Rootfs `json:"rootfs,omitempty"`
TimeZone string `json:"time_zone,omitempty"`
PublicKey string `json:"public_key,omitempty"`
}
type Rootfs ¶
type Rootfs struct {
Digest string `json:"digest"`
Size int64 `json:"size"`
BuildID string `json:"build_id"`
}
Rootfs is the compressed root filesystem an import reads from stdin, as the archive's manifest records it.
type Share ¶
type Share struct {
}
Share is a host tree mounted read-write at /mnt/host plus its canonical path.
type StartResult ¶
StartResult is the answer to start.