vsphere

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: MIT Imports: 19 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 (
	MgObjRefTypeFolder          string = "Folder"
	MgObjRefTypeDatacenter      string = "Datacenter"
	MgObjRefTypeComputeResource string = "ComputeResource"
	MgObjRefTypeResourcePool    string = "ResourcePool"
	MgObjRefTypeHostSystem      string = "HostSystem"
)

Managed Object Reference types

View Source
const CustomAttributeValNotSet string = "NotSet"

CustomAttributeValNotSet is used to indicate that a Custom Attribute value was not set on an object.

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

View Source
var ErrAvailableFieldValueNotDefined = errors.New("no custom attributes defined within vSphere environment for this type")

ErrAvailableFieldValueNotDefined is returned when no Custom Attributes are defined within an inventory for an associated managed object type.

View Source
var ErrAvailableFieldValueNotFound = errors.New("failed to find a matching available field name")

ErrAvailableFieldValueNotFound is returned when a specified Custom Attribute name cannot be located within an inventory. This might be the case if a specified Custom Attribute name has a typo.

View Source
var ErrConvertBaseCustomFieldValue = errors.New("failed to convert base custom field value to obtain key/value pair")

ErrConvertBaseCustomFieldValue is returned when a conversion error occurs or (type assertion failure) for a provided BaseCustomFieldValue.

TODO: Document how/when this might occur.

View Source
var ErrCustomAttributeKeyNotFound = errors.New("failed to find a matching custom attribute key/value pair for provided custom attribute key")

ErrCustomAttributeKeyNotFound is returned when a Custom Attribute key (and thus the desired value) cannot be found for a vSphere object. This can occur when a Custom Attribute exists within an inventory, but is not applied to a specific managed object.

View Source
var ErrCustomAttributeNotSet = errors.New("custom attributes not set")

ErrCustomAttributeNotSet is similar to ErrCustomAttributeKeyNotFound, but is returned when there are no Custom Attributes set for an associated managed object type.

View Source
var ErrDatastoreUsageCriticalLevel = errors.New("datastore usage critical level")

ErrDatastoreUsageCriticalLevel indicates that Datastore usage has crossed the CRITICAL level threshold.

View Source
var ErrDatastoreUsageWarningLevel = errors.New("datastore usage warning level")

ErrDatastoreUsageWarningLevel indicates that Datastore usage has crossed the CRITICAL level threshold.

View Source
var ErrHostDatastorePairingFailed = errors.New("failed to compile host/datastore pairings")

ErrHostDatastorePairingFailed is returned when compiling host and datastore pairings using provided the Custom Attribute fails. This is usually due to a lack of a match between Custom Attribute values used on hosts and datastores.

For example, this may occur if prefix matching is not enabled and the host Custom Attribute uses a Location attribute which contains a separator between a datacenter and the hosts rack position, whereas a datastore contains only the datacenter.

View Source
var ErrSnapshotAgeThresholdCrossed = errors.New("snapshot exceeds specified age threshold")

ErrSnapshotAgeThresholdCrossed indicates that a snapshot is older than a specified age threshold

View Source
var ErrSnapshotSizeThresholdCrossed = errors.New("snapshot exceeds specified size threshold")

ErrSnapshotSizeThresholdCrossed indicates that a snapshot is larger than a specified size threshold

View Source
var ErrVMDatastoreNotInVMHostPairedList = errors.New("host/datastore/vm mismatch")

ErrVMDatastoreNotInVMHostPairedList is returned when one or more datastores for a VirtualMachine are not in the list of datastores paired with the VirtualMachine's current host.

Functions

func CustomAttrKeyToValue added in v0.2.0

func CustomAttrKeyToValue(caKey int32, customValue []types.BaseCustomFieldValue) (string, error)

CustomAttrKeyToValue receives the key of a Custom Attribute key/value pair a slice of BaseCustomFieldValue which represents the Custom Attribute values for vSphere objects (e.g., HostSystem, Datastore). An error is returned if conversion fails or if the specified Custom Attribute key is not found.

