vsphere

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package vsphere provides various wrapper functions and types for interacting with and monitoring VMware vSphere environments.

Index

Constants

View Source
const ParentResourcePool string = "Resources"

ParentResourcePool represents the hidden resource pool named Resources which is present on virtual machine hosts. This resource pool is a parent of all resource pools of the host. Including this pool in "eligible" resource pool lists throws off calculations (e.g., causes a VM to show up twice).

Variables

This section is empty.

Functions

func ExcludeVMsByName

func ExcludeVMsByName(allVMs []mo.VirtualMachine, ignoreList []string) []mo.VirtualMachine

ExcludeVMsByName receives a collection of VirtualMachines and a list of VMs that should be ignored. A new collection minus ignored VirtualMachines is returned. If the collection of VirtualMachine is empty, an empty collection is returned. If the list of ignored VirtualMachines is empty, the same items from the received collection of VirtualMachines is returned. If the list of ignored VirtualMachines is greater than the list of received VirtualMachines, then only matching VirtualMachines will be excluded and any others silently skipped.

func FilterDatastoreByID

func FilterDatastoreByID(dss []mo.Datastore, dsID string) (mo.Datastore, error)

FilterDatastoreByID receives a collection of Datastores and a Datastore ID to filter against. An error is returned if the list of Datastores is empty or if a match was not found.

func FilterDatastoreByName

func FilterDatastoreByName(dss []mo.Datastore, dsName string) (mo.Datastore, error)

FilterDatastoreByName accepts a collection of Datastores and a Datastore name to filter against. An error is returned if the list of Datastores is empty or if a match was not found.

func FilterNetworkByID

func FilterNetworkByID(nets []mo.Network, netID string) (mo.Network, error)

FilterNetworkByID receives a collection of Networks and a Network ID to filter against. An error is returned if the list of Networks is empty or if a match was not found.

func FilterNetworkByName

func FilterNetworkByName(nets []mo.Network, netName string) (mo.Network, error)

FilterNetworkByName accepts a collection of Networks and a Network name to filter against. An error is returned if the list of Networks is empty or if a match was not found.

func FilterVMByID

func FilterVMByID(vms []mo.VirtualMachine, vmID string) (mo.VirtualMachine, error)

FilterVMByID receives a collection of VirtualMachines and a VirtualMachine ID to filter against. An error is returned if the list of VirtualMachines is empty or if a match was not found.

func FilterVMByName

func FilterVMByName(vms []mo.VirtualMachine, vmName string) (mo.VirtualMachine, error)

FilterVMByName accepts a collection of VirtualMachines and a VirtualMachine name to filter against. An error is returned if the list of VirtualMachines is empty or if a match was not found.

func FilterVMsByPowerState

func FilterVMsByPowerState(vms []mo.VirtualMachine, includePoweredOff bool) []mo.VirtualMachine

FilterVMsByPowerState accepts a collection of VirtualMachines and a boolean value to indicate whether powered off VMs should be included in the returned collection. If the collection of provided VirtualMachines is empty, an empty collection is returned.

func FilterVMsWithOldHardware

func FilterVMsWithOldHardware(vms []mo.VirtualMachine, hwIndex HardwareVersionsIndex) []mo.VirtualMachine

FilterVMsWithOldHardware filters the provided collection of VirtualMachines to just those with older hardware versions.

func FilterVMsWithToolsIssues

func FilterVMsWithToolsIssues(vms []mo.VirtualMachine) []mo.VirtualMachine

FilterVMsWithToolsIssues filters the provided collection of VirtualMachines to just those with non-OK status.

func GetDatastoreByName

func GetDatastoreByName(ctx context.Context, c *vim25.Client, dsName string, datacenter string, propsSubset bool) (mo.Datastore, error)

GetDatastoreByName accepts the name of a network, the name of a datacenter and a boolean value indicating whether only a subset of properties for the Datastore should be returned. If requested, a subset of all available properties will be retrieved (faster) instead of recursively fetching all properties (about 2x as slow). If the datacenter name is an empty string then the default datacenter will be used.

func GetDatastores

func GetDatastores(ctx context.Context, c *vim25.Client, propsSubset bool) ([]mo.Datastore, error)

GetDatastores accepts a context, a connected client and a boolean value indicating whether a subset of properties per Datastore are retrieved. A collection of Datastores with requested properties is returned. If requested, a subset of all available properties will be retrieved (faster) instead of recursively fetching all properties (about 2x as slow).

func GetEligibleRPs

func GetEligibleRPs(ctx context.Context, c *vim25.Client, includeRPs []string, excludeRPs []string, propsSubset bool) ([]mo.ResourcePool, error)

