tartvm

package
v0.0.0-...-ab84211 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

README

Package cloudeng.io/macos/tartvm

import cloudeng.io/macos/tartvm

Package tartvm implements cloudeng.io/vms.Instance using the tart CLI on macOS.

Constants

DefaultPollingInterval, DefaultOutputBufferSize, DefaultRunTimeout, DefaultForceStopTimeout
DefaultPollingInterval = 100 * time.Millisecond
DefaultOutputBufferSize = 16 * 1024 // 16KiB

DefaultRunTimeout = 2 * time.Minute
DefaultForceStopTimeout = 2 * time.Second

Functions

Func DefaultLinuxRunOptions
func DefaultLinuxRunOptions() []string
Func DefaultMacOSRunOptions
func DefaultMacOSRunOptions() []string
Func DefaultRunOptions
func DefaultRunOptions() []string

DefaultRunOptions are safe defaults that work with mac and linux tart VMs. Linux does not currently support suspend.

Types

Type CloneInfo
type CloneInfo struct {
	Source string
	Name   string
}
Methods
func (c CloneInfo) String() string
Type Instance
type Instance struct {
	// contains filtered or unexported fields
}

Instance implements vms.Instance backed by the tart CLI. source is the OCI reference used for cloning; name is the local VM name. All images must have the tart agent installed and be compatible with the tart CLI version installed locally.

Functions
func New(ctx context.Context, source, name string, opts ...Option) *Instance

New returns an Instance in StateInitial, source is the tart image or OCI reference to clone from; name is the local VM name.

Methods
func (inst *Instance) Clone(ctx context.Context) error

Clone runs "tart clone " and transitions to StateReadyToRun.

func (inst *Instance) Delete(ctx context.Context) error

Delete runs "tart delete " and transitions to StateDeleted.

func (inst *Instance) Exec(ctx context.Context, stdout, stderr io.Writer, cmd string, args ...string) error

Exec runs "tart exec <args...>" with the output connected to the provided writers. It returns when the command completes.

func (inst *Instance) ID() string

ID returns the local VM's ID/name.

func (inst *Instance) Properties(context.Context) (vms.Properties, error)

Properties returns VM properties. If the VM is running, it returns the IP address.

func (inst *Instance) Start(ctx context.Context, stdout, stderr io.Writer) error

Start runs "tart run --no-graphics --suspendable" by starting the tart process in the background, then blocks until tart reports the VM is running, an IP address is available, and a tart exec readiness check succeeds. On success, the instance transitions to StateRunning..

func (inst *Instance) State(_ context.Context) vms.State

State returns the current state and any error from a running instance that terminated without being stopped or suspend.

func (inst *Instance) Stop(ctx context.Context, timeout time.Duration) (runErr, stopErr error)
func (inst *Instance) Suspend(ctx context.Context) error

Suspend runs "tart suspend " and transitions to StateSuspended.

func (inst *Instance) Suspendable() bool
Type ListEntries
type ListEntries []ListEntry
Functions
func ListAll(ctx context.Context) (ListEntries, error)

ListAll calls "tart list --format json" and returns the entries.

Methods
func (e ListEntries) Len() int
func (e ListEntries) Lookup(name string) (ListEntry, bool)

Lookup returns the entry for name, or (zero, false) if the VM is not present.

func (e ListEntries) LookupSourceName(source, name string) (ListEntry, bool)

LookupSourceName returns the entry for source and name, or (zero, false) if the VM is not present.

Type ListEntry
type ListEntry struct {
	State    string
	Name     string
	Size     int
	Accessed time.Time
	Source   string
	Disk     int
	Running  bool
}

ListEntry represents an entry in the output of "tart list --format json".

Methods
func (e ListEntry) VMSState() vms.State

VMSState maps the tart state to a vms.State.

Type Option
type Option func(o *options)

Option represents an Option to New.

Functions
func WithForceStopTimeout(timeout time.Duration) Option

WithForceStopTimeout sets the timeout for forcefully stopping a VM when a run operation, or other operation, fails and the error recovery needs to stop the VM.

func WithLogger(logger *slog.Logger) Option

WithLogger sets a logger to use for logging tart commands and state transitions.

func WithPollingInterval(interval time.Duration) Option

WithPollingInterval sets the interval to use for polling the state of the VM when waiting for state transitions, network availability, etc.

The default is DefaultPollingInterval.
func WithRunOptions(opts ...string) Option

WithRunOptions sets additional options to pass to the "tart run" command. The default is the value returned by DefaultRunOptions.

func WithRunTimeout(timeout time.Duration) Option

WithRunTimeout sets a timeout for the VM to reach a running state after Start is called. The default is DefaultRunTimeout.

Documentation

Overview

Package tartvm implements cloudeng.io/vms.Instance using the tart CLI on macOS.

Index

Constants

