common

package
v0.0.0-...-40562d9 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: MPL-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GuestAdditionsModeDisable string = "disable"
	GuestAdditionsModeAttach  string = "attach"
	GuestAdditionsModeUpload  string = "upload"
)

These are the different valid mode values for "guest_additions_mode" which determine how guest additions are delivered to the guest.

View Source
const BuilderId = "naveenrajm7.utm"

This is the common builder ID to all of these artifacts.

Variables

View Source
var ControllerEnumMap = map[string]string{
	"none":   "QdIn",
	"ide":    "QdIi",
	"scsi":   "QdIs",
	"sd":     "QdId",
	"mtd":    "QdIm",
	"floppy": "QdIf",
	"pflash": "QdIp",
	"virtio": "QdIv",
	"nvme":   "QdIn",
	"usb":    "QdIu",
}

Map of controller names to their corresponding enum codes

Functions

func CommHost

func CommHost(host string) func(multistep.StateBag) (string, error)

func CommPort

func CommPort(state multistep.StateBag) (int, error)

func GetControllerEnumCode

func GetControllerEnumCode(controllerName string) (string, error)

Function to get the UTM enum code for a given controller name

func NewArtifact

func NewArtifact(dir string, vmName string, generatedData map[string]interface{}) (packersdk.Artifact, error)

NewArtifact returns a UTM artifact containing a .utm directory (file for UTM, which can be imported into UTM). in the given output directory

Types

type CommConfig

type CommConfig struct {
	Comm communicator.Config `mapstructure:",squash"`
	// The minimum port to use for the Communicator port on the host machine which is forwarded
	// to the SSH or WinRM port on the guest machine. By default this is 2222.
	HostPortMin int `mapstructure:"host_port_min" required:"false"`
	// The maximum port to use for the Communicator port on the host machine which is forwarded
	// to the SSH or WinRM port on the guest machine. Because Packer often runs in parallel,
	// Packer will choose a randomly available port in this range to use as the
	// host port. By default this is 4444.
	HostPortMax int `mapstructure:"host_port_max" required:"false"`
	// Defaults to false. When enabled, Packer
	// does not setup forwarded port mapping for communicator (SSH or WinRM) requests and uses ssh_port or winrm_port
	// on the host to communicate to the virtual machine.
	SkipNatMapping bool `mapstructure:"skip_nat_mapping" required:"false"`

	// These are deprecated, but we keep them around for backwards compatibility
	// TODO: remove later
	SSHHostPortMin int `mapstructure:"ssh_host_port_min" required:"false"`
	// TODO: remove later
	SSHHostPortMax int `mapstructure:"ssh_host_port_max"`
	// TODO: remove later
	SSHSkipNatMapping bool `mapstructure:"ssh_skip_nat_mapping" required:"false"`
}

func (*CommConfig) Prepare

func (c *CommConfig) Prepare(ctx *interpolate.Context) []error

type Driver

type Driver interface {
	// Delete a VM by name
	Delete(string) error

	// Executes the given AppleScript with the given arguments.
	ExecuteOsaScript(command ...string) (string, error)

	// Export a VM to a UTM file
	Export(string, string) error

	// Import a VM
	Import(string) (string, error)

	// Checks if the VM with the given id is running.
	IsRunning(string) (bool, error)

	// Get guest tools iso path
	GuestToolsIsoPath() (string, error)

	// Stop stops a running machine, forcefully.
	Stop(string) error

	// Utmctl executes the given Utmctl command
	// and returns the stdout channel as string
	Utmctl(...string) (string, error)

	// Verify checks to make sure that this driver should function
	// properly. If there is any indication the driver can't function,
	// this will return an error.
	Verify() error

	// Version reads the version of UTM that is installed.
	Version() (string, error)
}

A driver is able to talk to UTM and perform certain operations with it. Some of the operations on here may seem overly specific, but they were built specifically in mind to handle features of the UTM builder for Packer, and to abstract differences in versions out of the builder steps, so sometimes the methods are extremely specific.

func NewDriver

func NewDriver() (Driver, error)

NewDriver creates a new driver for UTM.

type DriverMock

