github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/vsphere/config.go (about) 1 package vsphere 2 3 import ( 4 "fmt" 5 "log" 6 "net/url" 7 8 "github.com/vmware/govmomi" 9 "golang.org/x/net/context" 10 ) 11 12 const ( 13 defaultInsecureFlag = true 14 ) 15 16 type Config struct { 17 User string 18 Password string 19 VSphereServer string 20 } 21 22 // Client() returns a new client for accessing VMWare vSphere. 23 func (c *Config) Client() (*govmomi.Client, error) { 24 u, err := url.Parse("https://" + c.VSphereServer + "/sdk") 25 if err != nil { 26 return nil, fmt.Errorf("Error parse url: %s", err) 27 } 28 29 u.User = url.UserPassword(c.User, c.Password) 30 31 client, err := govmomi.NewClient(context.TODO(), u, defaultInsecureFlag) 32 if err != nil { 33 return nil, fmt.Errorf("Error setting up client: %s", err) 34 } 35 36 log.Printf("[INFO] VMWare vSphere Client configured for URL: %s", u) 37 38 return client, nil 39 }