libvirttools

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: Apache-2.0 Imports: 36 Imported by: 8

Documentation

Index

Constants

View Source
const (

	// ContainerNsUUID template for container ns uuid generation
	ContainerNsUUID = "67b7fb47-7735-4b64-86d2-6d062d121966"

	// KubernetesPodNameLabel is pod name container label (copied from kubetypes).
	KubernetesPodNameLabel = "io.kubernetes.pod.name"
	// KubernetesPodNamespaceLabel is pod namespace container label (copied from kubetypes),
	KubernetesPodNamespaceLabel = "io.kubernetes.pod.namespace"
	// KubernetesPodUIDLabel is uid container label (copied from kubetypes).
	KubernetesPodUIDLabel = "io.kubernetes.pod.uid"
	// KubernetesContainerNameLabel is container name label (copied from kubetypes)
	KubernetesContainerNameLabel = "io.kubernetes.container.name"
)

Variables

This section is empty.

Functions

func ChownForEmulator added in v0.9.0

func ChownForEmulator(filePath string) error

ChownForEmulator makes a file or directory owned by the emulator user.

func SetConfigIsoDir added in v0.9.4

func SetConfigIsoDir(dir string)

SetConfigIsoDir sets a directory for config iso dir. It can be useful in tests

Types

type CloudInitGenerator

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

CloudInitGenerator provides a common part for Cloud Init ISO drive preparation for NoCloud and ConfigDrive volume sources.

func NewCloudInitGenerator

func NewCloudInitGenerator(config *types.VMConfig, isoDir string) *CloudInitGenerator

NewCloudInitGenerator returns new CloudInitGenerator.

func (*CloudInitGenerator) DiskDef added in v0.9.4

DiskDef returns a DomainDisk definition for Cloud Init ISO image to be included in VM pod libvirt domain definition.

func (*CloudInitGenerator) GenerateImage added in v0.9.4

func (g *CloudInitGenerator) GenerateImage(volumeMap diskPathMap) error

GenerateImage collects metadata, userdata and network configuration and uses them to prepare an ISO image for NoCloud or ConfigDrive selecting the type using an info from pod annotations.

func (*CloudInitGenerator) IsoPath

func (g *CloudInitGenerator) IsoPath() string

IsoPath returns a full path to iso image with configuration for VM pod.

type Connection

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

Connection combines accessors for methods which operated on libvirt storage and domains.

func NewConnection

func NewConnection(uri string) (*Connection, error)

NewConnection uses uri to construct connection to libvirt used later by both storage and domains manipulators.

func (Connection) CreateStoragePool added in v1.0.0

func (sc Connection) CreateStoragePool(def *libvirtxml.StoragePool) (virt.StoragePool, error)

func (Connection) DefineDomain added in v1.0.0

func (dc Connection) DefineDomain(def *libvirtxml.Domain) (virt.Domain, error)

func (Connection) DefineSecret added in v1.0.0

func (dc Connection) DefineSecret(def *libvirtxml.Secret) (virt.Secret, error)

func (Connection) ListDomains added in v1.0.0

func (dc Connection) ListDomains() ([]virt.Domain, error)

func (Connection) LookupDomainByName added in v1.0.0

func (dc Connection) LookupDomainByName(name string) (virt.Domain, error)

func (Connection) LookupDomainByUUIDString added in v1.0.0

func (dc Connection) LookupDomainByUUIDString(uuid string) (virt.Domain, error)

func (Connection) LookupSecretByUUIDString added in v1.0.0

func (dc Connection) LookupSecretByUUIDString(uuid string) (virt.Secret, error)

func (Connection) LookupSecretByUsageName added in v1.0.0

func (dc Connection) LookupSecretByUsageName(usageType string, usageName string) (virt.Secret, error)

func (Connection) LookupStoragePoolByName added in v1.0.0

func (sc Connection) LookupStoragePoolByName(name string) (virt.StoragePool, error)

type ImageManager

type ImageManager interface {
	GetImagePathAndVirtualSize(ref string) (string, uint64, error)
}

ImageManager describes a images info provider.

type VMVolume

type VMVolume interface {
	UUID() string
	Setup() (*libvirtxml.DomainDisk, error)
	WriteImage(diskPathMap) error
	Teardown() error
}

VMVolume describes a volume provider.

func GetConfigVolume added in v0.9.4

