blob: 3419c10f997b2b0e0194cc12ff8a8f792d680d79 [file] [log] [blame]
Ash Wilson8fecf332014-10-20 15:18:46 -04001// +build acceptance
2
3package v2
4
5import (
6 "errors"
7 "os"
8
9 "github.com/rackspace/gophercloud"
10 "github.com/rackspace/gophercloud/rackspace"
11)
12
13func 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
41type serverOpts struct {
42 imageID string
43 flavorID string
44}
45
46func 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}