func CustomAttrNameToKey added in v0.2.0

func CustomAttrNameToKey(caName string, availableField []types.CustomFieldDef) (int32, error)

CustomAttrNameToKey receives a user-provided Custom Attribute name and a slice of values which contain key/value fields. If a match for the user-provided Custom Attribute name is found, the matching key is returned. This key can be used to search for a match in the Custom Values associated with vSphere objects (e.g., Hosts, Datastores). An error is returned if a match is not found.

func DatastoreIDsToNames added in v0.2.0

func DatastoreIDsToNames(dsRefs []types.ManagedObjectReference, dss []mo.Datastore) []string

DatastoreIDsToNames returns a list of matching Datastore names for the provided list of Managed Object References for Datastores.

func DatastoreUsageOneLineCheckSummary added in v0.3.0

func DatastoreUsageOneLineCheckSummary(
	stateLabel string,
	dsUsageSummary DatastoreUsageSummary,
) string

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

func DatastoreUsageReport added in v0.3.0

func DatastoreUsageReport(
	c *vim25.Client,
	dsUsageSummary DatastoreUsageSummary,
	dsVMs []mo.VirtualMachine,
) string

DatastoreUsageReport generates a summary of Datastore 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 ExceedsAge added in v0.4.0

func ExceedsAge(snapshotCreated time.Time, days int) bool

ExceedsAge indicates whether a given snapshot creation date is older than the specified number of days.

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 FilterHostSystemByID added in v0.2.0

func FilterHostSystemByID(hss []mo.HostSystem, hsID string) (mo.HostSystem, error)

FilterHostSystemByID receives a collection of HostSystems and a HostSystem ID to filter against. An error is returned if the list of HostSystems is empty or if a match was not found.

func FilterHostSystemByName added in v0.2.0

func FilterHostSystemByName(hss []mo.HostSystem, hsName string) (mo.HostSystem, error)

FilterHostSystemByName accepts a collection of HostSystems and a HostSystem name to filter against. An error is returned if the list of HostSystems 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 FilterVMsWithSnapshots added in v0.4.0

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

FilterVMsWithSnapshots filters the provided collection of VirtualMachines to just those with snapshots. Later steps are responsible for validating whether those snapshots place the VMs into non-OK states.

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 datastore, 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 GetHostSystemByName added in v0.2.0

func GetHostSystemByName(ctx context.Context, c *vim25.Client, hsName string, datacenter string, propsSubset bool) (mo.HostSystem, error)

GetHostSystemByName accepts the name of a HostSystem, the name of a datacenter and a boolean value indicating whether only a subset of properties for the HostSystem 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 GetHostSystems added in v0.2.0

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

GetHostSystems accepts a context, a connected client and a boolean value indicating whether a subset of properties per HostSystem are retrieved. A collection of HostSystems 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 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 GetObjectCAVal added in v0.2.0

func GetObjectCAVal(caName string, obj mo.ManagedEntity) (string, error)

GetObjectCAVal receives the name of a Custom Attribute and a ManagedEntity, an abstract base type for all managed objects present in the inventory tree and returns the value for the specified Custom Attribute. An error is returned if the value could not be retrieved indicating the cause of the failure.

func GetRPByName added in v0.2.0

func GetRPByName(ctx context.Context, c *vim25.Client, rpName string, datacenter string, propsSubset bool) (mo.ResourcePool, error)

GetRPByName accepts the name of a Resource Pool, 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 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 GetVMsFromDatastore added in v0.3.0

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

GetVMsFromDatastore receives a Datastore object reference 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 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 H2D2VMsOneLineCheckSummary added in v0.2.0

func H2D2VMsOneLineCheckSummary(
	stateLabel string,
	vmDatastoresPairingIssues VMToMismatchedDatastoreNames,
	evaluatedVMs []mo.VirtualMachine,
	rps []mo.ResourcePool,
) string

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

func H2D2VMsReport added in v0.2.0

