util

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

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 Base64Decode

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

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

func DevicesFromConfigSpec

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

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

func IsDeviceDynamicDirectPathIO

func IsDeviceDynamicDirectPathIO(dev vimTypes.BaseVirtualDevice) bool

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

func IsDeviceVGPU

func IsDeviceVGPU(dev vimTypes.BaseVirtualDevice) bool

IsDeviceVGPU returns true if the provided device is a vGPU.

func IsEthernetCard

func IsEthernetCard(dev vimTypes.BaseVirtualDevice) 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 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(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 SelectVGPU added in v1.8.2

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

SelectVGPU returns a slice of 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