virtualmachine

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 53 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBackingUp = pkgerr.NoRequeueNoErr("backed up vm")
View Source
var (
	ErrSnapshotNotFound = errors.New("snapshot not found")
)

Snapshot related errors.

View Source
var VMDeletePropertiesSelector = []string{
	"recentTask",
	"config.extraConfig",
	"summary.runtime.connectionState",
}

VMDeletePropertiesSelector is the set of VM properties fetched at the start of provider DeleteVirtualMachine.

Functions

func BackupVirtualMachine

func BackupVirtualMachine(opts BackupVirtualMachineOptions) (result error)

BackupVirtualMachine backs up the required data of a VM into its ExtraConfig. Currently, the following data is backed up: - VM Kubernetes resource in YAMl. - Additional VM-relevant Kubernetes resources in YAML, separated by "---". - PVC disk data in JSON format (if DiskUUIDToPVC is not empty).

func CPUQuantityToMhz

func CPUQuantityToMhz(q resource.Quantity, cpuFreqMhz uint64) int64

func CleanupVMServiceState added in v1.10.0

func CleanupVMServiceState(
	vmCtx pkgctx.VirtualMachineContext,
	vcVM *object.VirtualMachine) error

CleanupVMServiceState removes all modifications made by VM Operator from a vCenter VM. This should be called when deleting a VM resource with the skip-delete-platform-resource annotation to ensure the vCenter VM is left in a clean state.

func CloneVM added in v1.10.0

func CloneVM(
	vmCtx pkgctx.VirtualMachineContext,
	vimClient *vim25.Client,
	vmPubReq *vmopv1.VirtualMachinePublishRequest,
	cl *imgregv1.ContentLibrary,
	storagePolicyID string) (string, error)

CloneVM clones a source virtual machine, as a VM template, into an inventory-backed content library as defined by the VirtualMachinePublishRequest object.

func ConfigSpecFromVMClassDevices

func ConfigSpecFromVMClassDevices(vmClassSpec *vmopv1.VirtualMachineClassSpec) vimtypes.VirtualMachineConfigSpec

ConfigSpecFromVMClassDevices creates a ConfigSpec that adds the standalone hardware devices from the VMClass if any. This ConfigSpec will be used as the class ConfigSpec to CreateConfigSpec, with the rest of the class fields - like CPU count - applied on top.

func CreateConfigSpec

CreateConfigSpec returns an initial ConfigSpec that is created by overlaying the base ConfigSpec with VM Class spec and other arguments. TODO: We eventually need to de-dupe much of this with the ConfigSpec manipulation that's later done in the "update" pre-power on path. That operates on a ConfigInfo so we'd need to populate that from the config we build here.

func CreateConfigSpecForPlacement

func CreateConfigSpecForPlacement(
	vmCtx pkgctx.VirtualMachineContext,
	configSpec vimtypes.VirtualMachineConfigSpec,
	storageClassesToIDs map[string]string) (vimtypes.VirtualMachineConfigSpec, error)

CreateConfigSpecForPlacement creates a ConfigSpec that is suitable for Placement. configSpec will likely be - or at least derived from - the ConfigSpec returned by CreateConfigSpec above.

func CreateInstanceStorageDiskDevices

func CreateInstanceStorageDiskDevices(isVolumes []vmopv1.VirtualMachineVolume) []vimtypes.BaseVirtualDevice

func CreatePCIDevicesFromConfigSpec

func CreatePCIDevicesFromConfigSpec(pciDevsFromConfigSpec []*vimtypes.VirtualPCIPassthrough) []vimtypes.BaseVirtualDevice

CreatePCIDevicesFromConfigSpec creates vim25 VirtualDevices from the specified list of PCI devices from the VM Class ConfigSpec.

func CreatePCIDevicesFromVMClass

func CreatePCIDevicesFromVMClass(pciDevicesFromVMClass vmopv1.VirtualDevices) []vimtypes.BaseVirtualDevice

CreatePCIDevicesFromVMClass creates vim25 VirtualDevices from the specified list of PCI devices from VM Class spec.

func CreatePCIPassThroughDevice

func CreatePCIPassThroughDevice(deviceKey int32, backingInfo vimtypes.BaseVirtualDeviceBackingInfo) vimtypes.BaseVirtualDevice

func CreateSnapshot added in v1.10.0

func CreateSnapshot(args SnapshotArgs) (*vimtypes.VirtualMachineSnapshotTree, error)

func DecryptWebMKS

func DecryptWebMKS(privKey *rsa.PrivateKey, ciphertext string) (string, error)

func DeleteSnapshot added in v1.10.0

func DeleteSnapshot(args SnapshotArgs) error

func DeleteVirtualMachine

func DeleteVirtualMachine(
	vmCtx pkgctx.VirtualMachineContext,
	vcVM *object.VirtualMachine) error

func EncryptWebMKS

func EncryptWebMKS(pubKey string, plaintext string) (string, error)

func FilteredExtraConfig added in v1.10.0

func FilteredExtraConfig(
	in pkgutil.OptionValues,
	reset bool) (pkgutil.OptionValues, error)

FilteredExtraConfig removes or resets those key entries which have prefix that is in the deny key prefix list, but not in the allow key list. It returns a new filtered OptionValues object if the operation is successful.

func FindSnapshot added in v1.10.0

func FindSnapshot(
	moVM mo.VirtualMachine,
	snapshotName string) (*vimtypes.VirtualMachineSnapshotTree, error)

FindSnapshot returns the snapshot matching a given name from the snapshots present on a VM. Much of this is taken from Govmomi, but we maintain our version because we don't want to make another property collector round trip to fetch those properties again.