type DriverMock struct {
	sync.Mutex

	DeleteCalled bool
	DeleteName   string
	DeleteErr    error

	ExecuteOsaCalls  [][]string
	ExecuteOsaErrs   []error
	ExecuteOsaResult string

	GuestToolsIsoPathCalled bool
	GuestToolsIsoPathErr    error

	ImportCalled bool
	ImportId     string
	ImportPath   string
	ImportErr    error

	IsRunningName   string
	IsRunningReturn bool
	IsRunningErr    error

	StopName string
	StopErr  error

	UtmctlCalls  [][]string
	UtmctlErrs   []error
	UtmctlResult string

	VerifyCalled bool
	VerifyErr    error

	VersionCalled bool
	VersionResult string
	VersionErr    error
}

func (*DriverMock) Delete

func (d *DriverMock) Delete(name string) error

func (*DriverMock) ExecuteOsaScript

func (d *DriverMock) ExecuteOsaScript(command ...string) (string, error)

func (*DriverMock) Export

func (d *DriverMock) Export(vmId string, path string) error

func (*DriverMock) GuestToolsIsoPath

func (d *DriverMock) GuestToolsIsoPath() (string, error)

func (*DriverMock) Import

func (d *DriverMock) Import(path string) (string, error)

func (*DriverMock) IsRunning

func (d *DriverMock) IsRunning(name string) (bool, error)

func (*DriverMock) Stop

func (d *DriverMock) Stop(name string) error

func (*DriverMock) Utmctl

func (d *DriverMock) Utmctl(args ...string) (string, error)

func (*DriverMock) Verify

func (d *DriverMock) Verify() error

func (*DriverMock) Version

func (d *DriverMock) Version() (string, error)

type ExportConfig

type ExportConfig struct {
	// Only UTM, this specifies the output format
	// of the exported virtual machine. This defaults to utm.
	Format string `mapstructure:"format" required:"false"`
}

func (*ExportConfig) Prepare

func (c *ExportConfig) Prepare(ctx *interpolate.Context) []error

type GuestAdditionsConfig

type GuestAdditionsConfig struct {
	// The method by which guest additions are
	// made available to the guest for installation. Valid options are `upload`,
	// `attach`, or `disable`. If the mode is `attach` the guest additions ISO will
	// be attached as a CD device to the virtual machine. If the mode is `upload`
	// the guest additions ISO will be uploaded to the path specified by
	// `guest_additions_path`. The default value is `upload`. If `disable` is used,
	// guest additions won't be downloaded, either.
	GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
	// The interface type to use to mount guest additions when
	// guest_additions_mode is set to attach. Will default to the value set in
	// iso_interface, if iso_interface is set. Will default to "USB", if
	// iso_interface is not set. Options are none/‌IDE/‌SCSI/‌SD/‌MTD/‌Floppy/‌PFlash/‌VirtIO/‌NVMe/‌USB.
	GuestAdditionsInterface string `mapstructure:"guest_additions_interface" required:"false"`
	// The path on the guest virtual machine
	//  where the UTM guest additions ISO will be uploaded. By default this
	//  is `utm-guest-tools-<version>.iso` which should upload into the login directory of
	//  the user.
	GuestAdditionsPath string `mapstructure:"guest_additions_path"`
	// The SHA256 checksum of the guest
	//  additions ISO that will be uploaded to the guest VM. By default the
	//  checksums will be downloaded from the UTM website, so this only needs
	//  to be set if you want to be explicit about the checksum.
	GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"`
	// The URL of the guest additions ISO
	//  to upload. This can also be a file URL if the ISO is at a local path. By
	//  default, the UTM builder will attempt to find the guest additions ISO
	//  on the local file system. If it is not available locally, the builder will
	//  download the proper guest additions ISO from the internet.
	GuestAdditionsURL string `mapstructure:"guest_additions_url" required:"false"`
}

func (*GuestAdditionsConfig) Prepare

func (c *GuestAdditionsConfig) Prepare(communicatorType string) []error

type HWConfig

type HWConfig struct {
	// The number of cpus to use for building the VM.
	// Defaults to 1.
	CpuCount int `mapstructure:"cpus" required:"false"`
	// The amount of memory to use for building the VM
	// in megabytes. Defaults to 512 megabytes.
	MemorySize int `mapstructure:"memory" required:"false"`
}

func (*HWConfig) Prepare

func (c *HWConfig) Prepare(ctx *interpolate.Context) []error

