incus

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManagementWarningUnmanaged = "unmanaged"
	ManagementWarningRecreate  = "recreate required"
)
View Source
const DefaultCommandTimeout = 30 * time.Minute

Variables

This section is empty.

Functions

func Diff

func Diff(current, desired string) (string, error)

Diff generates a human-readable diff between current and desired YAML configurations. Returns an empty string if configurations are identical. Only shows the top-level keys that have changes. Excludes immutable fields and incus-managed config keys (volatile.*).

func DiffResource

func DiffResource(currentYAML string, desired *config.Resource) ([]DiffChange, ManagementStatus, error)

DiffResource computes the preview diff for a resource. Managed resources are diffed against the previously stored incus-apply snapshot. Unmanaged resources fall back to live-state diffing.

func DiffWithIndent

func DiffWithIndent(current, desired, indent string) (string, error)

DiffWithIndent computes a diff with a custom indentation prefix. The indent is prepended to each line of the output.

func FormatDiffChanges

func FormatDiffChanges(changes []DiffChange, indent string) string

FormatDiffChanges renders a []DiffChange to a human-readable string with the given indent.

func FormatDiffChangesWithWidth

func FormatDiffChangesWithWidth(changes []DiffChange, indent string, maxWidth int) string

FormatDiffChangesWithWidth renders a []DiffChange to a human-readable string with the given indent and max inline width.

func FormatDiffChangesWithWidthAndTrailing added in v0.0.6

func FormatDiffChangesWithWidthAndTrailing(changes []DiffChange, indent string, maxWidth int, hasTrailingLine bool) string

FormatDiffChangesWithWidthAndTrailing renders a []DiffChange to a human-readable string with the given indent and max inline width. When hasTrailingLine is true, the final diff entry uses a branch connector because another sibling line will follow.

func HasChanges

func HasChanges(current, desired string) (bool, error)

HasChanges checks if there are any differences between current and desired config.

Types

type Client

type Client interface {
	// Ping verifies connectivity to the Incus daemon.
	Ping() error

	// Create creates a new resource in Incus.
	Create(res *config.Resource) *Result
	// Update updates an existing resource in Incus.
	Update(res *config.Resource) *Result
	// Delete removes a resource from Incus.
	Delete(res *config.Resource) *Result

	// Exists checks whether the resource already exists in Incus.
	Exists(res *config.Resource) (bool, error)
	// CurrentConfig retrieves the current YAML configuration of a resource.
	CurrentConfig(res *config.Resource) (string, error)
	// MergedConfig returns the merged config that would be applied during an update.
	MergedConfig(res *config.Resource) (string, error)

	// Start starts an instance.
	Start(res *config.Resource) *Result
	// Stop stops a running instance.
	Stop(res *config.Resource) *Result
	// Running checks if an instance is currently running.
	Running(res *config.Resource) bool
	// WaitInstanceAgent waits for a VM instance agent to become available.
	WaitInstanceAgent(res *config.Resource) *Result

	// WaitCloudInit waits for cloud-init to finish inside the instance.
	WaitCloudInit(res *config.Resource) *Result
}

Client is the interface for performing operations on Incus.

func New

func New(globalFlags []string, remote string, stop, verbose bool, timeout time.Duration) Client

New creates a new Incus client. remote is the target Incus remote (empty = default).

type DiffChange

type DiffChange struct {
	Path   string `json:"path"`
	Old    any    `json:"old,omitempty"`
	New    any    `json:"new,omitempty"`
	Action string `json:"action"` // "add", "remove", "modify"
}

DiffChange is an exported representation of a single field change.

func DiffChanges

func DiffChanges(current, desired string) ([]DiffChange, error)

DiffChanges returns structured diff changes between current and desired YAML. Returns nil if configurations are identical.

type ManagementStatus

type ManagementStatus struct {
	Managed            bool
	Snapshot           string
	Warning            string
	UnsupportedChanges []DiffChange
}

ManagementStatus reports whether a live resource is managed by incus-apply.

type Result

type Result struct {
	Command  string
	Stdout   string
	Stderr   string
	ExitCode int
	Error    error
}

Result represents the result of an incus command execution.

Jump to

Keyboard shortcuts

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