Documentation
¶
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) ContainerDataset(ctx context.Context, name string) (string, error)
- func (c *Client) CreateInstance(ctx context.Context, opts CreateInstanceOpts) (*truenas.VirtInstance, error)
- func (c *Client) DefaultNIC(ctx context.Context) (*NICOpts, error)
- func (c *Client) ListInstances(ctx context.Context) ([]truenas.VirtInstance, error)
- func (c *Client) ListSnapshots(ctx context.Context, dataset string) ([]truenas.Snapshot, error)
- func (c *Client) Provision(ctx context.Context, name string, opts ProvisionOpts) error
- func (c *Client) ReplaceContainerRootfs(ctx context.Context, containerName, snapshotID string) error
- func (c *Client) SnapshotRollback(ctx context.Context, snapshotID string) error
- func (c *Client) WriteAuthorizedKey(ctx context.Context, name, sshPubKey string) error
- func (c *Client) WriteContainerFile(ctx context.Context, name, path string, content []byte, mode fs.FileMode) error
- type CreateInstanceOpts
- type NICOpts
- type ProvisionOpts
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 (*Client) ContainerDataset ¶
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 ¶
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 ¶
ListInstances queries all Incus instances with the px- prefix.
func (*Client) ListSnapshots ¶
ListSnapshots queries snapshots for the given ZFS dataset.
func (*Client) Provision ¶
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 ¶
SnapshotRollback rolls back to the given snapshot ID (dataset@name).
func (*Client) WriteAuthorizedKey ¶
WriteAuthorizedKey writes an SSH public key to a running container's authorized_keys files (root and pixel user) via the TrueNAS file_receive API.
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.