session

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

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

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. 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.WithCachingTagsManager 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 tag name and its id. In case ID was passed, the original method from tags.Manager would be used.

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) 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. In case ID was passed, the original method from tags.Manager would be used.

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
	// contains filtered or unexported fields
}

Session is a vSphere session with a configured Finder.

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) GetTask

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

func (*Session) WithCachingTagsManager

func (s *Session) WithCachingTagsManager(ctx context.Context, f func(m *CachingTagsManager) error) error

func (*Session) WithRestClient

func (s *Session) WithRestClient(ctx context.Context, f func(c *rest.Client) error) error

Jump to

Keyboard shortcuts

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