type NoPauseConfig

type NoPauseConfig struct {
	// If true, the build process will not pause to add display.
	// false by default
	DisplayNoPause bool `mapstructure:"display_nopause" required:"false"`
	// If true, the build process will not pause to confirm successful boot.
	// false by default
	BootNoPause bool `mapstructure:"boot_nopause" required:"false"`
	// If true, the build process will not pause to allow pre-export steps.
	// false by default
	ExportNoPause bool `mapstructure:"export_nopause" required:"false"`
}

Temporary configuration to disable the pause step Once the pause step is removed, this configuration will be removed as well

func (*NoPauseConfig) Prepare

func (c *NoPauseConfig) Prepare(ctx *interpolate.Context) []error

type OutputConfig

type OutputConfig struct {
	// This is the path to the directory where the
	// resulting virtual machine will be created. This may be relative or absolute.
	// If relative, the path is relative to the working directory when packer
	// is executed. This directory must not exist or be empty prior to running
	// the builder. By default this is output-BUILDNAME where "BUILDNAME" is the
	// name of the build.
	OutputDir string `mapstructure:"output_directory" required:"false"`
	// This is the base name of the file (excluding the file extension) where
	// the resulting virtual machine will be created. By default this is the
	// `vm_name`.
	OutputFilename string `mapstructure:"output_filename" required:"false"`
}

func (*OutputConfig) Prepare

func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig) []error

type ShutdownConfig

type ShutdownConfig struct {
	// The command to use to gracefully shut down the
	// machine once all the provisioning is done. By default this is an empty
	// string, which tells Packer to just forcefully shut down the machine unless a
	// shutdown command takes place inside script so this may safely be omitted. If
	// one or more scripts require a reboot it is suggested to leave this blank
	// since reboots may fail and specify the final shutdown command in your
	// last script.
	ShutdownCommand string `mapstructure:"shutdown_command" required:"false"`
	// The amount of time to wait after executing the
	// shutdown_command for the virtual machine to actually shut down. If it
	// doesn't shut down in this time, it is an error. By default, the timeout is
	// 5m or five minutes.
	ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout" required:"false"`
	// The amount of time to wait after shutting
	// down the virtual machine. If you get the error
	// Error removing floppy controller, you might need to set this to 5m
	// or so. By default, the delay is 0s or disabled.
	PostShutdownDelay time.Duration `mapstructure:"post_shutdown_delay" required:"false"`
	// Packer normally halts the virtual machine after all provisioners have
	// run when no `shutdown_command` is defined.  If this is set to `true`, Packer
	// *will not* halt the virtual machine but will assume that you will send the stop
	// signal yourself through the preseed.cfg or your final provisioner.
	// Packer will wait for a default of 5 minutes until the virtual machine is shutdown.
	// The timeout can be changed using `shutdown_timeout` option.
	DisableShutdown bool `mapstructure:"disable_shutdown" required:"false"`
}

func (*ShutdownConfig) Prepare

func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error

type StepAttachDisplay

type StepAttachDisplay struct {
	HardwareType string
	// contains filtered or unexported fields
}

This step attaches a display to the virtual machine.

func (*StepAttachDisplay) Cleanup

func (s *StepAttachDisplay) Cleanup(state multistep.StateBag)

func (*StepAttachDisplay) Run

type StepAttachISOs

type StepAttachISOs struct {
	AttachBootISO           bool
	ISOInterface            string
	GuestAdditionsMode      string
	GuestAdditionsInterface string
	// contains filtered or unexported fields
}

This step attaches the boot ISO, cd_files iso, and guest additions to the virtual machine, if present.

func (*StepAttachISOs) Cleanup

func (s *StepAttachISOs) Cleanup(state multistep.StateBag)

func (*StepAttachISOs) Run

type StepCreateVM

type StepCreateVM struct {
	// takes
	VMName         string
	VMBackend      string
	VMArch         string
	VMIcon         string
	HWConfig       HWConfig
	UEFIBoot       bool
	Hypervisor     bool
	KeepRegistered bool
	// contains filtered or unexported fields
}

This step creates the actual virtual machine.

Produces:

vmId string - The UUID of the VM

func (*StepCreateVM) Cleanup

func (s *StepCreateVM) Cleanup(state multistep.StateBag)

