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 ¶
- func FreeSnapshots(log log.Logger, snapshots []Snapshot)
- func FreeVMs(log log.Logger, vms []VM)
- func GetStateString(state libvirt.DomainState) string
- type Snapshot
- type SnapshotSorter
- type VM
- func (vm *VM) CreateSnapshot(prefix string, description string) (Snapshot, error)
- func (vm *VM) Export(outputDirectory string, perm os.FileMode, logger log.Logger) error
- func (vm *VM) Free() error
- func (vm *VM) GetCurrentStateString() (string, error)
- func (vm *VM) ListMatchingSnapshots(regexes []string) ([]Snapshot, error)
- func (vm *VM) Transition(to libvirt.DomainState, forceShutdown bool, timeout int) (libvirt.DomainState, error)
- type VMSorter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FreeSnapshots ¶
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 ¶
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.
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) 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 ¶
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 ¶
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) Free ¶
Free ist just a convenience function to free the associated libvirt.Domain instance.
func (*VM) GetCurrentStateString ¶
GetCurrentStateString is a helper method that retrieves the current state of the VM and returns this state as human readable representation.
func (*VM) ListMatchingSnapshots ¶
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.