func H2D2VMsReport(
	c *vim25.Client,
	h2dIdx HostToDatastoreIndex,
	allVMs []mo.VirtualMachine,
	evaluatedVMs []mo.VirtualMachine,
	vmDatastoresPairingIssues VMToMismatchedDatastoreNames,
	vmsToExclude []string,
	evalPoweredOffVMs bool,
	includeRPs []string,
	excludeRPs []string,
	rps []mo.ResourcePool,
	ignoreMissingCA bool,
	ignoredDatastores []string,
	datastoreCAPrefixSeparator string,
	hostCAPrefixSeparator string,
	datastoreCAName string,
	hostCAName string,
) string

H2D2VMsReport generates a summary of host/datastore/vms pairings along with additional 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 Login

func Login(
	ctx context.Context,
	server string,
	port int,
	trustCert bool,
	username string,
	domain string,
	password string,
) (*govmomi.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 SnapshotsAgeOneLineCheckSummary added in v0.4.0

func SnapshotsAgeOneLineCheckSummary(
	stateLabel string,
	snapshotSets SnapshotSummarySets,
	snapshotsAgeCritical int,
	snapshotsAgeWarning int,
	evaluatedVMs []mo.VirtualMachine,
	rps []mo.ResourcePool,
) string

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

func SnapshotsAgeReport added in v0.4.0

func SnapshotsAgeReport(
	c *vim25.Client,
	snapshotSummarySets SnapshotSummarySets,
	snapshotsAgeCritical int,
	snapshotsAgeWarning int,
	allVMs []mo.VirtualMachine,
	evaluatedVMs []mo.VirtualMachine,
	vmsWithIssues []mo.VirtualMachine,
	vmsToExclude []string,
	evalPoweredOffVMs bool,
	includeRPs []string,
	excludeRPs []string,
	rps []mo.ResourcePool,
) string

SnapshotsAgeReport generates a summary of snapshot details 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 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,
	evalPoweredOffVMs bool,
	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,
	evalPoweredOffVMs bool,
	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,
	evalPoweredOffVMs bool,
	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 DatastoreIDToNameIndex added in v0.2.0

type DatastoreIDToNameIndex map[string]string

DatastoreIDToNameIndex maps a Datastore's ID value to its name.

type DatastoreUsageSummary added in v0.3.0

type DatastoreUsageSummary struct {
	Datastore               mo.Datastore
	StorageRemainingPercent float64
	StorageUsedPercent      float64
	StorageTotal            int64
	StorageUsed             int64
	StorageRemaining        int64
	CriticalThreshold       int
	WarningThreshold        int
}

DatastoreUsageSummary tracks usage details for a specific Datastore

func NewDatastoreUsageSummary added in v0.3.0

func NewDatastoreUsageSummary(ds mo.Datastore, criticalThreshold int, warningThreshold int) DatastoreUsageSummary

NewDatastoreUsageSummary receives a Datastore and generates summary information used to determine if usage levels have crossed user-specified thresholds.

func (DatastoreUsageSummary) IsCriticalState added in v0.3.0

func (dus DatastoreUsageSummary) IsCriticalState() bool

IsCriticalState indicates whether Datastore usage has crossed the CRITICAL level threshold.

func (DatastoreUsageSummary) IsWarningState added in v0.3.0

func (dus DatastoreUsageSummary) IsWarningState() bool

IsWarningState indicates whether Datastore usage has crossed the WARNING level threshold.

type DatastoreWithCA added in v0.2.0

type DatastoreWithCA struct {
	mo.Datastore
	CustomAttribute PairingCustomAttribute
}

DatastoreWithCA wraps the vSphere Datastore managed object type with a Custom Attribute key/value pair. This Custom Attribute is intended to link this datastore to a specific ESXi host.

type ErrHostDatastoreIdxIDToNameLookupFailed added in v0.2.0

type ErrHostDatastoreIdxIDToNameLookupFailed struct {
	DatastoreID string
	Err         error
}

ErrHostDatastoreIdxIDToNameLookupFailed is returned when a search of the host to datastore index fails to yield a name for a specified ID value. This can occur if the datastore for a VM is in a user-specified ignored datastores list.

func (ErrHostDatastoreIdxIDToNameLookupFailed) Error added in v0.2.0

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.

type HostDatastoresPairing added in v0.2.0

type HostDatastoresPairing struct {
	Host       HostWithCA
	Datastores []DatastoreWithCA
}

HostDatastoresPairing collects Host and Datastores pairings based on shared Custom Attribute name and value (literal) or prefix (if user-specified). This is intended to "pair" hosts and datastores within an environment that are known to work well together.

type HostToDatastoreIndex added in v0.2.0

type HostToDatastoreIndex map[string]HostDatastoresPairing

HostToDatastoreIndex indexes HostDatastorePairings based on host id values.

func NewHostToDatastoreIndex added in v0.2.0

func NewHostToDatastoreIndex(
	hosts []HostWithCA,
	datastores []DatastoreWithCA,
	usingPrefixes bool,
	hostCASep string,
	datastoreCASep string,
) (HostToDatastoreIndex, error)

NewHostToDatastoreIndex receives a collection of hosts and datastores wrapped with user-specified Custom Attributes, prefix separators and a boolean flag indicating whether prefix matching will be used. The resulting HostToDatastoreIndex is returned if no errors occur, otherwise nil and the error.

func (HostToDatastoreIndex) DatastoreIDToName added in v0.2.0

func (hdi HostToDatastoreIndex) DatastoreIDToName(dsID string) (string, error)

DatastoreIDToName returns the name associated with a Datastore ID. An error is returned if the name could not be retrieved from the index.

func (HostToDatastoreIndex) DatastoreIDToNameIndex added in v0.2.0

func (hdi HostToDatastoreIndex) DatastoreIDToNameIndex() DatastoreIDToNameIndex

DatastoreIDToNameIndex returns an index of all Datastore IDs to names in the index.

func (HostToDatastoreIndex) DatastoreNames added in v0.2.0

func (hdi HostToDatastoreIndex) DatastoreNames() []string

DatastoreNames returns a list of all Datastore names in the index.

func (HostToDatastoreIndex) IsDatastoreIDInIndex added in v0.2.0

func (hdi HostToDatastoreIndex) IsDatastoreIDInIndex(dsID string) bool

IsDatastoreIDInIndex indicates whether a provided Datastore ID is in the index.

func (HostToDatastoreIndex) ValidateVirtualMachinePairings added in v0.2.0

func (hdi HostToDatastoreIndex) ValidateVirtualMachinePairings(
	vmHostID string,
	allDatastores []mo.Datastore,
	vmDatastoreRefs []types.ManagedObjectReference,
	dsNamesToIgnore []string,
) ([]string, error)

ValidateVirtualMachinePairings receives a VirtualMachine ID, a collection of Datastore IDs associated with the VM and an optional list of Datastore names to ignore. A list of mismatched datastores is returned along with any errors that may occur.

type HostWithCA added in v0.2.0

type HostWithCA struct {
	mo.HostSystem
	CustomAttribute PairingCustomAttribute
}

HostWithCA wraps the vSphere HostSystem managed object type with a Custom Attribute key/value pair. This Custom Attribute is intended to link this host to one or more datastores.

type PairingCustomAttribute added in v0.2.0

type PairingCustomAttribute struct {
	Name  string
	Value string
}

PairingCustomAttribute represents the key/value Custom Attribute pair used to relate specific hosts with specific datastores. Most often this takes the form of a "Location" or "Datacenter" field to indicate which Datastore a VirtualMachine should reside on when running on a specific HostSystem.

type SnapshotSummary added in v0.4.0

type SnapshotSummary struct {

	// Name of the snapshot in human readable format.
	Name string

	// MOID is the Managed Object Reference value for the snapshot.
	MOID string

	// Description of the snapshot in human readable format.
	Description string

	// Size is the size of the snapshot.
	Size int64

	// ID is the unique identifier that distinguishes this snapshot from other
	// snapshots of the virtual machine.
	ID int32

	VMName string
	// contains filtered or unexported fields
}

SnapshotSummary is intended to be a summary of the most commonly used snapshot details for a specific VirtualMachine snapshot.

func (SnapshotSummary) Age added in v0.4.0

func (ss SnapshotSummary) Age() string

Age returns the age of a snapshot in formatted days.

func (SnapshotSummary) AgeDays added in v0.4.0

func (ss SnapshotSummary) AgeDays() float64

AgeDays returns the age of a snapshot in days.

func (SnapshotSummary) IsAgeCriticalState added in v0.4.0

func (ss SnapshotSummary) IsAgeCriticalState() bool

IsAgeCriticalState indicates whether the snapshot has exceeded the age CRITICAL threshold.

func (SnapshotSummary) IsAgeExceeded added in v0.4.0

func (ss SnapshotSummary) IsAgeExceeded(days int) bool

IsAgeExceeded indicates whether the snapshot is older than the specified number of days.

func (SnapshotSummary) IsAgeWarningState added in v0.4.0

func (ss SnapshotSummary) IsAgeWarningState() bool

IsAgeWarningState indicates whether the snapshot has exceeded the age WARNING threshold.

func (SnapshotSummary) IsCriticalState added in v0.4.0

func (ss SnapshotSummary) IsCriticalState() bool

IsCriticalState indicates whether the snapshot has exceeded age or size CRITICAL thresholds.

func (SnapshotSummary) IsSizeCriticalState added in v0.4.0

func (ss SnapshotSummary) IsSizeCriticalState() bool

IsSizeCriticalState indicates whether the snapshot has exceeded the size CRITICAL threshold.

func (SnapshotSummary) IsSizeWarningState added in v0.4.0

func (ss SnapshotSummary) IsSizeWarningState() bool

IsSizeWarningState indicates whether the snapshot has exceeded the size WARNING threshold.

func (SnapshotSummary) IsWarningState added in v0.4.0

func (ss SnapshotSummary) IsWarningState() bool

IsWarningState indicates whether the snapshot has exceeded age or size WARNING thresholds.

func (SnapshotSummary) SizeHR added in v0.4.0

func (ss SnapshotSummary) SizeHR() string

SizeHR returns the human readable size of the snapshot. TODO: See atc0005/check-vmware#4,vmware/govmomi#2243

type SnapshotSummarySet added in v0.4.0

type SnapshotSummarySet struct {
	VM        types.ManagedObjectReference
	Snapshots []SnapshotSummary
}

SnapshotSummarySet ties a collection of snapshot summary values to a specific VirtualMachine by way of a VirtualMachine Managed Object Reference.

func NewSnapshotSummarySet added in v0.4.0

func NewSnapshotSummarySet(
	vm mo.VirtualMachine,
	snapshotsAgeCritical int,
	snapshotsAgeWarning int,
	snapshotsSizeCritical int,
	snapshotsSizeWarning int,
) SnapshotSummarySet

NewSnapshotSummarySet returns a set of SnapshotSummary values for snapshots associated with a specified VirtualMachine.

func (SnapshotSummarySet) ExceedsAge added in v0.4.0

func (sss SnapshotSummarySet) ExceedsAge(days int) int

ExceedsAge indicates how many snapshots in the set are older than the specified number of days.

func (SnapshotSummarySet) IsAgeCriticalState added in v0.4.0

func (sss SnapshotSummarySet) IsAgeCriticalState() bool

IsAgeCriticalState indicates whether the snapshot set has exceeded the age CRITICAL threshold.

func (SnapshotSummarySet) IsAgeWarningState added in v0.4.0

func (sss SnapshotSummarySet) IsAgeWarningState() bool

IsAgeWarningState indicates whether the snapshot set has exceeded the age WARNING threshold.

func (SnapshotSummarySet) IsCriticalState added in v0.4.0

func (sss SnapshotSummarySet) IsCriticalState() bool

IsCriticalState indicates whether the snapshot set has exceeded age or size CRITICAL thresholds.

func (SnapshotSummarySet) IsSizeCriticalState added in v0.4.0

func (sss SnapshotSummarySet) IsSizeCriticalState() bool

IsSizeCriticalState indicates whether the snapshot set has exceeded the size CRITICAL threshold.

func (SnapshotSummarySet) IsSizeWarningState added in v0.4.0

func (sss SnapshotSummarySet) IsSizeWarningState() bool

IsSizeWarningState indicates whether the snapshot set has exceeded the size WARNING threshold.

func (SnapshotSummarySet) IsWarningState added in v0.4.0

func (sss SnapshotSummarySet) IsWarningState() bool

IsWarningState indicates whether the snapshot set has exceeded age or size WARNING thresholds.

func (SnapshotSummarySet) Size added in v0.4.0

func (sss SnapshotSummarySet) Size() int64

Size returns the size of all snapshots in the set. TODO: See atc0005/check-vmware#4,vmware/govmomi#2243

func (SnapshotSummarySet) SizeHR added in v0.4.0

func (sss SnapshotSummarySet) SizeHR() string

SizeHR returns the human readable size of all snapshots in the set. TODO: See atc0005/check-vmware#4,vmware/govmomi#2243

type SnapshotSummarySets added in v0.4.0

type SnapshotSummarySets []SnapshotSummarySet

SnapshotSummarySets is a collection of SnapshotSummarySet types for bulk operations. Most often this is used when determining the overall state of all sets in the collection.

func (SnapshotSummarySets) ExceedsAge added in v0.4.0

func (sss SnapshotSummarySets) ExceedsAge(days int) int

ExceedsAge indicates how many snapshots in any of the sets are older than the specified number of days.

func (SnapshotSummarySets) IsAgeCriticalState added in v0.4.0

func (sss SnapshotSummarySets) IsAgeCriticalState() bool

IsAgeCriticalState indicates whether the snapshot sets have exceeded the age CRITICAL threshold.

func (SnapshotSummarySets) IsAgeWarningState added in v0.4.0

func (sss SnapshotSummarySets) IsAgeWarningState() bool

IsAgeWarningState indicates whether the snapshot sets have exceeded the age WARNING threshold.

func (SnapshotSummarySets) IsCriticalState added in v0.4.0

func (sss SnapshotSummarySets) IsCriticalState() bool

IsCriticalState indicates whether the snapshot sets have exceeded age or size CRITICAL thresholds.

func (SnapshotSummarySets) IsSizeCriticalState added in v0.4.0

func (sss SnapshotSummarySets) IsSizeCriticalState() bool

IsSizeCriticalState indicates whether the snapshot sets have exceeded the size CRITICAL threshold.

func (SnapshotSummarySets) IsSizeWarningState added in v0.4.0

func (sss SnapshotSummarySets) IsSizeWarningState() bool

IsSizeWarningState indicates whether the snapshot sets have exceeded the size WARNING threshold.

func (SnapshotSummarySets) IsWarningState added in v0.4.0

func (sss SnapshotSummarySets) IsWarningState() bool

IsWarningState indicates whether the snapshot sets have exceeded age or size WARNING thresholds.

type SnapshotsIndex added in v0.4.0

type SnapshotsIndex map[string]types.VirtualMachineSnapshotTree

SnapshotsIndex is a mapping of Snapshot ManagedObjectReference to a tree of snapshot details. This type is intended to help with producing a superset type combining a summary of snapshot metadata with the original VirtualMachine object.

Deprecated ?

type VMHostDatastoresPairing added in v0.2.0

type VMHostDatastoresPairing struct {
	HostName       string
	DatastoreNames []string
}

VMHostDatastoresPairing collects HostSystem, VirtualMachine and Datastore name pairings.

type VMToMismatchedDatastoreNames added in v0.2.0

type VMToMismatchedDatastoreNames map[string]VMHostDatastoresPairing

VMToMismatchedDatastoreNames indexes VirtualMachine name to VMHostDatastoresPairing type. This index reflects mismatched Datastore names based on the current host for the VirtualMachine.

Jump to

Keyboard shortcuts

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