github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/vsphere/client.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package vsphere 5 6 import ( 7 "context" 8 "net/url" 9 10 "github.com/vmware/govmomi/object" 11 "github.com/vmware/govmomi/vim25/mo" 12 "github.com/vmware/govmomi/vim25/types" 13 14 "github.com/juju/juju/environs" 15 "github.com/juju/juju/provider/vsphere/internal/vsphereclient" 16 ) 17 18 // DialFunc is a function type for dialing vSphere client connections. 19 type DialFunc func(_ context.Context, _ *url.URL, datacenter string) (Client, error) 20 21 // Client is an interface for interacting with the vSphere API. 22 type Client interface { 23 Close(context.Context) error 24 ComputeResources(context.Context) ([]*mo.ComputeResource, error) 25 CreateVirtualMachine(context.Context, vsphereclient.CreateVirtualMachineParams) (*mo.VirtualMachine, error) 26 Datastores(context.Context) ([]*mo.Datastore, error) 27 DeleteDatastoreFile(context.Context, string) error 28 DestroyVMFolder(context.Context, string) error 29 EnsureVMFolder(context.Context, string) (*object.Folder, error) 30 MoveVMFolderInto(context.Context, string, string) error 31 MoveVMsInto(context.Context, string, ...types.ManagedObjectReference) error 32 RemoveVirtualMachines(context.Context, string) error 33 UpdateVirtualMachineExtraConfig(context.Context, *mo.VirtualMachine, map[string]string) error 34 VirtualMachines(context.Context, string) ([]*mo.VirtualMachine, error) 35 } 36 37 func dialClient( 38 ctx context.Context, 39 cloudSpec environs.CloudSpec, 40 dial DialFunc, 41 ) (Client, error) { 42 datacenter := cloudSpec.Region 43 credAttrs := cloudSpec.Credential.Attributes() 44 username := credAttrs[credAttrUser] 45 password := credAttrs[credAttrPassword] 46 connURL := &url.URL{ 47 Scheme: "https", 48 User: url.UserPassword(username, password), 49 Host: cloudSpec.Endpoint, 50 Path: "/sdk", 51 } 52 return dial(ctx, connURL, datacenter) 53 }