virtualdevice

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SubresourceControllerTypeIDE is a string representation of IDE controller
	// classes.
	SubresourceControllerTypeIDE = "ide"

	// SubresourceControllerTypeSATA is a string representation of SATA controller
	// classes.
	SubresourceControllerTypeSATA = "sata"

	// SubresourceControllerTypeSCSI is a string representation of all SCSI
	// controller types.
	//
	// This is mainly used when computing IDs so that we can use a more general
	// device search.
	SubresourceControllerTypeSCSI = "scsi"

	// SubresourceControllerTypeParaVirtual is a string representation of the
	// VMware PV SCSI controller type.
	SubresourceControllerTypeParaVirtual = "pvscsi"

	// SubresourceControllerTypeLsiLogic is a string representation of the
	// LSI Logic parallel virtual SCSI controller type.
	SubresourceControllerTypeLsiLogic = "lsilogic"

	// SubresourceControllerTypeLsiLogicSAS is a string representation of the
	// LSI Logic SAS virtual SCSI controller type.
	SubresourceControllerTypeLsiLogicSAS = "lsilogic-sas"

	// SubresourceControllerTypePCI is a string representation of PCI controller
	// classes.
	SubresourceControllerTypePCI = "pci"
)

Variables

SCSIBusSharingAllowedValues exports the list of supported SCSI bus sharing modes. These are the only modes that can be specified for scsi_bus_sharing and should be checked in a ValidateFunc.

SCSIBusTypeAllowedValues exports the currently list of SCSI controller types that we support in the resource. The user is only allowed to select a type in this list, which should be used in a ValidateFunc on the appropriate field.

Functions

func AppendDeviceChangeSpec added in v1.3.0

AppendDeviceChangeSpec appends unique copies of the supplied device change operations and appends them to spec. The resulting list is returned.

The object of this function is to provide deep copies of each virtual device to the spec as they looked like when the append operation was called, helping facilitate multiple update operations to the same device in a single reconfigure call.

func CdromApplyOperation

CdromApplyOperation processes an apply operation for all disks in the resource.

The function takes the root resource's ResourceData, the provider connection, and the device list as known to vSphere at the start of this operation. All disk operations are carried out, with both the complete, updated, VirtualDeviceList, and the complete list of changes returned as a slice of BaseVirtualDeviceConfigSpec.

func CdromDiffOperation added in v1.4.0

func CdromDiffOperation(d *schema.ResourceDiff, c *govmomi.Client) error

CdromDiffOperation performs operations relevant to managing the diff on cdrom sub-resources

func CdromPostCloneOperation

CdromPostCloneOperation normalizes CDROM devices on a freshly-cloned virtual machine and outputs any necessary device change operations. It also sets the state in advance of the post-create read.

This differs from a regular apply operation in that a configuration is already present, but we don't have any existing state, which the standard virtual device operations rely pretty heavily on.

func CdromRefreshOperation

func CdromRefreshOperation(d *schema.ResourceData, c *govmomi.Client, l object.VirtualDeviceList) error

CdromRefreshOperation processes a refresh operation for all of the disks in the resource.

This functions similar to CdromApplyOperation, but nothing to change is returned, all necessary values are just set and committed to state.

func CdromSubresourceSchema

func CdromSubresourceSchema() map[string]*schema.Schema

CdromSubresourceSchema represents the schema for the cdrom sub-resource.

func DeviceChangeString

func DeviceChangeString(specs []types.BaseVirtualDeviceConfigSpec) string

DeviceChangeString pretty-prints a slice of VirtualDeviceConfigSpec.

func DeviceListString

func DeviceListString(l object.VirtualDeviceList) string

DeviceListString pretty-prints each device in a virtual device list, used for logging purposes and what not.

func DiskApplyOperation

DiskApplyOperation processes an apply operation for all disks in the resource.

The function takes the root resource's ResourceData, the provider connection, and the device list as known to vSphere at the start of this operation. All disk operations are carried out, with both the complete, updated, VirtualDeviceList, and the complete list of changes returned as a slice of BaseVirtualDeviceConfigSpec.

