github.com/armen/terraform@v0.5.2-0.20150529052519-caa8117a08f1/builtin/providers/openstack/config.go (about) 1 package openstack 2 3 import ( 4 "crypto/tls" 5 "net/http" 6 7 "github.com/rackspace/gophercloud" 8 "github.com/rackspace/gophercloud/openstack" 9 ) 10 11 type Config struct { 12 Username string 13 UserID string 14 Password string 15 APIKey string 16 IdentityEndpoint string 17 TenantID string 18 TenantName string 19 DomainID string 20 DomainName string 21 Insecure bool 22 23 osClient *gophercloud.ProviderClient 24 } 25 26 func (c *Config) loadAndValidate() error { 27 ao := gophercloud.AuthOptions{ 28 Username: c.Username, 29 UserID: c.UserID, 30 Password: c.Password, 31 APIKey: c.APIKey, 32 IdentityEndpoint: c.IdentityEndpoint, 33 TenantID: c.TenantID, 34 TenantName: c.TenantName, 35 DomainID: c.DomainID, 36 DomainName: c.DomainName, 37 } 38 39 client, err := openstack.NewClient(ao.IdentityEndpoint) 40 if err != nil { 41 return err 42 } 43 44 if c.Insecure { 45 // Configure custom TLS settings. 46 config := &tls.Config{InsecureSkipVerify: true} 47 transport := &http.Transport{TLSClientConfig: config} 48 client.HTTPClient.Transport = transport 49 } 50 51 err = openstack.Authenticate(client, ao) 52 if err != nil { 53 return err 54 } 55 56 c.osClient = client 57 58 return nil 59 } 60 61 func (c *Config) blockStorageV1Client(region string) (*gophercloud.ServiceClient, error) { 62 return openstack.NewBlockStorageV1(c.osClient, gophercloud.EndpointOpts{ 63 Region: region, 64 }) 65 } 66 67 func (c *Config) computeV2Client(region string) (*gophercloud.ServiceClient, error) { 68 return openstack.NewComputeV2(c.osClient, gophercloud.EndpointOpts{ 69 Region: region, 70 }) 71 } 72 73 func (c *Config) networkingV2Client(region string) (*gophercloud.ServiceClient, error) { 74 return openstack.NewNetworkV2(c.osClient, gophercloud.EndpointOpts{ 75 Region: region, 76 }) 77 } 78 79 func (c *Config) objectStorageV1Client(region string) (*gophercloud.ServiceClient, error) { 80 return openstack.NewObjectStorageV1(c.osClient, gophercloud.EndpointOpts{ 81 Region: region, 82 }) 83 }