vsphere

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: Apache-2.0 Imports: 34 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
	// DatacenterTagCategory is the tag category for datacenter
	DatacenterTagCategory = "k8s-region"
	// ComputeClusterTagCategory is the tag category for compute cluster
	ComputeClusterTagCategory = "k8s-zone"
)

Variables

View Source
var IsAdminAccount = isAdminAccount

IsAdminAccount is defined to enable monkey patching the isAdminAccount function in integration tests

Functions

func ClearCache

func ClearCache(sessionKey string)

ClearCache deletes the session from the session cache

func ConfigureSSOClient added in v0.0.25

func ConfigureSSOClient(ctx context.Context, driver *CloudDriver) (*ssoadmin.Client, error)

ConfigureSSOClient configures the SSO client for the given driver

func GetVmwareUserPrivileges

func GetVmwareUserPrivileges(ctx context.Context, userPrincipal string, groupPrincipals []string, authManager *object.AuthorizationManager) (map[string]bool, error)

GetVmwareUserPrivileges returns a map of privileges for the user

Types

type AdditionalDisk added in v0.0.23

type AdditionalDisk struct {
	Name      string
	Device    string
	Capacity  string
	Used      string
	Available string
	Usage     string
}

AdditionalDisk defines an additional disk

type CloudAccount added in v0.0.27

type CloudAccount struct {
	// Insecure is a flag that controls whether to validate the vSphere server's certificate.
	Insecure bool `json:"insecure" yaml:"insecure"`

	// password
	// Required: true
	Password string `json:"password" yaml:"password"`

	// username
	// Required: true
	Username string `json:"username" yaml:"username"`

	// VcenterServer is the address of the vSphere endpoint
	// Required: true
	VcenterServer string `json:"vcenterServer" yaml:"vcenterServer"`
}

CloudAccount is a struct that contains the vSphere account details

type CloudDriver added in v0.0.27

type CloudDriver struct {
	VCenterServer   string
	VCenterUsername string
	VCenterPassword string
	Datacenter      string
	Client          *govmomi.Client
	RestClient      *rest.Client
	// contains filtered or unexported fields
}

CloudDriver is a struct that implements the Driver interface

func NewVSphereDriver

func NewVSphereDriver(vCenterServer, vCenterUsername, vCenterPassword, datacenter string, log logr.Logger) (*CloudDriver, error)

NewVSphereDriver creates a new instance of CloudDriver

func (*CloudDriver) CreateVSphereVMFolder added in v0.0.27

func (v *CloudDriver) CreateVSphereVMFolder(ctx context.Context, datacenter string, folders []string) error

CreateVSphereVMFolder creates a vSphere VM folder

func (*CloudDriver) FolderExists added in v0.0.27

func (v *CloudDriver) FolderExists(ctx context.Context, finder *find.Finder, folderName string) (bool, error)

FolderExists checks if a folder exists in the vSphere inventory

func (*CloudDriver) GetClusterIfExists added in v0.0.27

func (v *CloudDriver) GetClusterIfExists(ctx context.Context, finder *find.Finder, datacenter, clusterName string) (bool, *object.ClusterComputeResource, error)

GetClusterIfExists returns the cluster if it exists

func (*CloudDriver) GetCurrentVmwareUser added in v0.0.27

func (v *CloudDriver) GetCurrentVmwareUser(ctx context.Context) (string, error)

GetCurrentVmwareUser returns the user name the CloudDriver is currently authenticated with

func (*CloudDriver) GetDatacenterIfExists added in v0.0.27

func (v *CloudDriver) GetDatacenterIfExists(ctx context.Context, finder *find.Finder, datacenter string) (bool, *object.Datacenter, error)

GetDatacenterIfExists returns a datacenter object if it exists

func (*CloudDriver) GetFinderWithDatacenter added in v0.0.27

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

GetFinderWithDatacenter returns a finder and the datacenter name

func (*CloudDriver) GetFolderIfExists added in v0.0.27

func (v *CloudDriver) GetFolderIfExists(ctx context.Context, finder *find.Finder, folderName string) (bool, *object.Folder, error)

GetFolderIfExists returns the folder if it exists

func (*CloudDriver) GetFolderNameByID added in v0.0.27

func (v *CloudDriver) GetFolderNameByID(ctx context.Context, datacenter, id string) (string, error)

GetFolderNameByID returns the folder name by ID

func (*CloudDriver) GetHostClusterMapping added in v0.0.27

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

