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