Documentation ¶
Index ¶
- Constants
- func AddToMAC(mac net.HardwareAddr, addend uint) (net.HardwareAddr, error)
- func DynamicLayerName(name string) string
- func EnvmapToSlice(envMap map[string]string) []string
- func GenerateISO(files map[string][]byte) ([]byte, error)
- func QemuBaseMAC() net.HardwareAddr
- func QemuMAC(id uint) string
- type AfterNotifier
- type CpuArch
- func (c *CpuArch) CPU() *lx.DomainCPU
- func (c *CpuArch) DomainType() string
- func (c *CpuArch) Firmware() string
- func (c *CpuArch) Machine() string
- func (c *CpuArch) OSDomain() *lx.DomainOS
- func (c *CpuArch) PM() *lx.DomainPM
- func (c *CpuArch) QemuArch() string
- func (c *CpuArch) Set(s string) error
- func (c *CpuArch) String() string
- func (c *CpuArch) Type() string
- type Disk
- type HTTPClient
- type ImageBuildConfig
- type ImageBuildTools
- type LayerOperationOption
- type LibvirtConnection
- type LibvirtGetError
- type LocalImage
- func (l *LocalImage) ConfigFile() (*regv1.ConfigFile, error)
- func (l *LocalImage) ConfigName() (regv1.Hash, error)
- func (l *LocalImage) Digest() (regv1.Hash, error)
- func (l *LocalImage) LayerByDiffID(hash regv1.Hash) (regv1.Layer, error)
- func (l *LocalImage) LayerByDigest(hash regv1.Hash) (regv1.Layer, error)
- func (l *LocalImage) Layers() ([]regv1.Layer, error)
- func (l *LocalImage) Manifest() (*regv1.Manifest, error)
- func (l *LocalImage) MediaType() (types.MediaType, error)
- func (l *LocalImage) Name() string
- func (l *LocalImage) RawConfigFile() ([]byte, error)
- func (l *LocalImage) RawManifest() ([]byte, error)
- func (l *LocalImage) Size() (int64, error)
- func (l *LocalImage) TopLayer() *VolumeLayer
- type Mount
- type NIC
- type NICType
- type NewLayerOption
- type ProgressOpt
- type ProvisionConfig
- type ProvisionContainerCopyStep
- type ProvisionContainerStep
- type ProvisionOption
- type ProvisionRsyncStep
- type ProvisionShellStep
- type ProvisionStep
- type RawLayer
- func (rl *RawLayer) CloneAs(name string, opts ...LayerOperationOption) (*RawLayer, error)
- func (rl *RawLayer) Delete() error
- func (rl *RawLayer) DeleteAllIfUnused() error
- func (rl *RawLayer) DeleteIfUnused() (bool, error)
- func (rl *RawLayer) Dependency() (*VolumeLayer, error)
- func (rl *RawLayer) Descriptor() (lx.StorageVolume, error)
- func (rl *RawLayer) DiffID() (regv1.Hash, error)
- func (rl *RawLayer) Name() string
- func (rl *RawLayer) ToVolumeLayer(diffID *regv1.Hash, opts ...LayerOperationOption) (*VolumeLayer, error)
- func (rl *RawLayer) Uncompressed() (io.ReadCloser, error)
- func (rl *RawLayer) Upload(reader io.Reader) error
- type ShellClient
- type ShellClientBuilder
- type VMConfig
- type VMDisk
- type VMDiskDevice
- type VMMeta
- type VMNic
- type Virter
- func (v *Virter) AddDHCPHost(mac string, id uint) error
- func (v *Virter) Disconnect() error
- func (v *Virter) FindDynamicLayer(name string) (*RawLayer, error)
- func (v *Virter) FindImage(image string, opts ...LayerOperationOption) (*LocalImage, error)
- func (v *Virter) FindRawLayer(name string) (*RawLayer, error)
- func (v *Virter) FindVolumeLayer(name string) (*VolumeLayer, error)
- func (v *Virter) ForceDisconnect()
- func (v *Virter) GetVMID(wantedID uint, expectDHCPEntry bool) (uint, error)
- func (v *Virter) ImageBuild(ctx context.Context, tools ImageBuildTools, vmConfig VMConfig, ...) error
- func (v *Virter) ImageImport(name string, image regv1.Image, opts ...LayerOperationOption) (*LocalImage, error)
- func (v *Virter) ImageImportFromReader(image string, reader io.ReadCloser, opts ...LayerOperationOption) (*LocalImage, error)
- func (v *Virter) ImageList() ([]*LocalImage, error)
- func (v *Virter) ImageRm(name string) error
- func (v *Virter) ImageSpawn(name string, image *LocalImage, capacityKib uint64) (*RawLayer, error)
- func (v *Virter) LayerList() ([]*VolumeLayer, error)
- func (v *Virter) ListVM() ([]string, error)
- func (v *Virter) MakeImage(image string, topLayer *VolumeLayer, opts ...LayerOperationOption) (*LocalImage, error)
- func (v *Virter) NetworkAdd(desc libvirtxml.Network) error
- func (v *Virter) NetworkConfig(nics []NIC) (string, error)
- func (v *Virter) NetworkGet(netname string) (*libvirtxml.Network, error)
- func (v *Virter) NetworkList() ([]libvirtxml.Network, error)
- func (v *Virter) NetworkListAttached(netname string) ([]VMNic, error)
- func (v *Virter) NetworkRemove(netname string) error
- func (v *Virter) NewDynamicLayer(name string, opts ...NewLayerOption) (*RawLayer, error)
- func (v *Virter) RemoveMACDHCPEntries(mac string) error
- func (v *Virter) VMCommit(ctx context.Context, afterNotifier AfterNotifier, vmName, imageName string, ...) error
- func (v *Virter) VMExecContainer(ctx context.Context, containerProvider containerapi.ContainerProvider, ...) error
- func (v *Virter) VMExecCopy(ctx context.Context, copier netcopy.NetworkCopier, sourceSpecs []string, ...) error
- func (v *Virter) VMExecRsync(ctx context.Context, copier netcopy.NetworkCopier, vmNames []string, ...) error
- func (v *Virter) VMExecShell(ctx context.Context, vmNames []string, shellStep *ProvisionShellStep) error
- func (v *Virter) VMExists(vmName string) error
- func (v *Virter) VMGetKnownHosts(vmName string) (string, error)
- func (v *Virter) VMRm(vmName string, removeDHCPEntries bool, removeBoot bool) error
- func (v *Virter) VMRun(vmConfig VMConfig) error
- func (v *Virter) VMSSHSession(ctx context.Context, vmName string) error
- func (v *Virter) WaitVmReady(ctx context.Context, shellClientBuilder ShellClientBuilder, vmName string, ...) error
- type VmReadyConfig
- type VolumeLayer
- func (vl *VolumeLayer) DiffID() (regv1.Hash, error)
- func (vl *VolumeLayer) MediaType() (types.MediaType, error)
- func (vl *VolumeLayer) Squashed() (*RawLayer, error)
- func (vl *VolumeLayer) ToRegistryLayer(opts ...LayerOperationOption) (regv1.Layer, error)
- func (vl *VolumeLayer) ToVolumeLayer() (*VolumeLayer, error)
- func (vl *VolumeLayer) Upload(io.Reader) error
Constants ¶
const ( CpuArchAMD64 = CpuArch("amd64") CpuArchARM64 = CpuArch("arm64") CpuArchPPC64LE = CpuArch("ppc64le") CpuArchS390x = CpuArch("s390x") CpuArchNative = CpuArch(runtime.GOARCH) )
const ( RootFSType = "application/vnd.com.linbit.virter.image.v1.rootfs" ImageMediaType = "application/vnd.com.linbit.virter.image.v1" TagVolumePrefix = "virter:tag:" )
const ( // LayerMediaType is the media type used when upload a layer to a container registry. LayerMediaType = "application/vnd.com.linbit.virter.layer.v1.qcow2.gzip" // LayerVolumePrefix is the prefix for all VolumeLayer storage volumes in libvirt. LayerVolumePrefix = "virter:layer:" // WorkingLayerNamePrefix is the prefix for all layers that are actively attached to a libvirt VM. WorkingLayerNamePrefix = "virter:work:" )
const ( VMDiskDeviceDisk = "disk" VMDiskDeviceCDROM = "cdrom" )
const ( NICTypeNetwork = "network" NICTypeBridge = "bridge" )
const CurrentProvisionFileVersion = 1
const DrvFeatureNetworkUpdateHasCorrectOrder = 16
DrvFeatureNetworkUpdateHasCorrectOrder determines wheter the argument order for NetworkUpdate is fixed From https://github.com/libvirt/libvirt/blob/cac9608c172e9439d9cba350579af59b649b77e7/src/libvirt_internal.h#L133
Variables ¶
This section is empty.
Functions ¶
func AddToMAC ¶ added in v0.12.0
func AddToMAC(mac net.HardwareAddr, addend uint) (net.HardwareAddr, error)
func DynamicLayerName ¶ added in v0.14.0
DynamicLayerName returns the prefixed raw volume name for the given dynamic layer.
func EnvmapToSlice ¶
func GenerateISO ¶
GenerateISO generates a "CD-ROM" filesystem
func QemuBaseMAC ¶ added in v0.12.0
func QemuBaseMAC() net.HardwareAddr
Types ¶
type AfterNotifier ¶
AfterNotifier wait for a duration to elapse
type HTTPClient ¶
HTTPClient contains required HTTP methods.
type ImageBuildConfig ¶
type ImageBuildConfig struct { ImageName string ContainerName string ShutdownTimeout time.Duration ProvisionConfig ProvisionConfig ResetMachineID bool }
ImageBuildConfig contains the configuration for building an image
type ImageBuildTools ¶
type ImageBuildTools struct { ShellClientBuilder ShellClientBuilder ContainerProvider containerapi.ContainerProvider AfterNotifier AfterNotifier }
ImageBuildTools includes the dependencies for building an image
type LayerOperationOption ¶ added in v0.14.0
type LayerOperationOption = func(o *layerOperatorOpts)
func WithProgress ¶ added in v0.14.0
func WithProgress(p ProgressOpt) LayerOperationOption
type LibvirtConnection ¶
type LibvirtConnection interface { ConnectListAllDomains(NeedResults int32, Flags libvirt.ConnectListAllDomainsFlags) (rDomains []libvirt.Domain, rRet uint32, err error) StoragePoolLookupByName(Name string) (rPool libvirt.StoragePool, err error) StoragePoolListAllVolumes(Pool libvirt.StoragePool, NeedResults int32, Flags uint32) (rVols []libvirt.StorageVol, rRet uint32, err error) StorageVolCreateXML(Pool libvirt.StoragePool, XML string, Flags libvirt.StorageVolCreateFlags) (rVol libvirt.StorageVol, err error) StorageVolCreateXMLFrom(Pool libvirt.StoragePool, XML string, original libvirt.StorageVol, Flags libvirt.StorageVolCreateFlags) (rVol libvirt.StorageVol, err error) StorageVolDelete(Vol libvirt.StorageVol, Flags libvirt.StorageVolDeleteFlags) (err error) StorageVolLookupByName(Pool libvirt.StoragePool, Name string) (rVol libvirt.StorageVol, err error) StorageVolUpload(Vol libvirt.StorageVol, outStream io.Reader, Offset, Length uint64, Flags libvirt.StorageVolUploadFlags) (err error) StorageVolGetXMLDesc(Vol libvirt.StorageVol, Flags uint32) (rXML string, err error) StorageVolDownload(Vol libvirt.StorageVol, inStream io.Writer, Offset, Length uint64, Flags libvirt.StorageVolDownloadFlags) (err error) StorageVolGetInfo(Vol libvirt.StorageVol) (rType int8, rCapacity, rAllocation uint64, err error) ConnectListAllNetworks(NeedResults int32, Flags libvirt.ConnectListAllNetworksFlags) (rNets []libvirt.Network, rRet uint32, err error) NetworkGetDhcpLeases(Net libvirt.Network, Mac libvirt.OptString, NeedResults int32, Flags uint32) (rLeases []libvirt.NetworkDhcpLease, rRet uint32, err error) NetworkDefineXML(XML string) (rNet libvirt.Network, err error) NetworkSetAutostart(Net libvirt.Network, Autostart int32) (err error) NetworkCreate(Net libvirt.Network) (err error) NetworkDestroy(Net libvirt.Network) (err error) NetworkUndefine(Net libvirt.Network) (err error) NetworkLookupByName(Name string) (rNet libvirt.Network, err error) NetworkGetXMLDesc(Net libvirt.Network, Flags uint32) (rXML string, err error) NetworkUpdate(Net libvirt.Network, Command, Section uint32, ParentIndex int32, XML string, Flags libvirt.NetworkUpdateFlags) (err error) DomainLookupByName(Name string) (rDom libvirt.Domain, err error) DomainGetXMLDesc(Dom libvirt.Domain, Flags libvirt.DomainXMLFlags) (rXML string, err error) DomainDefineXML(XML string) (rDom libvirt.Domain, err error) DomainCreate(Dom libvirt.Domain) (err error) DomainIsActive(Dom libvirt.Domain) (rActive int32, err error) DomainIsPersistent(Dom libvirt.Domain) (rPersistent int32, err error) DomainShutdown(Dom libvirt.Domain) (err error) DomainDestroy(Dom libvirt.Domain) (err error) DomainUndefineFlags(Dom libvirt.Domain, Flags libvirt.DomainUndefineFlagsValues) (err error) DomainListAllSnapshots(Dom libvirt.Domain, NeedResults int32, Flags uint32) (rSnapshots []libvirt.DomainSnapshot, rRet int32, err error) DomainSnapshotDelete(Snap libvirt.DomainSnapshot, Flags libvirt.DomainSnapshotDeleteFlags) (err error) Disconnect() error ConnectSupportsFeature(Feature int32) (int32, error) ConnectGetDomainCapabilities(Emulatorbin libvirt.OptString, Arch libvirt.OptString, Machine libvirt.OptString, Virttype libvirt.OptString, Flags uint32) (rCapabilities string, err error) }
LibvirtConnection contains required libvirt connection methods.
type LibvirtGetError ¶ added in v0.5.0
func (*LibvirtGetError) Error ¶ added in v0.5.0
func (e *LibvirtGetError) Error() string
func (*LibvirtGetError) Unwrap ¶ added in v0.5.0
func (e *LibvirtGetError) Unwrap() error
type LocalImage ¶ added in v0.14.0
type LocalImage struct {
// contains filtered or unexported fields
}
LocalImage represents a list of local layers addressable by a human readable name.
An image is stored in libvirt as an empty volume prefixed by TagVolumePrefix. This volume has the actual VolumeLayer as backing store. This type implements the regv1.Image interface, i.e. it can be pushed to a container registry.
func (*LocalImage) ConfigFile ¶ added in v0.14.0
func (l *LocalImage) ConfigFile() (*regv1.ConfigFile, error)
ConfigFile returns this image's config file.
For containers this specifies metadata like which command to run and permissions. For us this simply carries the list layers by their uncompressed id.
func (*LocalImage) ConfigName ¶ added in v0.14.0
func (l *LocalImage) ConfigName() (regv1.Hash, error)
ConfigName returns the hash of the image's config file, also known as the Image ID.
func (*LocalImage) Digest ¶ added in v0.14.0
func (l *LocalImage) Digest() (regv1.Hash, error)
Digest returns the sha256 of this image's manifest.
func (*LocalImage) LayerByDiffID ¶ added in v0.14.0
LayerByDiffID is an analog to LayerByDigest, looking up by "diff id" (the uncompressed hash).
func (*LocalImage) LayerByDigest ¶ added in v0.14.0
LayerByDigest returns a Layer for interacting with a particular layer of the image, looking it up by "digest" (the compressed hash).
func (*LocalImage) Layers ¶ added in v0.14.0
func (l *LocalImage) Layers() ([]regv1.Layer, error)
Layers returns the ordered list of layers that make up this image.
The order of layers is oldest/base layer first, most recent/top layer last. Since VolumeLayer are not directly suitable for pushing to a registry, this method pre-computes the compatible layers and caches the result for later use.
func (*LocalImage) Manifest ¶ added in v0.14.0
func (l *LocalImage) Manifest() (*regv1.Manifest, error)
Manifest returns this image's Manifest object.
The manifest ties a tag to layers. When fetching an image from a registry, first the matching manifest is fetched. The manifest references the layers to fetch and the (container) configuration. For our purpose, only the layers are of interest.
func (*LocalImage) MediaType ¶ added in v0.14.0
func (l *LocalImage) MediaType() (types.MediaType, error)
MediaType of this image's manifest.
func (*LocalImage) Name ¶ added in v0.14.0
func (l *LocalImage) Name() string
Name returns the local name of the image.
func (*LocalImage) RawConfigFile ¶ added in v0.14.0
func (l *LocalImage) RawConfigFile() ([]byte, error)
RawConfigFile returns the serialized bytes of ConfigFile().
func (*LocalImage) RawManifest ¶ added in v0.14.0
func (l *LocalImage) RawManifest() ([]byte, error)
RawManifest returns the serialized bytes of Manifest()
func (*LocalImage) Size ¶ added in v0.14.0
func (l *LocalImage) Size() (int64, error)
Size returns the size of the manifest.
func (*LocalImage) TopLayer ¶ added in v0.14.0
func (l *LocalImage) TopLayer() *VolumeLayer
TopLayer returns the top most VolumeLayer.
The returned volume layer can be used as backing volume when starting a new VM based on this image.
type NewLayerOption ¶ added in v0.14.0
type NewLayerOption = func(volume *lx.StorageVolume) error
NewLayerOption can be passed when creating a new layer to make changes on the libvirt storage volume object.
func WithBackingLayer ¶ added in v0.14.0
func WithBackingLayer(layer *VolumeLayer) NewLayerOption
WithBackingLayer sets the backing layer.
func WithCapacity ¶ added in v0.14.0
func WithCapacity(minCapKib uint64) NewLayerOption
WithCapacity sets the minimal capacity of the new layer in KibiByte.
func WithFormat ¶ added in v0.14.0
func WithFormat(fmt string) NewLayerOption
WithFormat sets the format used by the storage volume.
Supported values are "qcow2" and "raw".
type ProgressOpt ¶ added in v0.14.0
type ProvisionConfig ¶
type ProvisionConfig struct { Version int `toml:"version"` Values map[string]string `toml:"values"` Env map[string]string `toml:"env"` Steps []ProvisionStep `toml:"steps"` }
ProvisionConfig holds the configuration of the whole provisioning
func NewProvisionConfig ¶
func NewProvisionConfig(provOpt ProvisionOption) (ProvisionConfig, error)
NewProvisionConfig returns a ProvisionConfig from a ProvisionOption
func (*ProvisionConfig) NeedsContainers ¶ added in v0.4.2
func (p *ProvisionConfig) NeedsContainers() bool
NeedsContainers checks if there is a provision step that requires a container provider (like Docker or Podman)
type ProvisionContainerCopyStep ¶ added in v0.23.0
type ProvisionContainerStep ¶ added in v0.23.0
type ProvisionContainerStep struct { Image string `toml:"image"` Pull pullpolicy.PullPolicy `toml:"pull"` Env map[string]string `toml:"env"` Command []string `toml:"command"` Copy *ProvisionContainerCopyStep `toml:"copy"` }
ProvisionContainerStep is a single provisioning step executed in a container
type ProvisionOption ¶
type ProvisionOption struct { FilePath string Overrides []string DefaultPullPolicy pullpolicy.PullPolicy OverridePullPolicy pullpolicy.PullPolicy }
ProvisionOption sumarizes all the options used for generating the final ProvisionConfig
type ProvisionRsyncStep ¶
ProvisionRsyncStep is used to copy files to the target via the rsync utility
type ProvisionShellStep ¶
ProvisionShellStep is a single provisioniong step executed in a shell (via ssh)
type ProvisionStep ¶
type ProvisionStep struct { Container *ProvisionContainerStep `toml:"container,omitempty"` Shell *ProvisionShellStep `toml:"shell,omitempty"` Rsync *ProvisionRsyncStep `toml:"rsync,omitempty"` }
ProvisionStep is a single provisioning step
type RawLayer ¶ added in v0.14.0
type RawLayer struct {
// contains filtered or unexported fields
}
RawLayer represents and wraps a libvirt storage volume.
func (*RawLayer) CloneAs ¶ added in v0.14.0
func (rl *RawLayer) CloneAs(name string, opts ...LayerOperationOption) (*RawLayer, error)
CloneAs creates a copy of this layer under the given name.
func (*RawLayer) Delete ¶ added in v0.14.0
Delete deletes this layer.
There are no checks that prevent deletion of an in-use layer (either directly attached, or part of a layer chain). A layer that did not exist in the backend will still delete successfully.
func (*RawLayer) DeleteAllIfUnused ¶ added in v0.14.0
func (*RawLayer) DeleteIfUnused ¶ added in v0.14.0
DeleteIfUnused deletes the layer if it not referenced as a backing layer of other layers.
This method assumes that only VolumeLayer can have child layers, i.e. if a non VolumeLayer layer depends on another non VolumeLayer layer, it will still be deleted. This should not be an issue, as only the top-most layers should be mutable (i.e. a non VolumeLayer layer).
func (*RawLayer) Dependency ¶ added in v0.14.0
func (rl *RawLayer) Dependency() (*VolumeLayer, error)
Dependency returns a reference to a backing VolumeLayer, if any.
Returns nil if no backing layer was found. Returns an error if the backing layer is not a VolumeLayer.
func (*RawLayer) Descriptor ¶ added in v0.14.0
func (rl *RawLayer) Descriptor() (lx.StorageVolume, error)
Descriptor returns the libvirt descriptor of the storage volume backing this layer.
func (*RawLayer) DiffID ¶ added in v0.14.0
DiffID computes a digest of the Uncompressed layer content.
func (*RawLayer) ToVolumeLayer ¶ added in v0.14.0
func (rl *RawLayer) ToVolumeLayer(diffID *regv1.Hash, opts ...LayerOperationOption) (*VolumeLayer, error)
ToVolumeLayer converts this layer into a VolumeLayer.
First, computes the DiffID of the given layer, creates a new VolumeLayer compatible volume and copies the content of this layer over to the new volume. Afterwards, deletes this layer in the libvirt backend. If diffID is nil, it will be computed from the volume content.
func (*RawLayer) Uncompressed ¶ added in v0.14.0
func (rl *RawLayer) Uncompressed() (io.ReadCloser, error)
Uncompressed returns a reader that yields the raw volume.
If the RawLayer is in qcow2 format, this will read the raw qcow2 file, without any backing store.
type ShellClient ¶
type ShellClient interface { DialContext(ctx context.Context) error Close() error StdoutPipe() (io.Reader, error) StderrPipe() (io.Reader, error) ExecScript(script string) error Shell() error }
ShellClient executes shell commands
type ShellClientBuilder ¶
type ShellClientBuilder interface {
NewShellClient(hostPort string, sshconfig ssh.ClientConfig) ShellClient
}
ShellClientBuilder provides SSH connections
type VMConfig ¶
type VMConfig struct { Image *LocalImage CpuArch CpuArch Name string MemoryKiB uint64 BootCapacityKiB uint64 VCPUs uint ID uint StaticDHCP bool ExtraSSHPublicKeys []string ConsolePath string Disks []Disk DiskCache string ExtraNics []NIC Mounts []Mount GDBPort uint SecureBoot bool VNCEnabled bool VNCPort int VNCIPv4BindAddress string SSHUserName string }
VMConfig contains the configuration for starting a VM
func CheckVMConfig ¶
CheckVMConfig takes a VMConfig, does basic checks, and returns it back.
type VMDiskDevice ¶ added in v0.2.0
type VMDiskDevice string
type Virter ¶
type Virter struct {
// contains filtered or unexported fields
}
Virter manipulates libvirt for virter.
func New ¶
func New(libvirtConnection LibvirtConnection, storagePoolName string, networkName string, store sshkeys.KeyStore) *Virter
New configures a new Virter.
func (*Virter) AddDHCPHost ¶ added in v0.6.0
AddDHCPHost determines the IP for an ID and adds a DHCP mapping from a MAC address to it. The same MAC address should always be paired with a given IP so that DHCP entries do not need to be released between removing a VM and creating another with the same ID.
func (*Virter) Disconnect ¶
Disconnect disconnects virter's connection to libvirt
func (*Virter) FindDynamicLayer ¶ added in v0.14.0
FindDynamicLayer searches the default storage pool for the given dynamic layer, suitable for attaching to a VM.
If no matching layer could be found, returns (nil, nil).
func (*Virter) FindImage ¶ added in v0.14.0
func (v *Virter) FindImage(image string, opts ...LayerOperationOption) (*LocalImage, error)
FindImage searches the default storage pool for a LocalImage of the given name.
If no matching image could be found, returns (nil, nil).
func (*Virter) FindRawLayer ¶ added in v0.14.0
FindRawLayer searches the default storage pool for the given volume and returns a RawLayer.
If the layer could not be found, will return (nil, nil).
func (*Virter) FindVolumeLayer ¶ added in v0.14.0
func (v *Virter) FindVolumeLayer(name string) (*VolumeLayer, error)
FindVolumeLayer searches the default storage pool for the given volume layer and returns a VolumeLayer.
The name is the raw layer name, i.e. "sha256:xxxx". If no matching volume is found, returns (nil, nil).
func (*Virter) ForceDisconnect ¶ added in v0.3.0
func (v *Virter) ForceDisconnect()
ForceDisconnect disconnects virter's connection to libvirt
It behaves like Disconnect(), except it does not return an error. If an error would be returned, the error will be logged and the program will terminate. Note: this is useful for `defer` statements
func (*Virter) GetVMID ¶ added in v0.5.0
GetVMID returns wantedID if it is not 0 and free. If wantedID is 0 GetVMID searches for an unused ID and returns the first it can find. For searching it uses the set libvirt network and already reserved DHCP entries.
func (*Virter) ImageBuild ¶
func (v *Virter) ImageBuild(ctx context.Context, tools ImageBuildTools, vmConfig VMConfig, readyConfig VmReadyConfig, buildConfig ImageBuildConfig, opts ...LayerOperationOption) error
ImageBuild builds an image by running a VM and provisioning it.
func (*Virter) ImageImport ¶ added in v0.14.0
func (v *Virter) ImageImport(name string, image regv1.Image, opts ...LayerOperationOption) (*LocalImage, error)
ImageImport imports the given registry image into the local storage pool
func (*Virter) ImageImportFromReader ¶ added in v0.14.0
func (v *Virter) ImageImportFromReader(image string, reader io.ReadCloser, opts ...LayerOperationOption) (*LocalImage, error)
ImageImportFromReader imports a new image into the local storage pool from a basic reader.
func (*Virter) ImageList ¶ added in v0.14.0
func (v *Virter) ImageList() ([]*LocalImage, error)
ImageList returns the list of images in the local storage pool.
func (*Virter) ImageRm ¶ added in v0.3.0
ImageRm removes an image from the local storage pool.
If no image of the given name is present, returns nil. This will recursively delete any layers that are not referenced by other images or currently in use by a VM.
func (*Virter) ImageSpawn ¶ added in v0.14.0
ImageSpawn creates a new rw volume backed by this image.
The returned RawLayer can be attached to a VM.
func (*Virter) LayerList ¶ added in v0.14.0
func (v *Virter) LayerList() ([]*VolumeLayer, error)
LayerList returns all known VolumeLayer in the default storage pool
func (*Virter) MakeImage ¶ added in v0.14.0
func (v *Virter) MakeImage(image string, topLayer *VolumeLayer, opts ...LayerOperationOption) (*LocalImage, error)
MakeImage creates a new LocalImage of the given name, pointing to the given VolumeLayer.
If an image of the given name already exists it will be deleted first.
func (*Virter) NetworkAdd ¶ added in v0.11.0
func (v *Virter) NetworkAdd(desc libvirtxml.Network) error
func (*Virter) NetworkConfig ¶ added in v0.19.0
NetworkConfig returns cloud-init configuration, initializing all networks with DHCP if possible.
See the end of ./doc/networks.md for limitations.
func (*Virter) NetworkGet ¶ added in v0.20.0
func (v *Virter) NetworkGet(netname string) (*libvirtxml.Network, error)
func (*Virter) NetworkList ¶ added in v0.11.0
func (v *Virter) NetworkList() ([]libvirtxml.Network, error)
func (*Virter) NetworkListAttached ¶ added in v0.11.0
func (*Virter) NetworkRemove ¶ added in v0.11.0
func (*Virter) NewDynamicLayer ¶ added in v0.14.0
func (v *Virter) NewDynamicLayer(name string, opts ...NewLayerOption) (*RawLayer, error)
NewDynamicLayer create a new (empty) layer suitable for attaching to a VM.
The volume name is prefix with WorkingLayerNamePrefix. To set a backing layer, set the minimum capacity and more, pass in one or more NewLayerOption.
func (*Virter) RemoveMACDHCPEntries ¶ added in v0.5.0
RemoveMACDHCPEntries removes DHCP host entries associated with the given MAC address
func (*Virter) VMCommit ¶
func (v *Virter) VMCommit(ctx context.Context, afterNotifier AfterNotifier, vmName, imageName string, shutdown bool, shutdownTimeout time.Duration, staticDHCP bool, opts ...LayerOperationOption) error
VMCommit commits a VM to an image. If shutdown is true, the VM is shut down before committing. If shutdown is false, the caller is responsible for ensuring that the VM is not running.
func (*Virter) VMExecContainer ¶ added in v0.23.0
func (v *Virter) VMExecContainer(ctx context.Context, containerProvider containerapi.ContainerProvider, vmNames []string, containerCfg *containerapi.ContainerConfig, copyStep *ProvisionContainerCopyStep) error
VMExecContainer runs a container against some VMs.
func (*Virter) VMExecCopy ¶ added in v0.3.0
func (*Virter) VMExecRsync ¶
func (v *Virter) VMExecRsync(ctx context.Context, copier netcopy.NetworkCopier, vmNames []string, rsyncStep *ProvisionRsyncStep) error
func (*Virter) VMExecShell ¶
func (v *Virter) VMExecShell(ctx context.Context, vmNames []string, shellStep *ProvisionShellStep) error
VMExecShell runs a simple shell command against some VMs.
func (*Virter) VMGetKnownHosts ¶ added in v0.20.0
func (*Virter) VMSSHSession ¶
VMSSHSession runs an interactive shell session in a VM
func (*Virter) WaitVmReady ¶ added in v0.16.0
func (v *Virter) WaitVmReady(ctx context.Context, shellClientBuilder ShellClientBuilder, vmName string, readyConfig VmReadyConfig) error
WaitVmReady repeatedly tries to connect to a VM and checks if it's ready to be used.
type VmReadyConfig ¶ added in v0.16.0
VmReadyConfig contains the configuration for waiting for a VM to be ready.
type VolumeLayer ¶ added in v0.14.0
type VolumeLayer struct {
RawLayer
}
VolumeLayer is an immutable RawLayer with additional restrictions.
A VolumeLayer is immutable. Since this is not enforceable on the libvirt level, enforcement is best-effort only. A VolumeLayer is always addressed by its content, i.e. the backing volume is named "virter:layer:sha256:<content-digest>".
func (*VolumeLayer) DiffID ¶ added in v0.14.0
func (vl *VolumeLayer) DiffID() (regv1.Hash, error)
DiffID computes a digest of the Uncompressed layer content.
Since a VolumeLayer is immutable and named after its content digest, this doesn't do any computation. Instead it uses its own name to determine the digest.
func (*VolumeLayer) MediaType ¶ added in v0.14.0
func (vl *VolumeLayer) MediaType() (types.MediaType, error)
MediaType returns the media type for the compressed Layer
func (*VolumeLayer) Squashed ¶ added in v0.14.0
func (vl *VolumeLayer) Squashed() (*RawLayer, error)
Squashed creates a squashed copy of this layer.
All backing layers are squashed into a single layer, the returned layer will not depend on any other layers.
func (*VolumeLayer) ToRegistryLayer ¶ added in v0.14.0
func (vl *VolumeLayer) ToRegistryLayer(opts ...LayerOperationOption) (regv1.Layer, error)
ToRegistryLayer wraps this VolumeLayer for pushing to a container registry.
A layer in a container registry is a compressed (gzipped) blob. To push a VolumeLayer to a registry, we need 1. the digest of the _uncompressed_ layer content 2. the compressed layer content 3. the digest of the _compressed_ layer content 4. the size of the _compressed_ layer content Points 2-4 are easily computed based on the uncompressed content. For efficiency we only compute it once, as the layers can be quite large.
func (*VolumeLayer) ToVolumeLayer ¶ added in v0.14.0
func (vl *VolumeLayer) ToVolumeLayer() (*VolumeLayer, error)
ToVolumeLayer converts this layer into a VolumeLayer.
Since VolumeLayer are immutable, this is a no-op.