vsphere

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 33 Imported by: 3

Documentation

Overview

Package vsphere is used to interact with vSphere

Index

Constants

View Source
const (
	// KeepAliveIntervalInMinute is the interval in minutes for keep alive in the govmomi vim25 client
	KeepAliveIntervalInMinute = 10

	// K8sDatacenterTagCategory is the tag category for kubernetes-enabled datacenters
	K8sDatacenterTagCategory = "k8s-region"

	// K8sComputeClusterTagCategory is the tag category for kubernetes-enabled compute clusters
	K8sComputeClusterTagCategory = "k8s-zone"
)

Variables

This section is empty.

Functions

func ClearCache

func ClearCache(sessionKey string)

ClearCache deletes the session from the session cache

func ToVMMetrics added in v0.0.27

func ToVMMetrics(name string, metrics []performance.EntityMetric) vcenter.Metrics

ToVMMetrics finds the EntityMetric with the provided name and converts it to Metrics

func ToVSphereVM added in v0.0.23

func ToVSphereVM(param mo.VirtualMachine, metrics []performance.EntityMetric, networks []object.NetworkReference,
	dsNames []*object.Datastore, folders []*object.Folder, hostSystems []mo.HostSystem,
	ccrs []*object.ClusterComputeResource, parentsRef []mo.VirtualMachine) vcenter.VM

ToVSphereVM converts a VirtualMachine to a VSphereVM

func ToVSphereVMs added in v0.0.23

func ToVSphereVMs(params []mo.VirtualMachine, metrics []performance.EntityMetric, networks []object.NetworkReference, dsNames []*object.Datastore, folders []*object.Folder, hostSystems []mo.HostSystem, ccrs []*object.ClusterComputeResource, parentsRef []mo.VirtualMachine) []vcenter.VM

ToVSphereVMs converts a list of VirtualMachines to a list of VSphereVMs

func ToVsphereMetrics added in v0.0.23

func ToVsphereMetrics(metric performance.EntityMetric) vcenter.Metrics

ToVsphereMetrics converts the EntityMetric to Metrics

Types

type Driver added in v0.0.27

type Driver interface {
	GetClusters(ctx context.Context, datacenter string) ([]string, error)
	GetClustersByTag(ctx context.Context, datacenter, tagCategory string) ([]string, error)
	GetDatacenters(ctx context.Context) ([]string, error)
	GetDatacentersByTag(ctx context.Context, tagCategory string) ([]string, error)
	GetDatastores(ctx context.Context, datacenter string) ([]string, error)
	GetDistributedVirtualPortgroups(ctx context.Context, datacenter string) ([]string, error)
	GetDistributedVirtualSwitches(ctx context.Context, datacenter string) ([]string, error)
	GetHostClusterMapping(ctx context.Context) (map[string]string, error)
	GetHostSystems(ctx context.Context, datacenter, cluster string) ([]vcenter.HostSystem, error)
	GetNetworks(ctx context.Context, datacenter string) ([]string, error)
	GetResourcePools(ctx context.Context, datacenter string, cluster string) ([]*object.ResourcePool, error)
	GetVApps(ctx context.Context) ([]mo.VirtualApp, error)
	GetVMFolders(ctx context.Context, datacenter string) ([]string, error)
	GetVMs(ctx context.Context, dcName string) ([]vcenter.VM, error)
	GetResourceTags(ctx context.Context, resourceType string) (map[string]tags.AttachedTags, error)
	ValidateCredentials() (bool, error)
	ValidateVersion(constraint string) error
}

Driver is an interface that defines the functions to interact with vSphere

type MockVsphereDriver added in v0.0.23