func (*StepCreateVM) Run

type StepDownloadGuestAdditions

type StepDownloadGuestAdditions struct {
	GuestAdditionsMode   string
	GuestAdditionsURL    string
	GuestAdditionsSHA256 string
	Ctx                  interpolate.Context
}

This step uploads a file containing the UTM version, which can be useful for various provisioning reasons.

Produces:

guest_additions_path string - Path to the guest additions.

func (*StepDownloadGuestAdditions) Cleanup

func (s *StepDownloadGuestAdditions) Cleanup(state multistep.StateBag)

func (*StepDownloadGuestAdditions) Run

type StepExport

type StepExport struct {
	Format         string
	OutputDir      string
	OutputFilename string
	ExportOpts     []string
	Bundling       UtmBundleConfig
	SkipNatMapping bool
	SkipExport     bool
}

This step cleans up forwarded ports and (TODO) exports the VM to an UTM file.

Uses:

Produces:

exportPath string - The path to the resulting export.

func (*StepExport) Cleanup

func (s *StepExport) Cleanup(state multistep.StateBag)

func (*StepExport) Run

type StepHTTPIPDiscover

type StepHTTPIPDiscover struct{}

Step to discover the http ip which guests use to reach the vm host To make sure the IP is set before boot command and http server steps

func (*StepHTTPIPDiscover) Cleanup

func (s *StepHTTPIPDiscover) Cleanup(state multistep.StateBag)

func (*StepHTTPIPDiscover) Run

type StepPause

type StepPause struct {
	Message string
	NoPause bool
}

func (*StepPause) Cleanup

func (s *StepPause) Cleanup(state multistep.StateBag)

func (*StepPause) Run

type StepPortForwarding

type StepPortForwarding struct {
	CommConfig             *communicator.Config
	HostPortMin            int
	HostPortMax            int
	SkipNatMapping         bool
	ClearNetworkInterfaces bool // if true, all network interfaces will be cleared before adding new ones
	// contains filtered or unexported fields
}

This step adds a Emulated VLAN port forwarding definition so that SSH (or WinRM ?) is available on the guest machine.

Uses:

driver Driver
ui packersdk.Ui
vmName string

Produces:

func (*StepPortForwarding) Cleanup

func (s *StepPortForwarding) Cleanup(state multistep.StateBag)

func (*StepPortForwarding) Run

type StepRemoveDevices

type StepRemoveDevices struct {
	Bundling UtmBundleConfig
}

This step removes any devices (floppy disks, ISOs, etc.) from the machine that we may have added.

Uses:

driver Driver
ui packersdk.Ui
vmName string

Produces:

func (*StepRemoveDevices) Cleanup

func (s *StepRemoveDevices) Cleanup(state multistep.StateBag)

func (*StepRemoveDevices) Run

type StepRun

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

This step starts the virtual machine.

Uses:

driver Driver
ui packersdk.Ui
vmName string

Produces:

func (*StepRun) Cleanup

func (s *StepRun) Cleanup(state multistep.StateBag)

func (*StepRun) Run

type StepShutdown

type StepShutdown struct {
	Command         string
	Timeout         time.Duration
	Delay           time.Duration
	DisableShutdown bool
}

This step shuts down the machine.

Uses:

communicator packersdk.Communicator
driver Driver
ui     packersdk.Ui
vmName string

Produces:

<nothing>

func (*StepShutdown) Cleanup

func (s *StepShutdown) Cleanup(state multistep.StateBag)

func (*StepShutdown) Run

type StepSshKeyPair

type StepSshKeyPair struct {
	Debug        bool
	DebugKeyPath string
	Comm         *communicator.Config
}

StepSshKeyPair executes the business logic for setting the SSH key pair in the specified communicator.Config.

func (*StepSshKeyPair) Cleanup

func (s *StepSshKeyPair) Cleanup(state multistep.StateBag)

func (*StepSshKeyPair) Run

type StepStopVm

type StepStopVm struct{}

This step stops the machine.

Uses:

driver Driver
ui     packersdk.Ui
vmId string

Produces:

<nothing>

func (*StepStopVm) Cleanup

func (s *StepStopVm) Cleanup(state multistep.StateBag)

func (*StepStopVm) Run

type StepUploadVersion

type StepUploadVersion struct {
	Path string
}

