vc

package
v0.0.0-...-b25b198 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package vc ...

Package vc ...

Package vc ...

Index

Constants

View Source
const (
	K8SVmPropertyID         = "KUBERNETES_SEMVER"
	OVAVersionPropertyID    = "VERSION"
	DistroNamePropertyID    = "DISTRO_NAME"
	DistroVersionPropertyID = "DISTRO_VERSION"
	DistroArchPropertyID    = "DISTRO_ARCH"
	VMPropertyCategoryCAPI  = "Cluster API Provider (CAPI)"
	VMGuestInfoUserDataKey  = "guestinfo.userdata"
	VCDefaultPort           = "443"
)

VSphere resource tags for tkg resource

View Source
const (
	TypeCluster         = "ClusterComputeResource"
	TypeComputeResource = "ComputeResource"
	TypeHostGroup       = "HostGroup"
	TypeResourcePool    = "ResourcePool"
	TypeDatacenter      = "Datacenter"
	TypeFolder          = "Folder"
	TypeDatastore       = "Datastore"
	TypeHost            = "HostSystem"
	TypeNetwork         = "Network"
	TypeDvpg            = "DistributedVirtualPortgroup"
	TypeDvs             = "VmwareDistributedVirtualSwitch"
	TypeOpaqueNetwork   = "OpaqueNetwork"
	TypeVirtualMachine  = "VirtualMachine"
)

vCenter Managed Object Type Names

Variables

This section is empty.

Functions

func FindMatchingVirtualMachineTemplate

func FindMatchingVirtualMachineTemplate(
	vms []*tkgtypes.VSphereVirtualMachine,
	ovaVersions []string,
) (matchedTemplateVMs []*tkgtypes.VSphereVirtualMachine, nonTemplateVMs []string)

FindMatchingVirtualMachineTemplate finds a virtual machine template that matches the ova versions

func GetDuplicateNetworks

func GetDuplicateNetworks(networks []*models.VSphereNetwork) map[string]bool

GetDuplicateNetworks return a map of duplicate networks from the available networks.

func GetVCThumbprint

func GetVCThumbprint(host string) (string, error)

GetVCThumbprint gets the vc thumbprint

func ValidateAndGetVirtualMachineTemplateForTKRVersion

func ValidateAndGetVirtualMachineTemplateForTKRVersion(vcClient Client, tkrVersion string, ovaVersions []string, templateName, dc string, k8sVMTemplates []*tkgtypes.VSphereVirtualMachine) (*tkgtypes.VSphereVirtualMachine, error)

ValidateAndGetVirtualMachineTemplateForTKRVersion gets a virtual machine for the given TKR version and validates it

Types

type Client