type MockVsphereDriver struct {
	Clusters                     []string
	Datacenters                  []string
	Datastores                   []string
	DistributedVirtualPortgroups []string
	DistributedVirtualSwitches   []string
	HostClusterMapping           map[string]string
	HostSystems                  map[string][]vcenter.HostSystem
	Networks                     []string
	ResourcePools                []*object.ResourcePool
	ResourceTags                 map[string]tags.AttachedTags
	VApps                        []mo.VirtualApp
	VMFolders                    []string
	VMs                          []vcenter.VM
}

MockVsphereDriver is a mock implementation of the Driver interface

func (MockVsphereDriver) GetClusters added in v0.1.0

func (d MockVsphereDriver) GetClusters(_ context.Context, _ string) ([]string, error)

GetClusters returns a mocked response

func (MockVsphereDriver) GetClustersByTag added in v0.1.0

func (d MockVsphereDriver) GetClustersByTag(_ context.Context, _, _ string) ([]string, error)

GetClustersByTag returns a mocked response

func (MockVsphereDriver) GetDatacenters added in v0.1.0

func (d MockVsphereDriver) GetDatacenters(_ context.Context) ([]string, error)

GetDatacenters returns a mocked response

func (MockVsphereDriver) GetDatacentersByTag added in v0.1.0

func (d MockVsphereDriver) GetDatacentersByTag(_ context.Context, _ string) ([]string, error)

GetDatacentersByTag returns a mocked response

func (MockVsphereDriver) GetDatastores added in v0.1.0

func (d MockVsphereDriver) GetDatastores(_ context.Context, _ string) ([]string, error)

GetDatastores returns a mocked response

func (MockVsphereDriver) GetDistributedVirtualPortgroups added in v0.1.0

func (d MockVsphereDriver) GetDistributedVirtualPortgroups(_ context.Context, _ string) ([]string, error)

GetDistributedVirtualPortgroups returns a mocked response

func (MockVsphereDriver) GetDistributedVirtualSwitches added in v0.1.0

func (d MockVsphereDriver) GetDistributedVirtualSwitches(_ context.Context, _ string) ([]string, error)

GetDistributedVirtualSwitches returns a mocked response

func (MockVsphereDriver) GetHostClusterMapping added in v0.0.23

func (d MockVsphereDriver) GetHostClusterMapping(_ context.Context) (map[string]string, error)

GetHostClusterMapping returns a mocked response

func (MockVsphereDriver) GetHostSystems added in v0.1.0

func (d MockVsphereDriver) GetHostSystems(_ context.Context, datacenter, cluster string) ([]vcenter.HostSystem, error)

GetHostSystems returns a mocked response

func (MockVsphereDriver) GetNetworks added in v0.1.0

func (d MockVsphereDriver) GetNetworks(_ context.Context, _ string) ([]string, error)

GetNetworks returns a mocked response

func (MockVsphereDriver) GetResourcePools added in v0.0.23

func (d MockVsphereDriver) GetResourcePools(_ context.Context, _ string, _ string) ([]*object.ResourcePool, error)

GetResourcePools returns a mocked response

func (MockVsphereDriver) GetResourceTags added in v0.0.23

func (d MockVsphereDriver) GetResourceTags(_ context.Context, _ string) (map[string]tags.AttachedTags, error)

GetResourceTags returns a mocked response

func (MockVsphereDriver) GetVApps added in v0.1.0

func (d MockVsphereDriver) GetVApps(_ context.Context) ([]mo.VirtualApp, error)

GetVApps returns a mocked response

func (MockVsphereDriver) GetVMFolders added in v0.1.0

func (d MockVsphereDriver) GetVMFolders(_ context.Context, _ string) ([]string, error)

GetVMFolders returns a mocked response

func (MockVsphereDriver) GetVMs added in v0.1.0

func (d MockVsphereDriver) GetVMs(_ context.Context, _ string) ([]vcenter.VM, error)

GetVMs returns a mocked response

func (MockVsphereDriver) ValidateCredentials added in v0.1.0

func (d MockVsphereDriver) ValidateCredentials() (bool, error)

ValidateCredentials returns a mocked response

