util

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const GuestInfoBootstrapCondition = "guestinfo.vmservice.bootstrap.condition"

GuestInfoBootstrapCondition is the ExtraConfig key at which possible info about the bootstrap status may be stored.

View Source
const (
	// XsiNamespace indicates the XML schema instance namespace.
	XsiNamespace = "http://www.w3.org/2001/XMLSchema-instance"
)

Variables

This section is empty.

Functions

func AppendNewExtraConfigValues added in v1.8.5

func AppendNewExtraConfigValues(
	extraConfig []vimTypes.BaseOptionValue,
	newECMap map[string]string) []vimTypes.BaseOptionValue

AppendNewExtraConfigValues add the new extra config values if not already present in the extra config.

func Base64Decode

func Base64Decode(src []byte) ([]byte, error)

Base64Decode returns a byte slice decoded from a base64 byte slice.

func CNSAttachmentNameForVolume added in v1.8.6

func CNSAttachmentNameForVolume(vmName, volumeName string) string

CNSAttachmentNameForVolume returns the name of the CnsNodeVmAttachment based on the VM and Volume name. This matches the naming used in previous code but there are situations where we may get a collision between VMs and Volume names. I'm not sure if there is an absolute way to avoid that: the same situation can happen with the claimName. Ideally, we would use GenerateName, but we lack the back-linkage to match Volumes and CnsNodeVmAttachment up. The VM webhook validate that this result will be a valid k8s name.

func DevicesFromConfigSpec

func DevicesFromConfigSpec(
	configSpec *vimTypes.VirtualMachineConfigSpec,
) []vimTypes.BaseVirtualDevice

DevicesFromConfigSpec returns a slice of devices from the ConfigSpec's DeviceChange property.

func EncodeGzipBase64 added in v1.8.5

func EncodeGzipBase64(s string) (string, error)

EncodeGzipBase64 compresses the input string using gzip and then encodes it using base64.

func EnsureMinHardwareVersionInConfigSpec added in v1.8.5

func EnsureMinHardwareVersionInConfigSpec(
	configSpec *vimTypes.VirtualMachineConfigSpec,
	minVersion int32)

EnsureMinHardwareVersionInConfigSpec ensures that the hardware version in the ConfigSpec is at least equal to the passed minimum hardware version value.

func ExtraConfigToMap added in v1.8.5

func ExtraConfigToMap(input []vimTypes.BaseOptionValue) (output map[string]string)

ExtraConfigToMap converts the ExtraConfig to a map with string values.

func GetBootstrapConditionValues added in v1.8.6

func GetBootstrapConditionValues(
	configInfo *vimTypes.VirtualMachineConfigInfo) (bool, string, string, bool)

GetBootstrapConditionValues returns the bootstrap condition values from a VM if the data is present.

func GetSecretData added in v1.8.6

func GetSecretData(
	ctx context.Context,
	k8sClient ctrlclient.Client,
	secretNamespace, secretName, secretKey string,
	out *string) error

func GetSecretResource added in v1.8.6

func GetSecretResource(
	ctx context.Context,
	k8sClient ctrlclient.Client,
	secretNamespace, secretName string) (*corev1.Secret, error)

func HasDeviceChangeDeviceByType added in v1.8.6

func HasDeviceChangeDeviceByType[T vimTypes.BaseVirtualDevice](
	deviceChanges []vimTypes.BaseVirtualDeviceConfigSpec,
) bool

HasDeviceChangeDeviceByType returns true of one of the device change's dev is that of type T.

func HasVirtualPCIPassthroughDeviceChange added in v1.8.6

func HasVirtualPCIPassthroughDeviceChange(
	devices []vimTypes.BaseVirtualDeviceConfigSpec,
) bool

HasVirtualPCIPassthroughDeviceChange returns true if any of the device changes are for a passthrough device.

func IsDeviceDynamicDirectPathIO

func IsDeviceDynamicDirectPathIO(dev vimTypes.BaseVirtualDevice) bool

IsDeviceDynamicDirectPathIO returns true if the provided device is a dynamic direct path I/O device.

func IsDeviceNvidiaVgpu added in v1.8.3

func IsDeviceNvidiaVgpu(dev vimTypes.BaseVirtualDevice) bool

