session

package
v0.2.1-0...-2615267 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsName

func IsName(id string) bool

IsName returns true if the id is not an urn. this method came from vSphere sdk, see https://github.com/vmware/govmomi/blob/a2fb82dc55a8eb00932233aa8028ce97140df784/vapi/tags/tags.go#L121 for more context.

Types

type CachingTagsManager

type CachingTagsManager struct {
	*tags.Manager
	// contains filtered or unexported fields
}

CachingTagsManager wraps tags.Manager from vSphere SDK for cache mapping between tags or categories name and their ids, and for caching the full tag/category objects themselves. Reasoning behind this is the implementation details of tags/categories lookup by name, to find a tag/category by name vSphere SDK gets a list of ids and then makes an additional request for every object till it will not find matched names. Such peculiarity causes a huge performance degradation within environments with a large number of tags/categories, because in the worst case number of rest requests for object lookup might be equal to the number of objects.

See tags.Manager methods for more details: https://github.com/vmware/govmomi/blob/a2fb82dc55a8eb00932233aa8028ce97140df784/vapi/tags/tags.go#L172

This structure is intended to be used from a Session instance (Session.GetCachingTagsManager method specifically) presented in this module.

func (*CachingTagsManager) GetCategory

func (t *CachingTagsManager) GetCategory(ctx context.Context, id string) (*tags.Category, error)

GetCategory fetches the category information for the given identifier. The id parameter can be a Category ID or Category Name. This method shadows original tags.Manager method and caches mapping between category name and its id as well as the full category object, so any hit path (object cache or name->id cache) returns without REST calls.

In case if a category was not found in vCenter, this would be cached for 12 hours and lookup won't happen till cache expiration.

func (*CachingTagsManager) GetTag

func (t *CachingTagsManager) GetTag(ctx context.Context, id string) (*tags.Tag, error)

GetTag fetches the tag information for the given identifier. The id parameter can be a Tag ID or Tag Name. This method shadows original tags.Manager method and caches mapping between tag name and its id as well as the full tag object, so any hit path (object cache or name->id cache) returns without REST calls.

In case if a tag was not found in vCenter, this would be cached for 12 hours and lookup won't happen till cache expiration.

func (*CachingTagsManager) ListTagsForCategory

func (t *CachingTagsManager) ListTagsForCategory(ctx context.Context, id string) ([]string, error)

ListTagsForCategory tag ids for the given category. The id parameter can be a Category ID or Category Name. Uses caching GetCategory method.

type Session

type Session struct {
	*govmomi.Client
	Finder     *find.Finder
	Datacenter *object.Datacenter
	TagManager *tags.Manager
	// contains filtered or unexported fields
}

Session is a vSphere session with a configured Finder. This implementation is inspired by cluster-api-provider-vsphere's session caching pattern to avoid excessive vCenter login/logout cycles for REST API operations. Reference: https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/blob/main/pkg/session/session.go

func GetOrCreate

func GetOrCreate(
	ctx context.Context,
	server, datacenter, username, password string, insecure bool) (*Session, error)

GetOrCreate gets a cached session or creates a new one if one does not already exist.

func (*Session) FindRefByInstanceUUID

func (s *Session) FindRefByInstanceUUID(ctx context.Context, UUID string) (object.Reference, error)

FindByInstanceUUID finds an object by its instance UUID.

func (*Session) FindVM

func (s *Session) FindVM(ctx context.Context, UUID, name string) (*object.VirtualMachine, error)

func (*Session) GetCachingTagsManager

func (s *Session) GetCachingTagsManager() *CachingTagsManager

GetCachingTagsManager returns the per-session CachingTagsManager that wraps the cached TagManager. It is created once when the session is created, so no new vCenter login/logout happens on access.

func (*Session) GetTask

func (s *Session) GetTask(ctx context.Context, taskRef string) (*mo.Task, error)

Jump to

Keyboard shortcuts

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