func (MockVsphereDriver) ValidateVersion added in v0.1.0

func (d MockVsphereDriver) ValidateVersion(_ string) error

ValidateVersion returns a mocked response

type Session

type Session struct {
	GovmomiClient *govmomi.Client
	RestClient    *rest.Client
}

Session is a struct that contains the govmomi and rest clients

func GetOrCreateSession

func GetOrCreateSession(ctx context.Context, account vcenter.Account, refreshRestClient bool) (Session, error)

GetOrCreateSession returns the session for the given server, username and password

type VCenterDriver added in v0.1.0

type VCenterDriver struct {
	Account    vcenter.Account
	Datacenter string
	Client     *govmomi.Client
	RestClient *rest.Client
	// contains filtered or unexported fields
}

VCenterDriver is a struct that implements the Driver interface

func NewVCenterDriver added in v0.1.0

func NewVCenterDriver(account vcenter.Account, datacenter string, log logr.Logger) (*VCenterDriver, error)

NewVCenterDriver creates a new VCenterDriver

func (*VCenterDriver) CurrentDomains added in v0.1.0

func (v *VCenterDriver) CurrentDomains(ctx context.Context) ([]string, error)

CurrentDomains returns the current domains for the user the vCenter driver is currently authenticated as.

func (*VCenterDriver) CurrentUser added in v0.1.0

func (v *VCenterDriver) CurrentUser(ctx context.Context) (string, error)

CurrentUser returns the username of the user the vCenter driver is currently authenticated as.

func (*VCenterDriver) FolderExists added in v0.1.0

func (v *VCenterDriver) FolderExists(ctx context.Context, finder *find.Finder, name string) bool

FolderExists checks if a folder exists in the vCenter inventory

func (*VCenterDriver) GetCluster added in v0.1.0

func (v *VCenterDriver) GetCluster(ctx context.Context, finder *find.Finder, datacenter, clusterName string) (*object.ClusterComputeResource, error)

GetCluster returns the cluster if it exists

func (*VCenterDriver) GetClusters added in v0.1.0

func (v *VCenterDriver) GetClusters(ctx context.Context, datacenter string) ([]string, error)

GetClusters returns a sorted list of all vCenter clusters within a datacenter.

func (*VCenterDriver) GetClustersByTag added in v0.1.0

func (v *VCenterDriver) GetClustersByTag(ctx context.Context, datacenter, tagCategory string) ([]string, error)

GetClustersByTag returns a sorted list of vCenter clusters within a datacenter, filtered by a tag category.

func (*VCenterDriver) GetDatacenter added in v0.1.0

func (v *VCenterDriver) GetDatacenter(ctx context.Context, finder *find.Finder, datacenter string) (*object.Datacenter, error)

GetDatacenter returns a datacenter object if it exists

func (*VCenterDriver) GetDatacenters added in v0.1.0

func (v *VCenterDriver) GetDatacenters(ctx context.Context) ([]string, error)

GetDatacenters returns a sorted list of datacenters in the vCenter environment.

func (*VCenterDriver) GetDatacentersByTag added in v0.1.0

func (v *VCenterDriver) GetDatacentersByTag(ctx context.Context, tagCategory string) ([]string, error)

GetDatacentersByTag returns a sorted list of datacenters in the vCenter environment having a specific tag.

func (*VCenterDriver) GetDatastore added in v0.1.0

func (v *VCenterDriver) GetDatastore(ctx context.Context, finder *find.Finder, datastore string) (*object.Datastore, error)

GetDatastore returns a datastore object if it exists

func (*VCenterDriver) GetDatastores added in v0.1.0

func (v *VCenterDriver) GetDatastores(ctx context.Context, datacenter string) ([]string, error)

GetDatastores returns a sorted list of all vCenter datastores within a datacenter.

func (*VCenterDriver) GetDistributedVirtualPortgroup added in v0.1.0