IsDeviceNvidiaVgpu returns true if the provided device is an Nvidia vGPU.

func IsEthernetCard

func IsEthernetCard(dev vimTypes.BaseVirtualDevice) bool

func IsNotFoundError added in v1.8.6

func IsNotFoundError(err error) bool

func MarshalConfigSpecToJSON

func MarshalConfigSpecToJSON(
	configSpec *vimTypes.VirtualMachineConfigSpec) ([]byte, error)

MarshalConfigSpecToJSON returns a byte slice of the provided ConfigSpec marshaled to a JSON string.

func MarshalConfigSpecToXML

func MarshalConfigSpecToXML(
	configSpec *vimTypes.VirtualMachineConfigSpec) ([]byte, error)

MarshalConfigSpecToXML returns a byte slice of the provided ConfigSpec marshalled to an XML string.

func MergeExtraConfig added in v1.8.5

func MergeExtraConfig(
	existingExtraConfig []vimTypes.BaseOptionValue,
	newKeyValuePairs map[string]string) []vimTypes.BaseOptionValue

MergeExtraConfig adds the key/value to the ExtraConfig if the key is not present or the new value is different than the existing value. It returns the newly added ExtraConfig. Please note the result *may* include keys with empty values. This indicates to vSphere to remove the key/value pair.

func RemoveDevicesFromConfigSpec

func RemoveDevicesFromConfigSpec(configSpec *vimTypes.VirtualMachineConfigSpec, fn func(vimTypes.BaseVirtualDevice) bool)

RemoveDevicesFromConfigSpec removes devices from config spec device changes based on the matcher function.

func SanitizeVMClassConfigSpec

func SanitizeVMClassConfigSpec(
	ctx context.Context,
	configSpec *vimTypes.VirtualMachineConfigSpec)

SanitizeVMClassConfigSpec clears fields in the class ConfigSpec that are not allowed or supported.

func SelectDevices

func SelectDevices[T vimTypes.BaseVirtualDevice](
	devices []vimTypes.BaseVirtualDevice,
	selectorFns ...SelectDeviceFn[T],
) []T

SelectDevices returns a slice of the devices that match at least one of the provided selector functions.

func SelectDevicesByBackingType

func SelectDevicesByBackingType[B vimTypes.BaseVirtualDeviceBackingInfo](
	devices []vimTypes.BaseVirtualDevice,
) []vimTypes.BaseVirtualDevice

SelectDevicesByBackingType returns a slice of the devices that have a backing of type B.

func SelectDevicesByDeviceAndBackingType

func SelectDevicesByDeviceAndBackingType[
	T vimTypes.BaseVirtualDevice,
	B vimTypes.BaseVirtualDeviceBackingInfo,
](
	devices []vimTypes.BaseVirtualDevice,
) []T

SelectDevicesByDeviceAndBackingType returns a slice of the devices that are of type T with a backing of type B.

func SelectDevicesByType

func SelectDevicesByType[T vimTypes.BaseVirtualDevice](
	devices []vimTypes.BaseVirtualDevice,
) []T

SelectDevicesByType returns a slice of the devices that are of type T.

func SelectDevicesByTypes

func SelectDevicesByTypes(
	devices []vimTypes.BaseVirtualDevice,
	deviceTypes ...vimTypes.BaseVirtualDevice,
) []vimTypes.BaseVirtualDevice

SelectDevicesByTypes returns a slice of the devices that match at least one the provided device types.

func SelectDynamicDirectPathIO

func SelectDynamicDirectPathIO(
	devices []vimTypes.BaseVirtualDevice,
) []*vimTypes.VirtualPCIPassthrough

SelectDynamicDirectPathIO returns a slice of dynamic direct path I/O devices.

func SelectNvidiaVgpu added in v1.8.3

func SelectNvidiaVgpu(
	devices []vimTypes.BaseVirtualDevice,
) []*vimTypes.VirtualPCIPassthrough

SelectNvidiaVgpu return a slice of Nvidia vGPU devices.

func SelectVirtualPCIPassthrough

func SelectVirtualPCIPassthrough(
	devices []vimTypes.BaseVirtualDevice,
) []*vimTypes.VirtualPCIPassthrough

SelectVirtualPCIPassthrough returns a slice of *VirtualPCIPassthrough devices.

func TryToDecodeBase64Gzip

