github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/vcd/config.go (about)

     1  package vcd
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  
     7  	"github.com/hmrc/vmware-govcd"
     8  )
     9  
    10  type Config struct {
    11  	User         string
    12  	Password     string
    13  	Org          string
    14  	Href         string
    15  	VDC          string
    16  	MaxRetryTimeout int
    17  }
    18  
    19  type VCDClient struct {
    20  	*govcd.VCDClient
    21  	MaxRetryTimeout int
    22  }
    23  
    24  func (c *Config) Client() (*VCDClient, error) {
    25  	u, err := url.ParseRequestURI(c.Href)
    26  	if err != nil {
    27  		return nil, fmt.Errorf("Something went wrong: %s", err)
    28  	}
    29  
    30  	vcdclient := &VCDClient{
    31  	   govcd.NewVCDClient(*u),
    32  	   c.MaxRetryTimeout}
    33  	org, vcd, err := vcdclient.Authenticate(c.User, c.Password, c.Org, c.VDC)
    34  	if err != nil {
    35  		return nil, fmt.Errorf("Something went wrong: %s", err)
    36  	}
    37  	vcdclient.Org = org
    38  	vcdclient.OrgVdc = vcd
    39  	return vcdclient, nil
    40  }