virtualdevice

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2017 License: MPL-2.0 Imports: 23 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

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 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 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 purely our source of truth. These disks are assigned to our disk sub-resources in config and the relocate specs are generated off of the filename and 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 that is defined.

func DiskCloneValidateOperation

func DiskCloneValidateOperation(d *schema.ResourceDiff, c *govmomi.Client, l object.VirtualDeviceList) 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.

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 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 ReadDiskSizes

func ReadDiskSizes(l object.VirtualDeviceList, count int) ([]int, error)

ReadDiskSizes returns a list of disk sizes. This is used in the VM data source to discover the sizes 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 ReadSCSIBusState

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

ReadSCSIBusState 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.

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.

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) NormalizeDiff

func (r *DiskSubresource) NormalizeDiff() error

NormalizeDiff checks the diff for a vsphere_virtual_machine disk sub-resource. It should be called after setting data and olddata to values that seems similar enough to be possibly the same resource, after which this function should then compare them and fill in any values that may be missing from the new set due to computed values, such as inferred datastore or path names.

Do not use resourceData in this function as it's not populated and calls to it will cause a panic.

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 short name of the disk, and the current device key and address.

func (*DiskSubresource) Update

Update updates a vsphere_virtual_machine disk sub-resource.

func (*DiskSubresource) ValidateDiff

func (r *DiskSubresource) ValidateDiff() error

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

Do not use resourceData in this function as it's not populated and calls to it will cause a panic.

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.

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