func GetConfigVolume(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

GetConfigVolume returns a config volume source which will produce an ISO image with CloudInit compatible configuration data.

func GetRootVolume

func GetRootVolume(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

GetRootVolume returns volume source for root volume clone.

func ScanFlexVolumes added in v1.0.0

func ScanFlexVolumes(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

ScanFlexVolumes using prepared by kubelet volumes and contained in pod sandbox annotations prepares volumes to be passed to libvirt as a DomainDisk definitions.

type VMVolumeSource

type VMVolumeSource func(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

VMVolumeSource is a function that provides `VMVolume`s for VMs

func CombineVMVolumeSources

func CombineVMVolumeSources(srcs ...VMVolumeSource) VMVolumeSource

CombineVMVolumeSources returns a function which will pass VM configuration to all listed volumes sources combining returned by them `VMVolume`s.

func GetDefaultVolumeSource added in v1.0.2

func GetDefaultVolumeSource() VMVolumeSource

GetDefaultVolumeSource returns a volume source that supports root volume, flexvolumes and a ConfigSource for cloud-init

type VirtualizationConfig added in v1.1.0

type VirtualizationConfig struct {
	// True if KVM should be disabled
	DisableKVM bool
	// True if SR-IOV support needs to be enabled
	EnableSriov bool
	// List of raw devices that can be accessed by the VM.
	RawDevices []string
	// Kubelet's root dir
	// FIXME: kubelet's --root-dir may be something other than /var/lib/kubelet
	// Need to remove it from daemonset mounts (both dev and non-dev)
	// Use 'nsenter -t 1 -m -- tar ...' or something to grab the path
	// from root namespace
	KubeletRootDir string
	// The path of streamer socket used for
	// logging. By default, the path is empty. When the path is empty,
	// logging is disabled for the VMs.
	StreamerSocketPath string
	// The name of libvirt volume pool to use for the VMs.
	VolumePoolName string
}

VirtualizationConfig specifies configuration options for VirtualizationTool.

type VirtualizationTool

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

VirtualizationTool provides methods to operate on libvirt.

func NewVirtualizationTool

func NewVirtualizationTool(domainConn virt.DomainConnection,
	storageConn virt.StorageConnection, imageManager ImageManager,
	metadataStore metadata.Store, volumeSource VMVolumeSource,
	config VirtualizationConfig) *VirtualizationTool

NewVirtualizationTool verifies existence of volumes pool in libvirt store and returns initialized VirtualizationTool.

func (*VirtualizationTool) ContainerInfo added in v1.0.3

func (v *VirtualizationTool) ContainerInfo(containerID string) (*types.ContainerInfo, error)

ContainerInfo returns info for the specified container, making sure it's also present among libvirt domains. If it isn't, the function returns nil

func (*VirtualizationTool) CreateContainer

func (v *VirtualizationTool) CreateContainer(config *types.VMConfig, netFdKey string) (string, error)

CreateContainer defines libvirt domain for VM, prepares it's disks and stores all info in metadata store. It returns domain uuid generated basing on pod sandbox id.

func (*VirtualizationTool) DomainConnection

func (v *VirtualizationTool) DomainConnection() virt.DomainConnection

DomainConnection implements volumeOwner DomainConnection method

func (*VirtualizationTool) GarbageCollect added in v0.8.1

func (v *VirtualizationTool) GarbageCollect() (allErrors []error)

GarbageCollect retrieves from metadata store list of container ids, passes it to all GC submodules, collecting from them list of possible errors, which is returned to outer scope

func (*VirtualizationTool) ImageManager

func (v *VirtualizationTool) ImageManager() ImageManager

ImageManager implements volumeOwner ImageManager method

func (*VirtualizationTool) KubeletRootDir

func (v *VirtualizationTool) KubeletRootDir() string

KubeletRootDir implements volumeOwner KubeletRootDir method

func (*VirtualizationTool) ListContainers

func (v *VirtualizationTool) ListContainers(filter *types.ContainerFilter) ([]*types.ContainerInfo, error)

ListContainers queries libvirt for domains denoted by container id or pod standbox id or for all domains and after gathering theirs description from metadata and conversion of status from libvirt to kubeapi compatible returns them as a list of kubeapi Containers.

func (*VirtualizationTool) RawDevices

func (v *VirtualizationTool) RawDevices() []string

RawDevices implements volumeOwner RawDevices method

func (*VirtualizationTool) RemoveContainer

func (v *VirtualizationTool) RemoveContainer(containerID string) error

RemoveContainer tries to gracefully stop domain, then forcibly removes it even if it's still running. It waits up to 5 sec for doing the job by libvirt.

func (*VirtualizationTool) SetClock

func (v *VirtualizationTool) SetClock(clock clockwork.Clock)

SetClock sets the clock to use (used in tests)

func (*VirtualizationTool) StartContainer

func (v *VirtualizationTool) StartContainer(containerID string) error

StartContainer calls libvirt to start domain, waits up to 10 seconds for DOMAIN_RUNNING state, then updates it's state in metadata store. If there was an error it will be returned to caller after an domain removal attempt. If also it had an error - both of them will be combined.

func (*VirtualizationTool) StopContainer

func (v *VirtualizationTool) StopContainer(containerID string, timeout time.Duration) error

StopContainer calls graceful shutdown of domain and if it was non successful it calls libvirt to destroy that domain. Successful shutdown or destroy of domain is followed by removal of VM info from metadata store. Succeeded removal of metadata is followed by volumes cleanup.

func (*VirtualizationTool) StoragePool

func (v *VirtualizationTool) StoragePool() (virt.StoragePool, error)

StoragePool implements volumeOwner StoragePool method

Jump to

Keyboard shortcuts

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