blob: 3ca6dc9b6c8dcf60a50398c5b01998f99dc30828 [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"
Ash Wilsonb17536b2014-10-22 15:36:45 -040010 "github.com/rackspace/gophercloud/acceptance/tools"
Ash Wilson8fecf332014-10-20 15:18:46 -040011 "github.com/rackspace/gophercloud/rackspace"
12)
13
14func newClient() (*gophercloud.ServiceClient, error) {
15 // Obtain credentials from the environment.
Ash Wilsona6ddde72014-10-22 15:26:42 -040016 options, err := rackspace.AuthOptionsFromEnv()
17 if err != nil {
Ash Wilsonb17536b2014-10-22 15:36:45 -040018 return nil, err
Ash Wilson8fecf332014-10-20 15:18:46 -040019 }
Ash Wilsona6ddde72014-10-22 15:26:42 -040020 options = tools.OnlyRS(options)
Ash Wilson8fecf332014-10-20 15:18:46 -040021 region := os.Getenv("RS_REGION")
22
23 if options.Username == "" {
24 return nil, errors.New("Please provide a Rackspace username as RS_USERNAME.")
25 }
26 if options.APIKey == "" {
Ash Wilsona6ddde72014-10-22 15:26:42 -040027 return nil, errors.New("Please provide a Rackspace API key as RS_API_KEY.")
Ash Wilson8fecf332014-10-20 15:18:46 -040028 }
29 if region == "" {
30 return nil, errors.New("Please provide a Rackspace region as RS_REGION.")
31 }
32
33 client, err := rackspace.AuthenticatedClient(options)
34 if err != nil {
35 return nil, err
36 }
37
38 return rackspace.NewComputeV2(client, gophercloud.EndpointOpts{
39 Region: region,
40 })
41}
42
43type serverOpts struct {
44 imageID string
45 flavorID string
46}
47
48func optionsFromEnv() (*serverOpts, error) {
49 options := &serverOpts{
50 imageID: os.Getenv("RS_IMAGE_ID"),
51 flavorID: os.Getenv("RS_FLAVOR_ID"),
52 }
53 if options.imageID == "" {
54 return nil, errors.New("Please provide a valid Rackspace image ID as RS_IMAGE_ID")
55 }
56 if options.flavorID == "" {
57 return nil, errors.New("Please provide a valid Rackspace flavor ID as RS_FLAVOR_ID")
58 }
59 return options, nil
60}