func DiskCloneRelocateOperation

DiskCloneRelocateOperation assembles the VirtualMachineRelocateSpecDiskLocator slice for a virtual machine clone operation.

This differs from a regular storage vMotion in that we have no existing devices in the resource to work off of - the disks in the source virtual machine is our source of truth. These disks are assigned to our disk sub-resources in config and the relocate specs are generated off of the backing data defined in config, taking on these filenames when cloned. After the clone is complete, natural re-configuration happens to bring the disk configurations fully in sync with what is defined.

func DiskCloneValidateOperation

func DiskCloneValidateOperation(d *schema.ResourceDiff, c *govmomi.Client, l object.VirtualDeviceList, linked bool) error

DiskCloneValidateOperation takes the VirtualDeviceList, which should come from a source VM or template, and validates the following:

* There are at least as many disks defined in the configuration as there are in the source VM or template. * All disks survive a disk sub-resource read operation.

This function is meant to be called during diff customization. It is a subset of the normal refresh behaviour as we don't worry about checking existing state.

func DiskDestroyOperation

DiskDestroyOperation process the destroy operation for virtual disks.

Disks are the only real operation that require special destroy logic, and that's because we want to check to make sure that we detach any disks that need to be simply detached (not deleted) before we destroy the entire virtual machine, as that would take those disks with it.

func DiskDiffOperation

func DiskDiffOperation(d *schema.ResourceDiff, c *govmomi.Client) error

DiskDiffOperation performs operations relevant to managing the diff on disk sub-resources.

Most importantly, this works to prevent spurious diffs by extrapolating the correct correlation between the old and new sets using the name as a primary key, and then normalizing the two diffs so that computed data is properly set.

The following validation operations are also carried out on the set as a whole:

* Ensuring all names are unique across the set. * Ensuring that at least one element in the set has a unit_number of 0.

func DiskImportOperation

func DiskImportOperation(d *schema.ResourceData, c *govmomi.Client, l object.VirtualDeviceList) error

DiskImportOperation validates the disk configuration of the virtual machine's VirtualDeviceList to ensure it will be imported properly, and also saves device addresses into state for disks defined in config. Both the imported device list is sorted by the device's unit number on the SCSI bus.

func DiskMigrateRelocateOperation

DiskMigrateRelocateOperation assembles the VirtualMachineRelocateSpecDiskLocator slice for a virtual machine migration operation, otherwise known as storage vMotion.

func DiskPostCloneOperation

DiskPostCloneOperation normalizes the virtual disks on a freshly-cloned virtual machine and outputs any necessary device change operations. It also sets the state in advance of the post-create read.

This differs from a regular apply operation in that a configuration is already present, but we don't have any existing state, which the standard virtual device operations rely pretty heavily on.

func DiskRefreshOperation

func DiskRefreshOperation(d *schema.ResourceData, c *govmomi.Client, l object.VirtualDeviceList) error

DiskRefreshOperation processes a refresh operation for all of the disks in the resource.

This functions similar to DiskApplyOperation, but nothing to change is returned, all necessary values are just set and committed to state.

func DiskSubresourceSchema

func DiskSubresourceSchema() map[string]*schema.Schema

DiskSubresourceSchema represents the schema for the disk sub-resource.

func NetworkInterfaceApplyOperation

NetworkInterfaceApplyOperation processes an apply operation for all network_interfaces in the resource.

The function takes the root resource's ResourceData, the provider connection, and the device list as known to vSphere at the start of this operation. All network_interface operations are carried out, with both the complete, updated, VirtualDeviceList, and the complete list of changes returned as a slice of BaseVirtualDeviceConfigSpec.

func NetworkInterfaceDiffOperation added in v1.1.1

func NetworkInterfaceDiffOperation(d *schema.ResourceDiff, c *govmomi.Client) error

NetworkInterfaceDiffOperation performs operations relevant to managing the diff on network_interface sub-resources.

func NetworkInterfacePostCloneOperation

NetworkInterfacePostCloneOperation normalizes the network interfaces on a freshly-cloned virtual machine and outputs any necessary device change operations. It also sets the state in advance of the post-create read.