View Source
const (
	DefaultPollingInterval  = 100 * time.Millisecond
	DefaultOutputBufferSize = 16 * 1024 // 16KiB
	DefaultRunTimeout       = 2 * time.Minute
	DefaultForceStopTimeout = 2 * time.Second
)

Variables

This section is empty.

Functions

func DefaultLinuxRunOptions

func DefaultLinuxRunOptions() []string

func DefaultMacOSRunOptions

func DefaultMacOSRunOptions() []string

func DefaultRunOptions

func DefaultRunOptions() []string

DefaultRunOptions are safe defaults that work with mac and linux tart VMs. Linux does not currently support suspend.

Types

type CloneInfo

type CloneInfo struct {
	Source string
	Name   string
}

func (CloneInfo) String

func (c CloneInfo) String() string

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

Instance implements vms.Instance backed by the tart CLI. source is the OCI reference used for cloning; name is the local VM name. All images must have the tart agent installed and be compatible with the tart CLI version installed locally.

func New

func New(ctx context.Context, source, name string, opts ...Option) *Instance

New returns an Instance in StateInitial, source is the tart image or OCI reference to clone from; name is the local VM name.

func (*Instance) Clone

func (inst *Instance) Clone(ctx context.Context) error

Clone runs "tart clone <source> <name>" and transitions to StateReadyToRun.

func (*Instance) Delete

func (inst *Instance) Delete(ctx context.Context) error

Delete runs "tart delete <name>" and transitions to StateDeleted.

func (*Instance) Exec

func (inst *Instance) Exec(ctx context.Context, stdout, stderr io.Writer, cmd string, args ...string) error

Exec runs "tart exec <name> <cmd> <args...>" with the output connected to the provided writers. It returns when the command completes.

func (*Instance) ID

func (inst *Instance) ID() string

ID returns the local VM's ID/name.

func (*Instance) Properties

func (inst *Instance) Properties(context.Context) (vms.Properties, error)

Properties returns VM properties. If the VM is running, it returns the IP address.

func (*Instance) Start

func (inst *Instance) Start(ctx context.Context, stdout, stderr io.Writer) error

Start runs "tart run <name> --no-graphics --suspendable" by starting the tart process in the background, then blocks until tart reports the VM is running, an IP address is available, and a tart exec readiness check succeeds. On success, the instance transitions to StateRunning..

func (*Instance) State

func (inst *Instance) State(_ context.Context) vms.State

State returns the current state and any error from a running instance that terminated without being stopped or suspend.

func (*Instance) Stop

func (inst *Instance) Stop(ctx context.Context, timeout time.Duration) (runErr, stopErr error)

func (*Instance) Suspend

func (inst *Instance) Suspend(ctx context.Context) error

Suspend runs "tart suspend <name>" and transitions to StateSuspended.

func (*Instance) Suspendable

func (inst *Instance) Suspendable() bool

type ListEntries

type ListEntries []ListEntry

func ListAll

func ListAll(ctx context.Context) (ListEntries, error)

ListAll calls "tart list --format json" and returns the entries.

func (ListEntries) Len

func (e ListEntries) Len() int

func (ListEntries) Lookup

func (e ListEntries) Lookup(name string) (ListEntry, bool)

Lookup returns the entry for name, or (zero, false) if the VM is not present.

func (ListEntries) LookupSourceName

func (e ListEntries) LookupSourceName(source, name string) (ListEntry, bool)

LookupSourceName returns the entry for source and name, or (zero, false) if the VM is not present.

type ListEntry

type ListEntry struct {
	State    string
	Name     string
	Size     int
	Accessed time.Time
	Source   string
	Disk     int
	Running  bool
}

ListEntry represents an entry in the output of "tart list --format json".

func (ListEntry) VMSState

func (e ListEntry) VMSState() vms.State

VMSState maps the tart state to a vms.State.

type Option

type Option func(o *options)

Option represents an Option to New.

func WithForceStopTimeout

func WithForceStopTimeout(timeout time.Duration) Option

WithForceStopTimeout sets the timeout for forcefully stopping a VM when a run operation, or other operation, fails and the error recovery needs to stop the VM.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets a logger to use for logging tart commands and state transitions.

func WithPollingInterval

func WithPollingInterval(interval time.Duration) Option

WithPollingInterval sets the interval to use for polling the state of the VM when waiting for state transitions, network availability, etc.

The default is DefaultPollingInterval.

func WithRunOptions

func WithRunOptions(opts ...string) Option

WithRunOptions sets additional options to pass to the "tart run" command. The default is the value returned by DefaultRunOptions.

func WithRunTimeout

func WithRunTimeout(timeout time.Duration) Option

WithRunTimeout sets a timeout for the VM to reach a running state after Start is called. The default is DefaultRunTimeout.

Jump to

Keyboard shortcuts

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