func TryToDecodeBase64Gzip(data []byte) (string, error)

TryToDecodeBase64Gzip base64-decodes the provided data until the DecodeString function fails. If the result is gzipped, then it is decompressed and returned. Otherwise the decoded data is returned.

This function will also return the original data as a string if it was neither base64 encoded or gzipped.

func UnmarshalConfigSpecFromBase64XML

func UnmarshalConfigSpecFromBase64XML(
	src []byte) (*vimTypes.VirtualMachineConfigSpec, error)

UnmarshalConfigSpecFromBase64XML returns a ConfigSpec object from a byte-slice of the ConfigSpec marshaled as a base64-encoded, XML string.

func UnmarshalConfigSpecFromJSON

func UnmarshalConfigSpecFromJSON(
	data []byte) (*vimTypes.VirtualMachineConfigSpec, error)

UnmarshalConfigSpecFromJSON returns a ConfigSpec object from a byte-slice of the ConfigSpec marshaled as a JSON string.

func UnmarshalConfigSpecFromXML

func UnmarshalConfigSpecFromXML(
	data []byte) (*vimTypes.VirtualMachineConfigSpec, error)

UnmarshalConfigSpecFromXML returns a ConfigSpec object from a byte-slice of the ConfigSpec marshaled as an XML string.

Types

type Cache added in v1.8.1

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is a generic implementation of a cache that can be configured with a maximum number of items and can evict items after a certain amount of time.

func NewCache added in v1.8.1

func NewCache[T any](
	expireAfter, checkExpireInterval time.Duration,
	maxItems int) *Cache[T]

NewCache initializes a new cache with the provided expiration options.

func (*Cache[T]) Close added in v1.8.1

func (c *Cache[T]) Close()

Close shuts down the cache. It is safe to call this function more than once.

func (*Cache[T]) Delete added in v1.8.1

func (c *Cache[T]) Delete(id string)

Delete removes the specified item from the cache.

func (*Cache[T]) ExpiredChan added in v1.8.1

func (c *Cache[T]) ExpiredChan() <-chan string

ExpiredChan returns a channel on which the IDs of items that are expired are sent. This channel is closed when the cache is closed, but only after all, pending eviction notices are received.

func (*Cache[T]) Get added in v1.8.1

func (c *Cache[T]) Get(id string, isHit func(t T) bool) (T, bool)

Get returns the cached item with the provided ID. The function isHit may be optionally provided to further determine whether a cached item should hit or miss.

func (*Cache[T]) Put added in v1.8.1

func (c *Cache[T]) Put(id string, t T) CachePutResult

Put stores the provided item in the cache, updating existing items.

type CacheItem added in v1.8.1

type CacheItem[T any] struct {
	// Item is the cached item.
	Item T

	// LastUpdated is the last time the item was updated.
	LastUpdated time.Time
}

CacheItem wraps T so it has a LastUpdated field and can be used with Cache.

type CachePutResult added in v1.8.1

type CachePutResult uint

CachePutResult describes the result of putting an item into the cache.

const (
	// CachePutResultCreate indicates the item was created in the cache.
	CachePutResultCreate CachePutResult = iota + 1

	// CachePutResultUpdate indicates an existing, cached item was updated.
	CachePutResultUpdate

	// CachePutResultMaxItemsExceeded indicates the item was not stored because
	// the cache's maximum number of items would have been exceeded.
	CachePutResultMaxItemsExceeded
)

type LockPool added in v1.8.1

type LockPool[K any, V sync.Locker] struct {
	// contains filtered or unexported fields
}

LockPool is a synchronized set of maps that can be obtained with a provided ID.

func (*LockPool[K, V]) Delete added in v1.8.1

func (p *LockPool[K, V]) Delete(id K)

Delete removes the specified lock from the pool.

func (*LockPool[K, V]) Get added in v1.8.1

func (p *LockPool[K, V]) Get(id K) sync.Locker

Get returns the lock for the provided ID.

type SelectDeviceFn

type SelectDeviceFn[T vimTypes.BaseVirtualDevice] func(dev vimTypes.BaseVirtualDevice) bool

SelectDeviceFn returns true if the provided virtual device is a match.

Directories

Path Synopsis
vsphere
vm

Jump to

Keyboard shortcuts

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