This differs from a regular apply operation in that a configuration is already present, but we don't have any existing state, which the standard virtual device operations rely pretty heavily on.

func NetworkInterfaceRefreshOperation

func NetworkInterfaceRefreshOperation(d *schema.ResourceData, c *govmomi.Client, l object.VirtualDeviceList) error

NetworkInterfaceRefreshOperation processes a refresh operation for all of the disks in the resource.

This functions similar to NetworkInterfaceApplyOperation, but nothing to change is returned, all necessary values are just set and committed to state.

func NetworkInterfaceSubresourceSchema

func NetworkInterfaceSubresourceSchema() map[string]*schema.Schema

NetworkInterfaceSubresourceSchema returns the schema for the disk sub-resource.

func NormalizeSCSIBus

NormalizeSCSIBus checks the SCSI controllers on the virtual machine and either creates them if they don't exist, or migrates them to the specified controller type. Devices are migrated to the new controller appropriately. A spec slice is returned with the changes.

The first number of slots specified by count are normalized by this function. Any others are left unchanged.

func ReadDiskAttrsForDataSource added in v1.1.0

func ReadDiskAttrsForDataSource(l object.VirtualDeviceList, count int) ([]map[string]interface{}, error)

ReadDiskAttrsForDataSource returns select attributes from the list of disks on a virtual machine. This is used in the VM data source to discover specific options of all of the disks on the virtual machine sorted by the order that they would be added in if a clone were to be done.

func ReadNetworkInterfaceTypes

func ReadNetworkInterfaceTypes(l object.VirtualDeviceList) ([]string, error)

ReadNetworkInterfaceTypes returns a list of network interface types. This is used in the VM data source to discover the types of the NIC drivers on the virtual machine. The list is sorted by the order that they would be added in if a clone were to be done.

func ReadSCSIBusSharing added in v1.7.0

func ReadSCSIBusSharing(l object.VirtualDeviceList, count int) string

ReadSCSIBusSharing checks the SCSI bus sharing and returns a sharing type depending on if all controllers are one specific kind or not. Only the first number of controllers specified by count are checked.

func ReadSCSIBusType added in v1.7.0

func ReadSCSIBusType(l object.VirtualDeviceList, count int) string

ReadSCSIBusType checks the SCSI bus state and returns a device type depending on if all controllers are one specific kind or not. Only the first number of controllers specified by count are checked.

func SelectDisks added in v1.3.0

func SelectDisks(l object.VirtualDeviceList, count int) object.VirtualDeviceList

SelectDisks looks for disks that Terraform is supposed to manage. count is the number of controllers that Terraform is managing and serves as an upper limit (count - 1) of the SCSI bus number for a controller that eligible disks need to be attached to.

func VerifyVAppTransport added in v1.4.0

func VerifyVAppTransport(d *schema.ResourceDiff, c *govmomi.Client) error

VerifyVAppTransport validates that all the required components are included in the virtual machine configuration if vApp properties are set.

Types

type CdromSubresource

type CdromSubresource struct {
	*Subresource
}

CdromSubresource represents a vsphere_virtual_machine cdrom sub-resource, with a complex device lifecycle.

func NewCdromSubresource

func NewCdromSubresource(client *govmomi.Client, rdd resourceDataDiff, d, old map[string]interface{}, idx int) *CdromSubresource

NewCdromSubresource returns a subresource populated with all of the necessary fields.

func (*CdromSubresource) Create

Create creates a vsphere_virtual_machine cdrom sub-resource.

func (*CdromSubresource) Delete

Delete deletes a vsphere_virtual_machine cdrom sub-resource.

func (*CdromSubresource) Read

Read reads a vsphere_virtual_machine cdrom sub-resource.

func (*CdromSubresource) Update

Update updates a vsphere_virtual_machine cdrom sub-resource.

func (*CdromSubresource) ValidateDiff added in v1.4.0

func (r *CdromSubresource) ValidateDiff() error

