Documentation ¶
Index ¶
- Constants
- func GenerateMAC() (string, error)
- func IsExtendDiskError(err error) bool
- func VerifyMAC(mac string) bool
- type Client
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) ComputeResources(ctx context.Context) ([]ComputeResource, error)
- func (c *Client) CreateVirtualMachine(ctx context.Context, args CreateVirtualMachineParams) (_ *mo.VirtualMachine, err error)
- func (c *Client) Datastores(ctx context.Context) ([]mo.Datastore, error)
- func (c *Client) DeleteDatastoreFile(ctx context.Context, datastorePath string) error
- func (c *Client) DestroyVMFolder(ctx context.Context, folderPath string) error
- func (c *Client) EnsureVMFolder(ctx context.Context, parentFolderName string, relativeFolderPath string) (*object.Folder, error)
- func (c *Client) FindFolder(ctx context.Context, folderPath string) (vmFolder *object.Folder, err error)
- func (c *Client) Folders(ctx context.Context) (*object.DatacenterFolders, error)
- func (c *Client) MoveVMFolderInto(ctx context.Context, parentPath, childPath string) error
- func (c *Client) MoveVMsInto(ctx context.Context, folderPath string, vms ...types.ManagedObjectReference) error
- func (c *Client) RemoveVirtualMachines(ctx context.Context, path string) error
- func (c *Client) ResourcePools(ctx context.Context, path string) ([]*object.ResourcePool, error)
- func (c *Client) UpdateVirtualMachineExtraConfig(ctx context.Context, vmInfo *mo.VirtualMachine, metadata map[string]string) error
- func (c *Client) UserHasRootLevelPrivilege(ctx context.Context, privilege string) (bool, error)
- func (c *Client) VirtualMachines(ctx context.Context, path string) ([]*mo.VirtualMachine, error)
- type ComputeResource
- type CreateVirtualMachineParams
- type NetworkDevice
Constants ¶
const UbuntuOVF = `` /* 10166-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func GenerateMAC ¶
GenerateMAC generates a random hardware address that meets VMWare requirements for MAC address: 00:50:56:XX:YY:ZZ where XX is between 00 and 3f. https://pubs.vmware.com/vsphere-4-esx-vcenter/index.jsp?topic=/com.vmware.vsphere.server_configclassic.doc_41/esx_server_config/advanced_networking/c_setting_up_mac_addresses.html
func IsExtendDiskError ¶
IsExtendDiskError returns whether the cause of this error was a failure to extend a VM disk.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client encapsulates a vSphere client, exposing the subset of functionality that we require in the Juju provider.
func Dial ¶
func Dial( ctx context.Context, u *url.URL, datacenter string, logger loggo.Logger, ) (*Client, error)
Dial dials a new vSphere client connection using the given URL, scoped to the specified datacenter. The resulting Client's Close method must be called in order to release resources allocated by Dial.
func (*Client) ComputeResources ¶
func (c *Client) ComputeResources(ctx context.Context) ([]ComputeResource, error)
ComputeResources returns a slice of all compute resources in the datacenter, along with a slice of each compute resource's full path.
func (*Client) CreateVirtualMachine ¶
func (c *Client) CreateVirtualMachine( ctx context.Context, args CreateVirtualMachineParams, ) (_ *mo.VirtualMachine, err error)
CreateVirtualMachine creates and powers on a new VM.
The creation process makes use of a vSphere feature called template VMs. If it doesn't already exist, a template VM will be created within args.VMDKDirectory based off of the OVA data provided by args.ReadOVA.
Once the template VM is available, a new instance will be cloned from it. Configuration settings from args.Constraints are then applied through a reconfigure step. Once the constraints are applied, the newly cloned VM will be powered on.
func (*Client) Datastores ¶
Datastores returns list of all datastores in the system.
func (*Client) DeleteDatastoreFile ¶
DeleteDatastoreFile deletes a file or directory in the datastore.
func (*Client) DestroyVMFolder ¶
DestroyVMFolder destroys a folder(folderPath could be either relative path of vmfolder of datacenter or full path).
func (*Client) EnsureVMFolder ¶
func (c *Client) EnsureVMFolder(ctx context.Context, parentFolderName string, relativeFolderPath string) (*object.Folder, error)
EnsureVMFolder creates the a VM folder with the given path if it doesn't already exist. Two string arguments needed: relativeFolderPath will be split on "/" whereas parentFolderName is the subfolder in DC's root-folder. The parentFolderName will fallback to DC's root-folder if it's an empty string.
func (*Client) FindFolder ¶
func (c *Client) FindFolder(ctx context.Context, folderPath string) (vmFolder *object.Folder, err error)
FindFolder should be able to search for both entire filepaths or relative (.) filepaths. If the user passes "test" or "/<DC>/vm/test" as folder, it should return the pointer for the same folder, and should also deal with the case where folderPath is nil or empty.
func (*Client) MoveVMFolderInto ¶
MoveVMFolderInto moves one VM folder into another.
func (*Client) MoveVMsInto ¶
func (c *Client) MoveVMsInto( ctx context.Context, folderPath string, vms ...types.ManagedObjectReference, ) error
MoveVMsInto moves a set of VMs into a folder.
func (*Client) RemoveVirtualMachines ¶
RemoveVirtualMachines removes VMs matching the given path from the system. The path may include wildcards, to match multiple VMs.
func (*Client) ResourcePools ¶
ResourcePools returns a list of all of the resource pools (possibly nested) under the given path.
func (*Client) UpdateVirtualMachineExtraConfig ¶
func (c *Client) UpdateVirtualMachineExtraConfig( ctx context.Context, vmInfo *mo.VirtualMachine, metadata map[string]string, ) error
UpdateVirtualMachineExtraConfig updates the "ExtraConfig" attributes of the specified virtual machine. Keys with empty values will be removed from the config; existing keys that are unspecified in the map will be untouched.
func (*Client) UserHasRootLevelPrivilege ¶
UserHasRootLevelPrivilege returns whether the connected user has the specified privilege on the root-level object.
func (*Client) VirtualMachines ¶
VirtualMachines return list of all VMs in the system matching the given path.
type ComputeResource ¶
type ComputeResource struct { Resource *mo.ComputeResource Path string }
ComputeResource stores an mo.ComputeResource along with its full path
type CreateVirtualMachineParams ¶
type CreateVirtualMachineParams struct { // Name is the name to give the virtual machine. The VM name is used // for its hostname also. Name string // Folder is the path of the VM folder, relative to the root VM folder, // in which to create the VM. Folder string // RootVMFolder is the customized root vm folder. RootVMFolder string // VMDKDirectory is the datastore path in which VMDKs are stored for // this controller. Within this directory there will be subdirectories // for each series, and within those the VMDKs will be stored. VMDKDirectory string // Series is the name of the OS series that the image will run. Series string // ReadOVA returns the location of, and an io.ReadCloser for, // the OVA from which to extract the VMDK. The location may be // used for reporting progress. The ReadCloser must be closed // by the caller when it is finished with it. ReadOVA func() (location string, _ io.ReadCloser, _ error) // OVASHA256 is the expected SHA-256 hash of the OVA. OVASHA256 string // UserData is the cloud-init user-data. UserData string // ComputeResource is the compute resource (host or cluster) to be used // to create the VM. ComputeResource *mo.ComputeResource // ResourcePool is a reference to the pool the VM should be // created in. ResourcePool types.ManagedObjectReference // Metadata are metadata key/value pairs to apply to the VM as // "extra config". Metadata map[string]string // Constraints contains the resource constraints for the virtual machine. Constraints constraints.Value // Networks contain a list of network devices the VM should have. NetworkDevices []NetworkDevice // UpdateProgress is a function that should be called before/during // long-running operations to provide a progress reporting. UpdateProgress func(string) // UpdateProgressInterval is the amount of time to wait between calls // to UpdateProgress. This should be lower when the operation is // interactive (bootstrap), and higher when non-interactive. UpdateProgressInterval time.Duration // Clock is used for controlling the timing of progress updates. Clock clock.Clock // EnableDiskUUID controls whether the VMware disk should expose a // consistent UUID to the guest OS. EnableDiskUUID bool // IsBootstrap indicates whether the requested instance will be a // newly bootstrapped controller. IsBootstrap bool }
CreateVirtualMachineParams contains the parameters required for creating a new virtual machine.
type NetworkDevice ¶
type NetworkDevice struct { // Network is the name of the network the device should be connected to. // If empty it will be connected to the default "VM Network" network. Network string // MAC is the hardware address of the network device. MAC string }
NetworkDevice defines a single network device attached to a newly created VM.