vsphereclient

package
v0.0.0-...-8ff1004 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const UbuntuOVF = `` /* 10166-byte string literal not displayed */

Variables

This section is empty.

Functions

func GenerateMAC

func GenerateMAC() (string, error)

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 VerifyMAC

func VerifyMAC(mac string) bool

VerifyMAC verifies that the MAC is valid for VMWare.

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 dataceter. The resulting Client's Close method must be called in order to release resources allocated by Dial.

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close logs out and closes the client connection.

func (*Client) ComputeResources

func (c *Client) ComputeResources(ctx context.Context) ([]*mo.ComputeResource, error)

ComputeResources returns list of all root compute resources in the system.

func (*Client) CreateVirtualMachine

func (c *Client) CreateVirtualMachine(
	ctx context.Context,
	args CreateVirtualMachineParams,
) (_ *mo.VirtualMachine, resultErr error)

CreateVirtualMachine creates and powers on a new VM.

This method imports an OVF template using the vSphere API. This process comprises the following steps:

  1. Ensure the VMDK contained within the OVA archive (args.OVA) is stored in the datastore, in this controller's cache. If it is there already, we use it; otherwise we remove any existing VMDK for the same series, and upload the new one.
  2. Call CreateImportSpec [0] with a pre-canned OVF, which validates the OVF descriptor against the hardware supported by the host system. If the validation succeeds,/the method returns an ImportSpec to use for importing the virtual machine.
  3. Prepare all necessary parameters (CPU, memory, root disk, etc.), and call the ImportVApp method [0]. This method is responsible for actually creating the VM. This VM is temporary, and used only to convert the VMDK file into a disk type file.
  4. Clone the temporary VM from step 3, to create the VM we will associate with the Juju machine.
  5. If the user specified a root-disk constraint, extend the VMDK if its capacity is less than the specified constraint.
  6. Power on the virtual machine.

[0] https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/ [1] https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.HttpNfcLease.html

func (*Client) Datastores

func (c *Client) Datastores(ctx context.Context) ([]*mo.Datastore, error)

Datastores returns list of all datastores in the system.

func (*Client) DeleteDatastoreFile

func (c *Client) DeleteDatastoreFile(ctx context.Context, datastorePath string) error

DeleteDatastoreFile deletes a file or directory in the datastore.

func (*Client) DestroyVMFolder

func (c *Client) DestroyVMFolder(ctx context.Context, folderPath string) error

DestroyVMFolder destroys a folder rooted at the datacenter's base VM folder.

func (*Client) EnsureVMFolder

func (c *Client) EnsureVMFolder(ctx context.Context, folderPath string) (*object.Folder, error)

EnsureVMFolder creates the a VM folder with the given path if it doesn't already exist.

func (*Client) MoveVMFolderInto

func (c *Client) MoveVMFolderInto(ctx context.Context, parentPath, childPath string) error

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

func (c *Client) RemoveVirtualMachines(ctx context.Context, path string) error

RemoveVirtualMachines removes VMs matching the given path from the system. The path may include wildcards, to match multiple VMs.

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

func (c *Client) VirtualMachines(ctx context.Context, path string) ([]*mo.VirtualMachine, error)

VirtualMachines return list of all VMs in the system matching the given 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

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

	// Datastore is the name of the datastore in which to create the VM.
	// If this is empty, any accessible datastore will be used.
	Datastore string

	// 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
}

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.

Jump to

Keyboard shortcuts

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