ValidateDiff performs any complex validation of an individual cdrom sub-resource that can't be done in schema alone.

type DiskSubresource

type DiskSubresource struct {
	*Subresource

	// The set hash for the device as it exists when NewDiskSubresource is
	// called.
	ID int
}

DiskSubresource represents a vsphere_virtual_machine disk sub-resource, with a complex device lifecycle.

func NewDiskSubresource

func NewDiskSubresource(client *govmomi.Client, rdd resourceDataDiff, d, old map[string]interface{}, idx int) *DiskSubresource

NewDiskSubresource returns a subresource populated with all of the necessary fields.

func (*DiskSubresource) Create

Create creates a vsphere_virtual_machine disk sub-resource.

func (*DiskSubresource) Delete

Delete deletes a vsphere_virtual_machine disk sub-resource.

func (*DiskSubresource) DiffExisting added in v1.5.0

func (r *DiskSubresource) DiffExisting() error

DiffExisting validates and normalizes the fields for an existing disk sub-resource. It handles carrying over existing values, so this should not be used on disks that have not been successfully matched up between current and old diffs.

func (*DiskSubresource) DiffGeneral added in v1.5.0

func (r *DiskSubresource) DiffGeneral() error

DiffGeneral performs complex validation of an individual disk sub-resource that can't be done in schema alone. Should be run on new and existing disks.

func (*DiskSubresource) Read

Read reads a vsphere_virtual_machine disk sub-resource and commits the data to the newData layer.

func (*DiskSubresource) Relocate

Relocate produces a VirtualMachineRelocateSpecDiskLocator for this resource and is used for both cloning and storage vMotion.

func (*DiskSubresource) String

func (r *DiskSubresource) String() string

String prints out the disk sub-resource's information including the ID at time of instantiation, the path of the disk, and the current device key and address.

func (*DiskSubresource) Update

Update updates a vsphere_virtual_machine disk sub-resource.

type NetworkInterfaceSubresource

type NetworkInterfaceSubresource struct {
	*Subresource
}

NetworkInterfaceSubresource represents a vsphere_virtual_machine network_interface sub-resource, with a complex device lifecycle.

func NewNetworkInterfaceSubresource

func NewNetworkInterfaceSubresource(client *govmomi.Client, rdd resourceDataDiff, d, old map[string]interface{}, idx int) *NetworkInterfaceSubresource

NewNetworkInterfaceSubresource returns a network_interface subresource populated with all of the necessary fields.

func (*NetworkInterfaceSubresource) Create

Create creates a vsphere_virtual_machine network_interface sub-resource.

func (*NetworkInterfaceSubresource) Delete

Delete deletes a vsphere_virtual_machine network_interface sub-resource.

func (*NetworkInterfaceSubresource) Read

Read reads a vsphere_virtual_machine network_interface sub-resource.

func (*NetworkInterfaceSubresource) Update

Update updates a vsphere_virtual_machine network_interface sub-resource.

func (*NetworkInterfaceSubresource) ValidateDiff added in v1.1.1

func (r *NetworkInterfaceSubresource) ValidateDiff() error

ValidateDiff performs any complex validation of an individual network_interface sub-resource that can't be done in schema alone.

type Subresource

type Subresource struct {
	// The index of this subresource - should either be an index or hash. It's up
	// to the upstream object to set this to something useful.
	Index int
	// contains filtered or unexported fields
}

Subresource defines a common interface for device sub-resources in the vsphere_virtual_machine resource.

This object is designed to be used by parts of the resource with workflows that are so complex in their own right that probably the only way to handle their management is to treat them like resources themselves.

This structure of this resource loosely follows schema.Resource with having CRUD and maintaining a set of resource data to work off of. However, since we are using schema.Resource, we take some liberties that we normally would not be able to take, or need to take considering the context of the data we are working with.

Inparticular functions implement this structure by creating an instance into it, much like how a resource creates itself by creating an instance of schema.Resource.

func (*Subresource) Addr

func (r *Subresource) Addr() string

Addr returns the resource address for this subresource.

func (*Subresource) ControllerForCreateUpdate

