libvirttools

package
v0.9.5-test5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2018 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (

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

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 *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 VMConfig

type VMConfig struct {
	// Id of the containing pod sandbox
	PodSandboxID string
	// Name of the containing pod sandbox
	PodName string
	// Namespace of the containing pod sandbox
	PodNamespace string
	// Name of the container (VM)
	Name string
	// Image to use for the VM
	Image string
	// Attempt is the number of container creation attempts before this one
	Attempt uint32
	// Memory limit in bytes. Default: 0 (not specified)
	MemoryLimitInBytes int64
	// CPU shares (relative weight vs. other containers). Default: 0 (not specified)
	CPUShares int64
	// CPU CFS (Completely Fair Scheduler) period. Default: 0 (not specified)
	CPUPeriod int64
	// CPU CFS (Completely Fair Scheduler) quota. Default: 0 (not specified)
	CPUQuota int64
	// Annotations for the containing pod
	PodAnnotations map[string]string
	// Annotations for the container
	ContainerAnnotations map[string]string
	// Labels for the container
	ContainerLabels map[string]string
	// Parsed representation of pod annotations. Populated by LoadAnnotations() call
	ParsedAnnotations *VirtletAnnotations
	// Domain UUID (set by the CreateContainer)
	// TODO: this field should be moved to VMStatus
	DomainUUID string
	// Environment variables to set in the VM
	Environment []*VMKeyValue
	// Host directories corresponding to the volumes which are to
	// be mounted inside the VM
	Mounts []*VMMount
	// ContainerSideNetwork stores info about container side network configuration
	ContainerSideNetwork *network.ContainerSideNetwork
}

VMConfig contains the information needed to start create a VM TODO: use this struct to store VM metadata

func GetVMConfig

GetVMConfig translates CRI's CreateContainerRequest and CNI info to a VMConfig

func (*VMConfig) LoadAnnotations

func (c *VMConfig) LoadAnnotations() error

LoadAnnotations parses pod annotations in the VM config an populates the ParsedAnnotations field.

type VMKeyValue

type VMKeyValue struct {
	Key   string
	Value string
}

VMKeyValue denotes a key-value pair

type VMMount

type VMMount struct {
	ContainerPath string
	HostPath      string
}

VMMount denotes a host directory corresponding to a volume which is to be mounted inside the VM

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 *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 *VMConfig, owner volumeOwner) ([]VMVolume, error)

GetRootVolume returns volume source for root volume clone.

func ScanFlexVolumes added in v1.0.0

func ScanFlexVolumes(config *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 *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.

type VirtletAnnotations

type VirtletAnnotations struct {
	VCPUCount         int
	ImageType         imageType
	MetaData          map[string]interface{}
	UserData          map[string]interface{}
	UserDataOverwrite bool
	UserDataScript    string
	SSHKeys           []string
	DiskDriver        diskDriverName
}

VirtletAnnotations contains parsed values for pod annotations supported by Virtlet.

func LoadAnnotations

func LoadAnnotations(ns string, podAnnotations map[string]string) (*VirtletAnnotations, error)

LoadAnnotations parses map of strings to VirtletAnnotations using provided ns value.

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, volumePoolName, rawDevices string, volumeSource VMVolumeSource) *VirtualizationTool

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

func (*VirtualizationTool) ContainerStatus

func (v *VirtualizationTool) ContainerStatus(containerID string) (*kubeapi.ContainerStatus, error)

ContainerStatus queries libvirt for domain setatus, converts it to corresponding kubeapi container status including container info retrieved from metadata store.

func (*VirtualizationTool) CreateContainer

func (v *VirtualizationTool) CreateContainer(config *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 *kubeapi.ContainerFilter) ([]*kubeapi.Container, 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) 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