virter

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VMDiskDeviceDisk  = "disk"
	VMDiskDeviceCDROM = "cdrom"
)

Variables

This section is empty.

Functions

func EnvmapToSlice

func EnvmapToSlice(envMap map[string]string) []string

func GenerateISO

func GenerateISO(files map[string][]byte) ([]byte, error)

GenerateISO generates a "CD-ROM" filesystem

func QemuMAC added in v0.5.0

func QemuMAC(id uint) string

QemuMAC calculates a MAC address for a given id

Types

type AfterNotifier

type AfterNotifier interface {
	After(d time.Duration) <-chan time.Time
}

AfterNotifier wait for a duration to elapse

type Disk added in v0.2.0

type Disk interface {
	GetName() string
	GetSizeKiB() uint64
	GetFormat() string
	GetBus() string
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (resp *http.Response, err error)
}

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

type LibvirtGetError struct {
	Message  string
	Err      error
	NotFound bool
}

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 ProvisionDockerCopyStep struct {
	Source string `toml:"source"`
	Dest   string `toml:"dest"`
}

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

type ProvisionOption struct {
	FilePath  string
	Overrides []string
}

ProvisionOption sumarizes all the options used for generating the final ProvisionConfig

type ProvisionRsyncStep

type ProvisionRsyncStep struct {
	Source string `toml:"source"`
	Dest   string `toml:"dest"`
}

ProvisionRsyncStep is used to copy files to the target via the rsync utility

type ProvisionShellStep

type ProvisionShellStep struct {
	Script string            `toml:"script"`
	Env    map[string]string `toml:"env"`
}

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

type SSHPingConfig struct {
	SSHPrivateKey []byte
	SSHPingCount  int
	SSHPingPeriod time.Duration
}

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

func CheckVMConfig(vmConfig VMConfig) (VMConfig, error)

CheckVMConfig takes a VMConfig, does basic checks, and returns it back.

type VMDisk added in v0.2.0

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

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

func (v *Virter) AddDHCPHost(mac string, id uint) error

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

func (v *Virter) Disconnect() error

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

func (v *Virter) GetVMID(wantedID uint, expectDHCPEntry bool) (uint, error)

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

func (v *Virter) ImageExists(imageName string) (bool, error)

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) ImageRm added in v0.3.0

func (v *Virter) ImageRm(ctx context.Context, name string) error

ImageRm removes an image from libvirt.

func (*Virter) ImageSave added in v0.3.0

func (v *Virter) ImageSave(name string, to io.Writer) error

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

func (v *Virter) RemoveMACDHCPEntries(mac string) error

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 (v *Virter) VMExecCopy(ctx context.Context, copier netcopy.NetworkCopier, sourceSpecs []string, destSpec string) error

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.

func (*Virter) VMRm

func (v *Virter) VMRm(vmName string, staticDHCP bool) error

VMRm removes a VM.

func (*Virter) VMRun

func (v *Virter) VMRun(vmConfig VMConfig) error

VMRun starts a VM.

func (*Virter) VMSSHSession

func (v *Virter) VMSSHSession(ctx context.Context, vmName string, sshPrivateKey []byte) error

VMSSHSession runs an interactive shell session in a VM

Jump to

Keyboard shortcuts

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