func (v *VCenterDriver) GetDistributedVirtualPortgroup(ctx context.Context, finder *find.Finder, path string) (*object.DistributedVirtualPortgroup, error)

GetDistributedVirtualPortgroup returns a distributed virtual port group object if it exists

func (*VCenterDriver) GetDistributedVirtualPortgroups added in v0.1.0

func (v *VCenterDriver) GetDistributedVirtualPortgroups(ctx context.Context, datacenter string) ([]string, error)

GetDistributedVirtualPortgroups returns a sorted list of all vCenter distributed port groups.

func (*VCenterDriver) GetDistributedVirtualSwitch added in v0.1.0

func (v *VCenterDriver) GetDistributedVirtualSwitch(ctx context.Context, finder *find.Finder, path string) (*object.DistributedVirtualSwitch, error)

GetDistributedVirtualSwitch returns a distributed virtual switch object if it exists

func (*VCenterDriver) GetDistributedVirtualSwitchNameFromPortGroup added in v0.1.3

func (v *VCenterDriver) GetDistributedVirtualSwitchNameFromPortGroup(ctx context.Context, dvp *object.DistributedVirtualPortgroup) (string, error)

GetDistributedVirtualSwitchNameFromPortGroup returns the name of a distributed port group's distributed switch

func (*VCenterDriver) GetDistributedVirtualSwitches added in v0.1.0

func (v *VCenterDriver) GetDistributedVirtualSwitches(ctx context.Context, datacenter string) ([]string, error)

GetDistributedVirtualSwitches returns a sorted list of all vCenter distributed switches.

func (*VCenterDriver) GetFinderWithDatacenter added in v0.1.0

func (v *VCenterDriver) GetFinderWithDatacenter(ctx context.Context, datacenter string) (*find.Finder, string, error)

GetFinderWithDatacenter returns a finder and the datacenter name

func (*VCenterDriver) GetFolder added in v0.1.0

func (v *VCenterDriver) GetFolder(ctx context.Context, datacenter, name string) (*object.Folder, error)

GetFolder returns the vCenter VM folder if it exists

func (*VCenterDriver) GetHost added in v0.1.0

func (v *VCenterDriver) GetHost(ctx context.Context, finder *find.Finder, datacenter, clusterName, hostName string) (*object.HostSystem, error)

GetHost returns the host system if it exists

func (*VCenterDriver) GetHostClusterMapping added in v0.1.0

func (v *VCenterDriver) GetHostClusterMapping(ctx context.Context) (map[string]string, error)

GetHostClusterMapping returns the host cluster mapping

func (*VCenterDriver) GetHostSystems added in v0.1.0

func (v *VCenterDriver) GetHostSystems(ctx context.Context, datacenter, cluster string) ([]vcenter.HostSystem, error)

GetHostSystems returns vCenter host systems

func (*VCenterDriver) GetMetrics added in v0.1.0

func (v *VCenterDriver) GetMetrics(ctx context.Context, c *vim25.Client) ([]performance.EntityMetric, error)

GetMetrics returns the metrics for the given VMs

func (*VCenterDriver) GetNetwork added in v0.1.0

func (v *VCenterDriver) GetNetwork(ctx context.Context, finder *find.Finder, path string) (*object.Network, error)

GetNetwork returns a network object if it exists

func (*VCenterDriver) GetNetworkTypeByName added in v0.1.0

func (v *VCenterDriver) GetNetworkTypeByName(ctx context.Context, datacenter, name string) (string, error)

GetNetworkTypeByName determines the type of a network given its datacenter and name.

func (*VCenterDriver) GetNetworks added in v0.1.0

func (v *VCenterDriver) GetNetworks(ctx context.Context, datacenter string) ([]string, error)

GetNetworks returns a sorted list of all vCenter networks.

func (*VCenterDriver) GetOpaqueNetwork added in v0.1.0

