vsphere

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultScheme is the default connection scheme.
	DefaultScheme = "https"
	// DefaultRoundTripperCount is the default SOAP round tripper count.
	DefaultRoundTripperCount = 3
)
View Source
const DatastoreInfoProperty = "info"

DatastoreInfoProperty refers to the property name info for the Datastore

Variables

View Source
var (
	// ErrVCAlreadyRegistered is returned when registration for a previously
	// registered virtual center is attempted.
	ErrVCAlreadyRegistered = errors.New("virtual center was already registered")
	// ErrVCNotFound is returned when a virtual center instance isn't found.
	ErrVCNotFound = errors.New("virtual center wasn't found in registry")
)
View Source
var ErrVMNotFound = errors.New("virtual machine wasn't found")

ErrVMNotFound is returned when a virtual machine isn't found.

Functions

func AsyncGetAllDatacenters

func AsyncGetAllDatacenters(ctx context.Context, buffSize int) (<-chan *Datacenter, <-chan error)

AsyncGetAllDatacenters fetches all Datacenters asynchronously. The *Datacenter chan returns a *Datacenter on discovering one. The error chan returns a single error if one occurs. Both channels are closed when nothing more is to be sent.

The buffer size for the *Datacenter chan can be specified via the buffSize parameter. For example, buffSize could be 1, in which case, the sender will buffer at most 1 *Datacenter instance (and possibly close the channel and terminate, if that was the only instance found).

Note that a context.Canceled error would be returned if the context was canceled at some point during the execution of this function.

func CompareKubernetesMetadata

func CompareKubernetesMetadata(pvMetaData *cnstypes.CnsKubernetesEntityMetadata, cnsMetaData *cnstypes.CnsKubernetesEntityMetadata) bool

CompareKubernetesMetadata compares the whole cnskubernetesEntityMetadata from two given parameters

func GetCnsKubernetesEntityMetaData

func GetCnsKubernetesEntityMetaData(entityName string, labels map[string]string, deleteFlag bool, entityType string, namespace string) *cnstypes.CnsKubernetesEntityMetadata

GetCnsKubernetesEntityMetaData creates a CnsKubernetesEntityMetadataObject object from given parameters

func GetContainerCluster

func GetContainerCluster(clusterid string, username string) cnstypes.CnsContainerCluster

GetContainerCluster creates ContainerCluster object from given parameters

func GetLabelsMapFromKeyValue

func GetLabelsMapFromKeyValue(labels []types.KeyValue) map[string]string

GetLabelsMapFromKeyValue creates a map object from given parameter

func GetVcenterIPs

func GetVcenterIPs(cfg *config.Config) ([]string, error)

GetVcenterIPs returns list of vCenter IPs from VSphereConfig

func IsInvalidCredentialsError

func IsInvalidCredentialsError(err error) bool

IsInvalidCredentialsError returns true if error is of type InvalidLogin

func NewCNSClient

func NewCNSClient(ctx context.Context, c *vim25.Client) (*cns.Client, error)

NewCNSClient creates a new CNS client

Types

type Datacenter

type Datacenter struct {
	// Datacenter represents the govmomi Datacenter.
	*object.Datacenter
	// VirtualCenterHost represents the virtual center host address.
	VirtualCenterHost string
}

Datacenter holds virtual center information along with the Datacenter.

func (*Datacenter) GetAllDatastores

func (dc *Datacenter) GetAllDatastores(ctx context.Context) (map[string]*DatastoreInfo, error)

GetAllDatastores gets the datastore URL to DatastoreInfo map for all the datastores in the datacenter.

func (*Datacenter) GetDatastoreByURL

func (dc *Datacenter) GetDatastoreByURL(ctx context.Context, datastoreURL string) (*Datastore, error)

GetDatastoreByURL returns the *Datastore instance given its URL.

func (*Datacenter) GetVMMoList

func (dc *Datacenter) GetVMMoList(ctx context.Context, vmObjList []*VirtualMachine, properties []string) ([]mo.VirtualMachine, error)

GetVMMoList gets the VM Managed Objects with the given properties from the VM object

func (*Datacenter) GetVirtualMachineByUUID

func (dc *Datacenter) GetVirtualMachineByUUID(ctx context.Context, uuid string, instanceUUID bool) (*VirtualMachine, error)

GetVirtualMachineByUUID returns the VirtualMachine instance given its UUID in a datacenter. If instanceUUID is set to true, then UUID is an instance UUID.

  • In this case, this function searches for virtual machines whose instance UUID matches the given uuid.

If instanceUUID is set to false, then UUID is BIOS UUID.

  • In this case, this function searches for virtual machines whose BIOS UUID matches the given uuid.

func (*Datacenter) String

