libvirt

package
v0.0.0-...-9fc8b42 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: UPL-1.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverName = "libvirt"

	// Manually specify the PCI bus/port for the bridge network
	// interface.  This ensures that the device name within Linux
	// can be calculated and fed into any configuration that gets
	// set within a VM.
	BridgeBus  = 1
	BridgeSlot = 0

	// Manually specify the PCI bus/port for user network interface
	// for the same reasons as the bridge network.
	UserBus  = 0
	UserSlot = 2

	// Calculate the bridge network device name from the bus/port
	// used to create it, following the Linux consistent network
	// device naming convention.  'en' stands for ethernet, 'p<num>'
	// stands for PCI port number (read: bus), 's<num>' stands for
	// the slot.
	BridgeNicPattern = "enp%ds%d"
)

Variables

This section is empty.

Functions

func CreateDriver

func CreateDriver(config *conftypes.Config, clusterConfig *conftypes.ClusterConfig) (driver.ClusterDriver, error)

func CreateStoragePool

func CreateStoragePool(l *libvirt.Libvirt, name string, path string) (*libvirt.StoragePool, error)

CreateStoagePool creates a storage pool and returns the libvirt object

func DoesBaseImageExist

func DoesBaseImageExist(l *libvirt.Libvirt, pool *libvirt.StoragePool, bootVolumeName string) bool

DoesBaseImageExist returns if the base image has been previously downloaded or manually placed in the default images pool

func FindOrCreateStoragePool

func FindOrCreateStoragePool(l *libvirt.Libvirt, uri *url.URL, storagePool string) (*libvirt.StoragePool, error)

FindOrCreateStoragePool gives back a reasonable place to locate volumes. First it checks to see if a storage pool is specified. If specified, then it proceeds to use it. Otherwise, it checks to see if a pool that matches the default configuration already exists. If so, that one is used. If not, it will scan all pools for something that looks acceptable. "Acceptable" is intentionally not defined. If an acceptable option does not exist, a new pool will be created with useful defaults.

func FindStoragePool

func FindStoragePool(l *libvirt.Libvirt, storagePool, poolPath string) (*libvirt.StoragePool, error)

FindStoragePool gives back a reasonable place to locate volumes. First it checks to see if a storage pool is specified. If specified, then it proceeds to use it. Otherwise, it checks to see if a pool that matches the default configuration already exists. If so, that one is used. If not, it will scan all pools for something that looks acceptable. "Acceptable" is intentionally not defined. If an acceptable option does not exist, no volume is returned

func GetStoragePoolPath

func GetStoragePoolPath(l *libvirt.Libvirt, pool *libvirt.StoragePool) (string, error)

GetStoragePoolPath gives back the path for a storage pool. If the storage pool is not backed by a path, an empty string is returned along with an error.

func StartStoragePool

func StartStoragePool(l *libvirt.Libvirt, pool *libvirt.StoragePool) error

StartStoragePool starts a storage pool if it is not already started.

func TransferBaseImage

func TransferBaseImage(l *libvirt.Libvirt, imageName string, pool *libvirt.StoragePool, volumeName string, arch string) error

TransferBaseImage uses the libvirt API to upload the boot.qcow2 from a container image to the target libvirtd instance, locating in the given Pool and assigning in the given name.

func TransferToPool

func TransferToPool(l *libvirt.Libvirt, in io.Reader, pool *libvirt.StoragePool, volumeName string, volType string, reupload bool, size uint64) error

TransferToPool uses the libvirt API to upload a stream to the target libvirtd instance, locating it in the given pool and assigning it the given name. This function does not create the pool if it does not already exist.

If reupload is false, the image is not re-transferred if it already exists on the target libvirt instance.

If size is non-zero, the volume is resized after upload to the given value.

Types

type ClusterData

type ClusterData struct {
	Host string
	IP   string
	Port uint16
}

type Domain

type Domain struct {
	Name               string
	Description        string
	VolumePool         string
	Volume             string
	IgnitionPath       string
	Hypervisor         string
	Networks           []Network
	Memory             int
	MemoryCapacityUnit string
	CPUs               int
	CPUArch            string
}

Domain defines a VM

type HostData

type HostData struct {
	IPs   UsedIPs
	Ports UsedPorts
}

type LibvirtDriver

