virter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2020 License: Apache-2.0 Imports: 30 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

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 DockerClient

type DockerClient interface {
	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error)
	ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error
	ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error
	ContainerWait(ctx context.Context, containerID string, condition container.WaitCondition) (<-chan container.ContainerWaitOKBody, <-chan error)
	ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error)
}

DockerClient contains the required docker methods.

type DockerContainerConfig

type DockerContainerConfig struct {
	ContainerName string   // the name of the container
	ImageName     string   // the name of the container image
	Env           []string // the environment (variables) passed to the container
}

DockerContainerConfig contains the configuration for a to be started container

type HTTPClient

type HTTPClient interface {
	Get(url string) (resp *http.Response, err error)
}

HTTPClient contains required HTTP methods.

type ImageBuildConfig

type ImageBuildConfig struct {
	DockerContainerConfig DockerContainerConfig
	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
	DockerClient       DockerClient
	AfterNotifier      AfterNotifier
}

ImageBuildTools includes the dependencies for building an image

type LibvirtConnection

type LibvirtConnection interface {
	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)
	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)
	LifecycleEvents() (<-chan libvirt.DomainEventLifecycleMsg, error)
	Disconnect() error
}

LibvirtConnection contains required libvirt connection methods.

type NetworkCopier

type NetworkCopier interface {
	// Copy transfers a list of files (source) from the local machine to
	// a target directory (destination) on a remote host (host).
	Copy(host string, source []string, destination string) error
}

NetworkCopier copies files over the network

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) NeedsDocker

func (p *ProvisionConfig) NeedsDocker() bool

NeedsDocker checks if there is a provision step that requires a docker client

type ProvisionDockerStep

type ProvisionDockerStep struct {
	Image string            `toml:"image"`
	Env   map[string]string `toml:"env"`
}

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 ShellClient

type ShellClient interface {
	Dial() 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
	VCPUs         uint
	ID            uint
	SSHPublicKeys []string
	SSHPrivateKey []byte
	WaitSSH       bool
	SSHPingCount  int
	SSHPingPeriod time.Duration
	ConsoleFile   *VMConsoleFile
	Disks         []Disk
}

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 VMConsoleFile

type VMConsoleFile struct {
	Path     string
	OwnerUID uint32
	OwnerGID uint32
}

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) Disconnect

func (v *Virter) Disconnect() error

Disconnect disconnects virter's connection to libvirt

func (*Virter) ImageBuild

func (v *Virter) ImageBuild(ctx context.Context, tools ImageBuildTools, vmConfig VMConfig, 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(client HTTPClient, readerProxy ReaderProxy, url string, name string) error

ImagePull pulls an image from a URL into libvirt.

func (*Virter) VMCommit

func (v *Virter) VMCommit(afterNotifier AfterNotifier, vmName string, shutdown bool, shutdownTimeout time.Duration) error

VMCommit commits a VM to an image. If shutdown is true, a goroutine to watch for events will be started. This goroutine will only terminate when the libvirt connection is closed, so take care of leaking goroutines.

func (*Virter) VMExecDocker

func (v *Virter) VMExecDocker(ctx context.Context, docker DockerClient, vmNames []string, dockerContainerConfig DockerContainerConfig, sshPrivateKey []byte) error

VMExecDocker runs a docker container against some VMs.

func (*Virter) VMExecRsync

func (v *Virter) VMExecRsync(ctx context.Context, copier 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) error

VMRm removes a VM.

func (*Virter) VMRun

func (v *Virter) VMRun(shellClientBuilder ShellClientBuilder, 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