func (dc *Datacenter) String() string

type Datastore

type Datastore struct {
	// Datastore represents the govmomi Datastore instance.
	*object.Datastore
	// Datacenter represents the datacenter on which the Datastore resides.
	Datacenter *Datacenter
}

Datastore holds Datastore and Datacenter information.

func (*Datastore) GetDatastoreURL

func (ds *Datastore) GetDatastoreURL(ctx context.Context) (string, error)

GetDatastoreURL returns the URL of datastore

type DatastoreInfo

type DatastoreInfo struct {
	*Datastore
	Info *types.DatastoreInfo
}

DatastoreInfo is a structure to store the Datastore and it's Info.

func (DatastoreInfo) String

func (di DatastoreInfo) String() string

type HostSystem

type HostSystem struct {
	// HostSystem represents the host system.
	*object.HostSystem
}

HostSystem holds details of a host instance.

func (*HostSystem) GetAllAccessibleDatastores

func (host *HostSystem) GetAllAccessibleDatastores(ctx context.Context) ([]*DatastoreInfo, error)

GetAllAccessibleDatastores gets the list of accessible datastores for the given host

type VirtualCenter

type VirtualCenter struct {
	// Config represents the virtual center configuration.
	Config *VirtualCenterConfig
	// Client represents the govmomi client instance for the connection.
	Client *govmomi.Client
	// PbmClient represents the govmomi PBM Client instance.
	PbmClient *pbm.Client
	// CnsClient represents the CNS client instance.
	CnsClient *cns.Client
	// contains filtered or unexported fields
}

VirtualCenter holds details of a virtual center instance.

func (*VirtualCenter) Connect

func (vc *VirtualCenter) Connect(ctx context.Context) error

Connect establishes connection with vSphere with existing credentials if session doesn't exist. If credentials are invalid then it fetches latest credential from credential store and connects with it.

func (*VirtualCenter) ConnectCNS

func (vc *VirtualCenter) ConnectCNS(ctx context.Context) error

ConnectCNS creates a CNS client for the virtual center.

func (*VirtualCenter) ConnectPbm

func (vc *VirtualCenter) ConnectPbm(ctx context.Context) error

ConnectPbm creates a PBM client for the virtual center.

func (*VirtualCenter) Disconnect

func (vc *VirtualCenter) Disconnect(ctx context.Context) error

Disconnect disconnects the virtual center host connection if connected.

func (*VirtualCenter) DisconnectCNS

func (vc *VirtualCenter) DisconnectCNS(ctx context.Context)

DisconnectCNS destroys the CNS client for the virtual center.

func (*VirtualCenter) DisconnectPbm

func (vc *VirtualCenter) DisconnectPbm(ctx context.Context) error

DisconnectPbm destroys the PBM client for the virtual center.

func (*VirtualCenter) GetDatacenters

func (vc *VirtualCenter) GetDatacenters(ctx context.Context) ([]*Datacenter, error)

GetDatacenters returns Datacenters found on the VirtualCenter. If no datacenters are mentioned in the VirtualCenterConfig during registration, all Datacenters for the given VirtualCenter will be returned. If DatacenterPaths is configured in VirtualCenterConfig during registration, only the listed Datacenters are returned.

func (*VirtualCenter) GetHostsByCluster

func (vc *VirtualCenter) GetHostsByCluster(ctx context.Context, clusterMorefValue string) ([]*HostSystem, error)

GetHostsByCluster return hosts inside the cluster using cluster moref.

func (*VirtualCenter) GetStoragePolicyIDByName

func (vc *VirtualCenter) GetStoragePolicyIDByName(ctx context.Context, storagePolicyName string) (string, error)

GetStoragePolicyIDByName gets storage policy ID by name.

func (*VirtualCenter) String

func (vc *VirtualCenter) String() string

func (*VirtualCenter) UpdateCredentials

func (vc *VirtualCenter) UpdateCredentials(username, password string)

UpdateCredentials updates username and password in the VirtualCenterConfig object

type VirtualCenterConfig

type VirtualCenterConfig struct {
	// Scheme represents the connection scheme. (Ex: https)
	Scheme string
	// Host represents the virtual center host address.
	Host string
	// Port represents the virtual center host port.
	Port int
	// Username represents the virtual center username.
	Username string
	// Password represents the virtual center password in clear text.
	Password string
	// Specifies whether to verify the server's certificate chain. Set to true to
	// skip verification.
	Insecure bool
	// Specifies the path to a CA certificate in PEM format. This has no effect if
	// Insecure is enabled. Optional; if not configured, the system's CA
	// certificates will be used.
	CAFile string
	// RoundTripperCount is the SOAP round tripper count. (retries = RoundTripperCount - 1)
	RoundTripperCount int
	// DatacenterPaths represents paths of datacenters on the virtual center.
	DatacenterPaths []string
}