func (r *Subresource) ControllerForCreateUpdate(l object.VirtualDeviceList, ct string, bus int) (types.BaseVirtualController, error)

ControllerForCreateUpdate wraps the controller selection logic to make it easier to use in create or update operations. If the controller type is a SCSI device, the bus number is searched as well.

func (*Subresource) Data

func (r *Subresource) Data() map[string]interface{}

Data returns the underlying data map.

func (*Subresource) DevAddr

func (r *Subresource) DevAddr() string

DevAddr returns the device_address attribute in the subresource. This function exists mainly as a functional counterpart to SaveDevIDs.

func (*Subresource) FindVirtualDevice

func (r *Subresource) FindVirtualDevice(l object.VirtualDeviceList) (types.BaseVirtualDevice, error)

FindVirtualDevice will attempt to find an address by its device key if it is > 0, otherwise it will attempt to locate it by its device address.

func (*Subresource) FindVirtualDeviceByAddr

func (r *Subresource) FindVirtualDeviceByAddr(l object.VirtualDeviceList) (types.BaseVirtualDevice, error)

FindVirtualDeviceByAddr locates the subresource's virtual device in the supplied VirtualDeviceList by its device address.

func (*Subresource) Get

func (r *Subresource) Get(key string) interface{}

Get hands off to r.data.Get, with an address relative to this subresource.

func (*Subresource) GetChange

func (r *Subresource) GetChange(key string) (interface{}, interface{})

GetChange gets the old and new values for the value specified by key.

func (*Subresource) GetWithRestart

func (r *Subresource) GetWithRestart(key string) interface{}

GetWithRestart checks to see if a field has been modified, returns the new value, and sets restart if it has changed.

func (*Subresource) GetWithVeto

func (r *Subresource) GetWithVeto(key string) (interface{}, error)

GetWithVeto returns the value specified by key, but returns an error if it has changed. The intention here is to block changes to the resource in a fashion that would otherwise result in forcing a new resource.

func (*Subresource) HasChange

func (r *Subresource) HasChange(key string) bool

HasChange checks to see if there has been a change in the resource data since the last update.

Note that this operation may only be useful during update operations, depending on subresource-specific workflow.

func (*Subresource) Hash

func (r *Subresource) Hash() int

Hash calculates a set hash for the current data. If you want a hash for error reporting a device address, it's probably a good idea to run this at the beginning of a run as any set calls will change the value this ultimately calculates.

func (*Subresource) SaveDevIDs

SaveDevIDs saves the device's current key, and also the device_address. The latter is a computed schema field that contains the controller type, the controller's bus number, and the device's unit number on that controller. This helps locate the device when the key is in flux (such as when devices are just being created).

func (*Subresource) Set

func (r *Subresource) Set(key string, value interface{})

Set sets the specified key/value pair in the subresource.

func (*Subresource) SetRestart

func (r *Subresource) SetRestart(key string)

SetRestart sets reboot_required in the global ResourceData. The key is only required for logging.

func (*Subresource) String

func (r *Subresource) String() string

String prints out the device sub-resource's information including the ID at time of instantiation, the short name of the disk, and the current device key and address.

type SubresourceInstance

type SubresourceInstance interface {
	Create(object.VirtualDeviceList) ([]types.BaseVirtualDeviceConfigSpec, error)
	Read(object.VirtualDeviceList) error
	Update(object.VirtualDeviceList) ([]types.BaseVirtualDeviceConfigSpec, error)
	Delete(object.VirtualDeviceList) ([]types.BaseVirtualDeviceConfigSpec, error)

	DevAddr() string
	Addr() string
	Set(string, interface{}) error
	Schema() map[string]*schema.Schema
	State() map[string]interface{}
}

SubresourceInstance is an interface for derivative objects of Subresource. It's used on the general apply and read operation methods, and contains both exported methods of the base Subresource type and the CRUD methods that should be supplied by derivative objects.

Note that this interface should be used sparingly - as such, only the methods that are needed by inparticular functions external to most virtual device workflows are exported into this interface.

Jump to

Keyboard shortcuts

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