GetEligibleRPs receives a list of Resource Pool names that should either be explicitly included or excluded along with a boolean value indicating whether only a subset of properties for the Resource Pools should be returned. If requested, a subset of all available properties will be retrieved (faster) instead of recursively fetching all properties (about 2x as slow). The filtered list of Resource Pools is returned, or an error if one occurs.

func GetNetworkByName

func GetNetworkByName(ctx context.Context, c *vim25.Client, netName string, datacenter string, propsSubset bool) (mo.Network, error)

GetNetworkByName accepts the name of a network, the name of a datacenter and a boolean value indicating whether only a subset of properties for the Network should be returned. If requested, a subset of all available properties will be retrieved (faster) instead of recursively fetching all properties (about 2x as slow). If the datacenter name is an empty string then the default datacenter will be used.

func GetNetworks

func GetNetworks(ctx context.Context, c *vim25.Client, propsSubset bool) ([]mo.Network, error)

GetNetworks accepts a context, a connected client and a boolean value indicating whether a subset of properties per Network are retrieved. If requested, a subset of all available properties will be retrieved (faster) instead of recursively fetching all properties (about 2x as slow). A collection of Networks with requested properties is returned or nil and an error, if one occurs.

func GetVMByName

func GetVMByName(ctx context.Context, c *vim25.Client, vmName string, datacenter string, propsSubset bool) (mo.VirtualMachine, error)

GetVMByName accepts the name of a VirtualMachine, the name of a datacenter and a boolean value indicating whether only a subset of properties for the VirtualMachine should be returned. If requested, a subset of all available properties will be retrieved (faster) instead of recursively fetching all properties (about 2x as slow). If the datacenter name is an empty string then the default datacenter will be used.

func GetVMToolsStatusSummary

func GetVMToolsStatusSummary(vms []mo.VirtualMachine) (string, int)

GetVMToolsStatusSummary accepts a collection of VirtualMachines and checks the ToolsStatus for each one providing an overall Nagios state label and exit code for the collection.

func GetVMs

func GetVMs(ctx context.Context, c *vim25.Client, propsSubset bool) ([]mo.VirtualMachine, error)

GetVMs accepts a context, a connected client and a boolean value indicating whether a subset of properties per VirtualMachine are retrieved. If requested, a subset of all available properties will be retrieved (faster) instead of recursively fetching all properties (about 2x as slow) A collection of VirtualMachines with requested properties is returned or nil and an error, if one occurs.

func GetVMsFromRPs

func GetVMsFromRPs(ctx context.Context, c *vim25.Client, rps []mo.ResourcePool, propsSubset bool) ([]mo.VirtualMachine, error)

GetVMsFromRPs receives a list of ResourcePool object references and returns a list of VirtualMachine object references. The propsSubset boolean value indicates whether a subset of properties per VirtualMachine are retrieved. If requested, a subset of all available properties will be retrieved (faster) instead of recursively fetching all properties (about 2x as slow) A collection of VirtualMachines with requested properties is returned or nil and an error, if one occurs.

func Login

func Login(
	ctx context.Context,
	server string,
	port int,
	trustCert bool,
	username string,
	domain string,
	password string,
) (*vim25.Client, error)

Login receives credentials and related settings used to handle creating a new client and logging into a specified vSphere environment. The initialized and logged-in client is returned for further use.

func VMToolsOneLineCheckSummary

func VMToolsOneLineCheckSummary(stateLabel string, vmsWithIssues []mo.VirtualMachine, evaluatedVMs []mo.VirtualMachine, rps []mo.ResourcePool) string

VMToolsOneLineCheckSummary is used to generate a one-line Nagios service check results summary. This is the line most prominent in notifications.

func VMToolsReport

func VMToolsReport(
	c *vim25.Client,
	allVMs []mo.VirtualMachine,
	evaluatedVMs []mo.VirtualMachine,
	vmsWithIssues []mo.VirtualMachine,
	vmsToExclude []string,
	includeRPs []string,
	excludeRPs []string,
	rps []mo.ResourcePool,
) string

VMToolsReport generates a comprehensive summary including any active issues along with various verbose details intended to aid in troubleshooting check results at a glance. This information is provided for use with the Long Service Output field commonly displayed on the detailed service check results display in the web UI or in the body of many notifications.

func ValidateRPs

func ValidateRPs(ctx context.Context, c *vim25.Client, includeRPs []string, excludeRPs []string) error

ValidateRPs is responsible for receiving two lists of resource pools, explicitly "included" (aka, "whitelisted") and explicitly "excluded" (aka, "blacklisted"). If any list entries are not found in the vSphere environment an error is returned listing which ones.

func VirtualCPUsOneLineCheckSummary