VirtualCenterConfig represents virtual center configuration.

func GetVirtualCenterConfig

func GetVirtualCenterConfig(cfg *config.Config) (*VirtualCenterConfig, error)

GetVirtualCenterConfig returns VirtualCenterConfig Object created using vSphere Configuration specified in the argurment.

func (*VirtualCenterConfig) String

func (vcc *VirtualCenterConfig) String() string

type VirtualCenterManager

type VirtualCenterManager interface {
	// GetVirtualCenter returns the VirtualCenter instance given the host.
	GetVirtualCenter(host string) (*VirtualCenter, error)
	// GetAllVirtualCenters returns all VirtualCenter instances. If virtual
	// centers are added or removed concurrently, they may or may not be
	// reflected in the result of a call to this method.
	GetAllVirtualCenters() []*VirtualCenter
	// RegisterVirtualCenter registers a virtual center, but doesn't initiate
	// the connection to the host.
	RegisterVirtualCenter(config *VirtualCenterConfig) (*VirtualCenter, error)
	// UnregisterVirtualCenter disconnects and unregisters the virtual center
	// given it's host.
	UnregisterVirtualCenter(host string) error
	// UnregisterAllVirtualCenters disconnects and unregisters all virtual centers.
	UnregisterAllVirtualCenters() error
}

VirtualCenterManager provides functionality to manage virtual centers.

func GetVirtualCenterManager

func GetVirtualCenterManager() VirtualCenterManager

GetVirtualCenterManager returns the VirtualCenterManager singleton.

type VirtualMachine

type VirtualMachine struct {
	// VirtualCenterHost represents the virtual machine's vCenter host.
	VirtualCenterHost string
	// UUID represents the virtual machine's UUID.
	UUID string
	// VirtualMachine represents the virtual machine.
	*object.VirtualMachine
	// Datacenter represents the datacenter to which the virtual machine belongs.
	Datacenter *Datacenter
}

VirtualMachine holds details of a virtual machine instance.

func GetVirtualMachineByUUID

func GetVirtualMachineByUUID(uuid string, instanceUUID bool) (*VirtualMachine, error)

GetVirtualMachineByUUID returns virtual machine given its UUID in entire VC. If instanceUuid is set to true, then UUID is an instance UUID. In this case, this function searches for virtual machines whose instance UUID matches the given uuid. If instanceUuid is set to false, then UUID is BIOS UUID. In this case, this function searches for virtual machines whose BIOS UUID matches the given uuid.

func (*VirtualMachine) GetAllAccessibleDatastores

func (vm *VirtualMachine) GetAllAccessibleDatastores(ctx context.Context) ([]*DatastoreInfo, error)

GetAllAccessibleDatastores gets the list of accessible Datastores for the given Virtual Machine

func (*VirtualMachine) GetAncestors

func (vm *VirtualMachine) GetAncestors(ctx context.Context) ([]mo.ManagedEntity, error)

GetAncestors returns ancestors of VM example result: "Folder", "Datacenter", "Cluster"

func (*VirtualMachine) GetHostSystem

func (vm *VirtualMachine) GetHostSystem(ctx context.Context) (*object.HostSystem, error)

GetHostSystem returns HostSystem object of the virtual machine

func (*VirtualMachine) GetTagManager

func (vm *VirtualMachine) GetTagManager(ctx context.Context) (*tags.Manager, error)

GetTagManager returns tagManager using vm client

func (*VirtualMachine) GetZoneRegion

func (vm *VirtualMachine) GetZoneRegion(ctx context.Context, zoneCategoryName string, regionCategoryName string) (zone string, region string, err error)

GetZoneRegion returns zone and region of the node vm

func (*VirtualMachine) IsActive

func (vm *VirtualMachine) IsActive(ctx context.Context) (bool, error)

IsActive returns true if Virtual Machine is powered on, else returns false.

func (*VirtualMachine) IsInZoneRegion

func (vm *VirtualMachine) IsInZoneRegion(ctx context.Context, zoneCategoryName string, regionCategoryName string, zoneValue string, regionValue string) (bool, error)

IsInZoneRegion checks if virtual machine belongs to specified zone and region This function returns true if virtual machine belongs to specified zone/region, else returns false.

func (*VirtualMachine) Renew

func (vm *VirtualMachine) Renew(reconnect bool) error

Renew renews the virtual machine and datacenter information. If reconnect is set to true, the virtual center connection is also renewed.

func (*VirtualMachine) String

func (vm *VirtualMachine) String() string

Jump to

Keyboard shortcuts

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