type LibvirtDriver struct {
	Name   string // Name is the name of the cluster
	Config conftypes.ClusterConfig

	// Basic connection information
	Connection *libvirt.Libvirt // Connection is the connection to libvirt
	URI        *url.URL         // URI is the URI of the libvirt target
	Local      bool             // Local indicates if the libvirt target is a local or remote system
	TargetIP   string           // TargetIP is the IP address of the libvirt target

	KubeAPIServerIP          string // KubeAPIServerIP is the IP address of Kubernetes from the perspective of the cluster nodes
	TunnelPort               uint16 // TunnelPort is a port on the target host that is used to tunnel connections to the Kubernetes API Server in the VM from the host
	LocalKubeconfigName      string
	LocalKubeconfigPath      string
	VMKubeconfigName         string
	VMKubeconfigPath         string
	PKIInfo                  *kubepki.PKIInfo
	NetworkName              string
	BridgeNetworking         bool
	NetworkingResolved       bool
	KubeVersion              string
	BootVolumeContainerImage string
	CPUArch                  string
	Info                     func(...interface{})
	Infof                    func(string, ...interface{})
	UploadCertificateKey     string
}

LibvirtDriver manages resource creation and cluster management for libvirt targets.

func (*LibvirtDriver) Close

func (ld *LibvirtDriver) Close() error

func (*LibvirtDriver) DefaultCNIInterfaces

func (ld *LibvirtDriver) DefaultCNIInterfaces() []string

func (*LibvirtDriver) Delete

func (ld *LibvirtDriver) Delete() error

func (*LibvirtDriver) GetKubeAPIServerAddress

func (ld *LibvirtDriver) GetKubeAPIServerAddress() string

func (*LibvirtDriver) GetKubeconfigPath

func (ld *LibvirtDriver) GetKubeconfigPath() string

func (*LibvirtDriver) Join

func (ld *LibvirtDriver) Join(kubeconfigPath string, controlPlaneNodes int, workerNodes int) error

func (*LibvirtDriver) PostInstallHelpStanza

func (ld *LibvirtDriver) PostInstallHelpStanza() string

func (*LibvirtDriver) PostStart

func (ld *LibvirtDriver) PostStart() error

func (*LibvirtDriver) Stage

func (ld *LibvirtDriver) Stage(version string) (string, string, bool, error)

Stage is a no-op

func (*LibvirtDriver) Start

func (ld *LibvirtDriver) Start() (bool, bool, error)

func (*LibvirtDriver) Stop

func (ld *LibvirtDriver) Stop() error

type LibvirtNetwork

type LibvirtNetwork struct {
	IP struct {
		Address string `xml:"address,attr"`
		Netmask string `xml:"netmask,attr"`
	} `xml:"ip"`
}

type Network

type Network struct {
	Type         string
	Network      string
	Bus          string
	Slot         string
	PortForwards []PortForward
}

Network defines a network for a VM

type NetworkInformation

type NetworkInformation struct {
	Hosts    map[string]*HostData
	Clusters map[string]*ClusterData
}

type Pool

type Pool struct {
	Name string
	Path string
}

Pool defines a libvirt Pool

type PortForward

type PortForward struct {
	From   uint16
	To     uint16
	Listen string
}

PortForward defines a pair of ports. From is forwarded to To. Listen is the IP to listen on.

type StoragePool

type StoragePool struct {
	XMLName xml.Name          `xml:"pool"`
	Name    string            `xml:"name"`
	Type    string            `xml:"type,attr"`
	Target  StoragePoolTarget `xml:"target"`
	Source  StoragePoolSource `xml:"source"`
}

type StoragePoolDir

type StoragePoolDir struct {
	Path string `xml:"path,attr"`
}

type StoragePoolPermissions

type StoragePoolPermissions struct {
	Mode string `xml:"mode"`
}

type StoragePoolSource

type StoragePoolSource struct {
}

type StoragePoolTarget

type StoragePoolTarget struct {
	Path        string                 `xml:"path"`
	Permissions StoragePoolPermissions `xml:"permissions"`
}

type UsedIPs

type UsedIPs map[string]bool

type UsedPorts

type UsedPorts map[uint16]bool

type Volume

type Volume struct {
	Key                string
	Name               string
	Path               string
	PathToBackingStore string
	Size               uint64
	StorageUnit        string
	Type               string
}

Volume defines a VM volume

Jump to

Keyboard shortcuts

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