Documentation ¶
Index ¶
- Constants
- func EnvmapToSlice(envMap map[string]string) []string
- func GenerateISO(files map[string][]byte) ([]byte, error)
- func QemuMAC(id uint) string
- type AfterNotifier
- type Disk
- type HTTPClient
- type ImageBuildConfig
- type ImageBuildTools
- type LibvirtConnection
- type LibvirtGetError
- type ProvisionConfig
- type ProvisionDockerCopyStep
- type ProvisionDockerStep
- type ProvisionOption
- type ProvisionRsyncStep
- type ProvisionShellStep
- type ProvisionStep
- type ReaderProxy
- type SSHPingConfig
- type ShellClient
- type ShellClientBuilder
- type VMConfig
- type VMDisk
- type VMDiskDevice
- type Virter
- func (v *Virter) AddDHCPHost(mac string, id uint) error
- func (v *Virter) Disconnect() 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) ImageExists(imageName string) (bool, error)
- func (v *Virter) ImagePull(ctx context.Context, client HTTPClient, readerProxy ReaderProxy, ...) error
- func (v *Virter) ImageRm(ctx context.Context, name string) error
- func (v *Virter) ImageSave(name string, to io.Writer) error
- func (v *Virter) PingSSH(ctx context.Context, shellClientBuilder ShellClientBuilder, vmName string, ...) error
- func (v *Virter) RemoveMACDHCPEntries(mac string) error
- func (v *Virter) VMCommit(ctx context.Context, afterNotifier AfterNotifier, vmName string, shutdown bool, ...) error
- func (v *Virter) VMExecCopy(ctx context.Context, copier netcopy.NetworkCopier, sourceSpecs []string, ...) error
- func (v *Virter) VMExecDocker(ctx context.Context, containerProvider containerapi.ContainerProvider, ...) error
- func (v *Virter) VMExecRsync(ctx context.Context, copier netcopy.NetworkCopier, vmNames []string, ...) error
- func (v *Virter) VMExecShell(ctx context.Context, vmNames []string, sshPrivateKey []byte, ...) error
- func (v *Virter) VMRm(vmName string, staticDHCP bool) error
- func (v *Virter) VMRun(vmConfig VMConfig) error
- func (v *Virter) VMSSHSession(ctx context.Context, vmName string, sshPrivateKey []byte) error
Constants ¶
const ( VMDiskDeviceDisk = "disk" VMDiskDeviceCDROM = "cdrom" )
Variables ¶
This section is empty.
Functions ¶
func EnvmapToSlice ¶
func GenerateISO ¶
GenerateISO generates a "CD-ROM" filesystem
Types ¶
type AfterNotifier ¶
AfterNotifier wait for a duration to elapse
type HTTPClient ¶
HTTPClient contains required HTTP methods.
type ImageBuildConfig ¶
type ImageBuildConfig struct { ContainerName string SSHPrivateKeyPath string SSHPrivateKey []byte 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 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) StorageVolCreateXML(Pool libvirt.StoragePool, XML string, Flags libvirt.StorageVolCreateFlags) (rVol libvirt.StorageVol, err error) StorageVolDelete(Vol libvirt.StorageVol, Flags libvirt.StorageVolDeleteFlags) (err error) StorageVolGetPath(Vol libvirt.StorageVol) (rName string, err error) StorageVolLookupByName(Pool libvirt.StoragePool, Name string) (rVol libvirt.StorageVol, err error) StorageVolUpload(Vol libvirt.StorageVol, outStream io.Reader, Offset uint64, Length uint64, Flags libvirt.StorageVolUploadFlags) (err error) StorageVolGetXMLDesc(Vol libvirt.StorageVol, Flags uint32) (rXML string, err error) StorageVolCreateXMLFrom(Pool libvirt.StoragePool, XML string, Clonevol libvirt.StorageVol, Flags libvirt.StorageVolCreateFlags) (rVol libvirt.StorageVol, err error) StorageVolDownload(Vol libvirt.StorageVol, inStream io.Writer, Offset uint64, Length uint64, Flags libvirt.StorageVolDownloadFlags) (err error) StorageVolGetInfo(Vol libvirt.StorageVol) (rType int8, rCapacity uint64, rAllocation uint64, 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 uint32, 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) DomainUndefine(Dom libvirt.Domain) (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 }
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 ProvisionConfig ¶
type ProvisionConfig struct { 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 docker client
type ProvisionDockerCopyStep ¶ added in v0.6.0
type ProvisionDockerStep ¶
type ProvisionDockerStep struct { Image string `toml:"image"` Env map[string]string `toml:"env"` Command []string `toml:"command"` Copy *ProvisionDockerCopyStep `toml:"copy"` }
ProvisionDockerStep is a single provisioniong step executed in a docker container
type ProvisionOption ¶
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 { Docker *ProvisionDockerStep `toml:"docker,omitempty"` Shell *ProvisionShellStep `toml:"shell,omitempty"` Rsync *ProvisionRsyncStep `toml:"rsync,omitempty"` }
ProvisionStep is a single provisioniong step
type ReaderProxy ¶
type ReaderProxy interface { SetTotal(total int64) ProxyReader(r io.ReadCloser) io.ReadCloser }
ReaderProxy wraps reading from a Reader with a known total size.
type SSHPingConfig ¶ added in v0.6.0
SSHPingConfig contains the configuration for pinging a VM via SSH
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 { ImageName string Name string MemoryKiB uint64 BootCapacityKiB uint64 VCPUs uint ID uint StaticDHCP bool SSHPublicKeys []string ConsolePath string Disks []Disk GDBPort uint }
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) *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) 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, pingConfig SSHPingConfig, buildConfig ImageBuildConfig) error
ImageBuild builds an image by running a VM and provisioning it
func (*Virter) ImageExists ¶
ImageExists checks whether an image called imageName exists in the libvirt virter storage pool.
func (*Virter) ImagePull ¶
func (v *Virter) ImagePull(ctx context.Context, client HTTPClient, readerProxy ReaderProxy, url, name string) error
ImagePull pulls an image from a URL into libvirt.
func (*Virter) PingSSH ¶ added in v0.6.0
func (v *Virter) PingSSH(ctx context.Context, shellClientBuilder ShellClientBuilder, vmName string, pingConfig SSHPingConfig) error
PingSSH repeatedly tries to connect to a VM via SSH until it succeeds
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 string, shutdown bool, shutdownTimeout time.Duration, staticDHCP bool) 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) VMExecCopy ¶ added in v0.3.0
func (*Virter) VMExecDocker ¶
func (v *Virter) VMExecDocker(ctx context.Context, containerProvider containerapi.ContainerProvider, vmNames []string, containerCfg *containerapi.ContainerConfig, sshPrivateKey []byte, copyStep *ProvisionDockerCopyStep) error
VMExecDocker runs a docker container against some VMs.
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, sshPrivateKey []byte, shellStep *ProvisionShellStep) error
VMExecShell runs a simple shell command against some VMs.