type Client interface {
	// Login authenticates with Virtual Center using user/password
	Login(ctx context.Context, user, password string) (string, error)

	// AcquireTicket acquires a new session ticket for the user associated with
	// the authenticated client.
	AcquireTicket() (string, error)

	// CheckUserSessionActive check if a user session is Active
	CheckUserSessionActive() (bool, error)

	// GetDatastores returns a list of datastores for the given datacenter
	GetDatastores(ctx context.Context, datacenterMOID string) ([]*models.VSphereDatastore, error)

	// GetDatacenters returns a list of all datacenters in the vSphere inventory.
	GetDatacenters(ctx context.Context) ([]*models.VSphereDatacenter, error)

	// GetDataCenterMOID returns the MOID of the datacenter
	GetDataCenterMOID(ctx context.Context, dcName string) (string, error)

	// GetNetworks returns list of network in the given datacenter
	GetNetworks(ctx context.Context, datacenterMOID string) ([]*models.VSphereNetwork, error)

	// GetResourcePools returns list of resource pools in the given datacenter
	GetResourcePools(ctx context.Context, datacenterMOID string) ([]*models.VSphereResourcePool, error)

	// GetVSphereVersion returns the vSphere version, and the build number
	GetVSphereVersion() (string, string, error)

	// GetVirtualMachine gets vms under given datacenter
	GetVirtualMachines(ctx context.Context, datacenterMOID string) ([]*models.VSphereVirtualMachine, error)

	// GetVirtualMachineImages gets vm templates for kubernetes
	GetVirtualMachineImages(ctx context.Context, datacenterMOID string) ([]*tkgtypes.VSphereVirtualMachine, error)

	// DetectPacific detects if project pacific is enabled on vSphere
	DetectPacific(ctx context.Context) (bool, error)

	// GetFolders gets all folders under a datacenter
	GetFolders(ctx context.Context, datacenterMOID string) ([]*models.VSphereFolder, error)

	// GetComputeResources gets resource pools and their ancestors
	GetComputeResources(ctx context.Context, datacenterMOID string) ([]*models.VSphereManagementObject, error)
	// FindResourcePool find the vSphere resource pool from path, return moid
	FindResourcePool(ctx context.Context, path, dcPath string) (string, error)
	// FindFolder find the vSphere folder from path, return moid
	FindFolder(ctx context.Context, path, dcPath string) (string, error)
	// FindVirtualMachine find the vSphere virtual machine from path, return moid
	FindVirtualMachine(ctx context.Context, path, dcPath string) (string, error)
	// FindDataCenter find the vSphere datacenter from path, return moid
	FindDataCenter(ctx context.Context, path string) (string, error)
	// FindDatastore find the vSphere datastore from path, return moid
	FindDatastore(ctx context.Context, path, dcPath string) (string, error)
	// FindNetwork finds the vSphere network from path, return moid
	FindNetwork(ctx context.Context, path, dcPath string) (string, error)
	// GetAndValidateVirtualMachineTemplateForK8sVersion validates and returns valid virtual machine template
	GetAndValidateVirtualMachineTemplate(ovaVersions []string, tkrName string, templateName, dc string, tkgConfigReaderWriter tkgconfigreaderwriter.TKGConfigReaderWriter) (*tkgtypes.VSphereVirtualMachine, error)
	// GetPath returns the full path of a valid vSphere resource
	GetPath(ctx context.Context, moid string) (string, []*models.VSphereManagementObject, error)
}

Client represents a vCenter client

func GetAuthenticatedVCClient

func GetAuthenticatedVCClient(vcHost, vcUsername, vcPassword, thumbprint string, insecure bool, vcClientFactory VcClientFactory) (Client, error)

GetAuthenticatedVCClient returns authenticated VC client

func NewClient

func NewClient(vcURL *url.URL, thumbprint string, insecure bool) (Client, error)

NewClient returns a new VC Client

type DefaultClient

type DefaultClient struct {
	// contains filtered or unexported fields
}

DefaultClient dafaults vc client

func (*DefaultClient) AcquireTicket

func (c *DefaultClient) AcquireTicket() (string, error)

AcquireTicket acquires a new session ticket for the user associated with the authenticated client.

func (*DefaultClient) CheckUserSessionActive

func (c *DefaultClient) CheckUserSessionActive() (bool, error)

CheckUserSessionActive checks if a user session is Active

func (*DefaultClient) DetectPacific

func (c *DefaultClient) DetectPacific(ctx context.Context) (bool, error)

DetectPacific detects if vcenter is a Pacific cluster

func (*DefaultClient) FindDataCenter

func (c *DefaultClient) FindDataCenter(ctx context.Context, path string) (string, error)

FindDataCenter find the vsphere datacenter from path, return moid

func (*DefaultClient) FindDatastore

func (c *DefaultClient) FindDatastore(ctx context.Context, path, dcPath string) (string, error)

FindDatastore find the vsphere datastore from path, return moid

func (*DefaultClient) FindFolder

func (c *DefaultClient) FindFolder(ctx context.Context, path, dcPath string) (string, error)

FindFolder find the vsphere folder from path, return moid

func (*DefaultClient) FindNetwork

func (c *DefaultClient) FindNetwork(ctx context.Context, path, dcPath string) (string, error)