This step uploads a file containing the UTM version, which can be useful for various provisioning reasons.

func (*StepUploadVersion) Cleanup

func (s *StepUploadVersion) Cleanup(state multistep.StateBag)

func (*StepUploadVersion) Run

type StepUtmDownload

type StepUtmDownload struct {
	// The checksum and the type of the checksum for the download
	Checksum string

	// A short description of the type of download being done. Example:
	// "ISO" or "Guest Additions"
	Description string

	// The name of the key where the final path of the ISO will be put
	// into the state.
	ResultKey string

	// The path where the result should go, otherwise it goes to the
	// cache directory.
	TargetPath string

	// A list of URLs to attempt to download this thing.
	Url []string

	// Extension is the extension to force for the file that is downloaded.
	// Some systems require a certain extension. If this isn't set, the
	// extension on the URL is used. Otherwise, this will be forced
	// on the downloaded file for every URL.
	Extension string
}

Uses:

ui    packersdk.Ui

func (*StepUtmDownload) Cleanup

func (s *StepUtmDownload) Cleanup(multistep.StateBag)

func (*StepUtmDownload) Run

type Utm45Driver

type Utm45Driver struct {
	// This is the path to the utmctl binary
	UtmctlPath string
}

Utm45Driver is the base type for UTM drivers

func (*Utm45Driver) Delete

func (d *Utm45Driver) Delete(name string) error

func (*Utm45Driver) ExecuteOsaScript

func (d *Utm45Driver) ExecuteOsaScript(command ...string) (string, error)

ExecuteOsaScript executes an AppleScript command with the given arguments.

func (*Utm45Driver) Export

func (d *Utm45Driver) Export(vmId string, path string) error

UTM 4.5 Doesn't support exporting VMs

func (*Utm45Driver) GuestToolsIsoPath

func (d *Utm45Driver) GuestToolsIsoPath() (string, error)

UTM 4.5 : doesn't support adding support guest tools

func (*Utm45Driver) Import

func (d *Utm45Driver) Import(path string) (string, error)

UTM 4.5 : We just create a VM shortcut using UTM open command.

func (*Utm45Driver) IsRunning

func (d *Utm45Driver) IsRunning(name string) (bool, error)

func (*Utm45Driver) Stop

func (d *Utm45Driver) Stop(name string) error

func (*Utm45Driver) Utmctl

func (d *Utm45Driver) Utmctl(args ...string) (string, error)

func (*Utm45Driver) Verify

func (d *Utm45Driver) Verify() error

func (*Utm45Driver) Version

func (d *Utm45Driver) Version() (string, error)

Version reads the version of UTM that is installed.

type Utm46Driver

type Utm46Driver struct {
	Utm45Driver
}

Utm46Driver are inherited from Utm45Driver.

func (*Utm46Driver) Export

func (d *Utm46Driver) Export(vmId string, path string) error

Export VM to UTM file

func (*Utm46Driver) GuestToolsIsoPath

func (d *Utm46Driver) GuestToolsIsoPath() (string, error)

Return the downloaded guest tools path if available.

func (*Utm46Driver) Import

func (d *Utm46Driver) Import(path string) (string, error)

UTM 4.6 : We import a VM by utm file using UTM import command.

type UtmBundleConfig

type UtmBundleConfig struct {
	// Defaults to false. When enabled, Packer includes
	// any attached ISO disc devices into the final virtual machine. Useful for
	// some live distributions that require installation media to continue to be
	// attached after installation.
	BundleISO bool `mapstructure:"bundle_iso" required:"false"`
}

func (*UtmBundleConfig) Prepare

func (c *UtmBundleConfig) Prepare(ctx *interpolate.Context) []error

type UtmVersionConfig

type UtmVersionConfig struct {
	// The path within the virtual machine to
	// upload a file that contains the UTM version that was used to create
	// the machine. This information can be useful for provisioning. By default
	// this is .utm_version, which will generally be upload it into the
	// home directory. Set to an empty string to skip uploading this file, which
	// can be useful when using the none communicator.
	UtmVersionFile *string `mapstructure:"utm_version_file" required:"false"`
}

func (*UtmVersionConfig) Prepare

func (c *UtmVersionConfig) Prepare(communicatorType string) []error

Jump to

Keyboard shortcuts

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