vm

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HardwareVersionProperty = "config.version"
	PowerStateProperty      = "runtime.powerState"
)
View Source
const (
	ReconcileMinHardwareVersionResultUpgraded = iota + 1
	ReconcileMinHardwareVersionResultNotPoweredOff
	ReconcileMinHardwareVersionResultAlreadyUpgraded
	ReconcileMinHardwareVersionResultMinHardwareVersionZero
)
View Source
const DefaultTrySoftTimeout = 5 * time.Minute

DefaultTrySoftTimeout is the default amount of time a TrySoft operation waits for a desired power state to be realized before switching to a Hard operation.

View Source
const (

	// ExtraConfigKeyLastRestartTime is the name of the key in a VM's
	// ExtraConfig array that contains the epoch of the last time the VM was
	// restarted.
	ExtraConfigKeyLastRestartTime = "vmservice.lastRestartTime"
)

Variables

This section is empty.

Functions

func GetLastRestartTimeFromExtraConfig

func GetLastRestartTimeFromExtraConfig(
	ctx context.Context,
	extraConfig []types.BaseOptionValue) (*time.Time, error)

GetLastRestartTimeFromExtraConfig inspects the provided ExtraConfig for the key "vmservice.lastRestartTime" and returns its value. If not found, nil is returned. If the key exists but the value is not an epoch, then an error is returned.

func ManagedObjectFromMoRef

func ManagedObjectFromMoRef(moRef types.ManagedObjectReference) mo.VirtualMachine

func ManagedObjectFromObject

func ManagedObjectFromObject(obj *object.VirtualMachine) mo.VirtualMachine

func ParsePowerState

func ParsePowerState(m string) types.VirtualMachinePowerState

ParsePowerState parses a VM Op API PowerState and returns the corresponding vim25 value.

func Restart

func Restart(
	ctx context.Context,
	client *vim25.Client,
	mo mo.VirtualMachine,
	fetchProperties bool,
	desiredLastRestartTime time.Time,
	powerOpBehavior PowerOpBehavior) <-chan any

Restart restarts a VM if the provided lastRestart timestamp occurs after the last time the VM was restarted. If fetchProperties is true, then even if already known, the required properties are fetched from vSphere. Either a PowerOpResult or error object will be sent on the returned channel prior to its closure.

func SetPowerState

func SetPowerState(
	ctx context.Context,
	client *vim25.Client,
	mo mo.VirtualMachine,
	fetchProperties bool,
	desiredPowerState types.VirtualMachinePowerState,
	powerOpBehavior PowerOpBehavior) <-chan any

SetPowerState updates a VM's power state if the power state in the provided, managed object is missing or does not match the desired power state. If fetchProperties is true, then even if already known, the required properties are fetched from vSphere. Either a PowerOpResult or error object will be sent on the returned channel prior to its closure.

Types

type ErrInvalidPowerOpBehavior

type ErrInvalidPowerOpBehavior struct {
	PowerOpBehavior PowerOpBehavior
}

ErrInvalidPowerOpBehavior is returned if a power op behavior is not one of the pre-defined constants that map to PowerOpBehavior in this package.

func (ErrInvalidPowerOpBehavior) Error

Error enables this type to be returned as a Golang error object.

type ErrInvalidPowerOpResult

type ErrInvalidPowerOpResult struct {
	PowerOpResult any
}

ErrInvalidPowerOpResult is returned if the channel returned by SetPowerState and/or Restart receives a value that is a type other than PowerOpResult or error.

func (ErrInvalidPowerOpResult) Error

func (e ErrInvalidPowerOpResult) Error() string

Error enables this type to be returned as a Golang error object.

type ErrInvalidPowerState

type ErrInvalidPowerState struct {
	PowerState types.VirtualMachinePowerState
}

ErrInvalidPowerState is returned if a power state does not map to "poweredOff", "poweredOn", or "suspended".

func (ErrInvalidPowerState) Error

func (e ErrInvalidPowerState) Error() string

Error enables this type to be returned as a Golang error object.

type PowerOpBehavior

type PowerOpBehavior uint8

PowerOpBehavior indicates the three behaviors for powering off or suspending a VM.

const (
	// PowerOpBehaviorHard causes a VM to be powered off with the PowerOff API
	// or to be suspended with the Suspend API.
	PowerOpBehaviorHard PowerOpBehavior = iota + 1

	// PowerOpBehaviorSoft causes a VM to be powered off with the ShutdownGuest
	// API or to be suspended with the StandbyGuest API.
	PowerOpBehaviorSoft

	// PowerOpBehaviorTrySoft causes an attempt to use the soft behavior, and
	// if the VM is not in the desired power state after 10 minutes, the next
	// attempt falls back to the hard behavior.
	PowerOpBehaviorTrySoft
)

func ParsePowerOpMode

func ParsePowerOpMode(m string) PowerOpBehavior

ParsePowerOpMode parses a VM Op API PowerOpMode and returns the corresponding PowerOpBehavior.

func (PowerOpBehavior) String

func (b PowerOpBehavior) String() string

String returns the stringified name of the behavior.

type PowerOpResult

type PowerOpResult uint8

PowerOpResult represents one of the possible results when calling SetPowerState or SetAndWaitOnPowerState.

const (
	// PowerOpResultNone indicates the power state was not changed
	// because the VM's power state matched the desired power state.
	PowerOpResultNone PowerOpResult = iota

	// PowerOpResultChanged indicates the power state was changed.
	// This is set if the VM was powered on.
	PowerOpResultChanged

	// PowerOpResultChangedHard indicates the power state was changed
	// with a hard operation. This is set if the VM was powered off,
	// suspended, or restarted.
	PowerOpResultChangedHard

	// PowerOpResultChangedSoft indicates the power state was changed
	// with a soft operation. This is set if the VM was powered off,
	// suspended, or restarted.
	PowerOpResultChangedSoft
)

func RestartAndWait

func RestartAndWait(
	ctx context.Context,
	client *vim25.Client,
	mo mo.VirtualMachine,
	fetchProperties bool,
	desiredLastRestartTime time.Time,
	powerOpBehavior PowerOpBehavior) (PowerOpResult, error)

RestartAndWait is the same as Restart but blocks until an error occurs or the operation completes successfully.

func SetAndWaitOnPowerState

func SetAndWaitOnPowerState(
	ctx context.Context,
	client *vim25.Client,
	mo mo.VirtualMachine,
	fetchProperties bool,
	desiredPowerState types.VirtualMachinePowerState,
	powerOpBehavior PowerOpBehavior) (PowerOpResult, error)

SetAndWaitOnPowerState is the same as SetPowerState but blocks until an error occurs or the operation completes successfully.

func (PowerOpResult) AnyChange

func (r PowerOpResult) AnyChange() bool

AnyChange returns true if the result indicates a change, whether that is a power on operation or a hard or soft power off/suspend operation.

type ReconcileMinHardwareVersionResult added in v1.8.6

type ReconcileMinHardwareVersionResult uint8

func ReconcileMinHardwareVersion added in v1.8.6

func ReconcileMinHardwareVersion(
	ctx context.Context,
	client *vim25.Client,
	mo mo.VirtualMachine,
	fetchProperties bool,
	minHardwareVersion int32) (ReconcileMinHardwareVersionResult, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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