github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/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 type Config struct { 13 User string 14 Password string 15 VSphereServer string 16 InsecureFlag bool 17 } 18 19 // Client() returns a new client for accessing VMWare vSphere. 20 func (c *Config) Client() (*govmomi.Client, error) { 21 u, err := url.Parse("https://" + c.VSphereServer + "/sdk") 22 if err != nil { 23 return nil, fmt.Errorf("Error parse url: %s", err) 24 } 25 26 u.User = url.UserPassword(c.User, c.Password) 27 28 client, err := govmomi.NewClient(context.TODO(), u, c.InsecureFlag) 29 if err != nil { 30 return nil, fmt.Errorf("Error setting up client: %s", err) 31 } 32 33 log.Printf("[INFO] VMWare vSphere Client configured for URL: %s", u) 34 35 return client, nil 36 }