func VirtualCPUsOneLineCheckSummary(
	stateLabel string,
	vCPUsAllocated int32,
	vCPUsMax int,
	evaluatedVMs []mo.VirtualMachine,
	rps []mo.ResourcePool,
) string

VirtualCPUsOneLineCheckSummary is used to generate a one-line Nagios service check results summary. This is the line most prominent in notifications.

func VirtualCPUsReport

func VirtualCPUsReport(
	c *vim25.Client,
	vCPUsAllocated int32,
	vCPUsMax int,
	allVMs []mo.VirtualMachine,
	evaluatedVMs []mo.VirtualMachine,
	vmsToExclude []string,
	includeRPs []string,
	excludeRPs []string,
	rps []mo.ResourcePool,
) string

VirtualCPUsReport generates a summary of vCPU usage along with various verbose details intended to aid in troubleshooting check results at a glance. This information is provided for use with the Long Service Output field commonly displayed on the detailed service check results display in the web UI or in the body of many notifications.

func VirtualHardwareOneLineCheckSummary

func VirtualHardwareOneLineCheckSummary(
	stateLabel string,
	hwvIndex HardwareVersionsIndex,
	vmsWithIssues []mo.VirtualMachine,
	evaluatedVMs []mo.VirtualMachine,
	rps []mo.ResourcePool,
) string

VirtualHardwareOneLineCheckSummary is used to generate a one-line Nagios service check results summary. This is the line most prominent in notifications.

func VirtualHardwareReport

func VirtualHardwareReport(
	c *vim25.Client,
	hwvIndex HardwareVersionsIndex,
	allVMs []mo.VirtualMachine,
	evaluatedVMs []mo.VirtualMachine,
	vmsWithIssues []mo.VirtualMachine,
	vmsToExclude []string,
	includeRPs []string,
	excludeRPs []string,
	rps []mo.ResourcePool,
) string

VirtualHardwareReport generates a summary of virtual hardware details intended to aid in troubleshooting check results at a glance. This information is provided for use with the Long Service Output field commonly displayed on the detailed service check results display in the web UI or in the body of many notifications.

Types

type HardwareVersion

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

HardwareVersion represents the virtual hardware version of a VirtualMachine.

func (HardwareVersion) Count

func (hv HardwareVersion) Count() int

Count returns the number of VirtualMachines with this specific virtual hardware version.

func (HardwareVersion) IsHighest

func (hv HardwareVersion) IsHighest() bool

IsHighest indicates whether this HardwareVersion is the highest version in our inventory.

func (HardwareVersion) String

func (hv HardwareVersion) String() string

String is a Stringer implementation to return the original formatted string.

func (HardwareVersion) VersionNumber

func (hv HardwareVersion) VersionNumber() int

VersionNumber returns the numeric version number of a VirtualMachine or -1 if there was an issue converting the prefixed string value to a usable number.

type HardwareVersions

type HardwareVersions []HardwareVersion

HardwareVersions represents a collection of HardwareVersion.

func (HardwareVersions) Sum

func (hvs HardwareVersions) Sum() int

Sum provides the total count of all HardwareVersion entries.

func (HardwareVersions) VersionNames

func (hvs HardwareVersions) VersionNames() []string

VersionNames returns a list of all hardware versions in their original string format.

func (HardwareVersions) VersionNumbers

func (hvs HardwareVersions) VersionNumbers() []int

VersionNumbers returns a list of all hardware versions in numerical format. -1 is returned for each hardware version if there was an issue converting the prefixed string value to a usable number.

type HardwareVersionsIndex

type HardwareVersionsIndex map[string]int

HardwareVersionsIndex is a map of hardware version to number of VMs present with that hardware version. This index serves as just that, an index. Accessor methods are provided to obtain HardwareVersion and HardwareVersions types which provide most of the useful methods for working with hardware version entries.

func (HardwareVersionsIndex) Count

func (hvi HardwareVersionsIndex) Count() int

Count returns the number of hardware versions stored in the index.

func (HardwareVersionsIndex) Newest

Newest returns the highest hardware version stored in the index. This value is returned as a HardwareVersion type, providing both the original vmx-123 formatted string in addition to the actual version number.

func (HardwareVersionsIndex) Oldest

Oldest returns the highest hardware version stored in the index. This value is returned as a HardwareVersion type, providing both the original vmx-123 formatted string in addition to the actual version number.

func (HardwareVersionsIndex) Outdated

func (hvi HardwareVersionsIndex) Outdated() HardwareVersions

Outdated returns a collection of all older HardwareVersion.

func (HardwareVersionsIndex) Versions

func (hvi HardwareVersionsIndex) Versions() HardwareVersions

Versions returns a collection of all HardwareVersion entries from the index.

Jump to

Keyboard shortcuts

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