add versioning to identity; add generic 'client' function
diff --git a/acceptance/openstack/compute/tools_test.go b/acceptance/openstack/compute/tools_test.go
index 0469053..5140caf 100644
--- a/acceptance/openstack/compute/tools_test.go
+++ b/acceptance/openstack/compute/tools_test.go
@@ -6,7 +6,7 @@
"crypto/rand"
"fmt"
"github.com/rackspace/gophercloud/openstack/compute/servers"
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
"github.com/rackspace/gophercloud/openstack/utils"
"os"
"text/tabwriter"
@@ -16,21 +16,21 @@
var errTimeout = fmt.Errorf("Timeout.")
type testState struct {
- o identity.AuthOptions
- a identity.AuthResults
- sc *identity.ServiceCatalog
- eps []identity.Endpoint
- w *tabwriter.Writer
- imageId string
- flavorId string
- region string
- ep string
- client *servers.Client
- createdServer *servers.Server
- gottenServer *servers.Server
- updatedServer *servers.Server
- serverName string
- alternateName string
+ o identity.AuthOptions
+ a identity.AuthResults
+ sc *identity.ServiceCatalog
+ eps []identity.Endpoint
+ w *tabwriter.Writer
+ imageId string
+ flavorId string
+ region string
+ ep string
+ client *servers.Client
+ createdServer *servers.Server
+ gottenServer *servers.Server
+ updatedServer *servers.Server
+ serverName string
+ alternateName string
flavorIdResize string
}
@@ -240,48 +240,48 @@
}
func MakeNewPassword(oldPass string) string {
- fmt.Println("Current password: "+oldPass)
+ fmt.Println("Current password: " + oldPass)
randomPassword := RandomString("", 16)
for randomPassword == oldPass {
randomPassword = RandomString("", 16)
}
- fmt.Println(" New password: "+randomPassword)
+ fmt.Println(" New password: " + randomPassword)
return randomPassword
}
func ChangeAdminPassword(ts *testState) error {
randomPassword := MakeNewPassword(ts.createdServer.AdminPass)
-
+
err := servers.ChangeAdminPassword(ts.client, ts.createdServer.Id, randomPassword)
if err != nil {
return err
}
-
+
err = WaitForStatus(ts, "PASSWORD")
if err != nil {
return err
}
-
+
return WaitForStatus(ts, "ACTIVE")
}
func RebootServer(ts *testState) error {
- fmt.Println("Attempting reboot of server "+ts.createdServer.Id)
+ fmt.Println("Attempting reboot of server " + ts.createdServer.Id)
err := servers.Reboot(ts.client, ts.createdServer.Id, servers.OSReboot)
if err != nil {
return err
}
-
+
err = WaitForStatus(ts, "REBOOT")
if err != nil {
return err
}
-
+
return WaitForStatus(ts, "ACTIVE")
}
func RebuildServer(ts *testState) error {
- fmt.Println("Attempting to rebuild server "+ts.createdServer.Id)
+ fmt.Println("Attempting to rebuild server " + ts.createdServer.Id)
newPassword := MakeNewPassword(ts.createdServer.AdminPass)
newName := RandomString("ACPTTEST", 16)
@@ -289,7 +289,7 @@
if err != nil {
return err
}
-
+
s, err := servers.GetServer(sr)
if err != nil {
return err
@@ -302,12 +302,12 @@
if err != nil {
return err
}
-
+
return WaitForStatus(ts, "ACTIVE")
}
func ResizeServer(ts *testState) error {
- fmt.Println("Attempting to resize server "+ts.createdServer.Id)
+ fmt.Println("Attempting to resize server " + ts.createdServer.Id)
err := servers.Resize(ts.client, ts.createdServer.Id, ts.flavorIdResize)
if err != nil {
@@ -323,19 +323,19 @@
}
func ConfirmResize(ts *testState) error {
- fmt.Println("Attempting to confirm resize for server "+ts.createdServer.Id)
-
+ fmt.Println("Attempting to confirm resize for server " + ts.createdServer.Id)
+
err := servers.ConfirmResize(ts.client, ts.createdServer.Id)
if err != nil {
return err
}
-
+
return WaitForStatus(ts, "ACTIVE")
}
func RevertResize(ts *testState) error {
- fmt.Println("Attempting to revert resize for server "+ts.createdServer.Id)
-
+ fmt.Println("Attempting to revert resize for server " + ts.createdServer.Id)
+
err := servers.RevertResize(ts.client, ts.createdServer.Id)
if err != nil {
return err
diff --git a/acceptance/openstack/identity_test.go b/acceptance/openstack/identity_test.go
index 02f86ad..f9c26ae 100644
--- a/acceptance/openstack/identity_test.go
+++ b/acceptance/openstack/identity_test.go
@@ -4,7 +4,7 @@
import (
"fmt"
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
"github.com/rackspace/gophercloud/openstack/utils"
"os"
"testing"
diff --git a/acceptance/openstack/storage_test.go b/acceptance/openstack/storage_test.go
index 9792335..5c835cf 100644
--- a/acceptance/openstack/storage_test.go
+++ b/acceptance/openstack/storage_test.go
@@ -4,94 +4,103 @@
import (
"bytes"
+ "github.com/rackspace/gophercloud/acceptance/tools"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
storage "github.com/rackspace/gophercloud/openstack/storage/v1"
"github.com/rackspace/gophercloud/openstack/storage/v1/accounts"
"github.com/rackspace/gophercloud/openstack/storage/v1/containers"
"github.com/rackspace/gophercloud/openstack/storage/v1/objects"
- "os"
+ "github.com/rackspace/gophercloud/openstack/utils"
"strings"
"testing"
- "github.com/rackspace/gophercloud/acceptance/tools"
)
-var objectStorage = "object-store"
var metadata = map[string]string{"gopher": "cloud"}
var numContainers = 2
var numObjects = 2
+func newClient() (*storage.Client, error) {
+ ao, err := utils.AuthOptions()
+ if err != nil {
+ return nil, err
+ }
+
+ client, err := ao.NewClient(identity.ClientOpts{
+ Type: "object-store",
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return storage.NewClient(client.Endpoint, client.Authority, client.Options), nil
+}
+
func TestAccount(t *testing.T) {
- ts, err := tools.SetupForList(objectStorage)
+ client, err := newClient()
if err != nil {
t.Error(err)
return
}
- region := os.Getenv("OS_REGION_NAME")
- for _, ep := range ts.EPs {
- if (region != "") && (region != ep.Region) {
- continue
+ err = accounts.Update(client, accounts.UpdateOpts{
+ Metadata: metadata,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ defer func() {
+ tempMap := make(map[string]string)
+ for k := range metadata {
+ tempMap[k] = ""
}
-
- client := storage.NewClient(ep.PublicURL, ts.A, ts.O)
-
- err := accounts.Update(client, accounts.UpdateOpts{
- Metadata: metadata,
+ err = accounts.Update(client, accounts.UpdateOpts{
+ Metadata: tempMap,
})
if err != nil {
t.Error(err)
return
}
- defer func() {
- tempMap := make(map[string]string)
- for k := range metadata {
- tempMap[k] = ""
- }
- err = accounts.Update(client, accounts.UpdateOpts{
- Metadata: tempMap,
- })
- if err != nil {
- t.Error(err)
- return
- }
- }()
+ }()
- gr, err := accounts.Get(client, accounts.GetOpts{})
- if err != nil {
- t.Error(err)
+ gr, err := accounts.Get(client, accounts.GetOpts{})
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ am := accounts.ExtractMetadata(gr)
+ for k := range metadata {
+ if am[k] != metadata[strings.Title(k)] {
+ t.Errorf("Expected custom metadata with key: %s", k)
return
}
- am := accounts.ExtractMetadata(gr)
- for k := range metadata {
- if am[k] != metadata[strings.Title(k)] {
- t.Errorf("Expected custom metadata with key: %s", k)
- return
- }
- }
}
}
func TestContainers(t *testing.T) {
- ts, err := tools.SetupForList(objectStorage)
+ client, err := newClient()
if err != nil {
t.Error(err)
return
}
- region := os.Getenv("OS_REGION_NAME")
- for _, ep := range ts.EPs {
- if (region != "") && (region != ep.Region) {
- continue
+ cNames := make([]string, numContainers)
+ for i := 0; i < numContainers; i++ {
+ cNames[i] = tools.RandomString("test-container-", 8)
+ }
+
+ for i := 0; i < len(cNames); i++ {
+ _, err := containers.Create(client, containers.CreateOpts{
+ Name: cNames[i],
+ })
+ if err != nil {
+ t.Error(err)
+ return
}
-
- client := storage.NewClient(ep.PublicURL, ts.A, ts.O)
-
- cNames := make([]string, numContainers)
- for i := 0; i < numContainers; i++ {
- cNames[i] = tools.RandomString("test-container-", 8)
- }
-
+ }
+ defer func() {
for i := 0; i < len(cNames); i++ {
- _, err := containers.Create(client, containers.CreateOpts{
+ err = containers.Delete(client, containers.DeleteOpts{
Name: cNames[i],
})
if err != nil {
@@ -99,264 +108,243 @@
return
}
}
- defer func() {
- for i := 0; i < len(cNames); i++ {
- err = containers.Delete(client, containers.DeleteOpts{
- Name: cNames[i],
- })
- if err != nil {
- t.Error(err)
- return
- }
- }
- }()
+ }()
- lr, err := containers.List(client, containers.ListOpts{
- Full: false,
- })
- if err != nil {
- t.Error(err)
- return
- }
- cns, err := containers.ExtractNames(lr)
- if err != nil {
- t.Error(err)
- return
- }
- if len(cns) != len(cNames) {
- t.Errorf("Expected %d names and got %d", len(cNames), len(cns))
- return
- }
+ lr, err := containers.List(client, containers.ListOpts{
+ Full: false,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ cns, err := containers.ExtractNames(lr)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if len(cns) != len(cNames) {
+ t.Errorf("Expected %d names and got %d", len(cNames), len(cns))
+ return
+ }
- lr, err = containers.List(client, containers.ListOpts{
- Full: true,
- })
- if err != nil {
- t.Error(err)
- return
- }
- cis, err := containers.ExtractInfo(lr)
- if err != nil {
- t.Error(err)
- return
- }
- if len(cis) != len(cNames) {
- t.Errorf("Expected %d containers and got %d", len(cNames), len(cis))
- return
- }
+ lr, err = containers.List(client, containers.ListOpts{
+ Full: true,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ cis, err := containers.ExtractInfo(lr)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if len(cis) != len(cNames) {
+ t.Errorf("Expected %d containers and got %d", len(cNames), len(cis))
+ return
+ }
+ err = containers.Update(client, containers.UpdateOpts{
+ Name: cNames[0],
+ Metadata: metadata,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ defer func() {
+ tempMap := make(map[string]string)
+ for k := range metadata {
+ tempMap[k] = ""
+ }
err = containers.Update(client, containers.UpdateOpts{
Name: cNames[0],
- Metadata: metadata,
+ Metadata: tempMap,
})
if err != nil {
t.Error(err)
return
}
- defer func() {
- tempMap := make(map[string]string)
- for k := range metadata {
- tempMap[k] = ""
- }
- err = containers.Update(client, containers.UpdateOpts{
- Name: cNames[0],
- Metadata: tempMap,
- })
- if err != nil {
- t.Error(err)
- return
- }
- }()
+ }()
- gr, err := containers.Get(client, containers.GetOpts{})
- if err != nil {
- t.Error(err)
+ gr, err := containers.Get(client, containers.GetOpts{})
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ cm := containers.ExtractMetadata(gr)
+ for k := range metadata {
+ if cm[k] != metadata[strings.Title(k)] {
+ t.Errorf("Expected custom metadata with key: %s", k)
return
}
- cm := containers.ExtractMetadata(gr)
- for k := range metadata {
- if cm[k] != metadata[strings.Title(k)] {
- t.Errorf("Expected custom metadata with key: %s", k)
- return
- }
- }
}
}
func TestObjects(t *testing.T) {
- ts, err := tools.SetupForList(objectStorage)
+ client, err := newClient()
if err != nil {
t.Error(err)
return
}
- region := os.Getenv("OS_REGION_NAME")
+ oNames := make([]string, numObjects)
+ for i := 0; i < len(oNames); i++ {
+ oNames[i] = tools.RandomString("test-object-", 8)
+ }
- for _, ep := range ts.EPs {
- if (region != "") && (region != ep.Region) {
- continue
- }
-
- client := storage.NewClient(ep.PublicURL, ts.A, ts.O)
-
- oNames := make([]string, numObjects)
- for i := 0; i < len(oNames); i++ {
- oNames[i] = tools.RandomString("test-object-", 8)
- }
-
- cName := tools.RandomString("test-container-", 8)
- _, err := containers.Create(client, containers.CreateOpts{
+ cName := tools.RandomString("test-container-", 8)
+ _, err = containers.Create(client, containers.CreateOpts{
+ Name: cName,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ defer func() {
+ err = containers.Delete(client, containers.DeleteOpts{
Name: cName,
})
if err != nil {
t.Error(err)
return
}
- defer func() {
- err = containers.Delete(client, containers.DeleteOpts{
- Name: cName,
- })
- if err != nil {
- t.Error(err)
- return
- }
- }()
+ }()
- oContents := make([]*bytes.Buffer, numObjects)
+ oContents := make([]*bytes.Buffer, numObjects)
+ for i := 0; i < numObjects; i++ {
+ oContents[i] = bytes.NewBuffer([]byte(tools.RandomString("", 10)))
+ err = objects.Create(client, objects.CreateOpts{
+ Container: cName,
+ Name: oNames[i],
+ Content: oContents[i],
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ }
+ defer func() {
for i := 0; i < numObjects; i++ {
- oContents[i] = bytes.NewBuffer([]byte(tools.RandomString("", 10)))
- err = objects.Create(client, objects.CreateOpts{
+ err = objects.Delete(client, objects.DeleteOpts{
Container: cName,
Name: oNames[i],
- Content: oContents[i],
})
- if err != nil {
- t.Error(err)
- return
- }
}
- defer func() {
- for i := 0; i < numObjects; i++ {
- err = objects.Delete(client, objects.DeleteOpts{
- Container: cName,
- Name: oNames[i],
- })
- }
- }()
+ }()
- lr, err := objects.List(client, objects.ListOpts{
- Full: false,
- Container: cName,
- })
- if err != nil {
- t.Error(err)
- return
- }
- ons, err := objects.ExtractNames(lr)
- if err != nil {
- t.Error(err)
- return
- }
- if len(ons) != len(oNames) {
- t.Errorf("Expected %d names and got %d", len(oNames), len(ons))
- return
- }
+ lr, err := objects.List(client, objects.ListOpts{
+ Full: false,
+ Container: cName,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ ons, err := objects.ExtractNames(lr)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if len(ons) != len(oNames) {
+ t.Errorf("Expected %d names and got %d", len(oNames), len(ons))
+ return
+ }
- lr, err = objects.List(client, objects.ListOpts{
- Full: true,
- Container: cName,
- })
- if err != nil {
- t.Error(err)
- return
- }
- ois, err := objects.ExtractInfo(lr)
- if err != nil {
- t.Error(err)
- return
- }
- if len(ois) != len(oNames) {
- t.Errorf("Expected %d containers and got %d", len(oNames), len(ois))
- return
- }
+ lr, err = objects.List(client, objects.ListOpts{
+ Full: true,
+ Container: cName,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ ois, err := objects.ExtractInfo(lr)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if len(ois) != len(oNames) {
+ t.Errorf("Expected %d containers and got %d", len(oNames), len(ois))
+ return
+ }
- err = objects.Copy(client, objects.CopyOpts{
- Container: cName,
- Name: oNames[0],
- NewContainer: cName,
- NewName: oNames[1],
- })
- if err != nil {
- t.Error(err)
- return
- }
+ err = objects.Copy(client, objects.CopyOpts{
+ Container: cName,
+ Name: oNames[0],
+ NewContainer: cName,
+ NewName: oNames[1],
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
- dr, err := objects.Download(client, objects.DownloadOpts{
- Container: cName,
- Name: oNames[1],
- })
- if err != nil {
- t.Error(err)
- return
- }
- o2Content, err := objects.ExtractContent(dr)
- if err != nil {
- t.Error(err)
- }
- dr, err = objects.Download(client, objects.DownloadOpts{
- Container: cName,
- Name: oNames[0],
- })
- if err != nil {
- t.Error(err)
- return
- }
- o1Content, err := objects.ExtractContent(dr)
- if err != nil {
- t.Error(err)
- return
- }
- if string(o2Content) != string(o1Content) {
- t.Errorf("Copy failed. Expected\n%s\nand got\n%s", string(o1Content), string(o2Content))
- return
- }
+ dr, err := objects.Download(client, objects.DownloadOpts{
+ Container: cName,
+ Name: oNames[1],
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ o2Content, err := objects.ExtractContent(dr)
+ if err != nil {
+ t.Error(err)
+ }
+ dr, err = objects.Download(client, objects.DownloadOpts{
+ Container: cName,
+ Name: oNames[0],
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ o1Content, err := objects.ExtractContent(dr)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if string(o2Content) != string(o1Content) {
+ t.Errorf("Copy failed. Expected\n%s\nand got\n%s", string(o1Content), string(o2Content))
+ return
+ }
+ err = objects.Update(client, objects.UpdateOpts{
+ Container: cName,
+ Name: oNames[0],
+ Metadata: metadata,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ defer func() {
+ tempMap := make(map[string]string)
+ for k := range metadata {
+ tempMap[k] = ""
+ }
err = objects.Update(client, objects.UpdateOpts{
Container: cName,
Name: oNames[0],
- Metadata: metadata,
+ Metadata: tempMap,
})
if err != nil {
t.Error(err)
return
}
- defer func() {
- tempMap := make(map[string]string)
- for k := range metadata {
- tempMap[k] = ""
- }
- err = objects.Update(client, objects.UpdateOpts{
- Container: cName,
- Name: oNames[0],
- Metadata: tempMap,
- })
- if err != nil {
- t.Error(err)
- return
- }
- }()
+ }()
- gr, err := objects.Get(client, objects.GetOpts{})
- if err != nil {
- t.Error(err)
+ gr, err := objects.Get(client, objects.GetOpts{})
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ om := objects.ExtractMetadata(gr)
+ for k := range metadata {
+ if om[k] != metadata[strings.Title(k)] {
+ t.Errorf("Expected custom metadata with key: %s", k)
return
}
- om := objects.ExtractMetadata(gr)
- for k := range metadata {
- if om[k] != metadata[strings.Title(k)] {
- t.Errorf("Expected custom metadata with key: %s", k)
- return
- }
- }
}
}
diff --git a/acceptance/rackspace/monitoring/rbac_test.go b/acceptance/rackspace/monitoring/rbac_test.go
index a6d1d54..cd01891 100644
--- a/acceptance/rackspace/monitoring/rbac_test.go
+++ b/acceptance/rackspace/monitoring/rbac_test.go
@@ -4,11 +4,11 @@
import (
"fmt"
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
"github.com/rackspace/gophercloud/openstack/utils"
"github.com/rackspace/gophercloud/rackspace/monitoring"
"github.com/rackspace/gophercloud/rackspace/monitoring/notificationPlans"
- "testing"
+ "testing"
)
func TestRBACPermissions(t *testing.T) {
diff --git a/acceptance/tools/tools.go b/acceptance/tools/tools.go
index ebb660a..5891c7f 100644
--- a/acceptance/tools/tools.go
+++ b/acceptance/tools/tools.go
@@ -6,7 +6,7 @@
"crypto/rand"
"fmt"
"github.com/rackspace/gophercloud/openstack/compute/servers"
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
"github.com/rackspace/gophercloud/openstack/utils"
"os"
"text/tabwriter"
@@ -16,21 +16,21 @@
var errTimeout = fmt.Errorf("Timeout.")
type testState struct {
- O identity.AuthOptions
- A identity.AuthResults
- SC *identity.ServiceCatalog
- EPs []identity.Endpoint
- W *tabwriter.Writer
- ImageId string
- FlavorId string
- Region string
- EP string
- Client *servers.Client
- CreatedServer *servers.Server
- GottenServer *servers.Server
- UpdatedServer *servers.Server
- ServerName string
- AlternateName string
+ O identity.AuthOptions
+ A identity.AuthResults
+ SC *identity.ServiceCatalog
+ EPs []identity.Endpoint
+ W *tabwriter.Writer
+ ImageId string
+ FlavorId string
+ Region string
+ EP string
+ Client *servers.Client
+ CreatedServer *servers.Server
+ GottenServer *servers.Server
+ UpdatedServer *servers.Server
+ ServerName string
+ AlternateName string
FlavorIdResize string
}
@@ -240,48 +240,48 @@
}
func MakeNewPassword(oldPass string) string {
- fmt.Println("Current password: "+oldPass)
+ fmt.Println("Current password: " + oldPass)
randomPassword := RandomString("", 16)
for randomPassword == oldPass {
randomPassword = RandomString("", 16)
}
- fmt.Println(" New password: "+randomPassword)
+ fmt.Println(" New password: " + randomPassword)
return randomPassword
}
func ChangeAdminPassword(ts *testState) error {
randomPassword := MakeNewPassword(ts.CreatedServer.AdminPass)
-
+
err := servers.ChangeAdminPassword(ts.Client, ts.CreatedServer.Id, randomPassword)
if err != nil {
return err
}
-
+
err = WaitForStatus(ts, "PASSWORD")
if err != nil {
return err
}
-
+
return WaitForStatus(ts, "ACTIVE")
}
func RebootServer(ts *testState) error {
- fmt.Println("Attempting reboot of server "+ts.CreatedServer.Id)
+ fmt.Println("Attempting reboot of server " + ts.CreatedServer.Id)
err := servers.Reboot(ts.Client, ts.CreatedServer.Id, servers.OSReboot)
if err != nil {
return err
}
-
+
err = WaitForStatus(ts, "REBOOT")
if err != nil {
return err
}
-
+
return WaitForStatus(ts, "ACTIVE")
}
func RebuildServer(ts *testState) error {
- fmt.Println("Attempting to rebuild server "+ts.CreatedServer.Id)
+ fmt.Println("Attempting to rebuild server " + ts.CreatedServer.Id)
newPassword := MakeNewPassword(ts.CreatedServer.AdminPass)
newName := RandomString("ACPTTEST", 16)
@@ -289,7 +289,7 @@
if err != nil {
return err
}
-
+
s, err := servers.GetServer(sr)
if err != nil {
return err
@@ -302,12 +302,12 @@
if err != nil {
return err
}
-
+
return WaitForStatus(ts, "ACTIVE")
}
func ResizeServer(ts *testState) error {
- fmt.Println("Attempting to resize server "+ts.CreatedServer.Id)
+ fmt.Println("Attempting to resize server " + ts.CreatedServer.Id)
err := servers.Resize(ts.Client, ts.CreatedServer.Id, ts.FlavorIdResize)
if err != nil {
@@ -323,19 +323,19 @@
}
func ConfirmResize(ts *testState) error {
- fmt.Println("Attempting to confirm resize for server "+ts.CreatedServer.Id)
-
+ fmt.Println("Attempting to confirm resize for server " + ts.CreatedServer.Id)
+
err := servers.ConfirmResize(ts.Client, ts.CreatedServer.Id)
if err != nil {
return err
}
-
+
return WaitForStatus(ts, "ACTIVE")
}
func RevertResize(ts *testState) error {
- fmt.Println("Attempting to revert resize for server "+ts.CreatedServer.Id)
-
+ fmt.Println("Attempting to revert resize for server " + ts.CreatedServer.Id)
+
err := servers.RevertResize(ts.Client, ts.CreatedServer.Id)
if err != nil {
return err
diff --git a/openstack/compute/flavors/client.go b/openstack/compute/flavors/client.go
index 2c64908..5676d36 100644
--- a/openstack/compute/flavors/client.go
+++ b/openstack/compute/flavors/client.go
@@ -2,8 +2,8 @@
import (
"fmt"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
"net/url"
- "github.com/rackspace/gophercloud/openstack/identity"
"strconv"
)
diff --git a/openstack/compute/images/client.go b/openstack/compute/images/client.go
index c5f1897..3390b99 100644
--- a/openstack/compute/images/client.go
+++ b/openstack/compute/images/client.go
@@ -1,7 +1,7 @@
package images
import (
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
)
type Client struct {
diff --git a/openstack/compute/servers/client.go b/openstack/compute/servers/client.go
index 3ce6965..611ff22 100644
--- a/openstack/compute/servers/client.go
+++ b/openstack/compute/servers/client.go
@@ -2,7 +2,7 @@
import (
"fmt"
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
)
// Client abstracts the connection information needed to make API requests for OpenStack compute endpoints.
diff --git a/openstack/identity/v2/client.go b/openstack/identity/v2/client.go
new file mode 100644
index 0000000..c736833
--- /dev/null
+++ b/openstack/identity/v2/client.go
@@ -0,0 +1,80 @@
+package identity
+
+import (
+ "os"
+)
+
+type Client struct {
+ Endpoint string
+ Authority AuthResults
+ Options AuthOptions
+}
+
+type ClientOpts struct {
+ Type string
+ Name string
+ Region string
+ URLType string
+}
+
+func (ao AuthOptions) NewClient(opts ClientOpts) (Client, error) {
+ client := Client{
+ Options: ao,
+ }
+
+ ar, err := Authenticate(ao)
+ if err != nil {
+ return client, err
+ }
+
+ client.Authority = ar
+
+ sc, err := GetServiceCatalog(ar)
+ if err != nil {
+ return client, err
+ }
+
+ ces, err := sc.CatalogEntries()
+ if err != nil {
+ return client, err
+ }
+
+ var eps []Endpoint
+
+ if opts.Name != "" {
+ for _, ce := range ces {
+ if ce.Type == opts.Type && ce.Name == opts.Name {
+ eps = ce.Endpoints
+ }
+ }
+ } else {
+ for _, ce := range ces {
+ if ce.Type == opts.Type {
+ eps = ce.Endpoints
+ }
+ }
+ }
+
+ region := os.Getenv("OS_REGION_NAME")
+ if opts.Region != "" {
+ region = opts.Region
+ }
+
+ var rep string
+ for _, ep := range eps {
+ if ep.Region == region {
+ switch opts.URLType {
+ case "public":
+ rep = ep.PublicURL
+ case "private":
+ rep = ep.InternalURL
+ default:
+ rep = ep.PublicURL
+ }
+ }
+ }
+
+ client.Endpoint = rep
+
+ return client, nil
+}
diff --git a/openstack/identity/common_test.go b/openstack/identity/v2/common_test.go
similarity index 100%
rename from openstack/identity/common_test.go
rename to openstack/identity/v2/common_test.go
diff --git a/openstack/identity/doc.go b/openstack/identity/v2/doc.go
similarity index 100%
rename from openstack/identity/doc.go
rename to openstack/identity/v2/doc.go
diff --git a/openstack/identity/errors.go b/openstack/identity/v2/errors.go
similarity index 100%
rename from openstack/identity/errors.go
rename to openstack/identity/v2/errors.go
diff --git a/openstack/identity/extensions.go b/openstack/identity/v2/extensions.go
similarity index 100%
rename from openstack/identity/extensions.go
rename to openstack/identity/v2/extensions.go
diff --git a/openstack/identity/extensions_test.go b/openstack/identity/v2/extensions_test.go
similarity index 100%
rename from openstack/identity/extensions_test.go
rename to openstack/identity/v2/extensions_test.go
diff --git a/openstack/identity/requests.go b/openstack/identity/v2/requests.go
similarity index 100%
rename from openstack/identity/requests.go
rename to openstack/identity/v2/requests.go
diff --git a/openstack/identity/service_catalog.go b/openstack/identity/v2/service_catalog.go
similarity index 100%
rename from openstack/identity/service_catalog.go
rename to openstack/identity/v2/service_catalog.go
diff --git a/openstack/identity/service_catalog_test.go b/openstack/identity/v2/service_catalog_test.go
similarity index 100%
rename from openstack/identity/service_catalog_test.go
rename to openstack/identity/v2/service_catalog_test.go
diff --git a/openstack/identity/token.go b/openstack/identity/v2/token.go
similarity index 100%
rename from openstack/identity/token.go
rename to openstack/identity/v2/token.go
diff --git a/openstack/identity/token_test.go b/openstack/identity/v2/token_test.go
similarity index 100%
rename from openstack/identity/token_test.go
rename to openstack/identity/v2/token_test.go
diff --git a/openstack/storage/v1/client.go b/openstack/storage/v1/client.go
index f616038..a457a74 100644
--- a/openstack/storage/v1/client.go
+++ b/openstack/storage/v1/client.go
@@ -2,7 +2,7 @@
import (
"fmt"
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
)
// Client is a structure that contains information for communicating with a provider.
diff --git a/openstack/utils/utils.go b/openstack/utils/utils.go
index a814c7e..99b0977 100644
--- a/openstack/utils/utils.go
+++ b/openstack/utils/utils.go
@@ -3,7 +3,7 @@
import (
"fmt"
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
"os"
)
diff --git a/rackspace/monitoring/common.go b/rackspace/monitoring/common.go
index d68a349..42c31ca 100644
--- a/rackspace/monitoring/common.go
+++ b/rackspace/monitoring/common.go
@@ -1,7 +1,7 @@
package monitoring
import (
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
)
type Options struct {
diff --git a/rackspace/monitoring/notificationPlans/requests.go b/rackspace/monitoring/notificationPlans/requests.go
index 1bef64d..37fb40b 100644
--- a/rackspace/monitoring/notificationPlans/requests.go
+++ b/rackspace/monitoring/notificationPlans/requests.go
@@ -3,7 +3,7 @@
import (
"fmt"
"github.com/racker/perigee"
- "github.com/rackspace/gophercloud/openstack/identity"
+ identity "github.com/rackspace/gophercloud/openstack/identity/v2"
"github.com/rackspace/gophercloud/rackspace/monitoring"
)