FindNetwork finds the vSphere network from path, return moid

func (*DefaultClient) FindResourcePool

func (c *DefaultClient) FindResourcePool(ctx context.Context, path, dcPath string) (string, error)

FindResourcePool find the vsphere resource pool from path, return moid

func (*DefaultClient) FindVirtualMachine

func (c *DefaultClient) FindVirtualMachine(ctx context.Context, path, dcPath string) (string, error)

FindVirtualMachine find the vsphere virtual machine from path, return moid

func (*DefaultClient) GetAndValidateVirtualMachineTemplate

func (c *DefaultClient) GetAndValidateVirtualMachineTemplate(
	ovaVersions []string,
	tkrVersion string,
	templateName,
	dc string,
	tkgConfigReaderWriter tkgconfigreaderwriter.TKGConfigReaderWriter) (*tkgtypes.VSphereVirtualMachine, error)

GetAndValidateVirtualMachineTemplate gets the vm template for specified k8s version if not provided if provided, it validates the k8s version

func (*DefaultClient) GetComputeResources

func (c *DefaultClient) GetComputeResources(ctx context.Context, datacenterMOID string) ([]*models.VSphereManagementObject, error)

GetComputeResources gets resource pools and their ancestors

func (*DefaultClient) GetDataCenterMOID

func (c *DefaultClient) GetDataCenterMOID(ctx context.Context, dcName string) (string, error)

GetDataCenterMOID return the MOID of the data center

func (*DefaultClient) GetDatacenters

func (c *DefaultClient) GetDatacenters(ctx context.Context) ([]*models.VSphereDatacenter, error)

GetDatacenters returns a list of all datacenters in the vSphere inventory.

func (*DefaultClient) GetDatastores

func (c *DefaultClient) GetDatastores(ctx context.Context, datacenterMOID string) ([]*models.VSphereDatastore, error)

GetDatastores returns a list of Datastores for the given datacenter

func (*DefaultClient) GetFolders

func (c *DefaultClient) GetFolders(ctx context.Context, datacenterMOID string) ([]*models.VSphereFolder, error)

GetFolders gets all folders under a datacenter

func (*DefaultClient) GetNetworks

func (c *DefaultClient) GetNetworks(ctx context.Context, datacenterMOID string) ([]*models.VSphereNetwork, error)

GetNetworks gets list of network for the given datacenter

func (*DefaultClient) GetPath

GetPath takes in the MOID of a vsphere resource and returns a fully qualified path

func (*DefaultClient) GetResourcePools

func (c *DefaultClient) GetResourcePools(ctx context.Context, datacenterMOID string) ([]*models.VSphereResourcePool, error)

GetResourcePools gets resourcepools for the given datacenter

func (*DefaultClient) GetVSphereVersion

func (c *DefaultClient) GetVSphereVersion() (string, string, error)

GetVSphereVersion returns the vSphere version, and the build number

func (*DefaultClient) GetVirtualMachineImages

func (c *DefaultClient) GetVirtualMachineImages(ctx context.Context, datacenterMOID string) ([]*tkgtypes.VSphereVirtualMachine, error)

GetVirtualMachineImages gets vm templates for kubernetes

func (*DefaultClient) GetVirtualMachines

func (c *DefaultClient) GetVirtualMachines(ctx context.Context, datacenterMOID string) ([]*models.VSphereVirtualMachine, error)

GetVirtualMachines gets vms under given datacenter

func (*DefaultClient) Login

func (c *DefaultClient) Login(ctx context.Context, user, password string) (string, error)

Login authenticates with vCenter using user/password

type VcClientFactory

type VcClientFactory interface {
	NewClient(vcURL *url.URL, thumbprint string, insecure bool) (Client, error)
}

VcClientFactory a factory for creating VC clients

func NewVcClientFactory

func NewVcClientFactory() VcClientFactory

NewVcClientFactory creates new vcclient factory

Jump to

Keyboard shortcuts

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