GetHostClusterMapping returns the host cluster mapping

func (*CloudDriver) GetHostIfExists added in v0.0.27

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

GetHostIfExists returns the host system if it exists

func (*CloudDriver) GetMetrics added in v0.0.27

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

GetMetrics returns the metrics for the given VMs

func (*CloudDriver) GetResourcePoolIfExists added in v0.0.27

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

GetResourcePoolIfExists returns the resource pool if it exists

func (*CloudDriver) GetResourcePools added in v0.0.27

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

GetResourcePools returns a list of resource pools

func (*CloudDriver) GetResourceTags added in v0.0.27

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

GetResourceTags returns a map of resource tags

func (*CloudDriver) GetVAppIfExists added in v0.0.27

func (v *CloudDriver) GetVAppIfExists(ctx context.Context, finder *find.Finder, vAppName string) (bool, *object.VirtualApp, error)

GetVAppIfExists returns the virtual app if it exists

func (*CloudDriver) GetVMIfExists added in v0.0.27

func (v *CloudDriver) GetVMIfExists(ctx context.Context, finder *find.Finder, vmName string) (bool, *object.VirtualMachine, error)

GetVMIfExists returns the VM if it exists

func (*CloudDriver) GetVSphereClusters added in v0.0.27

func (v *CloudDriver) GetVSphereClusters(ctx context.Context, datacenter string) ([]string, error)

GetVSphereClusters returns a sorted list of vSphere clusters

func (*CloudDriver) GetVSphereDatacenters added in v0.0.27

func (v *CloudDriver) GetVSphereDatacenters(ctx context.Context) ([]string, error)

GetVSphereDatacenters returns a sorted list of datacenters in the vSphere environment

func (*CloudDriver) GetVSphereHostSystems added in v0.0.27

func (v *CloudDriver) GetVSphereHostSystems(ctx context.Context, datacenter, cluster string) ([]HostSystem, error)

GetVSphereHostSystems returns the vSphere host systems

func (*CloudDriver) GetVSphereResourcePools added in v0.0.27

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

GetVSphereResourcePools returns a sorted list of resource pool paths

func (*CloudDriver) GetVSphereVMFolders added in v0.0.27

func (v *CloudDriver) GetVSphereVMFolders(ctx context.Context, datacenter string) ([]string, error)

GetVSphereVMFolders returns a list of vSphere VM folders

func (*CloudDriver) GetVSphereVms added in v0.0.27

func (v *CloudDriver) GetVSphereVms(ctx context.Context, dcName string) ([]VM, error)

GetVSphereVms returns a list of vSphere VMs

func (*CloudDriver) GetVapps added in v0.0.27

func (v *CloudDriver) GetVapps(ctx context.Context) ([]mo.VirtualApp, error)

GetVapps returns a list of virtual apps

func (*CloudDriver) IsAdminAccount added in v0.0.27

func (v *CloudDriver) IsAdminAccount(ctx context.Context) (bool, error)

IsAdminAccount checks if the current user is an admin account

func (*CloudDriver) IsValidVSphereCredentials added in v0.0.27

func (v *CloudDriver) IsValidVSphereCredentials() (bool, error)

IsValidVSphereCredentials checks if the vSphere credentials are valid

func (*CloudDriver) ValidateHostNTPSettings added in v0.0.27

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

ValidateHostNTPSettings validates the NTP settings for the hosts

func (*CloudDriver) ValidateUserPrivilegeOnEntities added in v0.0.27

func (v *CloudDriver) ValidateUserPrivilegeOnEntities(ctx context.Context, authManager *object.AuthorizationManager, datacenter string, finder *find.Finder, entityName, entityType string, privileges []string, userName, clusterName string) (isValid bool, failures []string, err error)

ValidateUserPrivilegeOnEntities validates the user privileges on the entities

func (*CloudDriver) ValidateVsphereVersion added in v0.0.27

func (v *CloudDriver) ValidateVsphereVersion(constraint string) error

ValidateVsphereVersion validates the vSphere version satisfies the given constraint

type Datastore added in v0.0.23

type Datastore struct {
	Name string
	ID   string
}

Datastore defines a datastore

type Driver added in v0.0.27

type Driver interface {
	GetVSphereVMFolders(ctx context.Context, datacenter string) ([]string, error)
	GetVSphereDatacenters(ctx context.Context) ([]string, error)
	GetVSphereClusters(ctx context.Context, datacenter string) ([]string, error)
	GetVSphereHostSystems(ctx context.Context, datacenter, cluster string) ([]HostSystem, error)
	IsValidVSphereCredentials() (bool, error)
	ValidateVsphereVersion(constraint string) error
	GetHostClusterMapping(ctx context.Context) (map[string]string, error)
	GetVSphereVms(ctx context.Context, dcName string) ([]VM, error)
	GetResourcePools(ctx context.Context, datacenter string, cluster string) ([]*object.ResourcePool, error)
	GetVapps(ctx context.Context) ([]mo.VirtualApp, error)
	GetResourceTags(ctx context.Context, resourceType string) (map[string]tags.AttachedTags, error)
	IsAdminAccount(ctx context.Context) (bool, error)
}

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

type HostDateInfo

type HostDateInfo struct {
	HostName   string
	NtpServers []string
	types.HostDateTimeInfo
	Service       *types.HostService
	Current       *time.Time
	ClientStatus  string
	ServiceStatus string
}

HostDateInfo defines the host date information

type HostSystem added in v0.0.27

type HostSystem struct {
	Name      string
	Reference string
}

HostSystem defines a vSphere host system

type LibvirtVMInfo added in v0.0.27

type LibvirtVMInfo struct {
	ImagePool string
	DataPool  string
}

LibvirtVMInfo defines a libvirt VM information

type Metrics added in v0.0.23

type Metrics struct {
	CPUCores        string
	CPUUsage        string
	MemoryBytes     string
	MemoryUsage     string
	DiskUsage       string
	DiskProvisioned string
}

Metrics defines the VM metrics

func ToVMMetrics added in v0.0.27

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

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

func ToVsphereMetrics added in v0.0.23

func ToVsphereMetrics(metric performance.EntityMetric) Metrics

ToVsphereMetrics converts the EntityMetric to Metrics

type MockVsphereDriver added in v0.0.23

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

MockVsphereDriver is a mock implementation of the Driver interface

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) 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) GetVSphereClusters added in v0.0.23

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

GetVSphereClusters returns a mocked response

func (MockVsphereDriver) GetVSphereDatacenters added in v0.0.23

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

GetVSphereDatacenters returns a mocked response

func (MockVsphereDriver) GetVSphereHostSystems added in v0.0.23

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

GetVSphereHostSystems returns a mocked response

func (MockVsphereDriver) GetVSphereVMFolders added in v0.0.23

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

GetVSphereVMFolders returns a mocked response

func (MockVsphereDriver) GetVSphereVms added in v0.0.23

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

GetVSphereVms returns a mocked response

func (MockVsphereDriver) GetVapps added in v0.0.23

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

GetVapps returns a mocked response

func (MockVsphereDriver) IsAdminAccount added in v0.0.26

func (d MockVsphereDriver) IsAdminAccount(_ context.Context) (bool, error)

IsAdminAccount returns a mocked response

func (MockVsphereDriver) IsValidVSphereCredentials added in v0.0.23

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

IsValidVSphereCredentials returns a mocked response

func (MockVsphereDriver) ValidateVsphereVersion added in v0.0.23

func (d MockVsphereDriver) ValidateVsphereVersion(_ string) error

ValidateVsphereVersion returns a mocked response

type Network added in v0.0.27

type Network struct {
	Type      string
	IP        string
	Interface string
}

Network defines a vSphere network

type SSHInfo added in v0.0.27

type SSHInfo struct {
	Username   string
	Password   string
	PublicKey  []string
	PrivateKey []string
}

SSHInfo defines the SSH information

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,
	server, username, password string, refreshRestClient bool) (Session, error)

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

type VM added in v0.0.27

type VM struct {
	Name           string
	Type           string
	Status         string
	IPAddress      string
	Host           string
	CPU            int32
	Memory         int32
	RootDiskSize   int32
	Network        []Network
	LibvirtVMInfo  LibvirtVMInfo
	VMInfo         VMInfo
	SSHInfo        SSHInfo
	AdditionalDisk []AdditionalDisk
	Metrics        Metrics
	Storage        []Datastore
}

VM defines a vSphere virtual machine

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) 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) []VM

ToVSphereVMs converts a list of VirtualMachines to a list of VSphereVMs

type VMInfo added in v0.0.27

type VMInfo struct {
	Folder    string
	Cluster   string
	Datastore string
	Network   string
}

VMInfo defines a vSphere VM information

Jump to

Keyboard shortcuts

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