func GetAllSnapshotSize added in v1.10.0

func GetAllSnapshotSize(
	ctx context.Context,
	moVM mo.VirtualMachine) (total, fcdTotal int64, _ error)

GetAllSnapshotSize calculates the size of a all snapshots of the VM in bytes. It returns two sizes, first one includes the memory file, the vmdk files, and the vmsn file, excludes FCDs. Second one only includes FCDs.

func GetBackingFileNameByImageRef added in v1.10.0

func GetBackingFileNameByImageRef(
	ctx context.Context,
	client ctrlclient.Client,
	imageRef vmopv1.VirtualMachineImageRef,
	ns string,
	syncFile bool,
	libManager *library.Manager) (string, error)

GetBackingFileNameByImageRef returns the ISO type content library file name based on the given VirtualMachineImageRef. It also syncs the content library if needed to ensure the file is available for CD-ROM connection.

func GetDefaultDiskProvisioningType

func GetDefaultDiskProvisioningType(
	vmCtx pkgctx.VirtualMachineContext,
	vcClient *vcclient.Client,
	storageProfileID string) (string, error)

GetDefaultDiskProvisioningType gets the default disk provisioning type specified for the VM.

func GetExtraConfigFromObject added in v1.10.0

func GetExtraConfigFromObject(
	ctx context.Context,
	vm *object.VirtualMachine) (pkgutil.OptionValues, error)

GetExtraConfigFromObject assumes VirtualMachine object is created properly with a vim25 client and a managed reference.

func GetExtraConfigGuestInfo

func GetExtraConfigGuestInfo(
	ctx context.Context,
	vm *object.VirtualMachine) (map[string]string, error)

func GetSnapshotSize added in v1.10.0

func GetSnapshotSize(
	ctx context.Context,
	moVM mo.VirtualMachine,
	vmSnapshot *vimtypes.ManagedObjectReference,
) (total, fcdTotal int64, _ error)

GetSnapshotSize calculates the size of a given snapshot in bytes. It returns two sizes, first one includes the memory file, the vmdk files, and the vmsn file, excludes FCDs. Second one only includes FCDs. The algorithm use almost the same logic as how VC UI calculates the snapshot size. The only difference is that this function returns the size of FCDs as a different variable, and returns an error if the snapshot is not found.

func GetVMClusterComputeResource

func GetVMClusterComputeResource(
	ctx context.Context,
	vcVM *object.VirtualMachine) (*object.ClusterComputeResource, error)

GetVMClusterComputeResource returns the VM's ClusterComputeResource.

func GetWebConsoleTicket

func GetWebConsoleTicket(
	vmCtx pkgctx.VirtualMachineContext,
	vm *object.VirtualMachine,
	pubKey string) (string, error)

func MemoryQuantityToMb

func MemoryQuantityToMb(q resource.Quantity) int64

func SnapshotVirtualMachine added in v1.10.0

func SnapshotVirtualMachine(
	args SnapshotArgs) (*vimtypes.VirtualMachineSnapshotTree, error)

func UpdateCdromDeviceChangesLegacy added in v1.10.0

func UpdateCdromDeviceChangesLegacy(
	vmCtx pkgctx.VirtualMachineContext,
	restClient *rest.Client,
	k8sClient ctrlclient.Client,
	curDevices object.VirtualDeviceList) ([]vimtypes.BaseVirtualDeviceConfigSpec, error)

UpdateCdromDeviceChangesLegacy implements CD-ROM reconciliation with automatic controller assignment (VMSharedDisks disabled). It creates controllers on demand if needed.

func UpdateCdromDeviceChangesWithSharedDisks added in v1.10.0

func UpdateCdromDeviceChangesWithSharedDisks(
	ctx context.Context,
	k8sClient ctrlclient.Client,
	vm *vmopv1.VirtualMachine,
	vcVM *object.VirtualMachine,
	moVM mo.VirtualMachine,
	configSpec *vimtypes.VirtualMachineConfigSpec) error

UpdateCdromDeviceChangesWithSharedDisks implements CD-ROM reconciliation with placement change support (VMSharedDisks enabled). It waits for controller changes to complete before reconciling CD-ROMs to ensure controllers are fully created before CD-ROMs reference them.

func UpdateConfigSpecCdromDeviceConnection

func UpdateConfigSpecCdromDeviceConnection(
	vmCtx pkgctx.VirtualMachineContext,
	restClient *rest.Client,
	k8sClient ctrlclient.Client,
	config *vimtypes.VirtualMachineConfigInfo,
	configSpec *vimtypes.VirtualMachineConfigSpec) error

UpdateConfigSpecCdromDeviceConnection updates the connection state of the VM's existing CD-ROM devices to match what specifies in VM.Spec.Cdrom list.

Types

type BackupVirtualMachineOptions

type BackupVirtualMachineOptions struct {
	VMCtx               pkgctx.VirtualMachineContext
	VcVM                *object.VirtualMachine
	DiskUUIDToPVC       map[string]corev1.PersistentVolumeClaim
	AdditionalResources []client.Object
	BackupVersion       string
	ClassicDiskUUIDs    map[string]struct{}
}

BackupVirtualMachineOptions contains the options for BackupVirtualMachine.

type SnapshotArgs added in v1.10.0

type SnapshotArgs struct {
	VMCtx          pkgctx.VirtualMachineContext
	VcVM           *object.VirtualMachine
	VMSnapshot     vmopv1.VirtualMachineSnapshot
	RemoveChildren bool
	Consolidate    *bool
}

SnapshotArgs contains the options for createSnapshot.

Jump to

Keyboard shortcuts

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