truenas

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Virt       truenas.VirtServiceAPI
	Snapshot   truenas.SnapshotServiceAPI
	Interface  truenas.InterfaceServiceAPI
	Network    truenas.NetworkServiceAPI
	Filesystem truenas.FilesystemServiceAPI
	Cron       truenas.CronServiceAPI
	// contains filtered or unexported fields
}

Client wraps a truenas-go WebSocket client and its typed services.

func Connect

func Connect(ctx context.Context, cfg *config.Config) (*Client, error)

Connect creates and connects a TrueNAS WebSocket client.

func (*Client) Close

func (c *Client) Close() error

func (*Client) ContainerDataset

func (c *Client) ContainerDataset(ctx context.Context, name string) (string, error)

ContainerDataset returns the ZFS dataset path for a container by name.

func (*Client) CreateInstance

func (c *Client) CreateInstance(ctx context.Context, opts CreateInstanceOpts) (*truenas.VirtInstance, error)

CreateInstance creates an Incus container via the Virt service.

func (*Client) DefaultNIC

func (c *Client) DefaultNIC(ctx context.Context) (*NICOpts, error)

DefaultNIC discovers the host's gateway interface and returns NIC options suitable for container creation. It queries TrueNAS for the default IPv4 gateway, then finds the physical interface whose subnet contains that gateway. Falls back to the first physical interface that is UP with an IPv4 address.

func (*Client) ListInstances

func (c *Client) ListInstances(ctx context.Context) ([]truenas.VirtInstance, error)

ListInstances queries all Incus instances with the px- prefix.

func (*Client) ListSnapshots

func (c *Client) ListSnapshots(ctx context.Context, dataset string) ([]truenas.Snapshot, error)

ListSnapshots queries snapshots for the given ZFS dataset.

func (*Client) Provision

func (c *Client) Provision(ctx context.Context, name string, opts ProvisionOpts) error

Provision writes SSH keys, rc.local for openssh-server install, dev tools setup, and optional DNS/env config into a running container's rootfs via file_receive.

func (*Client) ReplaceContainerRootfs

func (c *Client) ReplaceContainerRootfs(ctx context.Context, containerName, snapshotID string) error

ReplaceContainerRootfs destroys the container's ZFS dataset and clones the checkpoint snapshot in its place. The container must be stopped.

The pool.dataset.* APIs can't see .ix-virt managed datasets, so we use a temporary cron job to run raw ZFS commands on the host as root.

func (*Client) SnapshotRollback

func (c *Client) SnapshotRollback(ctx context.Context, snapshotID string) error

SnapshotRollback rolls back to the given snapshot ID (dataset@name).

func (*Client) WriteAuthorizedKey

func (c *Client) WriteAuthorizedKey(ctx context.Context, name, sshPubKey string) error

WriteAuthorizedKey writes an SSH public key to a running container's authorized_keys files (root and pixel user) via the TrueNAS file_receive API.

func (*Client) WriteContainerFile

func (c *Client) WriteContainerFile(ctx context.Context, name, path string, content []byte, mode fs.FileMode) error

WriteContainerFile writes a file into a running container's rootfs via the TrueNAS filesystem API (no SSH required).

type CreateInstanceOpts

type CreateInstanceOpts struct {
	Name      string
	Image     string
	CPU       string
	Memory    int64 // bytes
	Autostart bool
	NIC       *NICOpts
}

CreateInstanceOpts contains options for creating a container.

type NICOpts

type NICOpts struct {
	NICType string // "MACVLAN" or "BRIDGED"
	Parent  string // host interface (e.g. "eno1")
}

NICOpts describes a NIC device to attach during container creation.

type ProvisionOpts

type ProvisionOpts struct {
	SSHPubKey       string
	DNS             []string          // nameservers (e.g. ["1.1.1.1", "8.8.8.8"])
	Env             map[string]string // environment variables to inject into /etc/environment
	DevTools        bool              // whether to install dev tools (mise, claude-code, codex, opencode)
	Egress          string            // "unrestricted", "agent", or "allowlist"
	EgressAllow     []string          // custom domains (merged into agent, standalone for allowlist)
	ProvisionScript string            // zmx provision script content (written to /usr/local/bin/pixels-provision.sh)
	Log             io.Writer         // optional; verbose progress output
}

ProvisionOpts contains options for provisioning a container.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL