virt

package
v0.0.0-...-8c7d5b1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package virt implements high-level functions for handling virtual machines (VMS) that use the more low-level libvirt functions internally.

Package virt implements high-level functions for handling virtual machines (VMS) that use the more low-level libvirt functions internally.

Package virt implements high-level functions for handling virtual machines (VMS) that use the more low-level libvirt functions internally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreeSnapshots

func FreeSnapshots(log log.Logger, snapshots []Snapshot)

FreeSnapshots is a function that takes a slice of snapshots and frees any associated libvirt.DomainSnapshot. Usually, this is called after ListMatchingSnapshots with a "defer" statement.

func FreeVMs

func FreeVMs(log log.Logger, vms []VM)

FreeVMs is a function that takes a slice of VMs and frees any associated libvirt.Domain. Usually, this is called after ListMatchingVMs with a "defer" statement.

func GetStateString

func GetStateString(state libvirt.DomainState) string

GetStateString is a helper function that takes a VM state and returns this state as human readable representation.

Types

type Snapshot

type Snapshot struct {
	Instance   libvirt.DomainSnapshot
	Descriptor libvirtxml.DomainSnapshot
}

Snapshot is a simple wrapper type for a libvirt.DomainSnapshot with its corresponding XML descriptor unmarshalled as data type.

func (*Snapshot) Free

func (s *Snapshot) Free() error

Free is a convenience method for calling Free on the corresponding libvirt Snapshot instance.

type SnapshotSorter

type SnapshotSorter struct {
	Snapshots *[]Snapshot
}

SnapshotSorter is a sorter for sorting snapshots by creation date.

func (*SnapshotSorter) Len

func (s *SnapshotSorter) Len() int

func (*SnapshotSorter) Less

func (s *SnapshotSorter) Less(i int, j int) bool

func (*SnapshotSorter) Swap

func (s *SnapshotSorter) Swap(i int, j int)

type VM

type VM struct {
	Instance   libvirt.Domain
	Descriptor libvirtxml.Domain
	Logger     log.Logger
}

VM is a simple wrapper type for a libvirt.Domain with its corresponding XML descriptor unmarshalled as data type.

func ListMatchingVMs

func ListMatchingVMs(log log.Logger, regexes []string, socketURL string) ([]VM, error)

ListMatchingVMs is a method that allows to retrieve information about virtual machines that can be accessed via libvirt. The first parameter specifies the logger to be used to output warnings. The second parameter specifies a slice of regular expressions. Only virtual machines whose name matches at least one of the regular expressions are returned. The third parameter is the libvirt/qemu socket URL to connect to. The caller is responsible for calling FreeVMs on the returned slice to free any buffer in libvirt. The returned VMs are sorted lexically by name.

func (*VM) CreateSnapshot

func (vm *VM) CreateSnapshot(prefix string, description string) (Snapshot,
	error)

CreateSnapshot creates a snapshot for the given domain while checking whether the name is already used. The given prefix is prepended to the snapshots name. The caller is responsible for calling Free on snapshot.

func (*VM) Export

func (vm *VM) Export(outputDirectory string, perm os.FileMode, logger log.Logger) error

Export is a function that exports a given VM.

func (*VM) Free

func (vm *VM) Free() error

Free ist just a convenience function to free the associated libvirt.Domain instance.

func (*VM) GetCurrentStateString

func (vm *VM) GetCurrentStateString() (string, error)

GetCurrentStateString is a helper method that retrieves the current state of the VM and returns this state as human readable representation.

func (*VM) ListMatchingSnapshots

func (vm *VM) ListMatchingSnapshots(regexes []string) ([]Snapshot, error)

ListMatchingSnapshots is a method that allows to retrieve information about virtual machine snapshots hat can be accessed via libvirt. The first parameter specifies a slice of regular expressions. Only snapshots of virtual machines whose name matches at least one of the regular expressions are returned. The caller is responsible for calling FreeSnapshots on the returned slice to free any buffer in libvirt. The returned snapshots are sorted by creation time.

func (*VM) Transition

func (vm *VM) Transition(to libvirt.DomainState, forceShutdown bool,
	timeout int) (libvirt.DomainState, error)

Transition implements state transitions of the given VM. This method can be seen as implementation of an finite state machine (FSM). "to" specifies the target state of the VM. "forceShutdown" determines whether the VM should be forced to shutoff (plug the cable) after several tries of graceful shutdown before returning an error. "timeout" specifies the timeout in minutes a VM is allowed to take before forcing shutdown.

type VMSorter

type VMSorter struct {
	VMs *[]VM
}

VMSorter is a sorter for sorting snapshots by name lexically.

func (*VMSorter) Len

func (s *VMSorter) Len() int

func (*VMSorter) Less

func (s *VMSorter) Less(i int, j int) bool

func (*VMSorter) Swap

func (s *VMSorter) Swap(i int, j int)

Jump to

Keyboard shortcuts

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