func (v *VCenterDriver) GetOpaqueNetwork(ctx context.Context, finder *find.Finder, path string) (*object.OpaqueNetwork, error)

GetOpaqueNetwork returns an opaque network object if it exists

func (*VCenterDriver) GetOpaqueNetworks added in v0.1.0

func (v *VCenterDriver) GetOpaqueNetworks(ctx context.Context, datacenter string) ([]string, error)

GetOpaqueNetworks returns a sorted list of all vCenter opaque networks.

func (*VCenterDriver) GetResourcePool added in v0.1.0

func (v *VCenterDriver) GetResourcePool(ctx context.Context, finder *find.Finder, datacenter, cluster, resourcePoolName string) (*object.ResourcePool, error)

GetResourcePool returns the resource pool if it exists

func (*VCenterDriver) GetResourcePools added in v0.1.0

func (v *VCenterDriver) GetResourcePools(ctx context.Context, datacenter string, cluster string) ([]*object.ResourcePool, error)

GetResourcePools returns a list of resource pools

func (*VCenterDriver) GetResourceTags added in v0.1.0

func (v *VCenterDriver) GetResourceTags(ctx context.Context, resourceType string) (map[string]tags.AttachedTags, error)

GetResourceTags returns a map of resource tags

func (*VCenterDriver) GetVApp added in v0.1.0

func (v *VCenterDriver) GetVApp(ctx context.Context, finder *find.Finder, vAppName string) (*object.VirtualApp, error)

GetVApp returns the virtual app if it exists

func (*VCenterDriver) GetVApps added in v0.1.0

func (v *VCenterDriver) GetVApps(ctx context.Context) ([]mo.VirtualApp, error)

GetVApps returns a list of virtual apps

func (*VCenterDriver) GetVM added in v0.1.0

func (v *VCenterDriver) GetVM(ctx context.Context, finder *find.Finder, vmName string) (*object.VirtualMachine, error)

GetVM returns the vCenter VM if it exists

func (*VCenterDriver) GetVMFolders added in v0.1.0

func (v *VCenterDriver) GetVMFolders(ctx context.Context, datacenter string) ([]string, error)

GetVMFolders returns a list of vCenter VM folders

func (*VCenterDriver) GetVMs added in v0.1.0

func (v *VCenterDriver) GetVMs(ctx context.Context, datacenter string) ([]vcenter.VM, error)

GetVMs returns a list of vCenter VMs

func (*VCenterDriver) GetVSphereResourcePools added in v0.1.0

func (v *VCenterDriver) GetVSphereResourcePools(ctx context.Context, datacenter string, cluster string) (resourcePools []string, err error)

GetVSphereResourcePools returns a sorted list of resource pool paths

func (*VCenterDriver) ValidateCredentials added in v0.1.0

func (v *VCenterDriver) ValidateCredentials() (bool, error)

ValidateCredentials ensures that vCenter account credentials are valid

func (*VCenterDriver) ValidateHostNTPSettings added in v0.1.0

func (v *VCenterDriver) ValidateHostNTPSettings(ctx context.Context, finder *find.Finder, datacenter, clusterName string, hosts []string) (bool, []string, error)

ValidateHostNTPSettings validates the NTP settings for the hosts

func (*VCenterDriver) ValidateUserPrivilegeOnEntities added in v0.1.0

func (v *VCenterDriver) ValidateUserPrivilegeOnEntities(ctx context.Context, authManager *object.AuthorizationManager, datacenter, username string, finder *find.Finder, rule v1alpha1.PrivilegeValidationRule) ([]string, error)

ValidateUserPrivilegeOnEntities validates the user's privileges and permissions on a specific entity.

func (*VCenterDriver) ValidateVersion added in v0.1.0

func (v *VCenterDriver) ValidateVersion(constraint string) error

ValidateVersion ensures that the vSphere version satisfies the given constraint

Jump to

Keyboard shortcuts

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