Ash Wilson | 8fecf33 | 2014-10-20 15:18:46 -0400 | [diff] [blame^] | 1 | // +build acceptance |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "os" |
| 8 | |
| 9 | "github.com/rackspace/gophercloud" |
| 10 | "github.com/rackspace/gophercloud/rackspace" |
| 11 | ) |
| 12 | |
| 13 | func newClient() (*gophercloud.ServiceClient, error) { |
| 14 | // Obtain credentials from the environment. |
| 15 | options := gophercloud.AuthOptions{ |
| 16 | Username: os.Getenv("RS_USERNAME"), |
| 17 | APIKey: os.Getenv("RS_APIKEY"), |
| 18 | } |
| 19 | region := os.Getenv("RS_REGION") |
| 20 | |
| 21 | if options.Username == "" { |
| 22 | return nil, errors.New("Please provide a Rackspace username as RS_USERNAME.") |
| 23 | } |
| 24 | if options.APIKey == "" { |
| 25 | return nil, errors.New("Please provide a Rackspace API key as RS_APIKEY.") |
| 26 | } |
| 27 | if region == "" { |
| 28 | return nil, errors.New("Please provide a Rackspace region as RS_REGION.") |
| 29 | } |
| 30 | |
| 31 | client, err := rackspace.AuthenticatedClient(options) |
| 32 | if err != nil { |
| 33 | return nil, err |
| 34 | } |
| 35 | |
| 36 | return rackspace.NewComputeV2(client, gophercloud.EndpointOpts{ |
| 37 | Region: region, |
| 38 | }) |
| 39 | } |
| 40 | |
| 41 | type serverOpts struct { |
| 42 | imageID string |
| 43 | flavorID string |
| 44 | } |
| 45 | |
| 46 | func optionsFromEnv() (*serverOpts, error) { |
| 47 | options := &serverOpts{ |
| 48 | imageID: os.Getenv("RS_IMAGE_ID"), |
| 49 | flavorID: os.Getenv("RS_FLAVOR_ID"), |
| 50 | } |
| 51 | if options.imageID == "" { |
| 52 | return nil, errors.New("Please provide a valid Rackspace image ID as RS_IMAGE_ID") |
| 53 | } |
| 54 | if options.flavorID == "" { |
| 55 | return nil, errors.New("Please provide a valid Rackspace flavor ID as RS_FLAVOR_ID") |
| 56 | } |
| 57 | return options, nil |
| 58 | } |