mirror of https://github.com/docker/docs.git
Merge pull request #955 from ggiamarchi/keystone_v3_domains
Keystone v3 domains
This commit is contained in:
commit
2a93207bd9
|
@ -130,8 +130,8 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "github.com/rackspace/gophercloud",
|
||||
"Comment": "v1.0.0-473-g7ca169d",
|
||||
"Rev": "7ca169d371b29e3dbab9e631c3a6151896b06330"
|
||||
"Comment": "v1.0.0-558-ce0f487",
|
||||
"Rev": "ce0f487f6747ab43c4e4404722df25349385bebd"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/skarademir/naturalsort",
|
||||
|
|
|
@ -205,7 +205,7 @@ On of the easiest ways to get readily involved in our project is to let us know
|
|||
about your experiences using our SDK. Feedback like this is incredibly useful
|
||||
to us, because it allows us to refine and change features based on what our
|
||||
users want and expect of us. There are a bunch of ways to get in contact! You
|
||||
can [ping us](mailto:sdk-support@rackspace.com) via e-mail, talk to us on irc
|
||||
can [ping us](https://developer.rackspace.com/support/) via e-mail, talk to us on irc
|
||||
(#rackspace-dev on freenode), [tweet us](https://twitter.com/rackspace), or
|
||||
submit an issue on our [bug tracker](/issues). Things you might like to tell us
|
||||
are:
|
||||
|
|
|
@ -151,11 +151,10 @@ Engaging the community and lowering barriers for contributors is something we
|
|||
care a lot about. For this reason, we've taken the time to write a [contributing
|
||||
guide](./CONTRIBUTING.md) for folks interested in getting involved in our project.
|
||||
If you're not sure how you can get involved, feel free to submit an issue or
|
||||
[e-mail us](mailto:sdk-support@rackspace.com) privately. You don't need to be a
|
||||
[contact us](https://developer.rackspace.com/support/). You don't need to be a
|
||||
Go expert - all members of the community are welcome!
|
||||
|
||||
## Help and feedback
|
||||
|
||||
If you're struggling with something or have spotted a potential bug, feel free
|
||||
to submit an issue to our [bug tracker](/issues) or e-mail us directly at
|
||||
[sdk-support@rackspace.com](mailto:sdk-support@rackspace.com).
|
||||
to submit an issue to our [bug tracker](/issues) or [contact us directly](https://developer.rackspace.com/support/).
|
||||
|
|
|
@ -8,7 +8,7 @@ extensible, maintainable and easy-to-use.
|
|||
Below we've compiled upgrade instructions for the various services that
|
||||
existed before. If you have a specific issue that is not addressed below,
|
||||
please [submit an issue](/issues/new) or
|
||||
[e-mail our support team](mailto:sdk-support@rackspace.com).
|
||||
[e-mail our support team](https://developer.rackspace.com/support/).
|
||||
|
||||
* [Authentication](#authentication)
|
||||
* [Servers](#servers)
|
||||
|
|
|
@ -56,6 +56,9 @@ type ComputeChoices struct {
|
|||
// FlavorIDResize contains the ID of a different flavor available on the same OpenStack installation, that is distinct
|
||||
// from FlavorID.
|
||||
FlavorIDResize string
|
||||
|
||||
// NetworkName is the name of a network to launch the instance on.
|
||||
NetworkName string
|
||||
}
|
||||
|
||||
// ComputeChoicesFromEnv populates a ComputeChoices struct from environment variables.
|
||||
|
@ -64,6 +67,7 @@ func ComputeChoicesFromEnv() (*ComputeChoices, error) {
|
|||
imageID := os.Getenv("OS_IMAGE_ID")
|
||||
flavorID := os.Getenv("OS_FLAVOR_ID")
|
||||
flavorIDResize := os.Getenv("OS_FLAVOR_ID_RESIZE")
|
||||
networkName := os.Getenv("OS_NETWORK_NAME")
|
||||
|
||||
missing := make([]string, 0, 3)
|
||||
if imageID == "" {
|
||||
|
@ -75,6 +79,9 @@ func ComputeChoicesFromEnv() (*ComputeChoices, error) {
|
|||
if flavorIDResize == "" {
|
||||
missing = append(missing, "OS_FLAVOR_ID_RESIZE")
|
||||
}
|
||||
if networkName == "" {
|
||||
networkName = "public"
|
||||
}
|
||||
|
||||
notDistinct := ""
|
||||
if flavorID == flavorIDResize {
|
||||
|
@ -93,5 +100,5 @@ func ComputeChoicesFromEnv() (*ComputeChoices, error) {
|
|||
return nil, fmt.Errorf(text)
|
||||
}
|
||||
|
||||
return &ComputeChoices{ImageID: imageID, FlavorID: flavorID, FlavorIDResize: flavorIDResize}, nil
|
||||
return &ComputeChoices{ImageID: imageID, FlavorID: flavorID, FlavorIDResize: flavorIDResize, NetworkName: networkName}, nil
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ func networkingClient() (*gophercloud.ServiceClient, error) {
|
|||
}
|
||||
|
||||
return openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
|
||||
Name: "neutron",
|
||||
Region: os.Getenv("OS_REGION_NAME"),
|
||||
})
|
||||
}
|
||||
|
@ -74,7 +73,10 @@ func createServer(t *testing.T, client *gophercloud.ServiceClient, choices *Comp
|
|||
t.Fatalf("Unable to create a networking client: %v", err)
|
||||
}
|
||||
|
||||
pager := networks.List(networkingClient, networks.ListOpts{Name: "public", Limit: 1})
|
||||
pager := networks.List(networkingClient, networks.ListOpts{
|
||||
Name: choices.NetworkName,
|
||||
Limit: 1,
|
||||
})
|
||||
pager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
networks, err := networks.ExtractNetworks(page)
|
||||
if err != nil {
|
||||
|
@ -138,6 +140,32 @@ func TestCreateDestroyServer(t *testing.T) {
|
|||
if err = waitForStatus(client, server, "ACTIVE"); err != nil {
|
||||
t.Fatalf("Unable to wait for server: %v", err)
|
||||
}
|
||||
|
||||
pager := servers.ListAddresses(client, server.ID)
|
||||
pager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
networks, err := servers.ExtractAddresses(page)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for n, a := range networks {
|
||||
t.Logf("%s: %+v\n", n, a)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
|
||||
pager = servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName)
|
||||
pager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
addresses, err := servers.ExtractNetworkAddresses(page)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, a := range addresses {
|
||||
t.Logf("%+v\n", a)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpdateServer(t *testing.T) {
|
||||
|
|
109
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/openstack/compute/v2/tenantnetworks_test.go
generated
vendored
Normal file
109
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/openstack/compute/v2/tenantnetworks_test.go
generated
vendored
Normal file
|
@ -0,0 +1,109 @@
|
|||
// +build acceptance compute servers
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/acceptance/tools"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func getNetworkID(t *testing.T, client *gophercloud.ServiceClient, networkName string) (string, error) {
|
||||
allPages, err := tenantnetworks.List(client).AllPages()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to list networks: %v", err)
|
||||
}
|
||||
|
||||
networkList, err := tenantnetworks.ExtractNetworks(allPages)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to list networks: %v", err)
|
||||
}
|
||||
|
||||
networkID := ""
|
||||
for _, network := range networkList {
|
||||
t.Logf("Network: %v", network)
|
||||
if network.Name == networkName {
|
||||
networkID = network.ID
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("Found network ID for %s: %s\n", networkName, networkID)
|
||||
|
||||
return networkID, nil
|
||||
}
|
||||
|
||||
func createNetworkServer(t *testing.T, client *gophercloud.ServiceClient, choices *ComputeChoices, networkID string) (*servers.Server, error) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping test that requires server creation in short mode.")
|
||||
}
|
||||
|
||||
name := tools.RandomString("ACPTTEST", 16)
|
||||
t.Logf("Attempting to create server: %s\n", name)
|
||||
|
||||
pwd := tools.MakeNewPassword("")
|
||||
|
||||
networks := make([]servers.Network, 1)
|
||||
networks[0] = servers.Network{
|
||||
UUID: networkID,
|
||||
}
|
||||
|
||||
server, err := servers.Create(client, servers.CreateOpts{
|
||||
Name: name,
|
||||
FlavorRef: choices.FlavorID,
|
||||
ImageRef: choices.ImageID,
|
||||
AdminPass: pwd,
|
||||
Networks: networks,
|
||||
}).Extract()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create server: %v", err)
|
||||
}
|
||||
|
||||
th.AssertEquals(t, pwd, server.AdminPass)
|
||||
|
||||
return server, err
|
||||
}
|
||||
|
||||
func TestTenantNetworks(t *testing.T) {
|
||||
networkName := os.Getenv("OS_NETWORK_NAME")
|
||||
if networkName == "" {
|
||||
t.Fatalf("OS_NETWORK_NAME must be set")
|
||||
}
|
||||
|
||||
choices, err := ComputeChoicesFromEnv()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
client, err := newClient()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create a compute client: %v", err)
|
||||
}
|
||||
|
||||
networkID, err := getNetworkID(t, client, networkName)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to get network ID: %v", err)
|
||||
}
|
||||
|
||||
server, err := createNetworkServer(t, client, choices, networkID)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create server: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
servers.Delete(client, server.ID)
|
||||
t.Logf("Server deleted.")
|
||||
}()
|
||||
|
||||
if err = waitForStatus(client, server, "ACTIVE"); err != nil {
|
||||
t.Fatalf("Unable to wait for server: %v", err)
|
||||
}
|
||||
|
||||
allPages, err := tenantnetworks.List(client).AllPages()
|
||||
allNetworks, err := tenantnetworks.ExtractNetworks(allPages)
|
||||
th.AssertNoErr(t, err)
|
||||
t.Logf("Retrieved all %d networks: %+v", len(allNetworks), allNetworks)
|
||||
}
|
|
@ -87,3 +87,51 @@ func TestContainers(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestListAllContainers(t *testing.T) {
|
||||
// Create a new client to execute the HTTP requests. See common.go for newClient body.
|
||||
client := newClient(t)
|
||||
|
||||
numContainers := 20
|
||||
|
||||
// Create a slice of random container names.
|
||||
cNames := make([]string, numContainers)
|
||||
for i := 0; i < numContainers; i++ {
|
||||
cNames[i] = tools.RandomString("gophercloud-test-container-", 8)
|
||||
}
|
||||
|
||||
// Create numContainers containers.
|
||||
for i := 0; i < len(cNames); i++ {
|
||||
res := containers.Create(client, cNames[i], nil)
|
||||
th.AssertNoErr(t, res.Err)
|
||||
}
|
||||
// Delete the numContainers containers after function completion.
|
||||
defer func() {
|
||||
for i := 0; i < len(cNames); i++ {
|
||||
res := containers.Delete(client, cNames[i])
|
||||
th.AssertNoErr(t, res.Err)
|
||||
}
|
||||
}()
|
||||
|
||||
// List all the numContainer names that were just created. To just list those,
|
||||
// the 'prefix' parameter is used.
|
||||
allPages, err := containers.List(client, &containers.ListOpts{Full: true, Limit: 5, Prefix: "gophercloud-test-container-"}).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
containerInfoList, err := containers.ExtractInfo(allPages)
|
||||
th.AssertNoErr(t, err)
|
||||
for _, n := range containerInfoList {
|
||||
t.Logf("Container: Name [%s] Count [%d] Bytes [%d]",
|
||||
n.Name, n.Count, n.Bytes)
|
||||
}
|
||||
th.AssertEquals(t, numContainers, len(containerInfoList))
|
||||
|
||||
// List the info for all the numContainer containers that were created.
|
||||
allPages, err = containers.List(client, &containers.ListOpts{Full: false, Limit: 2, Prefix: "gophercloud-test-container-"}).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
containerNamesList, err := containers.ExtractNames(allPages)
|
||||
th.AssertNoErr(t, err)
|
||||
for _, n := range containerNamesList {
|
||||
t.Logf("Container: Name [%s]", n)
|
||||
}
|
||||
th.AssertEquals(t, numContainers, len(containerNamesList))
|
||||
}
|
||||
|
|
130
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/compute/v2/volumeattach_test.go
generated
vendored
Normal file
130
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/compute/v2/volumeattach_test.go
generated
vendored
Normal file
|
@ -0,0 +1,130 @@
|
|||
// +build acceptance compute servers
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/acceptance/tools"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
osVolumes "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
|
||||
osVolumeAttach "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach"
|
||||
osServers "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
|
||||
"github.com/rackspace/gophercloud/rackspace"
|
||||
"github.com/rackspace/gophercloud/rackspace/blockstorage/v1/volumes"
|
||||
"github.com/rackspace/gophercloud/rackspace/compute/v2/servers"
|
||||
"github.com/rackspace/gophercloud/rackspace/compute/v2/volumeattach"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func newBlockClient(t *testing.T) (*gophercloud.ServiceClient, error) {
|
||||
ao, err := rackspace.AuthOptionsFromEnv()
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
client, err := rackspace.AuthenticatedClient(ao)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
return openstack.NewBlockStorageV1(client, gophercloud.EndpointOpts{
|
||||
Region: os.Getenv("RS_REGION_NAME"),
|
||||
})
|
||||
}
|
||||
|
||||
func createVAServer(t *testing.T, computeClient *gophercloud.ServiceClient, choices *serverOpts) (*osServers.Server, error) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping test that requires server creation in short mode.")
|
||||
}
|
||||
|
||||
name := tools.RandomString("ACPTTEST", 16)
|
||||
t.Logf("Attempting to create server: %s\n", name)
|
||||
|
||||
pwd := tools.MakeNewPassword("")
|
||||
|
||||
server, err := servers.Create(computeClient, osServers.CreateOpts{
|
||||
Name: name,
|
||||
FlavorRef: choices.flavorID,
|
||||
ImageRef: choices.imageID,
|
||||
AdminPass: pwd,
|
||||
}).Extract()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create server: %v", err)
|
||||
}
|
||||
|
||||
th.AssertEquals(t, pwd, server.AdminPass)
|
||||
|
||||
return server, err
|
||||
}
|
||||
|
||||
func createVAVolume(t *testing.T, blockClient *gophercloud.ServiceClient) (*volumes.Volume, error) {
|
||||
volume, err := volumes.Create(blockClient, &osVolumes.CreateOpts{
|
||||
Size: 80,
|
||||
Name: "gophercloud-test-volume",
|
||||
}).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
defer func() {
|
||||
err = osVolumes.WaitForStatus(blockClient, volume.ID, "available", 60)
|
||||
th.AssertNoErr(t, err)
|
||||
}()
|
||||
|
||||
return volume, err
|
||||
}
|
||||
|
||||
func createVolumeAttachment(t *testing.T, computeClient *gophercloud.ServiceClient, blockClient *gophercloud.ServiceClient, serverID string, volumeID string) {
|
||||
va, err := volumeattach.Create(computeClient, serverID, &osVolumeAttach.CreateOpts{
|
||||
VolumeID: volumeID,
|
||||
}).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
defer func() {
|
||||
err = osVolumes.WaitForStatus(blockClient, volumeID, "in-use", 60)
|
||||
th.AssertNoErr(t, err)
|
||||
err = volumeattach.Delete(computeClient, serverID, va.ID).ExtractErr()
|
||||
th.AssertNoErr(t, err)
|
||||
err = osVolumes.WaitForStatus(blockClient, volumeID, "available", 60)
|
||||
th.AssertNoErr(t, err)
|
||||
}()
|
||||
t.Logf("Attached volume to server: %+v", va)
|
||||
}
|
||||
|
||||
func TestAttachVolume(t *testing.T) {
|
||||
choices, err := optionsFromEnv()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
computeClient, err := newClient()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create a compute client: %v", err)
|
||||
}
|
||||
|
||||
blockClient, err := newBlockClient(t)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create a blockstorage client: %v", err)
|
||||
}
|
||||
|
||||
server, err := createVAServer(t, computeClient, choices)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create server: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
servers.Delete(computeClient, server.ID)
|
||||
t.Logf("Server deleted.")
|
||||
}()
|
||||
|
||||
if err = osServers.WaitForStatus(computeClient, server.ID, "ACTIVE", 300); err != nil {
|
||||
t.Fatalf("Unable to wait for server: %v", err)
|
||||
}
|
||||
|
||||
volume, err := createVAVolume(t, blockClient)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create volume: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
err = volumes.Delete(blockClient, volume.ID).ExtractErr()
|
||||
th.AssertNoErr(t, err)
|
||||
t.Logf("Volume deleted.")
|
||||
}()
|
||||
|
||||
createVolumeAttachment(t, computeClient, blockClient, server.ID, volume.ID)
|
||||
|
||||
}
|
165
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/networking/v2/security_test.go
generated
vendored
Normal file
165
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/networking/v2/security_test.go
generated
vendored
Normal file
|
@ -0,0 +1,165 @@
|
|||
// +build acceptance networking security
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
osGroups "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/security/groups"
|
||||
osRules "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/security/rules"
|
||||
osNetworks "github.com/rackspace/gophercloud/openstack/networking/v2/networks"
|
||||
osPorts "github.com/rackspace/gophercloud/openstack/networking/v2/ports"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
rsNetworks "github.com/rackspace/gophercloud/rackspace/networking/v2/networks"
|
||||
rsPorts "github.com/rackspace/gophercloud/rackspace/networking/v2/ports"
|
||||
rsGroups "github.com/rackspace/gophercloud/rackspace/networking/v2/security/groups"
|
||||
rsRules "github.com/rackspace/gophercloud/rackspace/networking/v2/security/rules"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func TestSecurityGroups(t *testing.T) {
|
||||
Setup(t)
|
||||
defer Teardown()
|
||||
|
||||
// create security group
|
||||
groupID := createSecGroup(t)
|
||||
|
||||
// delete security group
|
||||
defer deleteSecGroup(t, groupID)
|
||||
|
||||
// list security group
|
||||
listSecGroups(t)
|
||||
|
||||
// get security group
|
||||
getSecGroup(t, groupID)
|
||||
}
|
||||
|
||||
func TestSecurityGroupRules(t *testing.T) {
|
||||
Setup(t)
|
||||
defer Teardown()
|
||||
|
||||
// create security group
|
||||
groupID := createSecGroup(t)
|
||||
|
||||
defer deleteSecGroup(t, groupID)
|
||||
|
||||
// create security group rule
|
||||
ruleID := createSecRule(t, groupID)
|
||||
|
||||
// delete security group rule
|
||||
defer deleteSecRule(t, ruleID)
|
||||
|
||||
// list security group rule
|
||||
listSecRules(t)
|
||||
|
||||
// get security group rule
|
||||
getSecRule(t, ruleID)
|
||||
}
|
||||
|
||||
func createSecGroup(t *testing.T) string {
|
||||
sg, err := rsGroups.Create(Client, osGroups.CreateOpts{
|
||||
Name: "new-webservers",
|
||||
Description: "security group for webservers",
|
||||
}).Extract()
|
||||
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
t.Logf("Created security group %s", sg.ID)
|
||||
|
||||
return sg.ID
|
||||
}
|
||||
|
||||
func listSecGroups(t *testing.T) {
|
||||
err := rsGroups.List(Client, osGroups.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
|
||||
list, err := osGroups.ExtractGroups(page)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to extract secgroups: %v", err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, sg := range list {
|
||||
t.Logf("Listing security group: ID [%s] Name [%s]", sg.ID, sg.Name)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
})
|
||||
|
||||
th.AssertNoErr(t, err)
|
||||
}
|
||||
|
||||
func getSecGroup(t *testing.T, id string) {
|
||||
sg, err := rsGroups.Get(Client, id).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
t.Logf("Getting security group: ID [%s] Name [%s] Description [%s]", sg.ID, sg.Name, sg.Description)
|
||||
}
|
||||
|
||||
func createSecGroupPort(t *testing.T, groupID string) (string, string) {
|
||||
n, err := rsNetworks.Create(Client, osNetworks.CreateOpts{Name: "tmp_network"}).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
t.Logf("Created network %s", n.ID)
|
||||
|
||||
opts := osPorts.CreateOpts{
|
||||
NetworkID: n.ID,
|
||||
Name: "my_port",
|
||||
SecurityGroups: []string{groupID},
|
||||
}
|
||||
p, err := rsPorts.Create(Client, opts).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
t.Logf("Created port %s with security group %s", p.ID, groupID)
|
||||
|
||||
return n.ID, p.ID
|
||||
}
|
||||
|
||||
func deleteSecGroup(t *testing.T, groupID string) {
|
||||
res := rsGroups.Delete(Client, groupID)
|
||||
th.AssertNoErr(t, res.Err)
|
||||
t.Logf("Deleted security group %s", groupID)
|
||||
}
|
||||
|
||||
func createSecRule(t *testing.T, groupID string) string {
|
||||
r, err := rsRules.Create(Client, osRules.CreateOpts{
|
||||
Direction: "ingress",
|
||||
PortRangeMin: 80,
|
||||
EtherType: "IPv4",
|
||||
PortRangeMax: 80,
|
||||
Protocol: "tcp",
|
||||
SecGroupID: groupID,
|
||||
}).Extract()
|
||||
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
t.Logf("Created security group rule %s", r.ID)
|
||||
|
||||
return r.ID
|
||||
}
|
||||
|
||||
func listSecRules(t *testing.T) {
|
||||
err := rsRules.List(Client, osRules.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
|
||||
list, err := osRules.ExtractRules(page)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to extract sec rules: %v", err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, r := range list {
|
||||
t.Logf("Listing security rule: ID [%s]", r.ID)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
})
|
||||
|
||||
th.AssertNoErr(t, err)
|
||||
}
|
||||
|
||||
func getSecRule(t *testing.T, id string) {
|
||||
r, err := rsRules.Get(Client, id).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
t.Logf("Getting security rule: ID [%s] Direction [%s] EtherType [%s] Protocol [%s]",
|
||||
r.ID, r.Direction, r.EtherType, r.Protocol)
|
||||
}
|
||||
|
||||
func deleteSecRule(t *testing.T, id string) {
|
||||
res := rsRules.Delete(Client, id)
|
||||
th.AssertNoErr(t, res.Err)
|
||||
t.Logf("Deleted security rule %s", id)
|
||||
}
|
36
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/cloudnetworks_test.go
generated
vendored
Normal file
36
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/cloudnetworks_test.go
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
// +build acceptance
|
||||
|
||||
package v3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/rackspace/rackconnect/v3/cloudnetworks"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func TestCloudNetworks(t *testing.T) {
|
||||
c := newClient(t)
|
||||
cnID := testListNetworks(t, c)
|
||||
testGetNetworks(t, c, cnID)
|
||||
}
|
||||
|
||||
func testListNetworks(t *testing.T, c *gophercloud.ServiceClient) string {
|
||||
allPages, err := cloudnetworks.List(c).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
allcn, err := cloudnetworks.ExtractCloudNetworks(allPages)
|
||||
fmt.Printf("Listing all cloud networks: %+v\n\n", allcn)
|
||||
var cnID string
|
||||
if len(allcn) > 0 {
|
||||
cnID = allcn[0].ID
|
||||
}
|
||||
return cnID
|
||||
}
|
||||
|
||||
func testGetNetworks(t *testing.T, c *gophercloud.ServiceClient, id string) {
|
||||
cn, err := cloudnetworks.Get(c, id).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
fmt.Printf("Retrieved cloud network: %+v\n\n", cn)
|
||||
}
|
26
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/common.go
generated
vendored
Normal file
26
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/common.go
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
// +build acceptance
|
||||
|
||||
package v3
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/rackspace"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func newClient(t *testing.T) *gophercloud.ServiceClient {
|
||||
ao, err := rackspace.AuthOptionsFromEnv()
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
client, err := rackspace.AuthenticatedClient(ao)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
c, err := rackspace.NewRackConnectV3(client, gophercloud.EndpointOpts{
|
||||
Region: os.Getenv("RS_REGION_NAME"),
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
return c
|
||||
}
|
71
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/lbpools_test.go
generated
vendored
Normal file
71
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/lbpools_test.go
generated
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
// +build acceptance
|
||||
|
||||
package v3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/rackspace/rackconnect/v3/lbpools"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func TestLBPools(t *testing.T) {
|
||||
c := newClient(t)
|
||||
pID := testListPools(t, c)
|
||||
testGetPools(t, c, pID)
|
||||
nID := testListNodes(t, c, pID)
|
||||
testListNodeDetails(t, c, pID)
|
||||
testGetNode(t, c, pID, nID)
|
||||
testGetNodeDetails(t, c, pID, nID)
|
||||
}
|
||||
|
||||
func testListPools(t *testing.T, c *gophercloud.ServiceClient) string {
|
||||
allPages, err := lbpools.List(c).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
allp, err := lbpools.ExtractPools(allPages)
|
||||
fmt.Printf("Listing all LB pools: %+v\n\n", allp)
|
||||
var pID string
|
||||
if len(allp) > 0 {
|
||||
pID = allp[0].ID
|
||||
}
|
||||
return pID
|
||||
}
|
||||
|
||||
func testGetPools(t *testing.T, c *gophercloud.ServiceClient, pID string) {
|
||||
p, err := lbpools.Get(c, pID).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
fmt.Printf("Retrieved LB pool: %+v\n\n", p)
|
||||
}
|
||||
|
||||
func testListNodes(t *testing.T, c *gophercloud.ServiceClient, pID string) string {
|
||||
allPages, err := lbpools.ListNodes(c, pID).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
alln, err := lbpools.ExtractNodes(allPages)
|
||||
fmt.Printf("Listing all LB pool nodes for pool (%s): %+v\n\n", pID, alln)
|
||||
var nID string
|
||||
if len(alln) > 0 {
|
||||
nID = alln[0].ID
|
||||
}
|
||||
return nID
|
||||
}
|
||||
|
||||
func testListNodeDetails(t *testing.T, c *gophercloud.ServiceClient, pID string) {
|
||||
allPages, err := lbpools.ListNodesDetails(c, pID).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
alln, err := lbpools.ExtractNodesDetails(allPages)
|
||||
fmt.Printf("Listing all LB pool nodes details for pool (%s): %+v\n\n", pID, alln)
|
||||
}
|
||||
|
||||
func testGetNode(t *testing.T, c *gophercloud.ServiceClient, pID, nID string) {
|
||||
n, err := lbpools.GetNode(c, pID, nID).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
fmt.Printf("Retrieved LB node: %+v\n\n", n)
|
||||
}
|
||||
|
||||
func testGetNodeDetails(t *testing.T, c *gophercloud.ServiceClient, pID, nID string) {
|
||||
n, err := lbpools.GetNodeDetails(c, pID, nID).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
fmt.Printf("Retrieved LB node details: %+v\n\n", n)
|
||||
}
|
45
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/publicips_test.go
generated
vendored
Normal file
45
Godeps/_workspace/src/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/publicips_test.go
generated
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
// +build acceptance
|
||||
|
||||
package v3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/rackspace/rackconnect/v3/publicips"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func TestPublicIPs(t *testing.T) {
|
||||
c := newClient(t)
|
||||
ipID := testListIPs(t, c)
|
||||
sID := testGetIP(t, c, ipID)
|
||||
testListIPsForServer(t, c, sID)
|
||||
}
|
||||
|
||||
func testListIPs(t *testing.T, c *gophercloud.ServiceClient) string {
|
||||
allPages, err := publicips.List(c).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
allip, err := publicips.ExtractPublicIPs(allPages)
|
||||
fmt.Printf("Listing all public IPs: %+v\n\n", allip)
|
||||
var ipID string
|
||||
if len(allip) > 0 {
|
||||
ipID = allip[0].ID
|
||||
}
|
||||
return ipID
|
||||
}
|
||||
|
||||
func testGetIP(t *testing.T, c *gophercloud.ServiceClient, ipID string) string {
|
||||
ip, err := publicips.Get(c, ipID).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
fmt.Printf("Retrieved public IP (%s): %+v\n\n", ipID, ip)
|
||||
return ip.CloudServer.ID
|
||||
}
|
||||
|
||||
func testListIPsForServer(t *testing.T, c *gophercloud.ServiceClient, sID string) {
|
||||
allPages, err := publicips.ListForServer(c, sID).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
allip, err := publicips.ExtractPublicIPs(allPages)
|
||||
fmt.Printf("Listing all public IPs for server (%s): %+v\n\n", sID, allip)
|
||||
}
|
|
@ -16,9 +16,6 @@ func List(c *gophercloud.ServiceClient) pagination.Pager {
|
|||
// type from the result, call the Extract method on the GetResult.
|
||||
func Get(client *gophercloud.ServiceClient, v string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = client.Request("GET", getURL(client, v), gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
JSONResponse: &res.Body,
|
||||
})
|
||||
_, res.Err = client.Get(getURL(client, v), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -67,10 +67,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", createURL(client), gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -78,9 +76,7 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
// Delete will delete the existing Snapshot with the provided ID.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Request("DELETE", deleteURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{202, 204},
|
||||
})
|
||||
_, res.Err = client.Delete(deleteURL(client, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -88,10 +84,7 @@ func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
|||
// object from the response, call the Extract method on the GetResult.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
JSONResponse: &res.Body,
|
||||
})
|
||||
_, res.Err = client.Get(getURL(client, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -173,10 +166,8 @@ func UpdateMetadata(client *gophercloud.ServiceClient, id string, opts UpdateMet
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("PUT", updateMetadataURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
_, res.Err = client.Put(updateMetadataURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -83,10 +83,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", createURL(client), gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -94,9 +92,7 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
// Delete will delete the existing Volume with the provided ID.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Request("DELETE", deleteURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{202, 204},
|
||||
})
|
||||
_, res.Err = client.Delete(deleteURL(client, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -104,10 +100,7 @@ func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
|||
// from the response, call the Extract method on the GetResult.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = client.Get(getURL(client, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -152,6 +145,7 @@ func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pa
|
|||
createPage := func(r pagination.PageResult) pagination.Page {
|
||||
return ListResult{pagination.SinglePageBase(r)}
|
||||
}
|
||||
|
||||
return pagination.NewPager(client, url, createPage)
|
||||
}
|
||||
|
||||
|
@ -202,10 +196,8 @@ func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("PUT", updateURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
_, res.Err = client.Put(updateURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -45,6 +45,32 @@ func TestList(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestListAll(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
|
||||
MockListResponse(t)
|
||||
|
||||
allPages, err := List(client.ServiceClient(), &ListOpts{}).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
actual, err := ExtractVolumes(allPages)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
expected := []Volume{
|
||||
Volume{
|
||||
ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
|
||||
Name: "vol-001",
|
||||
},
|
||||
Volume{
|
||||
ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
|
||||
Name: "vol-002",
|
||||
},
|
||||
}
|
||||
|
||||
th.CheckDeepEquals(t, expected, actual)
|
||||
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
|
|
|
@ -44,11 +44,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", createURL(client), gophercloud.RequestOpts{
|
||||
MoreHeaders: client.AuthenticatedHeaders(),
|
||||
OkCodes: []int{200, 201},
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -56,10 +53,7 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
// Delete will delete the volume type with the provided ID.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Request("DELETE", deleteURL(client, id), gophercloud.RequestOpts{
|
||||
MoreHeaders: client.AuthenticatedHeaders(),
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = client.Delete(deleteURL(client, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -67,11 +61,7 @@ func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
|||
// type from the result, call the Extract method on the GetResult.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, err := client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
|
||||
MoreHeaders: client.AuthenticatedHeaders(),
|
||||
OkCodes: []int{200},
|
||||
JSONResponse: &res.Body,
|
||||
})
|
||||
_, err := client.Get(getURL(client, id), &res.Body, nil)
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -6,17 +6,14 @@ import "github.com/rackspace/gophercloud"
|
|||
// entire API.
|
||||
func Get(c *gophercloud.ServiceClient) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", getURL(c), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(getURL(c), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Ping retrieves a ping to the server.
|
||||
func Ping(c *gophercloud.ServiceClient) PingResult {
|
||||
var res PingResult
|
||||
_, res.Err = c.Request("GET", pingURL(c), gophercloud.RequestOpts{
|
||||
_, res.Err = c.Get(pingURL(c), nil, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
MoreHeaders: map[string]string{"Accept": ""},
|
||||
})
|
||||
|
|
|
@ -17,18 +17,18 @@ func TestGetHomeDocument(t *testing.T) {
|
|||
|
||||
expected := HomeDocument{
|
||||
"rel/cdn": map[string]interface{}{
|
||||
"href-template": "services{?marker,limit}",
|
||||
"href-vars": map[string]interface{}{
|
||||
"marker": "param/marker",
|
||||
"limit": "param/limit",
|
||||
},
|
||||
"hints": map[string]interface{}{
|
||||
"allow": []string{"GET"},
|
||||
"formats": map[string]interface{}{
|
||||
"application/json": map[string]interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
"href-template": "services{?marker,limit}",
|
||||
"href-vars": map[string]interface{}{
|
||||
"marker": "param/marker",
|
||||
"limit": "param/limit",
|
||||
},
|
||||
"hints": map[string]interface{}{
|
||||
"allow": []string{"GET"},
|
||||
"formats": map[string]interface{}{
|
||||
"application/json": map[string]interface{}{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
th.CheckDeepEquals(t, expected, *actual)
|
||||
}
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
package flavors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// HandleListCDNFlavorsSuccessfully creates an HTTP handler at `/flavors` on the test handler mux
|
||||
// that responds with a `List` response.
|
||||
func HandleListCDNFlavorsSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/flavors", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
th.Mux.HandleFunc("/flavors", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"flavors": [
|
||||
{
|
||||
|
@ -44,19 +44,19 @@ func HandleListCDNFlavorsSuccessfully(t *testing.T) {
|
|||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HandleGetCDNFlavorSuccessfully creates an HTTP handler at `/flavors/{id}` on the test handler mux
|
||||
// that responds with a `Get` response.
|
||||
func HandleGetCDNFlavorSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/flavors/asia", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
th.Mux.HandleFunc("/flavors/asia", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"id" : "asia",
|
||||
"providers" : [
|
||||
|
@ -78,5 +78,5 @@ func HandleGetCDNFlavorSuccessfully(t *testing.T) {
|
|||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,9 +17,6 @@ func List(c *gophercloud.ServiceClient) pagination.Pager {
|
|||
// Get retrieves a specific flavor based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", getURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(getURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -1,90 +1,89 @@
|
|||
package flavors
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
|
||||
HandleListCDNFlavorsSuccessfully(t)
|
||||
HandleListCDNFlavorsSuccessfully(t)
|
||||
|
||||
count := 0
|
||||
count := 0
|
||||
|
||||
err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
|
||||
count++
|
||||
actual, err := ExtractFlavors(page)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to extract flavors: %v", err)
|
||||
return false, err
|
||||
}
|
||||
err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
|
||||
count++
|
||||
actual, err := ExtractFlavors(page)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to extract flavors: %v", err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
expected := []Flavor{
|
||||
Flavor{
|
||||
ID: "europe",
|
||||
Providers: []Provider{
|
||||
Provider{
|
||||
Provider: "Fastly",
|
||||
Links: []gophercloud.Link{
|
||||
gophercloud.Link{
|
||||
Href: "http://www.fastly.com",
|
||||
Rel: "provider_url",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Links: []gophercloud.Link{
|
||||
gophercloud.Link{
|
||||
Href: "https://www.poppycdn.io/v1.0/flavors/europe",
|
||||
Rel: "self",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
expected := []Flavor{
|
||||
Flavor{
|
||||
ID: "europe",
|
||||
Providers: []Provider{
|
||||
Provider{
|
||||
Provider: "Fastly",
|
||||
Links: []gophercloud.Link{
|
||||
gophercloud.Link{
|
||||
Href: "http://www.fastly.com",
|
||||
Rel: "provider_url",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Links: []gophercloud.Link{
|
||||
gophercloud.Link{
|
||||
Href: "https://www.poppycdn.io/v1.0/flavors/europe",
|
||||
Rel: "self",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
th.CheckDeepEquals(t, expected, actual)
|
||||
th.CheckDeepEquals(t, expected, actual)
|
||||
|
||||
return true, nil
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckEquals(t, 1, count)
|
||||
return true, nil
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckEquals(t, 1, count)
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
|
||||
HandleGetCDNFlavorSuccessfully(t)
|
||||
HandleGetCDNFlavorSuccessfully(t)
|
||||
|
||||
expected := &Flavor{
|
||||
ID: "asia",
|
||||
Providers: []Provider{
|
||||
Provider{
|
||||
Provider: "ChinaCache",
|
||||
Links: []gophercloud.Link{
|
||||
gophercloud.Link{
|
||||
Href: "http://www.chinacache.com",
|
||||
Rel: "provider_url",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Links: []gophercloud.Link{
|
||||
gophercloud.Link{
|
||||
Href: "https://www.poppycdn.io/v1.0/flavors/asia",
|
||||
Rel: "self",
|
||||
},
|
||||
},
|
||||
}
|
||||
expected := &Flavor{
|
||||
ID: "asia",
|
||||
Providers: []Provider{
|
||||
Provider{
|
||||
Provider: "ChinaCache",
|
||||
Links: []gophercloud.Link{
|
||||
gophercloud.Link{
|
||||
Href: "http://www.chinacache.com",
|
||||
Rel: "provider_url",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Links: []gophercloud.Link{
|
||||
gophercloud.Link{
|
||||
Href: "https://www.poppycdn.io/v1.0/flavors/asia",
|
||||
Rel: "self",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
actual, err := Get(fake.ServiceClient(), "asia").Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
th.AssertDeepEquals(t, expected, actual)
|
||||
actual, err := Get(fake.ServiceClient(), "asia").Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
th.AssertDeepEquals(t, expected, actual)
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package serviceassets
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// HandleDeleteCDNAssetSuccessfully creates an HTTP handler at `/services/{id}/assets` on the test handler mux
|
||||
// that responds with a `Delete` response.
|
||||
func HandleDeleteCDNAssetSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0/assets", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "DELETE")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
})
|
||||
th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0/assets", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "DELETE")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -43,8 +43,6 @@ func Delete(c *gophercloud.ServiceClient, idOrURL string, opts DeleteOptsBuilder
|
|||
}
|
||||
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", url, gophercloud.RequestOpts{
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = c.Delete(url, nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package serviceassets
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
|
||||
HandleDeleteCDNAssetSuccessfully(t)
|
||||
HandleDeleteCDNAssetSuccessfully(t)
|
||||
|
||||
err := Delete(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", nil).ExtractErr()
|
||||
th.AssertNoErr(t, err)
|
||||
err := Delete(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", nil).ExtractErr()
|
||||
th.AssertNoErr(t, err)
|
||||
}
|
||||
|
|
|
@ -177,10 +177,7 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
|||
}
|
||||
|
||||
// Send request to API
|
||||
resp, err := c.Request("POST", createURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
resp, err := c.Post(createURL(c), &reqBody, nil, nil)
|
||||
res.Header = resp.Header
|
||||
res.Err = err
|
||||
return res
|
||||
|
@ -199,10 +196,7 @@ func Get(c *gophercloud.ServiceClient, idOrURL string) GetResult {
|
|||
}
|
||||
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", url, gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(url, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -379,8 +373,6 @@ func Delete(c *gophercloud.ServiceClient, idOrURL string) DeleteResult {
|
|||
}
|
||||
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", url, gophercloud.RequestOpts{
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = c.Delete(url, nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -109,6 +109,7 @@ func v2auth(client *gophercloud.ProviderClient, endpoint string, options gopherc
|
|||
|
||||
if options.AllowReauth {
|
||||
client.ReauthFunc = func() error {
|
||||
client.TokenID = ""
|
||||
return AuthenticateV2(client, options)
|
||||
}
|
||||
}
|
||||
|
@ -132,10 +133,36 @@ func v3auth(client *gophercloud.ProviderClient, endpoint string, options gopherc
|
|||
v3Client.Endpoint = endpoint
|
||||
}
|
||||
|
||||
token, err := tokens3.Create(v3Client, options, nil).Extract()
|
||||
var scope *tokens3.Scope
|
||||
if options.TenantID != "" {
|
||||
scope = &tokens3.Scope{
|
||||
ProjectID: options.TenantID,
|
||||
}
|
||||
options.TenantID = ""
|
||||
options.TenantName = ""
|
||||
} else {
|
||||
if options.TenantName != "" {
|
||||
scope = &tokens3.Scope{
|
||||
ProjectName: options.TenantName,
|
||||
DomainID: options.DomainID,
|
||||
DomainName: options.DomainName,
|
||||
}
|
||||
options.TenantName = ""
|
||||
}
|
||||
}
|
||||
|
||||
result := tokens3.Create(v3Client, options, scope)
|
||||
|
||||
token, err := result.ExtractToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
catalog, err := result.ExtractServiceCatalog()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client.TokenID = token.ID
|
||||
|
||||
if options.AllowReauth {
|
||||
|
@ -144,7 +171,7 @@ func v3auth(client *gophercloud.ProviderClient, endpoint string, options gopherc
|
|||
}
|
||||
}
|
||||
client.EndpointLocator = func(opts gophercloud.EndpointOpts) (string, error) {
|
||||
return V3EndpointURL(v3Client, opts)
|
||||
return V3EndpointURL(catalog, opts)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/common/extensions/errors.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/common/extensions/errors.go
generated
vendored
Normal file → Executable file
5
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/common/extensions/requests.go
generated
vendored
Normal file → Executable file
5
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/common/extensions/requests.go
generated
vendored
Normal file → Executable file
|
@ -8,10 +8,7 @@ import (
|
|||
// Get retrieves information for a specific extension using its alias.
|
||||
func Get(c *gophercloud.ServiceClient, alias string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", ExtensionURL(c, alias), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(ExtensionURL(c, alias), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
|
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/common/extensions/results.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/common/extensions/results.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/common/extensions/urls_test.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/common/extensions/urls_test.go
generated
vendored
Normal file → Executable file
|
@ -99,10 +99,8 @@ func Create(client *gophercloud.ServiceClient, opts servers.CreateOptsBuilder) s
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", createURL(client), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200, 202},
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 202},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -73,10 +73,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
return result
|
||||
}
|
||||
|
||||
_, result.Err = client.Request("POST", rootURL(client), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
JSONBody: &reqBody,
|
||||
OkCodes: []int{200},
|
||||
_, result.Err = client.Post(rootURL(client), reqBody, &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return result
|
||||
|
@ -85,22 +83,13 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
// Get will return details for a particular default rule.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var result GetResult
|
||||
|
||||
_, result.Err = client.Request("GET", resourceURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
_, result.Err = client.Get(resourceURL(client, id), &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
||||
// Delete will permanently delete a default rule from the project.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
|
||||
var result gophercloud.ErrResult
|
||||
|
||||
_, result.Err = client.Request("DELETE", resourceURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
|
||||
_, result.Err = client.Delete(resourceURL(client, id), nil)
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -45,10 +45,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", createURL(client), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -56,19 +54,14 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
// Get returns data about a previously created FloatingIP.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = client.Get(getURL(client, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete requests the deletion of a previous allocated FloatingIP.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Request("DELETE", deleteURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = client.Delete(deleteURL(client, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -82,10 +75,7 @@ func Associate(client *gophercloud.ServiceClient, serverId, fip string) Associat
|
|||
addFloatingIp["address"] = fip
|
||||
reqBody := map[string]interface{}{"addFloatingIp": addFloatingIp}
|
||||
|
||||
_, res.Err = client.Request("POST", associateURL(client, serverId), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = client.Post(associateURL(client, serverId), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -97,9 +87,6 @@ func Disassociate(client *gophercloud.ServiceClient, serverId, fip string) Disas
|
|||
removeFloatingIp["address"] = fip
|
||||
reqBody := map[string]interface{}{"removeFloatingIp": removeFloatingIp}
|
||||
|
||||
_, res.Err = client.Request("POST", disassociateURL(client, serverId), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = client.Post(disassociateURL(client, serverId), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -81,10 +81,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", createURL(client), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -92,18 +90,13 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
// Get returns public data about a previously uploaded KeyPair.
|
||||
func Get(client *gophercloud.ServiceClient, name string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = client.Request("GET", getURL(client, name), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = client.Get(getURL(client, name), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete requests the deletion of a previous stored KeyPair from the server.
|
||||
func Delete(client *gophercloud.ServiceClient, name string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Request("DELETE", deleteURL(client, name), gophercloud.RequestOpts{
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = client.Delete(deleteURL(client, name), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -78,10 +78,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
return result
|
||||
}
|
||||
|
||||
_, result.Err = client.Request("POST", rootURL(client), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
JSONBody: &reqBody,
|
||||
OkCodes: []int{200},
|
||||
_, result.Err = client.Post(rootURL(client), reqBody, &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return result
|
||||
|
@ -123,10 +121,8 @@ func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder
|
|||
return result
|
||||
}
|
||||
|
||||
_, result.Err = client.Request("PUT", resourceURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
JSONBody: &reqBody,
|
||||
OkCodes: []int{200},
|
||||
_, result.Err = client.Put(resourceURL(client, id), reqBody, &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return result
|
||||
|
@ -135,23 +131,14 @@ func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder
|
|||
// Get will return details for a particular security group.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var result GetResult
|
||||
|
||||
_, result.Err = client.Request("GET", resourceURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
_, result.Err = client.Get(resourceURL(client, id), &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
||||
// Delete will permanently delete a security group from the project.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
|
||||
var result gophercloud.ErrResult
|
||||
|
||||
_, result.Err = client.Request("DELETE", resourceURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
_, result.Err = client.Delete(resourceURL(client, id), nil)
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -234,10 +221,8 @@ func CreateRule(client *gophercloud.ServiceClient, opts CreateRuleOptsBuilder) C
|
|||
return result
|
||||
}
|
||||
|
||||
_, result.Err = client.Request("POST", rootRuleURL(client), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
JSONBody: &reqBody,
|
||||
OkCodes: []int{200},
|
||||
_, result.Err = client.Post(rootRuleURL(client), reqBody, &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return result
|
||||
|
@ -246,11 +231,7 @@ func CreateRule(client *gophercloud.ServiceClient, opts CreateRuleOptsBuilder) C
|
|||
// DeleteRule will permanently delete a rule from a security group.
|
||||
func DeleteRule(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
|
||||
var result gophercloud.ErrResult
|
||||
|
||||
_, result.Err = client.Request("DELETE", resourceRuleURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
_, result.Err = client.Delete(resourceRuleURL(client, id), nil)
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -264,25 +245,13 @@ func actionMap(prefix, groupName string) map[string]map[string]string {
|
|||
// rules of the group on the server.
|
||||
func AddServerToGroup(client *gophercloud.ServiceClient, serverID, groupName string) gophercloud.ErrResult {
|
||||
var result gophercloud.ErrResult
|
||||
|
||||
_, result.Err = client.Request("POST", serverActionURL(client, serverID), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
JSONBody: actionMap("add", groupName),
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
_, result.Err = client.Post(serverActionURL(client, serverID), actionMap("add", groupName), &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
||||
// RemoveServerFromGroup will disassociate a server from a security group.
|
||||
func RemoveServerFromGroup(client *gophercloud.ServiceClient, serverID, groupName string) gophercloud.ErrResult {
|
||||
var result gophercloud.ErrResult
|
||||
|
||||
_, result.Err = client.Request("POST", serverActionURL(client, serverID), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
JSONBody: actionMap("remove", groupName),
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
_, result.Err = client.Post(serverActionURL(client, serverID), actionMap("remove", groupName), &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -9,27 +9,15 @@ func actionURL(client *gophercloud.ServiceClient, id string) string {
|
|||
// Start is the operation responsible for starting a Compute server.
|
||||
func Start(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
|
||||
var res gophercloud.ErrResult
|
||||
|
||||
reqBody := map[string]interface{}{"os-start": nil}
|
||||
|
||||
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
_, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Stop is the operation responsible for stopping a Compute server.
|
||||
func Stop(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
|
||||
var res gophercloud.ErrResult
|
||||
|
||||
reqBody := map[string]interface{}{"os-stop": nil}
|
||||
|
||||
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
_, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
|
2
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/doc.go
generated
vendored
Normal file
2
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
// Package tenantnetworks provides the ability for tenants to see information about the networks they have access to
|
||||
package tenantnetworks
|
84
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/fixtures.go
generated
vendored
Normal file
84
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/fixtures.go
generated
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
// +build fixtures
|
||||
|
||||
package tenantnetworks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
"github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// ListOutput is a sample response to a List call.
|
||||
const ListOutput = `
|
||||
{
|
||||
"networks": [
|
||||
{
|
||||
"cidr": "10.0.0.0/29",
|
||||
"id": "20c8acc0-f747-4d71-a389-46d078ebf047",
|
||||
"label": "mynet_0"
|
||||
},
|
||||
{
|
||||
"cidr": "10.0.0.10/29",
|
||||
"id": "20c8acc0-f747-4d71-a389-46d078ebf000",
|
||||
"label": "mynet_1"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
// GetOutput is a sample response to a Get call.
|
||||
const GetOutput = `
|
||||
{
|
||||
"network": {
|
||||
"cidr": "10.0.0.10/29",
|
||||
"id": "20c8acc0-f747-4d71-a389-46d078ebf000",
|
||||
"label": "mynet_1"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// FirstNetwork is the first result in ListOutput.
|
||||
var nilTime time.Time
|
||||
var FirstNetwork = Network{
|
||||
CIDR: "10.0.0.0/29",
|
||||
ID: "20c8acc0-f747-4d71-a389-46d078ebf047",
|
||||
Name: "mynet_0",
|
||||
}
|
||||
|
||||
// SecondNetwork is the second result in ListOutput.
|
||||
var SecondNetwork = Network{
|
||||
CIDR: "10.0.0.10/29",
|
||||
ID: "20c8acc0-f747-4d71-a389-46d078ebf000",
|
||||
Name: "mynet_1",
|
||||
}
|
||||
|
||||
// ExpectedNetworkSlice is the slice of results that should be parsed
|
||||
// from ListOutput, in the expected order.
|
||||
var ExpectedNetworkSlice = []Network{FirstNetwork, SecondNetwork}
|
||||
|
||||
// HandleListSuccessfully configures the test server to respond to a List request.
|
||||
func HandleListSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-tenant-networks", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, ListOutput)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleGetSuccessfully configures the test server to respond to a Get request
|
||||
// for an existing network.
|
||||
func HandleGetSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-tenant-networks/20c8acc0-f747-4d71-a389-46d078ebf000", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, GetOutput)
|
||||
})
|
||||
}
|
22
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/requests.go
generated
vendored
Normal file
22
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/requests.go
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
package tenantnetworks
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// List returns a Pager that allows you to iterate over a collection of Network.
|
||||
func List(client *gophercloud.ServiceClient) pagination.Pager {
|
||||
url := listURL(client)
|
||||
createPage := func(r pagination.PageResult) pagination.Page {
|
||||
return NetworkPage{pagination.SinglePageBase(r)}
|
||||
}
|
||||
return pagination.NewPager(client, url, createPage)
|
||||
}
|
||||
|
||||
// Get returns data about a previously created Network.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = client.Get(getURL(client, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
37
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/requests_test.go
generated
vendored
Normal file
37
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/requests_test.go
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
package tenantnetworks
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
"github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
HandleListSuccessfully(t)
|
||||
|
||||
count := 0
|
||||
err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
|
||||
count++
|
||||
actual, err := ExtractNetworks(page)
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckDeepEquals(t, ExpectedNetworkSlice, actual)
|
||||
|
||||
return true, nil
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckEquals(t, 1, count)
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
HandleGetSuccessfully(t)
|
||||
|
||||
actual, err := Get(client.ServiceClient(), "20c8acc0-f747-4d71-a389-46d078ebf000").Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckDeepEquals(t, &SecondNetwork, actual)
|
||||
}
|
68
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/results.go
generated
vendored
Normal file
68
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/results.go
generated
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
package tenantnetworks
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// A Network represents a nova-network that an instance communicates on
|
||||
type Network struct {
|
||||
// CIDR is the IPv4 subnet.
|
||||
CIDR string `mapstructure:"cidr"`
|
||||
|
||||
// ID is the UUID of the network.
|
||||
ID string `mapstructure:"id"`
|
||||
|
||||
// Name is the common name that the network has.
|
||||
Name string `mapstructure:"label"`
|
||||
}
|
||||
|
||||
// NetworkPage stores a single, only page of Networks
|
||||
// results from a List call.
|
||||
type NetworkPage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty determines whether or not a NetworkPage is empty.
|
||||
func (page NetworkPage) IsEmpty() (bool, error) {
|
||||
va, err := ExtractNetworks(page)
|
||||
return len(va) == 0, err
|
||||
}
|
||||
|
||||
// ExtractNetworks interprets a page of results as a slice of Networks
|
||||
func ExtractNetworks(page pagination.Page) ([]Network, error) {
|
||||
networks := page.(NetworkPage).Body
|
||||
var res struct {
|
||||
Networks []Network `mapstructure:"networks"`
|
||||
}
|
||||
|
||||
err := mapstructure.WeakDecode(networks, &res)
|
||||
|
||||
return res.Networks, err
|
||||
}
|
||||
|
||||
type NetworkResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a method that attempts to interpret any Network resource
|
||||
// response as a Network struct.
|
||||
func (r NetworkResult) Extract() (*Network, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
var res struct {
|
||||
Network *Network `json:"network" mapstructure:"network"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
return res.Network, err
|
||||
}
|
||||
|
||||
// GetResult is the response from a Get operation. Call its Extract method to interpret it
|
||||
// as a Network.
|
||||
type GetResult struct {
|
||||
NetworkResult
|
||||
}
|
17
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/urls.go
generated
vendored
Normal file
17
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/urls.go
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
package tenantnetworks
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
const resourcePath = "os-tenant-networks"
|
||||
|
||||
func resourceURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL(resourcePath)
|
||||
}
|
||||
|
||||
func listURL(c *gophercloud.ServiceClient) string {
|
||||
return resourceURL(c)
|
||||
}
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL(resourcePath, id)
|
||||
}
|
25
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/urls_test.go
generated
vendored
Normal file
25
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks/urls_test.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
package tenantnetworks
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
"github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
func TestListURL(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
c := client.ServiceClient()
|
||||
|
||||
th.CheckEquals(t, c.Endpoint+"os-tenant-networks", listURL(c))
|
||||
}
|
||||
|
||||
func TestGetURL(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
c := client.ServiceClient()
|
||||
id := "1"
|
||||
|
||||
th.CheckEquals(t, c.Endpoint+"os-tenant-networks/"+id, getURL(c, id))
|
||||
}
|
|
@ -54,10 +54,8 @@ func Create(client *gophercloud.ServiceClient, serverId string, opts CreateOptsB
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", createURL(client, serverId), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = client.Post(createURL(client, serverId), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -65,18 +63,13 @@ func Create(client *gophercloud.ServiceClient, serverId string, opts CreateOptsB
|
|||
// Get returns public data about a previously created VolumeAttachment.
|
||||
func Get(client *gophercloud.ServiceClient, serverId, aId string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = client.Request("GET", getURL(client, serverId, aId), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = client.Get(getURL(client, serverId, aId), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete requests the deletion of a previous stored VolumeAttachment from the server.
|
||||
func Delete(client *gophercloud.ServiceClient, serverId, aId string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Request("DELETE", deleteURL(client, serverId, aId), gophercloud.RequestOpts{
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = client.Delete(deleteURL(client, serverId, aId), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -62,9 +62,7 @@ func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) paginat
|
|||
// Get instructs OpenStack to provide details on a single flavor, identified by its ID.
|
||||
// Use ExtractFlavor to convert its result into a Flavor.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var gr GetResult
|
||||
_, gr.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &gr.Body,
|
||||
})
|
||||
return gr
|
||||
var res GetResult
|
||||
_, res.Err = client.Get(getURL(client, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -60,9 +60,6 @@ func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) paginat
|
|||
// Use ExtractImage() to interpret the result as an openstack Image.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var result GetResult
|
||||
_, result.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, result.Err = client.Get(getURL(client, id), &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -567,3 +567,87 @@ func HandleMetadataUpdateSuccessfully(t *testing.T) {
|
|||
w.Write([]byte(`{ "metadata": {"foo":"baz", "this":"those"}}`))
|
||||
})
|
||||
}
|
||||
|
||||
// ListAddressesExpected represents an expected repsonse from a ListAddresses request.
|
||||
var ListAddressesExpected = map[string][]Address{
|
||||
"public": []Address{
|
||||
Address{
|
||||
Version: 4,
|
||||
Address: "80.56.136.39",
|
||||
},
|
||||
Address{
|
||||
Version: 6,
|
||||
Address: "2001:4800:790e:510:be76:4eff:fe04:82a8",
|
||||
},
|
||||
},
|
||||
"private": []Address{
|
||||
Address{
|
||||
Version: 4,
|
||||
Address: "10.880.3.154",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// HandleAddressListSuccessfully sets up the test server to respond to a ListAddresses request.
|
||||
func HandleAddressListSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/servers/asdfasdfasdf/ips", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `{
|
||||
"addresses": {
|
||||
"public": [
|
||||
{
|
||||
"version": 4,
|
||||
"addr": "50.56.176.35"
|
||||
},
|
||||
{
|
||||
"version": 6,
|
||||
"addr": "2001:4800:780e:510:be76:4eff:fe04:84a8"
|
||||
}
|
||||
],
|
||||
"private": [
|
||||
{
|
||||
"version": 4,
|
||||
"addr": "10.180.3.155"
|
||||
}
|
||||
]
|
||||
}
|
||||
}`)
|
||||
})
|
||||
}
|
||||
|
||||
// ListNetworkAddressesExpected represents an expected repsonse from a ListAddressesByNetwork request.
|
||||
var ListNetworkAddressesExpected = []Address{
|
||||
Address{
|
||||
Version: 4,
|
||||
Address: "50.56.176.35",
|
||||
},
|
||||
Address{
|
||||
Version: 6,
|
||||
Address: "2001:4800:780e:510:be76:4eff:fe04:84a8",
|
||||
},
|
||||
}
|
||||
|
||||
// HandleNetworkAddressListSuccessfully sets up the test server to respond to a ListAddressesByNetwork request.
|
||||
func HandleNetworkAddressListSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/servers/asdfasdfasdf/ips/public", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `{
|
||||
"public": [
|
||||
{
|
||||
"version": 4,
|
||||
"addr": "50.56.176.35"
|
||||
},
|
||||
{
|
||||
"version": 6,
|
||||
"addr": "2001:4800:780e:510:be76:4eff:fe04:84a8"
|
||||
}
|
||||
]
|
||||
}`)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -216,29 +216,22 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", listURL(client), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
JSONBody: reqBody,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = client.Post(listURL(client), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete requests that a server previously provisioned be removed from your account.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Request("DELETE", deleteURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = client.Delete(deleteURL(client, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get requests details on a single server, by ID.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var result GetResult
|
||||
_, result.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{200, 203},
|
||||
_, result.Err = client.Get(getURL(client, id), &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 203},
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
@ -280,9 +273,9 @@ func (opts UpdateOpts) ToServerUpdateMap() map[string]interface{} {
|
|||
// Update requests that various attributes of the indicated server be changed.
|
||||
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) UpdateResult {
|
||||
var result UpdateResult
|
||||
_, result.Err = client.Request("PUT", updateURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
JSONBody: opts.ToServerUpdateMap(),
|
||||
reqBody := opts.ToServerUpdateMap()
|
||||
_, result.Err = client.Put(updateURL(client, id), reqBody, &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
@ -298,12 +291,7 @@ func ChangeAdminPassword(client *gophercloud.ServiceClient, id, newPassword stri
|
|||
req.ChangePassword.AdminPass = newPassword
|
||||
|
||||
var res ActionResult
|
||||
|
||||
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: req,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
_, res.Err = client.Post(actionURL(client, id), req, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -367,15 +355,13 @@ func Reboot(client *gophercloud.ServiceClient, id string, how RebootMethod) Acti
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: struct {
|
||||
C map[string]string `json:"reboot"`
|
||||
}{
|
||||
map[string]string{"type": string(how)},
|
||||
},
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
reqBody := struct {
|
||||
C map[string]string `json:"reboot"`
|
||||
}{
|
||||
map[string]string{"type": string(how)},
|
||||
}
|
||||
|
||||
_, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -468,12 +454,7 @@ func Rebuild(client *gophercloud.ServiceClient, id string, opts RebuildOptsBuild
|
|||
return result
|
||||
}
|
||||
|
||||
_, result.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
_, result.Err = client.Post(actionURL(client, id), reqBody, &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -514,11 +495,7 @@ func Resize(client *gophercloud.ServiceClient, id string, opts ResizeOptsBuilder
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
_, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -527,11 +504,10 @@ func Resize(client *gophercloud.ServiceClient, id string, opts ResizeOptsBuilder
|
|||
func ConfirmResize(client *gophercloud.ServiceClient, id string) ActionResult {
|
||||
var res ActionResult
|
||||
|
||||
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: map[string]interface{}{"confirmResize": nil},
|
||||
OkCodes: []int{204},
|
||||
reqBody := map[string]interface{}{"confirmResize": nil}
|
||||
_, res.Err = client.Post(actionURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{201, 202, 204},
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -539,12 +515,8 @@ func ConfirmResize(client *gophercloud.ServiceClient, id string) ActionResult {
|
|||
// See Resize() for more details.
|
||||
func RevertResize(client *gophercloud.ServiceClient, id string) ActionResult {
|
||||
var res ActionResult
|
||||
|
||||
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: map[string]interface{}{"revertResize": nil},
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
|
||||
reqBody := map[string]interface{}{"revertResize": nil}
|
||||
_, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -586,10 +558,8 @@ func Rescue(client *gophercloud.ServiceClient, id string, opts RescueOptsBuilder
|
|||
return result
|
||||
}
|
||||
|
||||
_, result.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
JSONBody: &reqBody,
|
||||
OkCodes: []int{200},
|
||||
_, result.Err = client.Post(actionURL(client, id), reqBody, &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return result
|
||||
|
@ -625,9 +595,8 @@ func ResetMetadata(client *gophercloud.ServiceClient, id string, opts ResetMetad
|
|||
res.Err = err
|
||||
return res
|
||||
}
|
||||
_, res.Err = client.Request("PUT", metadataURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: metadata,
|
||||
JSONResponse: &res.Body,
|
||||
_, res.Err = client.Put(metadataURL(client, id), metadata, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -635,9 +604,7 @@ func ResetMetadata(client *gophercloud.ServiceClient, id string, opts ResetMetad
|
|||
// Metadata requests all the metadata for the given server ID.
|
||||
func Metadata(client *gophercloud.ServiceClient, id string) GetMetadataResult {
|
||||
var res GetMetadataResult
|
||||
_, res.Err = client.Request("GET", metadataURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
})
|
||||
_, res.Err = client.Get(metadataURL(client, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -657,9 +624,8 @@ func UpdateMetadata(client *gophercloud.ServiceClient, id string, opts UpdateMet
|
|||
res.Err = err
|
||||
return res
|
||||
}
|
||||
_, res.Err = client.Request("POST", metadataURL(client, id), gophercloud.RequestOpts{
|
||||
JSONBody: metadata,
|
||||
JSONResponse: &res.Body,
|
||||
_, res.Err = client.Post(metadataURL(client, id), metadata, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -695,9 +661,8 @@ func CreateMetadatum(client *gophercloud.ServiceClient, id string, opts Metadatu
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("PUT", metadatumURL(client, id, key), gophercloud.RequestOpts{
|
||||
JSONBody: metadatum,
|
||||
JSONResponse: &res.Body,
|
||||
_, res.Err = client.Put(metadatumURL(client, id, key), metadatum, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -714,8 +679,25 @@ func Metadatum(client *gophercloud.ServiceClient, id, key string) GetMetadatumRe
|
|||
// DeleteMetadatum will delete the key-value pair with the given key for the given server ID.
|
||||
func DeleteMetadatum(client *gophercloud.ServiceClient, id, key string) DeleteMetadatumResult {
|
||||
var res DeleteMetadatumResult
|
||||
_, res.Err = client.Request("DELETE", metadatumURL(client, id, key), gophercloud.RequestOpts{
|
||||
_, res.Err = client.Delete(metadatumURL(client, id, key), &gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
// ListAddresses makes a request against the API to list the servers IP addresses.
|
||||
func ListAddresses(client *gophercloud.ServiceClient, id string) pagination.Pager {
|
||||
createPageFn := func(r pagination.PageResult) pagination.Page {
|
||||
return AddressPage{pagination.SinglePageBase(r)}
|
||||
}
|
||||
return pagination.NewPager(client, listAddressesURL(client, id), createPageFn)
|
||||
}
|
||||
|
||||
// ListAddressesByNetwork makes a request against the API to list the servers IP addresses
|
||||
// for the given network.
|
||||
func ListAddressesByNetwork(client *gophercloud.ServiceClient, id, network string) pagination.Pager {
|
||||
createPageFn := func(r pagination.PageResult) pagination.Page {
|
||||
return NetworkAddressPage{pagination.SinglePageBase(r)}
|
||||
}
|
||||
return pagination.NewPager(client, listAddressesByNetworkURL(client, id, network), createPageFn)
|
||||
}
|
||||
|
|
|
@ -39,6 +39,19 @@ func TestListServers(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestListAllServers(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
HandleServerListSuccessfully(t)
|
||||
|
||||
allPages, err := List(client.ServiceClient(), ListOpts{}).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
actual, err := ExtractServers(allPages)
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckDeepEquals(t, ServerHerp, actual[0])
|
||||
th.CheckDeepEquals(t, ServerDerp, actual[1])
|
||||
}
|
||||
|
||||
func TestCreateServer(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
|
@ -264,3 +277,51 @@ func TestUpdateMetadata(t *testing.T) {
|
|||
th.AssertNoErr(t, err)
|
||||
th.AssertDeepEquals(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestListAddresses(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
HandleAddressListSuccessfully(t)
|
||||
|
||||
expected := ListAddressesExpected
|
||||
pages := 0
|
||||
err := ListAddresses(client.ServiceClient(), "asdfasdfasdf").EachPage(func(page pagination.Page) (bool, error) {
|
||||
pages++
|
||||
|
||||
actual, err := ExtractAddresses(page)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatalf("Expected 2 networks, got %d", len(actual))
|
||||
}
|
||||
th.CheckDeepEquals(t, expected, actual)
|
||||
|
||||
return true, nil
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckEquals(t, 1, pages)
|
||||
}
|
||||
|
||||
func TestListAddressesByNetwork(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
HandleNetworkAddressListSuccessfully(t)
|
||||
|
||||
expected := ListNetworkAddressesExpected
|
||||
pages := 0
|
||||
err := ListAddressesByNetwork(client.ServiceClient(), "asdfasdfasdf", "public").EachPage(func(page pagination.Page) (bool, error) {
|
||||
pages++
|
||||
|
||||
actual, err := ExtractNetworkAddresses(page)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatalf("Expected 2 addresses, got %d", len(actual))
|
||||
}
|
||||
th.CheckDeepEquals(t, expected, actual)
|
||||
|
||||
return true, nil
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckEquals(t, 1, pages)
|
||||
}
|
||||
|
|
|
@ -194,7 +194,6 @@ func ExtractServers(page pagination.Page) ([]Server, error) {
|
|||
|
||||
err = decoder.Decode(casted)
|
||||
|
||||
//err := mapstructure.Decode(casted, &response)
|
||||
return response.Servers, err
|
||||
}
|
||||
|
||||
|
@ -272,3 +271,77 @@ func toMapFromString(from reflect.Kind, to reflect.Kind, data interface{}) (inte
|
|||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Address represents an IP address.
|
||||
type Address struct {
|
||||
Version int `mapstructure:"version"`
|
||||
Address string `mapstructure:"addr"`
|
||||
}
|
||||
|
||||
// AddressPage abstracts the raw results of making a ListAddresses() request against the API.
|
||||
// As OpenStack extensions may freely alter the response bodies of structures returned
|
||||
// to the client, you may only safely access the data provided through the ExtractAddresses call.
|
||||
type AddressPage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty returns true if an AddressPage contains no networks.
|
||||
func (r AddressPage) IsEmpty() (bool, error) {
|
||||
addresses, err := ExtractAddresses(r)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return len(addresses) == 0, nil
|
||||
}
|
||||
|
||||
// ExtractAddresses interprets the results of a single page from a ListAddresses() call,
|
||||
// producing a map of addresses.
|
||||
func ExtractAddresses(page pagination.Page) (map[string][]Address, error) {
|
||||
casted := page.(AddressPage).Body
|
||||
|
||||
var response struct {
|
||||
Addresses map[string][]Address `mapstructure:"addresses"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(casted, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response.Addresses, err
|
||||
}
|
||||
|
||||
// NetworkAddressPage abstracts the raw results of making a ListAddressesByNetwork() request against the API.
|
||||
// As OpenStack extensions may freely alter the response bodies of structures returned
|
||||
// to the client, you may only safely access the data provided through the ExtractAddresses call.
|
||||
type NetworkAddressPage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty returns true if a NetworkAddressPage contains no addresses.
|
||||
func (r NetworkAddressPage) IsEmpty() (bool, error) {
|
||||
addresses, err := ExtractNetworkAddresses(r)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return len(addresses) == 0, nil
|
||||
}
|
||||
|
||||
// ExtractNetworkAddresses interprets the results of a single page from a ListAddressesByNetwork() call,
|
||||
// producing a slice of addresses.
|
||||
func ExtractNetworkAddresses(page pagination.Page) ([]Address, error) {
|
||||
casted := page.(NetworkAddressPage).Body
|
||||
|
||||
var response map[string][]Address
|
||||
err := mapstructure.Decode(casted, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var key string
|
||||
for k := range response {
|
||||
key = k
|
||||
}
|
||||
|
||||
return response[key], err
|
||||
}
|
||||
|
|
|
@ -37,3 +37,11 @@ func metadatumURL(client *gophercloud.ServiceClient, id, key string) string {
|
|||
func metadataURL(client *gophercloud.ServiceClient, id string) string {
|
||||
return client.ServiceURL("servers", id, "metadata")
|
||||
}
|
||||
|
||||
func listAddressesURL(client *gophercloud.ServiceClient, id string) string {
|
||||
return client.ServiceURL("servers", id, "ips")
|
||||
}
|
||||
|
||||
func listAddressesByNetworkURL(client *gophercloud.ServiceClient, id, network string) string {
|
||||
return client.ServiceURL("servers", id, "ips", network)
|
||||
}
|
||||
|
|
87
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/endpoint_location.go
generated
vendored
87
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/endpoint_location.go
generated
vendored
|
@ -5,9 +5,7 @@ import (
|
|||
|
||||
"github.com/rackspace/gophercloud"
|
||||
tokens2 "github.com/rackspace/gophercloud/openstack/identity/v2/tokens"
|
||||
endpoints3 "github.com/rackspace/gophercloud/openstack/identity/v3/endpoints"
|
||||
services3 "github.com/rackspace/gophercloud/openstack/identity/v3/services"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
tokens3 "github.com/rackspace/gophercloud/openstack/identity/v3/tokens"
|
||||
)
|
||||
|
||||
// V2EndpointURL discovers the endpoint URL for a specific service from a ServiceCatalog acquired
|
||||
|
@ -52,73 +50,42 @@ func V2EndpointURL(catalog *tokens2.ServiceCatalog, opts gophercloud.EndpointOpt
|
|||
return "", gophercloud.ErrEndpointNotFound
|
||||
}
|
||||
|
||||
// V3EndpointURL discovers the endpoint URL for a specific service using multiple calls against
|
||||
// an identity v3 service endpoint. The specified EndpointOpts are used to identify a unique,
|
||||
// V3EndpointURL discovers the endpoint URL for a specific service from a Catalog acquired
|
||||
// during the v3 identity service. The specified EndpointOpts are used to identify a unique,
|
||||
// unambiguous endpoint to return. It's an error both when multiple endpoints match the provided
|
||||
// criteria and when none do. The minimum that can be specified is a Type, but you will also often
|
||||
// need to specify a Name and/or a Region depending on what's available on your OpenStack
|
||||
// deployment.
|
||||
func V3EndpointURL(v3Client *gophercloud.ServiceClient, opts gophercloud.EndpointOpts) (string, error) {
|
||||
// Discover the service we're interested in.
|
||||
var services = make([]services3.Service, 0, 1)
|
||||
servicePager := services3.List(v3Client, services3.ListOpts{ServiceType: opts.Type})
|
||||
err := servicePager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
part, err := services3.ExtractServices(page)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, service := range part {
|
||||
if service.Name == opts.Name {
|
||||
services = append(services, service)
|
||||
func V3EndpointURL(catalog *tokens3.ServiceCatalog, opts gophercloud.EndpointOpts) (string, error) {
|
||||
// Extract Endpoints from the catalog entries that match the requested Type, Interface,
|
||||
// Name if provided, and Region if provided.
|
||||
var endpoints = make([]tokens3.Endpoint, 0, 1)
|
||||
for _, entry := range catalog.Entries {
|
||||
if (entry.Type == opts.Type) && (opts.Name == "" || entry.Name == opts.Name) {
|
||||
for _, endpoint := range entry.Endpoints {
|
||||
if opts.Availability != gophercloud.AvailabilityAdmin &&
|
||||
opts.Availability != gophercloud.AvailabilityPublic &&
|
||||
opts.Availability != gophercloud.AvailabilityInternal {
|
||||
return "", fmt.Errorf("Unexpected availability in endpoint query: %s", opts.Availability)
|
||||
}
|
||||
if (opts.Availability == gophercloud.Availability(endpoint.Interface)) &&
|
||||
(opts.Region == "" || endpoint.Region == opts.Region) {
|
||||
endpoints = append(endpoints, endpoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(services) == 0 {
|
||||
return "", gophercloud.ErrServiceNotFound
|
||||
}
|
||||
if len(services) > 1 {
|
||||
return "", fmt.Errorf("Discovered %d matching services: %#v", len(services), services)
|
||||
}
|
||||
service := services[0]
|
||||
|
||||
// Enumerate the endpoints available for this service.
|
||||
var endpoints []endpoints3.Endpoint
|
||||
endpointPager := endpoints3.List(v3Client, endpoints3.ListOpts{
|
||||
Availability: opts.Availability,
|
||||
ServiceID: service.ID,
|
||||
})
|
||||
err = endpointPager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
part, err := endpoints3.ExtractEndpoints(page)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, endpoint := range part {
|
||||
if opts.Region == "" || endpoint.Region == opts.Region {
|
||||
endpoints = append(endpoints, endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(endpoints) == 0 {
|
||||
return "", gophercloud.ErrEndpointNotFound
|
||||
}
|
||||
// Report an error if the options were ambiguous.
|
||||
if len(endpoints) > 1 {
|
||||
return "", fmt.Errorf("Discovered %d matching endpoints: %#v", len(endpoints), endpoints)
|
||||
}
|
||||
endpoint := endpoints[0]
|
||||
|
||||
return gophercloud.NormalizeURL(endpoint.URL), nil
|
||||
// Extract the URL from the matching Endpoint.
|
||||
for _, endpoint := range endpoints {
|
||||
return gophercloud.NormalizeURL(endpoint.URL), nil
|
||||
}
|
||||
|
||||
// Report an error if there were no matching endpoints.
|
||||
return "", gophercloud.ErrEndpointNotFound
|
||||
}
|
||||
|
|
217
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/endpoint_location_test.go
generated
vendored
217
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/endpoint_location_test.go
generated
vendored
|
@ -1,15 +1,13 @@
|
|||
package openstack
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
tokens2 "github.com/rackspace/gophercloud/openstack/identity/v2/tokens"
|
||||
tokens3 "github.com/rackspace/gophercloud/openstack/identity/v3/tokens"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// Service catalog fixtures take too much vertical space!
|
||||
|
@ -107,119 +105,124 @@ func TestV2EndpointBadAvailability(t *testing.T) {
|
|||
Region: "same",
|
||||
Availability: "wat",
|
||||
})
|
||||
th.CheckEquals(t, err.Error(), "Unexpected availability in endpoint query: wat")
|
||||
th.CheckEquals(t, "Unexpected availability in endpoint query: wat", err.Error())
|
||||
}
|
||||
|
||||
func setupV3Responses(t *testing.T) {
|
||||
// Mock the service query.
|
||||
th.Mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"links": {
|
||||
"next": null,
|
||||
"previous": null
|
||||
var catalog3 = tokens3.ServiceCatalog{
|
||||
Entries: []tokens3.CatalogEntry{
|
||||
tokens3.CatalogEntry{
|
||||
Type: "same",
|
||||
Name: "same",
|
||||
Endpoints: []tokens3.Endpoint{
|
||||
tokens3.Endpoint{
|
||||
ID: "1",
|
||||
Region: "same",
|
||||
Interface: "public",
|
||||
URL: "https://public.correct.com/",
|
||||
},
|
||||
"services": [
|
||||
{
|
||||
"description": "Correct",
|
||||
"id": "1234",
|
||||
"name": "same",
|
||||
"type": "same"
|
||||
},
|
||||
{
|
||||
"description": "Bad Name",
|
||||
"id": "9876",
|
||||
"name": "different",
|
||||
"type": "same"
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
// Mock the endpoint query.
|
||||
th.Mux.HandleFunc("/endpoints", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
th.TestFormValues(t, r, map[string]string{
|
||||
"service_id": "1234",
|
||||
"interface": "public",
|
||||
})
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"endpoints": [
|
||||
{
|
||||
"id": "12",
|
||||
"interface": "public",
|
||||
"name": "the-right-one",
|
||||
"region": "same",
|
||||
"service_id": "1234",
|
||||
"url": "https://correct:9000/"
|
||||
},
|
||||
{
|
||||
"id": "14",
|
||||
"interface": "public",
|
||||
"name": "bad-region",
|
||||
"region": "different",
|
||||
"service_id": "1234",
|
||||
"url": "https://bad-region:9001/"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"next": null,
|
||||
"previous": null
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
tokens3.Endpoint{
|
||||
ID: "2",
|
||||
Region: "same",
|
||||
Interface: "admin",
|
||||
URL: "https://admin.correct.com/",
|
||||
},
|
||||
tokens3.Endpoint{
|
||||
ID: "3",
|
||||
Region: "same",
|
||||
Interface: "internal",
|
||||
URL: "https://internal.correct.com/",
|
||||
},
|
||||
tokens3.Endpoint{
|
||||
ID: "4",
|
||||
Region: "different",
|
||||
Interface: "public",
|
||||
URL: "https://badregion.com/",
|
||||
},
|
||||
},
|
||||
},
|
||||
tokens3.CatalogEntry{
|
||||
Type: "same",
|
||||
Name: "different",
|
||||
Endpoints: []tokens3.Endpoint{
|
||||
tokens3.Endpoint{
|
||||
ID: "5",
|
||||
Region: "same",
|
||||
Interface: "public",
|
||||
URL: "https://badname.com/",
|
||||
},
|
||||
tokens3.Endpoint{
|
||||
ID: "6",
|
||||
Region: "different",
|
||||
Interface: "public",
|
||||
URL: "https://badname.com/+badregion",
|
||||
},
|
||||
},
|
||||
},
|
||||
tokens3.CatalogEntry{
|
||||
Type: "different",
|
||||
Name: "different",
|
||||
Endpoints: []tokens3.Endpoint{
|
||||
tokens3.Endpoint{
|
||||
ID: "7",
|
||||
Region: "same",
|
||||
Interface: "public",
|
||||
URL: "https://badtype.com/+badname",
|
||||
},
|
||||
tokens3.Endpoint{
|
||||
ID: "8",
|
||||
Region: "different",
|
||||
Interface: "public",
|
||||
URL: "https://badtype.com/+badregion+badname",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestV3EndpointExact(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
setupV3Responses(t)
|
||||
expectedURLs := map[gophercloud.Availability]string{
|
||||
gophercloud.AvailabilityPublic: "https://public.correct.com/",
|
||||
gophercloud.AvailabilityAdmin: "https://admin.correct.com/",
|
||||
gophercloud.AvailabilityInternal: "https://internal.correct.com/",
|
||||
}
|
||||
|
||||
actual, err := V3EndpointURL(fake.ServiceClient(), gophercloud.EndpointOpts{
|
||||
for availability, expected := range expectedURLs {
|
||||
actual, err := V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
|
||||
Type: "same",
|
||||
Name: "same",
|
||||
Region: "same",
|
||||
Availability: availability,
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckEquals(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV3EndpointNone(t *testing.T) {
|
||||
_, err := V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
|
||||
Type: "nope",
|
||||
Availability: gophercloud.AvailabilityPublic,
|
||||
})
|
||||
th.CheckEquals(t, gophercloud.ErrEndpointNotFound, err)
|
||||
}
|
||||
|
||||
func TestV3EndpointMultiple(t *testing.T) {
|
||||
_, err := V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
|
||||
Type: "same",
|
||||
Region: "same",
|
||||
Availability: gophercloud.AvailabilityPublic,
|
||||
})
|
||||
if !strings.HasPrefix(err.Error(), "Discovered 2 matching endpoints:") {
|
||||
t.Errorf("Received unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV3EndpointBadAvailability(t *testing.T) {
|
||||
_, err := V3EndpointURL(&catalog3, gophercloud.EndpointOpts{
|
||||
Type: "same",
|
||||
Name: "same",
|
||||
Region: "same",
|
||||
Availability: gophercloud.AvailabilityPublic,
|
||||
Availability: "wat",
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckEquals(t, actual, "https://correct:9000/")
|
||||
}
|
||||
|
||||
func TestV3EndpointNoService(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
|
||||
th.Mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"links": {
|
||||
"next": null,
|
||||
"previous": null
|
||||
},
|
||||
"services": []
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
_, err := V3EndpointURL(fake.ServiceClient(), gophercloud.EndpointOpts{
|
||||
Type: "nope",
|
||||
Name: "same",
|
||||
Region: "same",
|
||||
Availability: gophercloud.AvailabilityPublic,
|
||||
})
|
||||
th.CheckEquals(t, gophercloud.ErrServiceNotFound, err)
|
||||
th.CheckEquals(t, "Unexpected availability in endpoint query: wat", err.Error())
|
||||
}
|
||||
|
|
|
@ -19,11 +19,7 @@ func List(client *gophercloud.ServiceClient) pagination.Pager {
|
|||
// ID is a required argument.
|
||||
func AddUserRole(client *gophercloud.ServiceClient, tenantID, userID, roleID string) UserRoleResult {
|
||||
var result UserRoleResult
|
||||
|
||||
_, result.Err = client.Request("PUT", userRoleURL(client, tenantID, userID, roleID), gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
|
||||
_, result.Err = client.Put(userRoleURL(client, tenantID, userID, roleID), nil, nil, nil)
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -32,10 +28,6 @@ func AddUserRole(client *gophercloud.ServiceClient, tenantID, userID, roleID str
|
|||
// tenant ID is a required argument.
|
||||
func DeleteUserRole(client *gophercloud.ServiceClient, tenantID, userID, roleID string) UserRoleResult {
|
||||
var result UserRoleResult
|
||||
|
||||
_, result.Err = client.Request("DELETE", userRoleURL(client, tenantID, userID, roleID), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
|
||||
_, result.Err = client.Delete(userRoleURL(client, tenantID, userID, roleID), nil)
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -75,10 +75,8 @@ func Create(client *gophercloud.ServiceClient, auth AuthOptionsBuilder) CreateRe
|
|||
}
|
||||
|
||||
var result CreateResult
|
||||
_, result.Err = client.Request("POST", CreateURL(client), gophercloud.RequestOpts{
|
||||
JSONBody: &request,
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{200, 203},
|
||||
_, result.Err = client.Post(CreateURL(client), request, &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 203},
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -90,10 +90,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Request("POST", rootURL(client), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
JSONBody: reqBody,
|
||||
OkCodes: []int{200, 201},
|
||||
_, res.Err = client.Post(rootURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -102,12 +100,7 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
|
|||
// Get requests details on a single user, either by ID.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var result GetResult
|
||||
|
||||
_, result.Err = client.Request("GET", ResourceURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
_, result.Err = client.Get(ResourceURL(client, id), &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -145,24 +138,17 @@ func (opts UpdateOpts) ToUserUpdateMap() map[string]interface{} {
|
|||
// Update is the operation responsible for updating exist users by their UUID.
|
||||
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) UpdateResult {
|
||||
var result UpdateResult
|
||||
|
||||
_, result.Err = client.Request("PUT", ResourceURL(client, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
JSONBody: opts.ToUserUpdateMap(),
|
||||
OkCodes: []int{200},
|
||||
reqBody := opts.ToUserUpdateMap()
|
||||
_, result.Err = client.Put(ResourceURL(client, id), reqBody, &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Delete is the operation responsible for permanently deleting an API user.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var result DeleteResult
|
||||
|
||||
_, result.Err = client.Request("DELETE", ResourceURL(client, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
|
||||
_, result.Err = client.Delete(ResourceURL(client, id), nil)
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
@ -56,11 +56,7 @@ func Create(client *gophercloud.ServiceClient, opts EndpointOpts) CreateResult {
|
|||
reqBody.Endpoint.Region = gophercloud.MaybeString(opts.Region)
|
||||
|
||||
var result CreateResult
|
||||
_, result.Err = client.Request("POST", listURL(client), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, result.Err = client.Post(listURL(client), reqBody, &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -122,8 +118,6 @@ func Update(client *gophercloud.ServiceClient, endpointID string, opts EndpointO
|
|||
// Delete removes an endpoint from the service catalog.
|
||||
func Delete(client *gophercloud.ServiceClient, endpointID string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Request("DELETE", endpointURL(client, endpointID), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = client.Delete(endpointURL(client, endpointID), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -18,11 +18,7 @@ func Create(client *gophercloud.ServiceClient, serviceType string) CreateResult
|
|||
req := request{Type: serviceType}
|
||||
|
||||
var result CreateResult
|
||||
_, result.Err = client.Request("POST", listURL(client), gophercloud.RequestOpts{
|
||||
JSONBody: &req,
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, result.Err = client.Post(listURL(client), req, &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -51,10 +47,7 @@ func List(client *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
|
|||
// Get returns additional information about a service, given its ID.
|
||||
func Get(client *gophercloud.ServiceClient, serviceID string) GetResult {
|
||||
var result GetResult
|
||||
_, result.Err = client.Request("GET", serviceURL(client, serviceID), gophercloud.RequestOpts{
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, result.Err = client.Get(serviceURL(client, serviceID), &result.Body, nil)
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -79,8 +72,6 @@ func Update(client *gophercloud.ServiceClient, serviceID string, serviceType str
|
|||
// It either deletes all associated endpoints, or fails until all endpoints are deleted.
|
||||
func Delete(client *gophercloud.ServiceClient, serviceID string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Request("DELETE", serviceURL(client, serviceID), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = client.Delete(serviceURL(client, serviceID), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -235,11 +235,7 @@ func Create(c *gophercloud.ServiceClient, options gophercloud.AuthOptions, scope
|
|||
|
||||
var result CreateResult
|
||||
var response *http.Response
|
||||
response, result.Err = c.Request("POST", tokenURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &req,
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
response, result.Err = c.Post(tokenURL(c), req, &result.Body, nil)
|
||||
if result.Err != nil {
|
||||
return result
|
||||
}
|
||||
|
@ -251,10 +247,9 @@ func Create(c *gophercloud.ServiceClient, options gophercloud.AuthOptions, scope
|
|||
func Get(c *gophercloud.ServiceClient, token string) GetResult {
|
||||
var result GetResult
|
||||
var response *http.Response
|
||||
response, result.Err = c.Request("GET", tokenURL(c), gophercloud.RequestOpts{
|
||||
MoreHeaders: subjectTokenHeaders(c, token),
|
||||
JSONResponse: &result.Body,
|
||||
OkCodes: []int{200, 203},
|
||||
response, result.Err = c.Get(tokenURL(c), &result.Body, &gophercloud.RequestOpts{
|
||||
MoreHeaders: subjectTokenHeaders(c, token),
|
||||
OkCodes: []int{200, 203},
|
||||
})
|
||||
if result.Err != nil {
|
||||
return result
|
||||
|
@ -279,9 +274,8 @@ func Validate(c *gophercloud.ServiceClient, token string) (bool, error) {
|
|||
// Revoke immediately makes specified token invalid.
|
||||
func Revoke(c *gophercloud.ServiceClient, token string) RevokeResult {
|
||||
var res RevokeResult
|
||||
_, res.Err = c.Request("DELETE", tokenURL(c), gophercloud.RequestOpts{
|
||||
_, res.Err = c.Delete(tokenURL(c), &gophercloud.RequestOpts{
|
||||
MoreHeaders: subjectTokenHeaders(c, token),
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -7,13 +7,58 @@ import (
|
|||
"github.com/rackspace/gophercloud"
|
||||
)
|
||||
|
||||
// Endpoint represents a single API endpoint offered by a service.
|
||||
// It matches either a public, internal or admin URL.
|
||||
// If supported, it contains a region specifier, again if provided.
|
||||
// The significance of the Region field will depend upon your provider.
|
||||
type Endpoint struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Region string `mapstructure:"region"`
|
||||
Interface string `mapstructure:"interface"`
|
||||
URL string `mapstructure:"url"`
|
||||
}
|
||||
|
||||
// CatalogEntry provides a type-safe interface to an Identity API V3 service catalog listing.
|
||||
// Each class of service, such as cloud DNS or block storage services, could have multiple
|
||||
// CatalogEntry representing it (one by interface type, e.g public, admin or internal).
|
||||
//
|
||||
// Note: when looking for the desired service, try, whenever possible, to key off the type field.
|
||||
// Otherwise, you'll tie the representation of the service to a specific provider.
|
||||
type CatalogEntry struct {
|
||||
|
||||
// Service ID
|
||||
ID string `mapstructure:"id"`
|
||||
|
||||
// Name will contain the provider-specified name for the service.
|
||||
Name string `mapstructure:"name"`
|
||||
|
||||
// Type will contain a type string if OpenStack defines a type for the service.
|
||||
// Otherwise, for provider-specific services, the provider may assign their own type strings.
|
||||
Type string `mapstructure:"type"`
|
||||
|
||||
// Endpoints will let the caller iterate over all the different endpoints that may exist for
|
||||
// the service.
|
||||
Endpoints []Endpoint `mapstructure:"endpoints"`
|
||||
}
|
||||
|
||||
// ServiceCatalog provides a view into the service catalog from a previous, successful authentication.
|
||||
type ServiceCatalog struct {
|
||||
Entries []CatalogEntry
|
||||
}
|
||||
|
||||
// commonResult is the deferred result of a Create or a Get call.
|
||||
type commonResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract interprets a commonResult as a Token.
|
||||
// Extract is a shortcut for ExtractToken.
|
||||
// This function is deprecated and still present for backward compatibility.
|
||||
func (r commonResult) Extract() (*Token, error) {
|
||||
return r.ExtractToken()
|
||||
}
|
||||
|
||||
// ExtractToken interprets a commonResult as a Token.
|
||||
func (r commonResult) ExtractToken() (*Token, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
@ -40,7 +85,28 @@ func (r commonResult) Extract() (*Token, error) {
|
|||
return &token, err
|
||||
}
|
||||
|
||||
// CreateResult is the deferred response from a Create call.
|
||||
// ExtractServiceCatalog returns the ServiceCatalog that was generated along with the user's Token.
|
||||
func (result CreateResult) ExtractServiceCatalog() (*ServiceCatalog, error) {
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
var response struct {
|
||||
Token struct {
|
||||
Entries []CatalogEntry `mapstructure:"catalog"`
|
||||
} `mapstructure:"token"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(result.Body, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ServiceCatalog{Entries: response.Token.Entries}, nil
|
||||
}
|
||||
|
||||
// CreateResult defers the interpretation of a created token.
|
||||
// Use ExtractToken() to interpret it as a Token, or ExtractServiceCatalog() to interpret it as a service catalog.
|
||||
type CreateResult struct {
|
||||
commonResult
|
||||
}
|
||||
|
|
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/delegate_test.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/delegate_test.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/external/doc.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/external/doc.go
generated
vendored
Normal file → Executable file
|
@ -1,6 +1,10 @@
|
|||
package external
|
||||
|
||||
import "github.com/rackspace/gophercloud/openstack/networking/v2/networks"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/networks"
|
||||
)
|
||||
|
||||
// AdminState gives users a solid type to work with for create and update
|
||||
// operations. It is recommended that users use the `Up` and `Down` enums.
|
||||
|
@ -25,6 +29,15 @@ type CreateOpts struct {
|
|||
|
||||
// ToNetworkCreateMap casts a CreateOpts struct to a map.
|
||||
func (o CreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) {
|
||||
|
||||
// DO NOT REMOVE. Though this line seemingly does nothing of value, it is a
|
||||
// splint to prevent the unit test from failing on Go Tip. We suspect it is a
|
||||
// compiler issue that will hopefully be worked out prior to our next release.
|
||||
// Again, for all the unit tests to pass, this line is necessary and sufficient
|
||||
// at the moment. We should reassess after the Go 1.5 release to determine
|
||||
// if this line is still needed.
|
||||
time.Sleep(0 * time.Millisecond)
|
||||
|
||||
outer, err := o.Parent.ToNetworkCreateMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -68,7 +68,7 @@ func ExtractUpdate(r networks.UpdateResult) (*NetworkExternal, error) {
|
|||
}
|
||||
|
||||
// ExtractList accepts a Page struct, specifically a NetworkPage struct, and
|
||||
// extracts the elements into a slice of NetworkExtAttrs structs. In other
|
||||
// extracts the elements into a slice of NetworkExternal structs. In other
|
||||
// words, a generic collection is mapped into a relevant slice.
|
||||
func ExtractList(page pagination.Page) ([]NetworkExternal, error) {
|
||||
var resp struct {
|
||||
|
|
|
@ -139,21 +139,14 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular firewall based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -209,10 +202,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -220,8 +211,6 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
// Delete will permanently delete a particular firewall based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -128,21 +128,14 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular firewall policy based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -198,10 +191,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -209,9 +200,7 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
// Delete will permanently delete a particular firewall policy based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -230,10 +219,8 @@ func InsertRule(c *gophercloud.ServiceClient, policyID, ruleID, beforeID, afterI
|
|||
|
||||
// Send request to API
|
||||
var res commonResult
|
||||
_, res.Err = c.Request("PUT", insertURL(c, policyID), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(insertURL(c, policyID), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res.Err
|
||||
}
|
||||
|
@ -249,10 +236,8 @@ func RemoveRule(c *gophercloud.ServiceClient, policyID, ruleID string) error {
|
|||
|
||||
// Send request to API
|
||||
var res commonResult
|
||||
_, res.Err = c.Request("PUT", removeURL(c, policyID), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(removeURL(c, policyID), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res.Err
|
||||
}
|
||||
|
|
|
@ -163,21 +163,14 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular firewall rule based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -277,10 +270,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -289,8 +280,6 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
// Delete will permanently delete a particular firewall rule based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -107,23 +107,14 @@ func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
|
|||
TenantID: opts.TenantID,
|
||||
}}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular floating IP resource based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -159,10 +150,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
|
||||
// Send request to API
|
||||
var res UpdateResult
|
||||
_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -173,8 +162,6 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
// internal ports.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
33
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/routers/requests.go
generated
vendored
Normal file → Executable file
33
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/routers/requests.go
generated
vendored
Normal file → Executable file
|
@ -81,21 +81,14 @@ func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
|
|||
}
|
||||
|
||||
var res CreateResult
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular router based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -133,10 +126,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
|
||||
// Send request to API
|
||||
var res UpdateResult
|
||||
_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -145,9 +136,7 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
// Delete will permanently delete a particular router based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -197,10 +186,8 @@ func AddInterface(c *gophercloud.ServiceClient, id string, opts InterfaceOpts) I
|
|||
|
||||
body := request{SubnetID: opts.SubnetID, PortID: opts.PortID}
|
||||
|
||||
_, res.Err = c.Request("PUT", addInterfaceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &body,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(addInterfaceURL(c, id), body, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -229,10 +216,8 @@ func RemoveInterface(c *gophercloud.ServiceClient, id string, opts InterfaceOpts
|
|||
|
||||
body := request{SubnetID: opts.SubnetID, PortID: opts.PortID}
|
||||
|
||||
_, res.Err = c.Request("PUT", removeInterfaceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &body,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(removeInterfaceURL(c, id), body, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return res
|
||||
|
|
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/routers/requests_test.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/routers/requests_test.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/routers/results.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/routers/results.go
generated
vendored
Normal file → Executable file
|
@ -79,21 +79,14 @@ func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
|
|||
}}
|
||||
|
||||
var res CreateResult
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular pool member based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -116,10 +109,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
|
||||
// Send request to API
|
||||
var res UpdateResult
|
||||
_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201, 202},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -127,8 +118,6 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
// Delete will permanently delete a particular member based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -176,22 +176,14 @@ func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
|
|||
AdminStateUp: opts.AdminStateUp,
|
||||
}}
|
||||
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular health monitor based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -258,10 +250,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
AdminStateUp: opts.AdminStateUp,
|
||||
}}
|
||||
|
||||
_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200, 202},
|
||||
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 202},
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -270,8 +260,6 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
// Delete will permanently delete a particular monitor based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -99,21 +99,14 @@ func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
|
|||
}}
|
||||
|
||||
var res CreateResult
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular pool based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -145,10 +138,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
|
||||
// Send request to API
|
||||
var res UpdateResult
|
||||
_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -156,9 +147,7 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
// Delete will permanently delete a particular pool based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -178,11 +167,7 @@ func AssociateMonitor(c *gophercloud.ServiceClient, poolID, monitorID string) As
|
|||
reqBody := request{hm{ID: monitorID}}
|
||||
|
||||
var res AssociateResult
|
||||
_, res.Err = c.Request("POST", associateURL(c, poolID), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(associateURL(c, poolID), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -191,8 +176,6 @@ func AssociateMonitor(c *gophercloud.ServiceClient, poolID, monitorID string) As
|
|||
// check for the health of the members of the pool.
|
||||
func DisassociateMonitor(c *gophercloud.ServiceClient, poolID, monitorID string) AssociateResult {
|
||||
var res AssociateResult
|
||||
_, res.Err = c.Request("DELETE", disassociateURL(c, poolID, monitorID), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(disassociateURL(c, poolID, monitorID), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -178,22 +178,14 @@ func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
|
|||
reqBody.VirtualIP.Persistence = opts.Persistence
|
||||
}
|
||||
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular virtual IP based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -249,10 +241,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
}
|
||||
|
||||
var res UpdateResult
|
||||
_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200, 202},
|
||||
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 202},
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -261,8 +251,6 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResu
|
|||
// Delete will permanently delete a particular virtual IP based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/provider/doc.go
generated
vendored
Normal file → Executable file
0
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/provider/doc.go
generated
vendored
Normal file → Executable file
8
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/provider/results.go
generated
vendored
Normal file → Executable file
8
Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/networking/v2/extensions/provider/results.go
generated
vendored
Normal file → Executable file
|
@ -73,7 +73,7 @@ func ExtractGet(r networks.GetResult) (*NetworkExtAttrs, error) {
|
|||
Network *NetworkExtAttrs `json:"network"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
err := mapstructure.WeakDecode(r.Body, &res)
|
||||
|
||||
return res.Network, err
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func ExtractCreate(r networks.CreateResult) (*NetworkExtAttrs, error) {
|
|||
Network *NetworkExtAttrs `json:"network"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
err := mapstructure.WeakDecode(r.Body, &res)
|
||||
|
||||
return res.Network, err
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func ExtractUpdate(r networks.UpdateResult) (*NetworkExtAttrs, error) {
|
|||
Network *NetworkExtAttrs `json:"network"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
err := mapstructure.WeakDecode(r.Body, &res)
|
||||
|
||||
return res.Network, err
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func ExtractList(page pagination.Page) ([]NetworkExtAttrs, error) {
|
|||
Networks []NetworkExtAttrs `mapstructure:"networks" json:"networks"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(page.(networks.NetworkPage).Body, &resp)
|
||||
err := mapstructure.WeakDecode(page.(networks.NetworkPage).Body, &resp)
|
||||
|
||||
return resp.Networks, err
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func TestList(t *testing.T) {
|
|||
"tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
|
||||
"shared": true,
|
||||
"id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
|
||||
"provider:segmentation_id": null,
|
||||
"provider:segmentation_id": 1234567890,
|
||||
"provider:physical_network": null,
|
||||
"provider:network_type": "local"
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func TestList(t *testing.T) {
|
|||
ID: "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
|
||||
NetworkType: "local",
|
||||
PhysicalNetwork: "",
|
||||
SegmentationID: "",
|
||||
SegmentationID: "1234567890",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
//
|
||||
// For ingress traffic (to an instance)
|
||||
// - Only traffic matched with security group rules are allowed.
|
||||
// - When there is no rule defined, all traffic are dropped.
|
||||
// - When there is no rule defined, all traffic is dropped.
|
||||
//
|
||||
// For egress traffic (from an instance)
|
||||
// - Only traffic matched with security group rules are allowed.
|
||||
// - When there is no rule defined, all egress traffic are dropped.
|
||||
// - When a new security group is created, rules to allow all egress traffic
|
||||
// are automatically added.
|
||||
// is automatically added.
|
||||
//
|
||||
// "default security group" is defined for each tenant.
|
||||
// - For the default security group a rule which allows intercommunication
|
||||
|
|
|
@ -74,30 +74,20 @@ func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
|
|||
Description: opts.Description,
|
||||
}}
|
||||
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular security group based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete will permanently delete a particular security group based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -150,30 +150,20 @@ func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
|
|||
RemoteIPPrefix: opts.RemoteIPPrefix,
|
||||
}}
|
||||
|
||||
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
|
||||
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a particular security group based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(resourceURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete will permanently delete a particular security group based on its unique ID.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", resourceURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(resourceURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -79,10 +79,7 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
|
|||
// Get retrieves a specific network based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", getURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(getURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -134,12 +131,7 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
|||
return res
|
||||
}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("POST", createURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(createURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -184,10 +176,8 @@ func Update(c *gophercloud.ServiceClient, networkID string, opts UpdateOptsBuild
|
|||
}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("PUT", updateURL(c, networkID), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200, 201},
|
||||
_, res.Err = c.Put(updateURL(c, networkID), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -196,8 +186,6 @@ func Update(c *gophercloud.ServiceClient, networkID string, opts UpdateOptsBuild
|
|||
// Delete accepts a unique ID and deletes the network associated with it.
|
||||
func Delete(c *gophercloud.ServiceClient, networkID string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", deleteURL(c, networkID), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(deleteURL(c, networkID), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -79,10 +79,7 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
|
|||
// Get retrieves a specific port based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", getURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(getURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -155,13 +152,7 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
|||
return res
|
||||
}
|
||||
|
||||
// Response
|
||||
_, res.Err = c.Request("POST", createURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
|
||||
_, res.Err = c.Post(createURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -220,10 +211,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = c.Request("PUT", updateURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200, 201},
|
||||
_, res.Err = c.Put(updateURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -231,8 +220,6 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
// Delete accepts a unique ID and deletes the port associated with it.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", deleteURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(deleteURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -78,10 +78,7 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
|
|||
// Get retrieves a specific subnet based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", getURL(c, id), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(getURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -171,12 +168,7 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = c.Request("POST", createURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
|
||||
_, res.Err = c.Post(createURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -229,10 +221,8 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = c.Request("PUT", updateURL(c, id), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200, 201},
|
||||
_, res.Err = c.Put(updateURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
|
||||
return res
|
||||
|
@ -241,8 +231,6 @@ func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) Upd
|
|||
// Delete accepts a unique ID and deletes the subnet associated with it.
|
||||
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", deleteURL(c, id), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(deleteURL(c, id), nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ func Update(c *gophercloud.ServiceClient, opts UpdateOptsBuilder) UpdateResult {
|
|||
|
||||
resp, err := c.Request("POST", updateURL(c), gophercloud.RequestOpts{
|
||||
MoreHeaders: h,
|
||||
OkCodes: []int{204},
|
||||
OkCodes: []int{201, 202, 204},
|
||||
})
|
||||
res.Header = resp.Header
|
||||
res.Err = err
|
||||
|
|
|
@ -55,6 +55,14 @@ func HandleListContainerInfoSuccessfully(t *testing.T) {
|
|||
"name": "marktwain"
|
||||
}
|
||||
]`)
|
||||
case "janeausten":
|
||||
fmt.Fprintf(w, `[
|
||||
{
|
||||
"count": 1,
|
||||
"bytes": 14,
|
||||
"name": "marktwain"
|
||||
}
|
||||
]`)
|
||||
case "marktwain":
|
||||
fmt.Fprintf(w, `[]`)
|
||||
default:
|
||||
|
@ -77,6 +85,8 @@ func HandleListContainerNamesSuccessfully(t *testing.T) {
|
|||
switch marker {
|
||||
case "":
|
||||
fmt.Fprintf(w, "janeausten\nmarktwain\n")
|
||||
case "janeausten":
|
||||
fmt.Fprintf(w, "marktwain\n")
|
||||
case "marktwain":
|
||||
fmt.Fprintf(w, ``)
|
||||
default:
|
||||
|
|
|
@ -122,9 +122,7 @@ func Create(c *gophercloud.ServiceClient, containerName string, opts CreateOptsB
|
|||
// Delete is a function that deletes a container.
|
||||
func Delete(c *gophercloud.ServiceClient, containerName string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Request("DELETE", deleteURL(c, containerName), gophercloud.RequestOpts{
|
||||
OkCodes: []int{202, 204},
|
||||
})
|
||||
_, res.Err = c.Delete(deleteURL(c, containerName), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -180,7 +178,7 @@ func Update(c *gophercloud.ServiceClient, containerName string, opts UpdateOptsB
|
|||
|
||||
resp, err := c.Request("POST", updateURL(c, containerName), gophercloud.RequestOpts{
|
||||
MoreHeaders: h,
|
||||
OkCodes: []int{202, 204},
|
||||
OkCodes: []int{201, 202, 204},
|
||||
})
|
||||
res.Header = resp.Header
|
||||
res.Err = err
|
||||
|
|
|
@ -29,6 +29,18 @@ func TestListContainerInfo(t *testing.T) {
|
|||
th.CheckEquals(t, count, 1)
|
||||
}
|
||||
|
||||
func TestListAllContainerInfo(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
HandleListContainerInfoSuccessfully(t)
|
||||
|
||||
allPages, err := List(fake.ServiceClient(), &ListOpts{Full: true}).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
actual, err := ExtractInfo(allPages)
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckDeepEquals(t, ExpectedListInfo, actual)
|
||||
}
|
||||
|
||||
func TestListContainerNames(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
|
@ -51,6 +63,18 @@ func TestListContainerNames(t *testing.T) {
|
|||
th.CheckEquals(t, count, 1)
|
||||
}
|
||||
|
||||
func TestListAllContainerNames(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
HandleListContainerNamesSuccessfully(t)
|
||||
|
||||
allPages, err := List(fake.ServiceClient(), &ListOpts{Full: false}).AllPages()
|
||||
th.AssertNoErr(t, err)
|
||||
actual, err := ExtractNames(allPages)
|
||||
th.AssertNoErr(t, err)
|
||||
th.CheckDeepEquals(t, ExpectedListNames, actual)
|
||||
}
|
||||
|
||||
func TestCreateContainer(t *testing.T) {
|
||||
th.SetupHTTP()
|
||||
defer th.TeardownHTTP()
|
||||
|
|
|
@ -211,7 +211,6 @@ func Create(c *gophercloud.ServiceClient, containerName, objectName string, cont
|
|||
ropts := gophercloud.RequestOpts{
|
||||
RawBody: content,
|
||||
MoreHeaders: h,
|
||||
OkCodes: []int{201, 202},
|
||||
}
|
||||
|
||||
resp, err := c.Request("PUT", url, ropts)
|
||||
|
@ -310,9 +309,7 @@ func Delete(c *gophercloud.ServiceClient, containerName, objectName string, opts
|
|||
url += query
|
||||
}
|
||||
|
||||
resp, err := c.Request("DELETE", url, gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
resp, err := c.Delete(url, nil)
|
||||
res.Header = resp.Header
|
||||
res.Err = err
|
||||
return res
|
||||
|
@ -412,7 +409,6 @@ func Update(c *gophercloud.ServiceClient, containerName, objectName string, opts
|
|||
url := updateURL(c, containerName, objectName)
|
||||
resp, err := c.Request("POST", url, gophercloud.RequestOpts{
|
||||
MoreHeaders: h,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
res.Header = resp.Header
|
||||
res.Err = err
|
||||
|
|
|
@ -5,9 +5,6 @@ import "github.com/rackspace/gophercloud"
|
|||
// Get retreives data for the given stack template.
|
||||
func Get(c *gophercloud.ServiceClient) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", getURL(c), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(getURL(c), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ func Find(c *gophercloud.ServiceClient, stackName string) FindResult {
|
|||
|
||||
_, res.Err = c.Request("GET", findURL(c, stackName), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -197,9 +196,8 @@ func ListResourceEvents(client *gophercloud.ServiceClient, stackName, stackID, r
|
|||
// Get retreives data for the given stack resource.
|
||||
func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName, eventID string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Request("GET", getURL(c, stackName, stackID, resourceName, eventID), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Get(getURL(c, stackName, stackID, resourceName, eventID), &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package stackevents
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
@ -106,7 +108,15 @@ func ExtractEvents(page pagination.Page) ([]Event, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
events := casted.(map[string]interface{})["events"].([]interface{})
|
||||
var events []interface{}
|
||||
switch casted.(type) {
|
||||
case map[string]interface{}:
|
||||
events = casted.(map[string]interface{})["events"].([]interface{})
|
||||
case map[string][]interface{}:
|
||||
events = casted.(map[string][]interface{})["events"]
|
||||
default:
|
||||
return res.Res, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
|
||||
}
|
||||
|
||||
for i, eventRaw := range events {
|
||||
event := eventRaw.(map[string]interface{})
|
||||
|
|
|
@ -12,7 +12,6 @@ func Find(c *gophercloud.ServiceClient, stackName string) FindResult {
|
|||
// Send request to API
|
||||
_, res.Err = c.Request("GET", findURL(c, stackName), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -71,9 +70,8 @@ func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName string)
|
|||
var res GetResult
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("GET", getURL(c, stackName, stackID, resourceName), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Get(getURL(c, stackName, stackID, resourceName), &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -83,9 +81,8 @@ func Metadata(c *gophercloud.ServiceClient, stackName, stackID, resourceName str
|
|||
var res MetadataResult
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("GET", metadataURL(c, stackName, stackID, resourceName), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Get(metadataURL(c, stackName, stackID, resourceName), &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -106,9 +103,8 @@ func Schema(c *gophercloud.ServiceClient, resourceType string) SchemaResult {
|
|||
var res SchemaResult
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("GET", schemaURL(c, resourceType), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Get(schemaURL(c, resourceType), &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -118,9 +114,8 @@ func Template(c *gophercloud.ServiceClient, resourceType string) TemplateResult
|
|||
var res TemplateResult
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("GET", templateURL(c, resourceType), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Get(templateURL(c, resourceType), &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package stackresources
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
@ -94,7 +96,15 @@ func ExtractResources(page pagination.Page) ([]Resource, error) {
|
|||
}
|
||||
err := mapstructure.Decode(casted, &response)
|
||||
|
||||
resources := casted.(map[string]interface{})["resources"].([]interface{})
|
||||
var resources []interface{}
|
||||
switch casted.(type) {
|
||||
case map[string]interface{}:
|
||||
resources = casted.(map[string]interface{})["resources"].([]interface{})
|
||||
case map[string][]interface{}:
|
||||
resources = casted.(map[string][]interface{})["resources"]
|
||||
default:
|
||||
return response.Resources, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
|
||||
}
|
||||
|
||||
for i, resourceRaw := range resources {
|
||||
resource := resourceRaw.(map[string]interface{})
|
||||
|
|
|
@ -111,12 +111,7 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
|||
return res
|
||||
}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("POST", createURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(createURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -221,12 +216,7 @@ func Adopt(c *gophercloud.ServiceClient, opts AdoptOptsBuilder) AdoptResult {
|
|||
return res
|
||||
}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("POST", adoptURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{201},
|
||||
})
|
||||
_, res.Err = c.Post(adoptURL(c), reqBody, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -302,12 +292,7 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
|
|||
// Get retreives a stack based on the stack name and stack ID.
|
||||
func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult {
|
||||
var res GetResult
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("GET", getURL(c, stackName, stackID), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, res.Err = c.Get(getURL(c, stackName, stackID), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -388,22 +373,14 @@ func Update(c *gophercloud.ServiceClient, stackName, stackID string, opts Update
|
|||
return res
|
||||
}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("PUT", updateURL(c, stackName, stackID), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
_, res.Err = c.Put(updateURL(c, stackName, stackID), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete deletes a stack based on the stack name and stack ID.
|
||||
func Delete(c *gophercloud.ServiceClient, stackName, stackID string) DeleteResult {
|
||||
var res DeleteResult
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("DELETE", deleteURL(c, stackName, stackID), gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
})
|
||||
_, res.Err = c.Delete(deleteURL(c, stackName, stackID), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -498,10 +475,8 @@ func Preview(c *gophercloud.ServiceClient, opts PreviewOptsBuilder) PreviewResul
|
|||
}
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("POST", previewURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Post(previewURL(c), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -510,9 +485,7 @@ func Preview(c *gophercloud.ServiceClient, opts PreviewOptsBuilder) PreviewResul
|
|||
// resources intact, and returns data describing the stack and its resources.
|
||||
func Abandon(c *gophercloud.ServiceClient, stackName, stackID string) AbandonResult {
|
||||
var res AbandonResult
|
||||
|
||||
// Send request to API
|
||||
_, res.Err = c.Request("DELETE", abandonURL(c, stackName, stackID), gophercloud.RequestOpts{
|
||||
_, res.Err = c.Delete(abandonURL(c, stackName, stackID), &gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
|
|
@ -2,6 +2,8 @@ package stacks
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
@ -73,6 +75,8 @@ type ListedStack struct {
|
|||
// ExtractStacks extracts and returns a slice of ListedStack. It is used while iterating
|
||||
// over a stacks.List call.
|
||||
func ExtractStacks(page pagination.Page) ([]ListedStack, error) {
|
||||
casted := page.(StackPage).Body
|
||||
|
||||
var res struct {
|
||||
Stacks []ListedStack `mapstructure:"stacks"`
|
||||
}
|
||||
|
@ -82,7 +86,16 @@ func ExtractStacks(page pagination.Page) ([]ListedStack, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
rawStacks := (((page.(StackPage).Body).(map[string]interface{}))["stacks"]).([]interface{})
|
||||
var rawStacks []interface{}
|
||||
switch casted.(type) {
|
||||
case map[string]interface{}:
|
||||
rawStacks = casted.(map[string]interface{})["stacks"].([]interface{})
|
||||
case map[string][]interface{}:
|
||||
rawStacks = casted.(map[string][]interface{})["stacks"]
|
||||
default:
|
||||
return res.Stacks, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
|
||||
}
|
||||
|
||||
for i := range rawStacks {
|
||||
thisStack := (rawStacks[i]).(map[string]interface{})
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult {
|
|||
var res GetResult
|
||||
_, res.Err = c.Request("GET", getURL(c, stackName, stackID), gophercloud.RequestOpts{
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
@ -52,10 +51,8 @@ func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) ValidateRe
|
|||
return res
|
||||
}
|
||||
|
||||
_, res.Err = c.Request("POST", validateURL(c), gophercloud.RequestOpts{
|
||||
JSONBody: reqBody,
|
||||
JSONResponse: &res.Body,
|
||||
OkCodes: []int{200},
|
||||
_, res.Err = c.Post(validateURL(c), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue