Update vendor dir and Godeps.json with new Godep
This commit is contained in:
57
vendor/github.com/rackspace/gophercloud/acceptance/README.md
generated
vendored
57
vendor/github.com/rackspace/gophercloud/acceptance/README.md
generated
vendored
@@ -1,57 +0,0 @@
|
||||
# Gophercloud Acceptance tests
|
||||
|
||||
The purpose of these acceptance tests is to validate that SDK features meet
|
||||
the requirements of a contract - to consumers, other parts of the library, and
|
||||
to a remote API.
|
||||
|
||||
> **Note:** Because every test will be run against a real API endpoint, you
|
||||
> may incur bandwidth and service charges for all the resource usage. These
|
||||
> tests *should* remove their remote products automatically. However, there may
|
||||
> be certain cases where this does not happen; always double-check to make sure
|
||||
> you have no stragglers left behind.
|
||||
|
||||
### Step 1. Set environment variables
|
||||
|
||||
A lot of tests rely on environment variables for configuration - so you will need
|
||||
to set them before running the suite. If you're testing against pure OpenStack APIs,
|
||||
you can download a file that contains all of these variables for you: just visit
|
||||
the `project/access_and_security` page in your control panel and click the "Download
|
||||
OpenStack RC File" button at the top right. For all other providers, you will need
|
||||
to set them manually.
|
||||
|
||||
#### Authentication
|
||||
|
||||
|Name|Description|
|
||||
|---|---|
|
||||
|`OS_USERNAME`|Your API username|
|
||||
|`OS_PASSWORD`|Your API password|
|
||||
|`OS_AUTH_URL`|The identity URL you need to authenticate|
|
||||
|`OS_TENANT_NAME`|Your API tenant name|
|
||||
|`OS_TENANT_ID`|Your API tenant ID|
|
||||
|`RS_USERNAME`|Your Rackspace username|
|
||||
|`RS_API_KEY`|Your Rackspace API key|
|
||||
|
||||
#### General
|
||||
|
||||
|Name|Description|
|
||||
|---|---|
|
||||
|`OS_REGION_NAME`|The region you want your resources to reside in|
|
||||
|`RS_REGION`|Rackspace region you want your resource to reside in|
|
||||
|
||||
#### Compute
|
||||
|
||||
|Name|Description|
|
||||
|---|---|
|
||||
|`OS_IMAGE_ID`|The ID of the image your want your server to be based on|
|
||||
|`OS_FLAVOR_ID`|The ID of the flavor you want your server to be based on|
|
||||
|`OS_FLAVOR_ID_RESIZE`|The ID of the flavor you want your server to be resized to|
|
||||
|`RS_IMAGE_ID`|The ID of the image you want servers to be created with|
|
||||
|`RS_FLAVOR_ID`|The ID of the flavor you want your server to be created with|
|
||||
|
||||
### 2. Run the test suite
|
||||
|
||||
From the root directory, run:
|
||||
|
||||
```
|
||||
./script/acceptancetest
|
||||
```
|
3
vendor/github.com/rackspace/gophercloud/acceptance/openstack/blockstorage/v1/pkg.go
generated
vendored
3
vendor/github.com/rackspace/gophercloud/acceptance/openstack/blockstorage/v1/pkg.go
generated
vendored
@@ -1,3 +0,0 @@
|
||||
// The v1 package contains acceptance tests for the Openstack Cinder V1 service.
|
||||
|
||||
package v1
|
3
vendor/github.com/rackspace/gophercloud/acceptance/openstack/compute/v2/pkg.go
generated
vendored
3
vendor/github.com/rackspace/gophercloud/acceptance/openstack/compute/v2/pkg.go
generated
vendored
@@ -1,3 +0,0 @@
|
||||
// The v2 package contains acceptance tests for the Openstack Compute V2 service.
|
||||
|
||||
package v2
|
70
vendor/github.com/rackspace/gophercloud/acceptance/openstack/db/v1/common.go
generated
vendored
70
vendor/github.com/rackspace/gophercloud/acceptance/openstack/db/v1/common.go
generated
vendored
@@ -1,70 +0,0 @@
|
||||
// +build acceptance db
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/db/v1/instances"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func newClient(t *testing.T) *gophercloud.ServiceClient {
|
||||
ao, err := openstack.AuthOptionsFromEnv()
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
client, err := openstack.AuthenticatedClient(ao)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
c, err := openstack.NewDBV1(client, gophercloud.EndpointOpts{
|
||||
Region: os.Getenv("OS_REGION_NAME"),
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
type context struct {
|
||||
test *testing.T
|
||||
client *gophercloud.ServiceClient
|
||||
instanceID string
|
||||
DBIDs []string
|
||||
users []string
|
||||
}
|
||||
|
||||
func newContext(t *testing.T) context {
|
||||
return context{
|
||||
test: t,
|
||||
client: newClient(t),
|
||||
}
|
||||
}
|
||||
|
||||
func (c context) Logf(msg string, args ...interface{}) {
|
||||
if len(args) > 0 {
|
||||
c.test.Logf(msg, args...)
|
||||
} else {
|
||||
c.test.Log(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (c context) AssertNoErr(err error) {
|
||||
th.AssertNoErr(c.test, err)
|
||||
}
|
||||
|
||||
func (c context) WaitUntilActive(id string) {
|
||||
err := gophercloud.WaitFor(60, func() (bool, error) {
|
||||
inst, err := instances.Get(c.client, id).Extract()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if inst.Status == "ACTIVE" {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
|
||||
c.AssertNoErr(err)
|
||||
}
|
1
vendor/github.com/rackspace/gophercloud/acceptance/openstack/db/v1/pkg.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/acceptance/openstack/db/v1/pkg.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package v1
|
1
vendor/github.com/rackspace/gophercloud/acceptance/openstack/identity/v2/pkg.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/acceptance/openstack/identity/v2/pkg.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package v2
|
1
vendor/github.com/rackspace/gophercloud/acceptance/openstack/identity/v3/pkg.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/acceptance/openstack/identity/v3/pkg.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package v3
|
39
vendor/github.com/rackspace/gophercloud/acceptance/openstack/networking/v2/common.go
generated
vendored
39
vendor/github.com/rackspace/gophercloud/acceptance/openstack/networking/v2/common.go
generated
vendored
@@ -1,39 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
var Client *gophercloud.ServiceClient
|
||||
|
||||
func NewClient() (*gophercloud.ServiceClient, error) {
|
||||
opts, err := openstack.AuthOptionsFromEnv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
provider, err := openstack.AuthenticatedClient(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
|
||||
Name: "neutron",
|
||||
Region: os.Getenv("OS_REGION_NAME"),
|
||||
})
|
||||
}
|
||||
|
||||
func Setup(t *testing.T) {
|
||||
client, err := NewClient()
|
||||
th.AssertNoErr(t, err)
|
||||
Client = client
|
||||
}
|
||||
|
||||
func Teardown() {
|
||||
Client = nil
|
||||
}
|
@@ -1 +0,0 @@
|
||||
package fwaas
|
@@ -1,78 +0,0 @@
|
||||
package lbaas
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
base "github.com/rackspace/gophercloud/acceptance/openstack/networking/v2"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/monitors"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/pools"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/networks"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/subnets"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func SetupTopology(t *testing.T) (string, string) {
|
||||
// create network
|
||||
n, err := networks.Create(base.Client, networks.CreateOpts{Name: "tmp_network"}).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
t.Logf("Created network %s", n.ID)
|
||||
|
||||
// create subnet
|
||||
s, err := subnets.Create(base.Client, subnets.CreateOpts{
|
||||
NetworkID: n.ID,
|
||||
CIDR: "192.168.199.0/24",
|
||||
IPVersion: subnets.IPv4,
|
||||
Name: "tmp_subnet",
|
||||
}).Extract()
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
t.Logf("Created subnet %s", s.ID)
|
||||
|
||||
return n.ID, s.ID
|
||||
}
|
||||
|
||||
func DeleteTopology(t *testing.T, networkID string) {
|
||||
res := networks.Delete(base.Client, networkID)
|
||||
th.AssertNoErr(t, res.Err)
|
||||
t.Logf("Deleted network %s", networkID)
|
||||
}
|
||||
|
||||
func CreatePool(t *testing.T, subnetID string) string {
|
||||
p, err := pools.Create(base.Client, pools.CreateOpts{
|
||||
LBMethod: pools.LBMethodRoundRobin,
|
||||
Protocol: "HTTP",
|
||||
Name: "tmp_pool",
|
||||
SubnetID: subnetID,
|
||||
}).Extract()
|
||||
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
t.Logf("Created pool %s", p.ID)
|
||||
|
||||
return p.ID
|
||||
}
|
||||
|
||||
func DeletePool(t *testing.T, poolID string) {
|
||||
res := pools.Delete(base.Client, poolID)
|
||||
th.AssertNoErr(t, res.Err)
|
||||
t.Logf("Deleted pool %s", poolID)
|
||||
}
|
||||
|
||||
func CreateMonitor(t *testing.T) string {
|
||||
m, err := monitors.Create(base.Client, monitors.CreateOpts{
|
||||
Delay: 10,
|
||||
Timeout: 10,
|
||||
MaxRetries: 3,
|
||||
Type: monitors.TypeHTTP,
|
||||
ExpectedCodes: "200",
|
||||
URLPath: "/login",
|
||||
HTTPMethod: "GET",
|
||||
}).Extract()
|
||||
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
t.Logf("Created monitor ID [%s]", m.ID)
|
||||
|
||||
return m.ID
|
||||
}
|
@@ -1 +0,0 @@
|
||||
package lbaas
|
@@ -1 +0,0 @@
|
||||
package extensions
|
1
vendor/github.com/rackspace/gophercloud/acceptance/openstack/networking/v2/pkg.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/acceptance/openstack/networking/v2/pkg.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package v2
|
28
vendor/github.com/rackspace/gophercloud/acceptance/openstack/objectstorage/v1/common.go
generated
vendored
28
vendor/github.com/rackspace/gophercloud/acceptance/openstack/objectstorage/v1/common.go
generated
vendored
@@ -1,28 +0,0 @@
|
||||
// +build acceptance
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
var metadata = map[string]string{"gopher": "cloud"}
|
||||
|
||||
func newClient(t *testing.T) *gophercloud.ServiceClient {
|
||||
ao, err := openstack.AuthOptionsFromEnv()
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
client, err := openstack.AuthenticatedClient(ao)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
c, err := openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{
|
||||
Region: os.Getenv("OS_REGION_NAME"),
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
return c
|
||||
}
|
44
vendor/github.com/rackspace/gophercloud/acceptance/openstack/orchestration/v1/common.go
generated
vendored
44
vendor/github.com/rackspace/gophercloud/acceptance/openstack/orchestration/v1/common.go
generated
vendored
@@ -1,44 +0,0 @@
|
||||
// +build acceptance
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
var template = fmt.Sprintf(`
|
||||
{
|
||||
"heat_template_version": "2013-05-23",
|
||||
"description": "Simple template to test heat commands",
|
||||
"parameters": {},
|
||||
"resources": {
|
||||
"hello_world": {
|
||||
"type":"OS::Nova::Server",
|
||||
"properties": {
|
||||
"flavor": "%s",
|
||||
"image": "%s",
|
||||
"user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}`, os.Getenv("OS_FLAVOR_ID"), os.Getenv("OS_IMAGE_ID"))
|
||||
|
||||
func newClient(t *testing.T) *gophercloud.ServiceClient {
|
||||
ao, err := openstack.AuthOptionsFromEnv()
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
client, err := openstack.AuthenticatedClient(ao)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
c, err := openstack.NewOrchestrationV1(client, gophercloud.EndpointOpts{
|
||||
Region: os.Getenv("OS_REGION_NAME"),
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
return c
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"heat_template_version": "2013-05-23",
|
||||
"resources": {
|
||||
"compute_instance": {
|
||||
"type": "OS::Nova::Server",
|
||||
"properties": {
|
||||
"flavor": "m1.small",
|
||||
"image": "cirros-0.3.2-x86_64-disk",
|
||||
"name": "Single Compute Instance"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
4
vendor/github.com/rackspace/gophercloud/acceptance/openstack/pkg.go
generated
vendored
4
vendor/github.com/rackspace/gophercloud/acceptance/openstack/pkg.go
generated
vendored
@@ -1,4 +0,0 @@
|
||||
// +build acceptance
|
||||
|
||||
package openstack
|
||||
|
38
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/blockstorage/v1/common.go
generated
vendored
38
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/blockstorage/v1/common.go
generated
vendored
@@ -1,38 +0,0 @@
|
||||
// +build acceptance
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/acceptance/tools"
|
||||
"github.com/rackspace/gophercloud/rackspace"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func newClient() (*gophercloud.ServiceClient, error) {
|
||||
opts, err := rackspace.AuthOptionsFromEnv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts = tools.OnlyRS(opts)
|
||||
region := os.Getenv("RS_REGION")
|
||||
|
||||
provider, err := rackspace.AuthenticatedClient(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
|
||||
Region: region,
|
||||
})
|
||||
}
|
||||
|
||||
func setup(t *testing.T) *gophercloud.ServiceClient {
|
||||
client, err := newClient()
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
return client
|
||||
}
|
23
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/cdn/v1/common.go
generated
vendored
23
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/cdn/v1/common.go
generated
vendored
@@ -1,23 +0,0 @@
|
||||
// +build acceptance
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"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.NewCDNV1(client, gophercloud.EndpointOpts{})
|
||||
th.AssertNoErr(t, err)
|
||||
return c
|
||||
}
|
1
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/compute/v2/pkg.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/compute/v2/pkg.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package v2
|
73
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/db/v1/common.go
generated
vendored
73
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/db/v1/common.go
generated
vendored
@@ -1,73 +0,0 @@
|
||||
// +build acceptance db rackspace
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/acceptance/tools"
|
||||
"github.com/rackspace/gophercloud/rackspace"
|
||||
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func newClient(t *testing.T) *gophercloud.ServiceClient {
|
||||
opts, err := rackspace.AuthOptionsFromEnv()
|
||||
th.AssertNoErr(t, err)
|
||||
opts = tools.OnlyRS(opts)
|
||||
|
||||
client, err := rackspace.AuthenticatedClient(opts)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
c, err := rackspace.NewDBV1(client, gophercloud.EndpointOpts{
|
||||
Region: "IAD",
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
type context struct {
|
||||
test *testing.T
|
||||
client *gophercloud.ServiceClient
|
||||
instanceID string
|
||||
DBIDs []string
|
||||
replicaID string
|
||||
backupID string
|
||||
configGroupID string
|
||||
users []string
|
||||
}
|
||||
|
||||
func newContext(t *testing.T) context {
|
||||
return context{
|
||||
test: t,
|
||||
client: newClient(t),
|
||||
}
|
||||
}
|
||||
|
||||
func (c context) Logf(msg string, args ...interface{}) {
|
||||
if len(args) > 0 {
|
||||
c.test.Logf(msg, args...)
|
||||
} else {
|
||||
c.test.Log(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (c context) AssertNoErr(err error) {
|
||||
th.AssertNoErr(c.test, err)
|
||||
}
|
||||
|
||||
func (c context) WaitUntilActive(id string) {
|
||||
err := gophercloud.WaitFor(60, func() (bool, error) {
|
||||
inst, err := instances.Get(c.client, id).Extract()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if inst.Status == "ACTIVE" {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
c.AssertNoErr(err)
|
||||
}
|
1
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/db/v1/pkg.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/db/v1/pkg.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package v1
|
1
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/identity/v2/pkg.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/identity/v2/pkg.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package v2
|
62
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/lb/v1/common.go
generated
vendored
62
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/lb/v1/common.go
generated
vendored
@@ -1,62 +0,0 @@
|
||||
// +build acceptance lbs
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/acceptance/tools"
|
||||
"github.com/rackspace/gophercloud/rackspace"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func newProvider() (*gophercloud.ProviderClient, error) {
|
||||
opts, err := rackspace.AuthOptionsFromEnv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts = tools.OnlyRS(opts)
|
||||
|
||||
return rackspace.AuthenticatedClient(opts)
|
||||
}
|
||||
|
||||
func newClient() (*gophercloud.ServiceClient, error) {
|
||||
provider, err := newProvider()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rackspace.NewLBV1(provider, gophercloud.EndpointOpts{
|
||||
Region: os.Getenv("RS_REGION"),
|
||||
})
|
||||
}
|
||||
|
||||
func newComputeClient() (*gophercloud.ServiceClient, error) {
|
||||
provider, err := newProvider()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
|
||||
Region: os.Getenv("RS_REGION"),
|
||||
})
|
||||
}
|
||||
|
||||
func setup(t *testing.T) *gophercloud.ServiceClient {
|
||||
client, err := newClient()
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func intsToStr(ids []int) string {
|
||||
strIDs := []string{}
|
||||
for _, id := range ids {
|
||||
strIDs = append(strIDs, strconv.Itoa(id))
|
||||
}
|
||||
return strings.Join(strIDs, ", ")
|
||||
}
|
39
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/networking/v2/common.go
generated
vendored
39
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/networking/v2/common.go
generated
vendored
@@ -1,39 +0,0 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/rackspace"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
var Client *gophercloud.ServiceClient
|
||||
|
||||
func NewClient() (*gophercloud.ServiceClient, error) {
|
||||
opts, err := rackspace.AuthOptionsFromEnv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
provider, err := rackspace.AuthenticatedClient(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rackspace.NewNetworkV2(provider, gophercloud.EndpointOpts{
|
||||
Name: "cloudNetworks",
|
||||
Region: os.Getenv("RS_REGION"),
|
||||
})
|
||||
}
|
||||
|
||||
func Setup(t *testing.T) {
|
||||
client, err := NewClient()
|
||||
th.AssertNoErr(t, err)
|
||||
Client = client
|
||||
}
|
||||
|
||||
func Teardown() {
|
||||
Client = nil
|
||||
}
|
54
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/objectstorage/v1/common.go
generated
vendored
54
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/objectstorage/v1/common.go
generated
vendored
@@ -1,54 +0,0 @@
|
||||
// +build acceptance rackspace objectstorage v1
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/acceptance/tools"
|
||||
"github.com/rackspace/gophercloud/rackspace"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
func rackspaceAuthOptions(t *testing.T) gophercloud.AuthOptions {
|
||||
// Obtain credentials from the environment.
|
||||
options, err := rackspace.AuthOptionsFromEnv()
|
||||
th.AssertNoErr(t, err)
|
||||
options = tools.OnlyRS(options)
|
||||
|
||||
if options.Username == "" {
|
||||
t.Fatal("Please provide a Rackspace username as RS_USERNAME.")
|
||||
}
|
||||
if options.APIKey == "" {
|
||||
t.Fatal("Please provide a Rackspace API key as RS_API_KEY.")
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
func createClient(t *testing.T, cdn bool) (*gophercloud.ServiceClient, error) {
|
||||
region := os.Getenv("RS_REGION")
|
||||
if region == "" {
|
||||
t.Fatal("Please provide a Rackspace region as RS_REGION")
|
||||
}
|
||||
|
||||
ao := rackspaceAuthOptions(t)
|
||||
|
||||
provider, err := rackspace.NewClient(ao.IdentityEndpoint)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
err = rackspace.Authenticate(provider, ao)
|
||||
th.AssertNoErr(t, err)
|
||||
|
||||
if cdn {
|
||||
return rackspace.NewObjectCDNV1(provider, gophercloud.EndpointOpts{
|
||||
Region: region,
|
||||
})
|
||||
}
|
||||
|
||||
return rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
|
||||
Region: region,
|
||||
})
|
||||
}
|
45
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/orchestration/v1/common.go
generated
vendored
45
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/orchestration/v1/common.go
generated
vendored
@@ -1,45 +0,0 @@
|
||||
// +build acceptance
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/rackspace"
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
)
|
||||
|
||||
var template = fmt.Sprintf(`
|
||||
{
|
||||
"heat_template_version": "2013-05-23",
|
||||
"description": "Simple template to test heat commands",
|
||||
"parameters": {},
|
||||
"resources": {
|
||||
"hello_world": {
|
||||
"type":"OS::Nova::Server",
|
||||
"properties": {
|
||||
"flavor": "%s",
|
||||
"image": "%s",
|
||||
"user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`, os.Getenv("RS_FLAVOR_ID"), os.Getenv("RS_IMAGE_ID"))
|
||||
|
||||
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.NewOrchestrationV1(client, gophercloud.EndpointOpts{
|
||||
Region: os.Getenv("RS_REGION_NAME"),
|
||||
})
|
||||
th.AssertNoErr(t, err)
|
||||
return c
|
||||
}
|
1
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/pkg.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/pkg.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package rackspace
|
26
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/common.go
generated
vendored
26
vendor/github.com/rackspace/gophercloud/acceptance/rackspace/rackconnect/v3/common.go
generated
vendored
@@ -1,26 +0,0 @@
|
||||
// +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
|
||||
}
|
1
vendor/github.com/rackspace/gophercloud/acceptance/tools/pkg.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/acceptance/tools/pkg.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package tools
|
89
vendor/github.com/rackspace/gophercloud/acceptance/tools/tools.go
generated
vendored
89
vendor/github.com/rackspace/gophercloud/acceptance/tools/tools.go
generated
vendored
@@ -1,89 +0,0 @@
|
||||
// +build acceptance common
|
||||
|
||||
package tools
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
mrand "math/rand"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
)
|
||||
|
||||
// ErrTimeout is returned if WaitFor takes longer than 300 second to happen.
|
||||
var ErrTimeout = errors.New("Timed out")
|
||||
|
||||
// OnlyRS overrides the default Gophercloud behavior of using OS_-prefixed environment variables
|
||||
// if RS_ variables aren't present. Otherwise, they'll stomp over each other here in the acceptance
|
||||
// tests, where you need to have both defined.
|
||||
func OnlyRS(original gophercloud.AuthOptions) gophercloud.AuthOptions {
|
||||
if os.Getenv("RS_AUTH_URL") == "" {
|
||||
original.IdentityEndpoint = ""
|
||||
}
|
||||
if os.Getenv("RS_USERNAME") == "" {
|
||||
original.Username = ""
|
||||
}
|
||||
if os.Getenv("RS_PASSWORD") == "" {
|
||||
original.Password = ""
|
||||
}
|
||||
if os.Getenv("RS_API_KEY") == "" {
|
||||
original.APIKey = ""
|
||||
}
|
||||
return original
|
||||
}
|
||||
|
||||
// WaitFor polls a predicate function once per second to wait for a certain state to arrive.
|
||||
func WaitFor(predicate func() (bool, error)) error {
|
||||
for i := 0; i < 300; i++ {
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
satisfied, err := predicate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if satisfied {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return ErrTimeout
|
||||
}
|
||||
|
||||
// MakeNewPassword generates a new string that's guaranteed to be different than the given one.
|
||||
func MakeNewPassword(oldPass string) string {
|
||||
randomPassword := RandomString("", 16)
|
||||
for randomPassword == oldPass {
|
||||
randomPassword = RandomString("", 16)
|
||||
}
|
||||
return randomPassword
|
||||
}
|
||||
|
||||
// RandomString generates a string of given length, but random content.
|
||||
// All content will be within the ASCII graphic character set.
|
||||
// (Implementation from Even Shaw's contribution on
|
||||
// http://stackoverflow.com/questions/12771930/what-is-the-fastest-way-to-generate-a-long-random-string-in-go).
|
||||
func RandomString(prefix string, n int) string {
|
||||
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
var bytes = make([]byte, n)
|
||||
rand.Read(bytes)
|
||||
for i, b := range bytes {
|
||||
bytes[i] = alphanum[b%byte(len(alphanum))]
|
||||
}
|
||||
return prefix + string(bytes)
|
||||
}
|
||||
|
||||
// RandomInt will return a random integer between a specified range.
|
||||
func RandomInt(min, max int) int {
|
||||
mrand.Seed(time.Now().Unix())
|
||||
return mrand.Intn(max-min) + min
|
||||
}
|
||||
|
||||
// Elide returns the first bit of its input string with a suffix of "..." if it's longer than
|
||||
// a comfortable 40 characters.
|
||||
func Elide(value string) string {
|
||||
if len(value) > 40 {
|
||||
return value[0:37] + "..."
|
||||
}
|
||||
return value
|
||||
}
|
3
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/apiversions/doc.go
generated
vendored
3
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/apiversions/doc.go
generated
vendored
@@ -1,3 +0,0 @@
|
||||
// Package apiversions provides information and interaction with the different
|
||||
// API versions for the OpenStack Block Storage service, code-named Cinder.
|
||||
package apiversions
|
@@ -1,21 +0,0 @@
|
||||
package apiversions
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// List lists all the Cinder API versions available to end-users.
|
||||
func List(c *gophercloud.ServiceClient) pagination.Pager {
|
||||
return pagination.NewPager(c, listURL(c), func(r pagination.PageResult) pagination.Page {
|
||||
return APIVersionPage{pagination.SinglePageBase(r)}
|
||||
})
|
||||
}
|
||||
|
||||
// Get will retrieve the volume type with the provided ID. To extract the volume
|
||||
// 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.Get(getURL(client, v), &res.Body, nil)
|
||||
return res
|
||||
}
|
58
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/apiversions/results.go
generated
vendored
58
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/apiversions/results.go
generated
vendored
@@ -1,58 +0,0 @@
|
||||
package apiversions
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// APIVersion represents an API version for Cinder.
|
||||
type APIVersion struct {
|
||||
ID string `json:"id" mapstructure:"id"` // unique identifier
|
||||
Status string `json:"status" mapstructure:"status"` // current status
|
||||
Updated string `json:"updated" mapstructure:"updated"` // date last updated
|
||||
}
|
||||
|
||||
// APIVersionPage is the page returned by a pager when traversing over a
|
||||
// collection of API versions.
|
||||
type APIVersionPage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty checks whether an APIVersionPage struct is empty.
|
||||
func (r APIVersionPage) IsEmpty() (bool, error) {
|
||||
is, err := ExtractAPIVersions(r)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return len(is) == 0, nil
|
||||
}
|
||||
|
||||
// ExtractAPIVersions takes a collection page, extracts all of the elements,
|
||||
// and returns them a slice of APIVersion structs. It is effectively a cast.
|
||||
func ExtractAPIVersions(page pagination.Page) ([]APIVersion, error) {
|
||||
var resp struct {
|
||||
Versions []APIVersion `mapstructure:"versions"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(page.(APIVersionPage).Body, &resp)
|
||||
|
||||
return resp.Versions, err
|
||||
}
|
||||
|
||||
// GetResult represents the result of a get operation.
|
||||
type GetResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a function that accepts a result and extracts an API version resource.
|
||||
func (r GetResult) Extract() (*APIVersion, error) {
|
||||
var resp struct {
|
||||
Version *APIVersion `mapstructure:"version"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(r.Body, &resp)
|
||||
|
||||
return resp.Version, err
|
||||
}
|
18
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/apiversions/urls.go
generated
vendored
18
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/apiversions/urls.go
generated
vendored
@@ -1,18 +0,0 @@
|
||||
package apiversions
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"net/url"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
)
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient, version string) string {
|
||||
return c.ServiceURL(strings.TrimRight(version, "/") + "/")
|
||||
}
|
||||
|
||||
func listURL(c *gophercloud.ServiceClient) string {
|
||||
u, _ := url.Parse(c.ServiceURL(""))
|
||||
u.Path = "/"
|
||||
return u.String()
|
||||
}
|
5
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/doc.go
generated
vendored
5
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/doc.go
generated
vendored
@@ -1,5 +0,0 @@
|
||||
// Package snapshots provides information and interaction with snapshots in the
|
||||
// OpenStack Block Storage service. A snapshot is a point in time copy of the
|
||||
// data contained in an external storage volume, and can be controlled
|
||||
// programmatically.
|
||||
package snapshots
|
114
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/fixtures.go
generated
vendored
114
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/fixtures.go
generated
vendored
@@ -1,114 +0,0 @@
|
||||
package snapshots
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
func MockListResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/snapshots", 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")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"snapshots": [
|
||||
{
|
||||
"id": "289da7f8-6440-407c-9fb4-7db01ec49164",
|
||||
"display_name": "snapshot-001"
|
||||
},
|
||||
{
|
||||
"id": "96c3bda7-c82a-4f50-be73-ca7621794835",
|
||||
"display_name": "snapshot-002"
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func MockGetResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/snapshots/d32019d3-bc6e-4319-9c1d-6722fc136a22", 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")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"snapshot": {
|
||||
"display_name": "snapshot-001",
|
||||
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func MockCreateResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/snapshots", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
th.TestHeader(t, r, "Content-Type", "application/json")
|
||||
th.TestHeader(t, r, "Accept", "application/json")
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"snapshot": {
|
||||
"volume_id": "1234",
|
||||
"display_name": "snapshot-001"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"snapshot": {
|
||||
"volume_id": "1234",
|
||||
"display_name": "snapshot-001",
|
||||
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func MockUpdateMetadataResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/snapshots/123/metadata", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "PUT")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
th.TestHeader(t, r, "Content-Type", "application/json")
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"metadata": {
|
||||
"key": "v1"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"metadata": {
|
||||
"key": "v1"
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func MockDeleteResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/snapshots/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "DELETE")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
}
|
206
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/requests.go
generated
vendored
206
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/requests.go
generated
vendored
@@ -1,206 +0,0 @@
|
||||
package snapshots
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// CreateOptsBuilder allows extensions to add additional parameters to the
|
||||
// Create request.
|
||||
type CreateOptsBuilder interface {
|
||||
ToSnapshotCreateMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// CreateOpts contains options for creating a Snapshot. This object is passed to
|
||||
// the snapshots.Create function. For more information about these parameters,
|
||||
// see the Snapshot object.
|
||||
type CreateOpts struct {
|
||||
// OPTIONAL
|
||||
Description string
|
||||
// OPTIONAL
|
||||
Force bool
|
||||
// OPTIONAL
|
||||
Metadata map[string]interface{}
|
||||
// OPTIONAL
|
||||
Name string
|
||||
// REQUIRED
|
||||
VolumeID string
|
||||
}
|
||||
|
||||
// ToSnapshotCreateMap assembles a request body based on the contents of a
|
||||
// CreateOpts.
|
||||
func (opts CreateOpts) ToSnapshotCreateMap() (map[string]interface{}, error) {
|
||||
s := make(map[string]interface{})
|
||||
|
||||
if opts.VolumeID == "" {
|
||||
return nil, fmt.Errorf("Required CreateOpts field 'VolumeID' not set.")
|
||||
}
|
||||
s["volume_id"] = opts.VolumeID
|
||||
|
||||
if opts.Description != "" {
|
||||
s["display_description"] = opts.Description
|
||||
}
|
||||
if opts.Force == true {
|
||||
s["force"] = opts.Force
|
||||
}
|
||||
if opts.Metadata != nil {
|
||||
s["metadata"] = opts.Metadata
|
||||
}
|
||||
if opts.Name != "" {
|
||||
s["display_name"] = opts.Name
|
||||
}
|
||||
|
||||
return map[string]interface{}{"snapshot": s}, nil
|
||||
}
|
||||
|
||||
// Create will create a new Snapshot based on the values in CreateOpts. To
|
||||
// extract the Snapshot object from the response, call the Extract method on the
|
||||
// CreateResult.
|
||||
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
||||
var res CreateResult
|
||||
|
||||
reqBody, err := opts.ToSnapshotCreateMap()
|
||||
if err != nil {
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete will delete the existing Snapshot with the provided ID.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Delete(deleteURL(client, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves the Snapshot with the provided ID. To extract the Snapshot
|
||||
// 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.Get(getURL(client, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// ListOptsBuilder allows extensions to add additional parameters to the List
|
||||
// request.
|
||||
type ListOptsBuilder interface {
|
||||
ToSnapshotListQuery() (string, error)
|
||||
}
|
||||
|
||||
// ListOpts hold options for listing Snapshots. It is passed to the
|
||||
// snapshots.List function.
|
||||
type ListOpts struct {
|
||||
Name string `q:"display_name"`
|
||||
Status string `q:"status"`
|
||||
VolumeID string `q:"volume_id"`
|
||||
}
|
||||
|
||||
// ToSnapshotListQuery formats a ListOpts into a query string.
|
||||
func (opts ListOpts) ToSnapshotListQuery() (string, error) {
|
||||
q, err := gophercloud.BuildQueryString(opts)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return q.String(), nil
|
||||
}
|
||||
|
||||
// List returns Snapshots optionally limited by the conditions provided in
|
||||
// ListOpts.
|
||||
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
|
||||
url := listURL(client)
|
||||
if opts != nil {
|
||||
query, err := opts.ToSnapshotListQuery()
|
||||
if err != nil {
|
||||
return pagination.Pager{Err: err}
|
||||
}
|
||||
url += query
|
||||
}
|
||||
|
||||
createPage := func(r pagination.PageResult) pagination.Page {
|
||||
return ListResult{pagination.SinglePageBase(r)}
|
||||
}
|
||||
return pagination.NewPager(client, url, createPage)
|
||||
}
|
||||
|
||||
// UpdateMetadataOptsBuilder allows extensions to add additional parameters to
|
||||
// the Update request.
|
||||
type UpdateMetadataOptsBuilder interface {
|
||||
ToSnapshotUpdateMetadataMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// UpdateMetadataOpts contain options for updating an existing Snapshot. This
|
||||
// object is passed to the snapshots.Update function. For more information
|
||||
// about the parameters, see the Snapshot object.
|
||||
type UpdateMetadataOpts struct {
|
||||
Metadata map[string]interface{}
|
||||
}
|
||||
|
||||
// ToSnapshotUpdateMetadataMap assembles a request body based on the contents of
|
||||
// an UpdateMetadataOpts.
|
||||
func (opts UpdateMetadataOpts) ToSnapshotUpdateMetadataMap() (map[string]interface{}, error) {
|
||||
v := make(map[string]interface{})
|
||||
|
||||
if opts.Metadata != nil {
|
||||
v["metadata"] = opts.Metadata
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// UpdateMetadata will update the Snapshot with provided information. To
|
||||
// extract the updated Snapshot from the response, call the ExtractMetadata
|
||||
// method on the UpdateMetadataResult.
|
||||
func UpdateMetadata(client *gophercloud.ServiceClient, id string, opts UpdateMetadataOptsBuilder) UpdateMetadataResult {
|
||||
var res UpdateMetadataResult
|
||||
|
||||
reqBody, err := opts.ToSnapshotUpdateMetadataMap()
|
||||
if err != nil {
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Put(updateMetadataURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
// IDFromName is a convienience function that returns a snapshot's ID given its name.
|
||||
func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) {
|
||||
snapshotCount := 0
|
||||
snapshotID := ""
|
||||
if name == "" {
|
||||
return "", fmt.Errorf("A snapshot name must be provided.")
|
||||
}
|
||||
pager := List(client, nil)
|
||||
pager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
snapshotList, err := ExtractSnapshots(page)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, s := range snapshotList {
|
||||
if s.Name == name {
|
||||
snapshotCount++
|
||||
snapshotID = s.ID
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
|
||||
switch snapshotCount {
|
||||
case 0:
|
||||
return "", fmt.Errorf("Unable to find snapshot: %s", name)
|
||||
case 1:
|
||||
return snapshotID, nil
|
||||
default:
|
||||
return "", fmt.Errorf("Found %d snapshots matching %s", snapshotCount, name)
|
||||
}
|
||||
}
|
123
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/results.go
generated
vendored
123
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/results.go
generated
vendored
@@ -1,123 +0,0 @@
|
||||
package snapshots
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// Snapshot contains all the information associated with an OpenStack Snapshot.
|
||||
type Snapshot struct {
|
||||
// Currect status of the Snapshot.
|
||||
Status string `mapstructure:"status"`
|
||||
|
||||
// Display name.
|
||||
Name string `mapstructure:"display_name"`
|
||||
|
||||
// Instances onto which the Snapshot is attached.
|
||||
Attachments []string `mapstructure:"attachments"`
|
||||
|
||||
// Logical group.
|
||||
AvailabilityZone string `mapstructure:"availability_zone"`
|
||||
|
||||
// Is the Snapshot bootable?
|
||||
Bootable string `mapstructure:"bootable"`
|
||||
|
||||
// Date created.
|
||||
CreatedAt string `mapstructure:"created_at"`
|
||||
|
||||
// Display description.
|
||||
Description string `mapstructure:"display_discription"`
|
||||
|
||||
// See VolumeType object for more information.
|
||||
VolumeType string `mapstructure:"volume_type"`
|
||||
|
||||
// ID of the Snapshot from which this Snapshot was created.
|
||||
SnapshotID string `mapstructure:"snapshot_id"`
|
||||
|
||||
// ID of the Volume from which this Snapshot was created.
|
||||
VolumeID string `mapstructure:"volume_id"`
|
||||
|
||||
// User-defined key-value pairs.
|
||||
Metadata map[string]string `mapstructure:"metadata"`
|
||||
|
||||
// Unique identifier.
|
||||
ID string `mapstructure:"id"`
|
||||
|
||||
// Size of the Snapshot, in GB.
|
||||
Size int `mapstructure:"size"`
|
||||
}
|
||||
|
||||
// CreateResult contains the response body and error from a Create request.
|
||||
type CreateResult struct {
|
||||
commonResult
|
||||
}
|
||||
|
||||
// GetResult contains the response body and error from a Get request.
|
||||
type GetResult struct {
|
||||
commonResult
|
||||
}
|
||||
|
||||
// DeleteResult contains the response body and error from a Delete request.
|
||||
type DeleteResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
||||
|
||||
// ListResult is a pagination.Pager that is returned from a call to the List function.
|
||||
type ListResult struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty returns true if a ListResult contains no Snapshots.
|
||||
func (r ListResult) IsEmpty() (bool, error) {
|
||||
volumes, err := ExtractSnapshots(r)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return len(volumes) == 0, nil
|
||||
}
|
||||
|
||||
// ExtractSnapshots extracts and returns Snapshots. It is used while iterating over a snapshots.List call.
|
||||
func ExtractSnapshots(page pagination.Page) ([]Snapshot, error) {
|
||||
var response struct {
|
||||
Snapshots []Snapshot `json:"snapshots"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(page.(ListResult).Body, &response)
|
||||
return response.Snapshots, err
|
||||
}
|
||||
|
||||
// UpdateMetadataResult contains the response body and error from an UpdateMetadata request.
|
||||
type UpdateMetadataResult struct {
|
||||
commonResult
|
||||
}
|
||||
|
||||
// ExtractMetadata returns the metadata from a response from snapshots.UpdateMetadata.
|
||||
func (r UpdateMetadataResult) ExtractMetadata() (map[string]interface{}, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
m := r.Body.(map[string]interface{})["metadata"]
|
||||
return m.(map[string]interface{}), nil
|
||||
}
|
||||
|
||||
type commonResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract will get the Snapshot object out of the commonResult object.
|
||||
func (r commonResult) Extract() (*Snapshot, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
var res struct {
|
||||
Snapshot *Snapshot `json:"snapshot"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
|
||||
return res.Snapshot, err
|
||||
}
|
27
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/urls.go
generated
vendored
27
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/urls.go
generated
vendored
@@ -1,27 +0,0 @@
|
||||
package snapshots
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
func createURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL("snapshots")
|
||||
}
|
||||
|
||||
func deleteURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL("snapshots", id)
|
||||
}
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return deleteURL(c, id)
|
||||
}
|
||||
|
||||
func listURL(c *gophercloud.ServiceClient) string {
|
||||
return createURL(c)
|
||||
}
|
||||
|
||||
func metadataURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL("snapshots", id, "metadata")
|
||||
}
|
||||
|
||||
func updateMetadataURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return metadataURL(c, id)
|
||||
}
|
22
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/util.go
generated
vendored
22
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots/util.go
generated
vendored
@@ -1,22 +0,0 @@
|
||||
package snapshots
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
)
|
||||
|
||||
// WaitForStatus will continually poll the resource, checking for a particular
|
||||
// status. It will do this for the amount of seconds defined.
|
||||
func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error {
|
||||
return gophercloud.WaitFor(secs, func() (bool, error) {
|
||||
current, err := Get(c, id).Extract()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if current.Status == status {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
})
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
/*
|
||||
This is package created is to hold fixtures (which imports testing),
|
||||
so that importing volumes package does not inadvertently import testing into production code
|
||||
More information here:
|
||||
https://github.com/rackspace/gophercloud/issues/473
|
||||
*/
|
||||
package testing
|
@@ -1,113 +0,0 @@
|
||||
package testing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
func MockListResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/volumes", 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")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"volumes": [
|
||||
{
|
||||
"id": "289da7f8-6440-407c-9fb4-7db01ec49164",
|
||||
"display_name": "vol-001"
|
||||
},
|
||||
{
|
||||
"id": "96c3bda7-c82a-4f50-be73-ca7621794835",
|
||||
"display_name": "vol-002"
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func MockGetResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", 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")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"volume": {
|
||||
"display_name": "vol-001",
|
||||
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
|
||||
"attachments": [
|
||||
{
|
||||
"device": "/dev/vde",
|
||||
"server_id": "a740d24b-dc5b-4d59-ac75-53971c2920ba",
|
||||
"id": "d6da11e5-2ed3-413e-88d8-b772ba62193d",
|
||||
"volume_id": "d6da11e5-2ed3-413e-88d8-b772ba62193d"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func MockCreateResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
th.TestHeader(t, r, "Content-Type", "application/json")
|
||||
th.TestHeader(t, r, "Accept", "application/json")
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"volume": {
|
||||
"size": 75
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"volume": {
|
||||
"size": 4,
|
||||
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func MockDeleteResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "DELETE")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
}
|
||||
|
||||
func MockUpdateResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "PUT")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"volume": {
|
||||
"display_name": "vol-002",
|
||||
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
9
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumetypes/doc.go
generated
vendored
9
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumetypes/doc.go
generated
vendored
@@ -1,9 +0,0 @@
|
||||
// Package volumetypes provides information and interaction with volume types
|
||||
// in the OpenStack Block Storage service. A volume type indicates the type of
|
||||
// a block storage volume, such as SATA, SCSCI, SSD, etc. These can be
|
||||
// customized or defined by the OpenStack admin.
|
||||
//
|
||||
// You can also define extra_specs associated with your volume types. For
|
||||
// instance, you could have a VolumeType=SATA, with extra_specs (RPM=10000,
|
||||
// RAID-Level=5) . Extra_specs are defined and customized by the admin.
|
||||
package volumetypes
|
@@ -1,60 +0,0 @@
|
||||
package volumetypes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
func MockListResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/types", 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")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"volume_types": [
|
||||
{
|
||||
"id": "289da7f8-6440-407c-9fb4-7db01ec49164",
|
||||
"name": "vol-type-001",
|
||||
"extra_specs": {
|
||||
"capabilities": "gpu"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "96c3bda7-c82a-4f50-be73-ca7621794835",
|
||||
"name": "vol-type-002",
|
||||
"extra_specs": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func MockGetResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc("/types/d32019d3-bc6e-4319-9c1d-6722fc136a22", 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")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"volume_type": {
|
||||
"name": "vol-type-001",
|
||||
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
|
||||
"extra_specs": {
|
||||
"serverNumber": "2"
|
||||
}
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
package volumetypes
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// CreateOptsBuilder allows extensions to add additional parameters to the
|
||||
// Create request.
|
||||
type CreateOptsBuilder interface {
|
||||
ToVolumeTypeCreateMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// CreateOpts are options for creating a volume type.
|
||||
type CreateOpts struct {
|
||||
// OPTIONAL. See VolumeType.
|
||||
ExtraSpecs map[string]interface{}
|
||||
// OPTIONAL. See VolumeType.
|
||||
Name string
|
||||
}
|
||||
|
||||
// ToVolumeTypeCreateMap casts a CreateOpts struct to a map.
|
||||
func (opts CreateOpts) ToVolumeTypeCreateMap() (map[string]interface{}, error) {
|
||||
vt := make(map[string]interface{})
|
||||
|
||||
if opts.ExtraSpecs != nil {
|
||||
vt["extra_specs"] = opts.ExtraSpecs
|
||||
}
|
||||
if opts.Name != "" {
|
||||
vt["name"] = opts.Name
|
||||
}
|
||||
|
||||
return map[string]interface{}{"volume_type": vt}, nil
|
||||
}
|
||||
|
||||
// Create will create a new volume. To extract the created volume type object,
|
||||
// call the Extract method on the CreateResult.
|
||||
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
||||
var res CreateResult
|
||||
|
||||
reqBody, err := opts.ToVolumeTypeCreateMap()
|
||||
if err != nil {
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200, 201},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete will delete the volume type with the provided ID.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
|
||||
var res DeleteResult
|
||||
_, res.Err = client.Delete(deleteURL(client, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Get will retrieve the volume type with the provided ID. To extract the volume
|
||||
// type from the result, call the Extract method on the GetResult.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, err := client.Get(getURL(client, id), &res.Body, nil)
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
// List returns all volume types.
|
||||
func List(client *gophercloud.ServiceClient) pagination.Pager {
|
||||
createPage := func(r pagination.PageResult) pagination.Page {
|
||||
return ListResult{pagination.SinglePageBase(r)}
|
||||
}
|
||||
|
||||
return pagination.NewPager(client, listURL(client), createPage)
|
||||
}
|
72
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumetypes/results.go
generated
vendored
72
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumetypes/results.go
generated
vendored
@@ -1,72 +0,0 @@
|
||||
package volumetypes
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// VolumeType contains all information associated with an OpenStack Volume Type.
|
||||
type VolumeType struct {
|
||||
ExtraSpecs map[string]interface{} `json:"extra_specs" mapstructure:"extra_specs"` // user-defined metadata
|
||||
ID string `json:"id" mapstructure:"id"` // unique identifier
|
||||
Name string `json:"name" mapstructure:"name"` // display name
|
||||
}
|
||||
|
||||
// CreateResult contains the response body and error from a Create request.
|
||||
type CreateResult struct {
|
||||
commonResult
|
||||
}
|
||||
|
||||
// GetResult contains the response body and error from a Get request.
|
||||
type GetResult struct {
|
||||
commonResult
|
||||
}
|
||||
|
||||
// DeleteResult contains the response error from a Delete request.
|
||||
type DeleteResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
||||
|
||||
// ListResult is a pagination.Pager that is returned from a call to the List function.
|
||||
type ListResult struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty returns true if a ListResult contains no Volume Types.
|
||||
func (r ListResult) IsEmpty() (bool, error) {
|
||||
volumeTypes, err := ExtractVolumeTypes(r)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return len(volumeTypes) == 0, nil
|
||||
}
|
||||
|
||||
// ExtractVolumeTypes extracts and returns Volume Types.
|
||||
func ExtractVolumeTypes(page pagination.Page) ([]VolumeType, error) {
|
||||
var response struct {
|
||||
VolumeTypes []VolumeType `mapstructure:"volume_types"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(page.(ListResult).Body, &response)
|
||||
return response.VolumeTypes, err
|
||||
}
|
||||
|
||||
type commonResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract will get the Volume Type object out of the commonResult object.
|
||||
func (r commonResult) Extract() (*VolumeType, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
var res struct {
|
||||
VolumeType *VolumeType `json:"volume_type" mapstructure:"volume_type"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
|
||||
return res.VolumeType, err
|
||||
}
|
19
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumetypes/urls.go
generated
vendored
19
vendor/github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumetypes/urls.go
generated
vendored
@@ -1,19 +0,0 @@
|
||||
package volumetypes
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
func listURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL("types")
|
||||
}
|
||||
|
||||
func createURL(c *gophercloud.ServiceClient) string {
|
||||
return listURL(c)
|
||||
}
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL("types", id)
|
||||
}
|
||||
|
||||
func deleteURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return getURL(c, id)
|
||||
}
|
4
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/doc.go
generated
vendored
4
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/doc.go
generated
vendored
@@ -1,4 +0,0 @@
|
||||
// Package base provides information and interaction with the base API
|
||||
// resource in the OpenStack CDN service. This API resource allows for
|
||||
// retrieving the Home Document and pinging the root URL.
|
||||
package base
|
53
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/fixtures.go
generated
vendored
53
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/fixtures.go
generated
vendored
@@ -1,53 +0,0 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// HandleGetSuccessfully creates an HTTP handler at `/` on the test handler mux
|
||||
// that responds with a `Get` response.
|
||||
func HandleGetSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
th.TestHeader(t, r, "Accept", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"resources": {
|
||||
"rel/cdn": {
|
||||
"href-template": "services{?marker,limit}",
|
||||
"href-vars": {
|
||||
"marker": "param/marker",
|
||||
"limit": "param/limit"
|
||||
},
|
||||
"hints": {
|
||||
"allow": [
|
||||
"GET"
|
||||
],
|
||||
"formats": {
|
||||
"application/json": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// HandlePingSuccessfully creates an HTTP handler at `/ping` on the test handler
|
||||
// mux that responds with a `Ping` response.
|
||||
func HandlePingSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "GET")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
}
|
21
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/requests.go
generated
vendored
21
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/requests.go
generated
vendored
@@ -1,21 +0,0 @@
|
||||
package base
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
// Get retrieves the home document, allowing the user to discover the
|
||||
// entire API.
|
||||
func Get(c *gophercloud.ServiceClient) GetResult {
|
||||
var res GetResult
|
||||
_, 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.Get(pingURL(c), nil, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{204},
|
||||
MoreHeaders: map[string]string{"Accept": ""},
|
||||
})
|
||||
return res
|
||||
}
|
35
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/results.go
generated
vendored
35
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/results.go
generated
vendored
@@ -1,35 +0,0 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
)
|
||||
|
||||
// HomeDocument is a resource that contains all the resources for the CDN API.
|
||||
type HomeDocument map[string]interface{}
|
||||
|
||||
// GetResult represents the result of a Get operation.
|
||||
type GetResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a function that accepts a result and extracts a home document resource.
|
||||
func (r GetResult) Extract() (*HomeDocument, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
submap, ok := r.Body.(map[string]interface{})["resources"]
|
||||
if !ok {
|
||||
return nil, errors.New("Unexpected HomeDocument structure")
|
||||
}
|
||||
casted := HomeDocument(submap.(map[string]interface{}))
|
||||
|
||||
return &casted, nil
|
||||
}
|
||||
|
||||
// PingResult represents the result of a Ping operation.
|
||||
type PingResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
11
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/urls.go
generated
vendored
11
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/base/urls.go
generated
vendored
@@ -1,11 +0,0 @@
|
||||
package base
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL()
|
||||
}
|
||||
|
||||
func pingURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL("ping")
|
||||
}
|
6
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/doc.go
generated
vendored
6
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/doc.go
generated
vendored
@@ -1,6 +0,0 @@
|
||||
// Package flavors provides information and interaction with the flavors API
|
||||
// resource in the OpenStack CDN service. This API resource allows for
|
||||
// listing flavors and retrieving a specific flavor.
|
||||
//
|
||||
// A flavor is a mapping configuration to a CDN provider.
|
||||
package flavors
|
82
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/fixtures.go
generated
vendored
82
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/fixtures.go
generated
vendored
@@ -1,82 +0,0 @@
|
||||
package flavors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
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)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"flavors": [
|
||||
{
|
||||
"id": "europe",
|
||||
"providers": [
|
||||
{
|
||||
"provider": "Fastly",
|
||||
"links": [
|
||||
{
|
||||
"href": "http://www.fastly.com",
|
||||
"rel": "provider_url"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"links": [
|
||||
{
|
||||
"href": "https://www.poppycdn.io/v1.0/flavors/europe",
|
||||
"rel": "self"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"id" : "asia",
|
||||
"providers" : [
|
||||
{
|
||||
"provider" : "ChinaCache",
|
||||
"links": [
|
||||
{
|
||||
"href": "http://www.chinacache.com",
|
||||
"rel": "provider_url"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"links": [
|
||||
{
|
||||
"href": "https://www.poppycdn.io/v1.0/flavors/asia",
|
||||
"rel": "self"
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
22
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/requests.go
generated
vendored
22
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/requests.go
generated
vendored
@@ -1,22 +0,0 @@
|
||||
package flavors
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// List returns a single page of CDN flavors.
|
||||
func List(c *gophercloud.ServiceClient) pagination.Pager {
|
||||
url := listURL(c)
|
||||
createPage := func(r pagination.PageResult) pagination.Page {
|
||||
return FlavorPage{pagination.SinglePageBase(r)}
|
||||
}
|
||||
return pagination.NewPager(c, url, createPage)
|
||||
}
|
||||
|
||||
// Get retrieves a specific flavor based on its unique ID.
|
||||
func Get(c *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Get(getURL(c, id), &res.Body, nil)
|
||||
return res
|
||||
}
|
71
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/results.go
generated
vendored
71
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/results.go
generated
vendored
@@ -1,71 +0,0 @@
|
||||
package flavors
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// Provider represents a provider for a particular flavor.
|
||||
type Provider struct {
|
||||
// Specifies the name of the provider. The name must not exceed 64 bytes in
|
||||
// length and is limited to unicode, digits, underscores, and hyphens.
|
||||
Provider string `mapstructure:"provider"`
|
||||
// Specifies a list with an href where rel is provider_url.
|
||||
Links []gophercloud.Link `mapstructure:"links"`
|
||||
}
|
||||
|
||||
// Flavor represents a mapping configuration to a CDN provider.
|
||||
type Flavor struct {
|
||||
// Specifies the name of the flavor. The name must not exceed 64 bytes in
|
||||
// length and is limited to unicode, digits, underscores, and hyphens.
|
||||
ID string `mapstructure:"id"`
|
||||
// Specifies the list of providers mapped to this flavor.
|
||||
Providers []Provider `mapstructure:"providers"`
|
||||
// Specifies the self-navigating JSON document paths.
|
||||
Links []gophercloud.Link `mapstructure:"links"`
|
||||
}
|
||||
|
||||
// FlavorPage is the page returned by a pager when traversing over a
|
||||
// collection of CDN flavors.
|
||||
type FlavorPage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty returns true if a FlavorPage contains no Flavors.
|
||||
func (r FlavorPage) IsEmpty() (bool, error) {
|
||||
flavors, err := ExtractFlavors(r)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return len(flavors) == 0, nil
|
||||
}
|
||||
|
||||
// ExtractFlavors extracts and returns Flavors. It is used while iterating over
|
||||
// a flavors.List call.
|
||||
func ExtractFlavors(page pagination.Page) ([]Flavor, error) {
|
||||
var response struct {
|
||||
Flavors []Flavor `json:"flavors"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(page.(FlavorPage).Body, &response)
|
||||
return response.Flavors, err
|
||||
}
|
||||
|
||||
// GetResult represents the result of a get operation.
|
||||
type GetResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a function that extracts a flavor from a GetResult.
|
||||
func (r GetResult) Extract() (*Flavor, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
var res Flavor
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
|
||||
return &res, err
|
||||
}
|
11
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/urls.go
generated
vendored
11
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/flavors/urls.go
generated
vendored
@@ -1,11 +0,0 @@
|
||||
package flavors
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
func listURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL("flavors")
|
||||
}
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL("flavors", id)
|
||||
}
|
7
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/doc.go
generated
vendored
7
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/doc.go
generated
vendored
@@ -1,7 +0,0 @@
|
||||
// Package serviceassets provides information and interaction with the
|
||||
// serviceassets API resource in the OpenStack CDN service. This API resource
|
||||
// allows for deleting cached assets.
|
||||
//
|
||||
// A service distributes assets across the network. Service assets let you
|
||||
// interrogate properties about these assets and perform certain actions on them.
|
||||
package serviceassets
|
19
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/fixtures.go
generated
vendored
19
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/fixtures.go
generated
vendored
@@ -1,19 +0,0 @@
|
||||
package serviceassets
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
48
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/requests.go
generated
vendored
48
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/requests.go
generated
vendored
@@ -1,48 +0,0 @@
|
||||
package serviceassets
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
)
|
||||
|
||||
// DeleteOptsBuilder allows extensions to add additional parameters to the Delete
|
||||
// request.
|
||||
type DeleteOptsBuilder interface {
|
||||
ToCDNAssetDeleteParams() (string, error)
|
||||
}
|
||||
|
||||
// DeleteOpts is a structure that holds options for deleting CDN service assets.
|
||||
type DeleteOpts struct {
|
||||
// If all is set to true, specifies that the delete occurs against all of the
|
||||
// assets for the service.
|
||||
All bool `q:"all"`
|
||||
// Specifies the relative URL of the asset to be deleted.
|
||||
URL string `q:"url"`
|
||||
}
|
||||
|
||||
// ToCDNAssetDeleteParams formats a DeleteOpts into a query string.
|
||||
func (opts DeleteOpts) ToCDNAssetDeleteParams() (string, error) {
|
||||
q, err := gophercloud.BuildQueryString(opts)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return q.String(), nil
|
||||
}
|
||||
|
||||
// Delete accepts a unique service ID or URL and deletes the CDN service asset associated with
|
||||
// it. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and
|
||||
// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0"
|
||||
// are valid options for idOrURL.
|
||||
func Delete(c *gophercloud.ServiceClient, idOrURL string, opts DeleteOptsBuilder) DeleteResult {
|
||||
var url string
|
||||
if strings.Contains(idOrURL, "/") {
|
||||
url = idOrURL
|
||||
} else {
|
||||
url = deleteURL(c, idOrURL)
|
||||
}
|
||||
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Delete(url, nil)
|
||||
return res
|
||||
}
|
8
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/results.go
generated
vendored
8
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/results.go
generated
vendored
@@ -1,8 +0,0 @@
|
||||
package serviceassets
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
// DeleteResult represents the result of a Delete operation.
|
||||
type DeleteResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
7
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/urls.go
generated
vendored
7
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/serviceassets/urls.go
generated
vendored
@@ -1,7 +0,0 @@
|
||||
package serviceassets
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
func deleteURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL("services", id, "assets")
|
||||
}
|
7
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/doc.go
generated
vendored
7
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/doc.go
generated
vendored
@@ -1,7 +0,0 @@
|
||||
// Package services provides information and interaction with the services API
|
||||
// resource in the OpenStack CDN service. This API resource allows for
|
||||
// listing, creating, updating, retrieving, and deleting services.
|
||||
//
|
||||
// A service represents an application that has its content cached to the edge
|
||||
// nodes.
|
||||
package services
|
7
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/errors.go
generated
vendored
7
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/errors.go
generated
vendored
@@ -1,7 +0,0 @@
|
||||
package services
|
||||
|
||||
import "fmt"
|
||||
|
||||
func no(str string) error {
|
||||
return fmt.Errorf("Required parameter %s not provided", str)
|
||||
}
|
372
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/fixtures.go
generated
vendored
372
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/fixtures.go
generated
vendored
@@ -1,372 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// HandleListCDNServiceSuccessfully creates an HTTP handler at `/services` on the test handler mux
|
||||
// that responds with a `List` response.
|
||||
func HandleListCDNServiceSuccessfully(t *testing.T) {
|
||||
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().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
r.ParseForm()
|
||||
marker := r.Form.Get("marker")
|
||||
switch marker {
|
||||
case "":
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"links": [
|
||||
{
|
||||
"rel": "next",
|
||||
"href": "https://www.poppycdn.io/v1.0/services?marker=96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0&limit=20"
|
||||
}
|
||||
],
|
||||
"services": [
|
||||
{
|
||||
"id": "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0",
|
||||
"name": "mywebsite.com",
|
||||
"domains": [
|
||||
{
|
||||
"domain": "www.mywebsite.com"
|
||||
}
|
||||
],
|
||||
"origins": [
|
||||
{
|
||||
"origin": "mywebsite.com",
|
||||
"port": 80,
|
||||
"ssl": false
|
||||
}
|
||||
],
|
||||
"caching": [
|
||||
{
|
||||
"name": "default",
|
||||
"ttl": 3600
|
||||
},
|
||||
{
|
||||
"name": "home",
|
||||
"ttl": 17200,
|
||||
"rules": [
|
||||
{
|
||||
"name": "index",
|
||||
"request_url": "/index.htm"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "images",
|
||||
"ttl": 12800,
|
||||
"rules": [
|
||||
{
|
||||
"name": "images",
|
||||
"request_url": "*.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mywebsite.com",
|
||||
"referrer": "www.mywebsite.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"flavor_id": "asia",
|
||||
"status": "deployed",
|
||||
"errors" : [],
|
||||
"links": [
|
||||
{
|
||||
"href": "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0",
|
||||
"rel": "self"
|
||||
},
|
||||
{
|
||||
"href": "mywebsite.com.cdn123.poppycdn.net",
|
||||
"rel": "access_url"
|
||||
},
|
||||
{
|
||||
"href": "https://www.poppycdn.io/v1.0/flavors/asia",
|
||||
"rel": "flavor"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1",
|
||||
"name": "myothersite.com",
|
||||
"domains": [
|
||||
{
|
||||
"domain": "www.myothersite.com"
|
||||
}
|
||||
],
|
||||
"origins": [
|
||||
{
|
||||
"origin": "44.33.22.11",
|
||||
"port": 80,
|
||||
"ssl": false
|
||||
},
|
||||
{
|
||||
"origin": "77.66.55.44",
|
||||
"port": 80,
|
||||
"ssl": false,
|
||||
"rules": [
|
||||
{
|
||||
"name": "videos",
|
||||
"request_url": "^/videos/*.m3u"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"caching": [
|
||||
{
|
||||
"name": "default",
|
||||
"ttl": 3600
|
||||
}
|
||||
],
|
||||
"restrictions": [
|
||||
{}
|
||||
],
|
||||
"flavor_id": "europe",
|
||||
"status": "deployed",
|
||||
"links": [
|
||||
{
|
||||
"href": "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1",
|
||||
"rel": "self"
|
||||
},
|
||||
{
|
||||
"href": "myothersite.com.poppycdn.net",
|
||||
"rel": "access_url"
|
||||
},
|
||||
{
|
||||
"href": "https://www.poppycdn.io/v1.0/flavors/europe",
|
||||
"rel": "flavor"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
case "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1":
|
||||
fmt.Fprintf(w, `{
|
||||
"services": []
|
||||
}`)
|
||||
default:
|
||||
t.Fatalf("Unexpected marker: [%s]", marker)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// HandleCreateCDNServiceSuccessfully creates an HTTP handler at `/services` on the test handler mux
|
||||
// that responds with a `Create` response.
|
||||
func HandleCreateCDNServiceSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"name": "mywebsite.com",
|
||||
"domains": [
|
||||
{
|
||||
"domain": "www.mywebsite.com"
|
||||
},
|
||||
{
|
||||
"domain": "blog.mywebsite.com"
|
||||
}
|
||||
],
|
||||
"origins": [
|
||||
{
|
||||
"origin": "mywebsite.com",
|
||||
"port": 80,
|
||||
"ssl": false
|
||||
}
|
||||
],
|
||||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mywebsite.com",
|
||||
"referrer": "www.mywebsite.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"caching": [
|
||||
{
|
||||
"name": "default",
|
||||
"ttl": 3600
|
||||
}
|
||||
],
|
||||
|
||||
"flavor_id": "cdn"
|
||||
}
|
||||
`)
|
||||
w.Header().Add("Location", "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0")
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleGetCDNServiceSuccessfully creates an HTTP handler at `/services/{id}` on the test handler mux
|
||||
// that responds with a `Get` response.
|
||||
func HandleGetCDNServiceSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", 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, `
|
||||
{
|
||||
"id": "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0",
|
||||
"name": "mywebsite.com",
|
||||
"domains": [
|
||||
{
|
||||
"domain": "www.mywebsite.com",
|
||||
"protocol": "http"
|
||||
}
|
||||
],
|
||||
"origins": [
|
||||
{
|
||||
"origin": "mywebsite.com",
|
||||
"port": 80,
|
||||
"ssl": false
|
||||
}
|
||||
],
|
||||
"caching": [
|
||||
{
|
||||
"name": "default",
|
||||
"ttl": 3600
|
||||
},
|
||||
{
|
||||
"name": "home",
|
||||
"ttl": 17200,
|
||||
"rules": [
|
||||
{
|
||||
"name": "index",
|
||||
"request_url": "/index.htm"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "images",
|
||||
"ttl": 12800,
|
||||
"rules": [
|
||||
{
|
||||
"name": "images",
|
||||
"request_url": "*.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mywebsite.com",
|
||||
"referrer": "www.mywebsite.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"flavor_id": "cdn",
|
||||
"status": "deployed",
|
||||
"errors" : [],
|
||||
"links": [
|
||||
{
|
||||
"href": "https://global.cdn.api.rackspacecloud.com/v1.0/110011/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0",
|
||||
"rel": "self"
|
||||
},
|
||||
{
|
||||
"href": "blog.mywebsite.com.cdn1.raxcdn.com",
|
||||
"rel": "access_url"
|
||||
},
|
||||
{
|
||||
"href": "https://global.cdn.api.rackspacecloud.com/v1.0/110011/flavors/cdn",
|
||||
"rel": "flavor"
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleUpdateCDNServiceSuccessfully creates an HTTP handler at `/services/{id}` on the test handler mux
|
||||
// that responds with a `Update` response.
|
||||
func HandleUpdateCDNServiceSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "PATCH")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
th.TestJSONRequest(t, r, `
|
||||
[
|
||||
{
|
||||
"op": "add",
|
||||
"path": "/domains/-",
|
||||
"value": {"domain": "appended.mocksite4.com"}
|
||||
},
|
||||
{
|
||||
"op": "add",
|
||||
"path": "/domains/4",
|
||||
"value": {"domain": "inserted.mocksite4.com"}
|
||||
},
|
||||
{
|
||||
"op": "add",
|
||||
"path": "/domains",
|
||||
"value": [
|
||||
{"domain": "bulkadded1.mocksite4.com"},
|
||||
{"domain": "bulkadded2.mocksite4.com"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/origins/2",
|
||||
"value": {"origin": "44.33.22.11", "port": 80, "ssl": false}
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/origins",
|
||||
"value": [
|
||||
{"origin": "44.33.22.11", "port": 80, "ssl": false},
|
||||
{"origin": "55.44.33.22", "port": 443, "ssl": true}
|
||||
]
|
||||
},
|
||||
{
|
||||
"op": "remove",
|
||||
"path": "/caching/8"
|
||||
},
|
||||
{
|
||||
"op": "remove",
|
||||
"path": "/caching"
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/name",
|
||||
"value": "differentServiceName"
|
||||
}
|
||||
]
|
||||
`)
|
||||
w.Header().Add("Location", "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0")
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleDeleteCDNServiceSuccessfully creates an HTTP handler at `/services/{id}` on the test handler mux
|
||||
// that responds with a `Delete` response.
|
||||
func HandleDeleteCDNServiceSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", 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)
|
||||
})
|
||||
}
|
378
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/requests.go
generated
vendored
378
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/requests.go
generated
vendored
@@ -1,378 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// ListOptsBuilder allows extensions to add additional parameters to the
|
||||
// List request.
|
||||
type ListOptsBuilder interface {
|
||||
ToCDNServiceListQuery() (string, error)
|
||||
}
|
||||
|
||||
// ListOpts allows the filtering and sorting of paginated collections through
|
||||
// the API. Marker and Limit are used for pagination.
|
||||
type ListOpts struct {
|
||||
Marker string `q:"marker"`
|
||||
Limit int `q:"limit"`
|
||||
}
|
||||
|
||||
// ToCDNServiceListQuery formats a ListOpts into a query string.
|
||||
func (opts ListOpts) ToCDNServiceListQuery() (string, error) {
|
||||
q, err := gophercloud.BuildQueryString(opts)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return q.String(), nil
|
||||
}
|
||||
|
||||
// List returns a Pager which allows you to iterate over a collection of
|
||||
// CDN services. It accepts a ListOpts struct, which allows for pagination via
|
||||
// marker and limit.
|
||||
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
|
||||
url := listURL(c)
|
||||
if opts != nil {
|
||||
query, err := opts.ToCDNServiceListQuery()
|
||||
if err != nil {
|
||||
return pagination.Pager{Err: err}
|
||||
}
|
||||
url += query
|
||||
}
|
||||
|
||||
createPage := func(r pagination.PageResult) pagination.Page {
|
||||
p := ServicePage{pagination.MarkerPageBase{PageResult: r}}
|
||||
p.MarkerPageBase.Owner = p
|
||||
return p
|
||||
}
|
||||
|
||||
pager := pagination.NewPager(c, url, createPage)
|
||||
return pager
|
||||
}
|
||||
|
||||
// CreateOptsBuilder is the interface options structs have to satisfy in order
|
||||
// to be used in the main Create operation in this package. Since many
|
||||
// extensions decorate or modify the common logic, it is useful for them to
|
||||
// satisfy a basic interface in order for them to be used.
|
||||
type CreateOptsBuilder interface {
|
||||
ToCDNServiceCreateMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// CreateOpts is the common options struct used in this package's Create
|
||||
// operation.
|
||||
type CreateOpts struct {
|
||||
// REQUIRED. Specifies the name of the service. The minimum length for name is
|
||||
// 3. The maximum length is 256.
|
||||
Name string
|
||||
// REQUIRED. Specifies a list of domains used by users to access their website.
|
||||
Domains []Domain
|
||||
// REQUIRED. Specifies a list of origin domains or IP addresses where the
|
||||
// original assets are stored.
|
||||
Origins []Origin
|
||||
// REQUIRED. Specifies the CDN provider flavor ID to use. For a list of
|
||||
// flavors, see the operation to list the available flavors. The minimum
|
||||
// length for flavor_id is 1. The maximum length is 256.
|
||||
FlavorID string
|
||||
// OPTIONAL. Specifies the TTL rules for the assets under this service. Supports wildcards for fine-grained control.
|
||||
Caching []CacheRule
|
||||
// OPTIONAL. Specifies the restrictions that define who can access assets (content from the CDN cache).
|
||||
Restrictions []Restriction
|
||||
}
|
||||
|
||||
// ToCDNServiceCreateMap casts a CreateOpts struct to a map.
|
||||
func (opts CreateOpts) ToCDNServiceCreateMap() (map[string]interface{}, error) {
|
||||
s := make(map[string]interface{})
|
||||
|
||||
if opts.Name == "" {
|
||||
return nil, no("Name")
|
||||
}
|
||||
s["name"] = opts.Name
|
||||
|
||||
if opts.Domains == nil {
|
||||
return nil, no("Domains")
|
||||
}
|
||||
for _, domain := range opts.Domains {
|
||||
if domain.Domain == "" {
|
||||
return nil, no("Domains[].Domain")
|
||||
}
|
||||
}
|
||||
s["domains"] = opts.Domains
|
||||
|
||||
if opts.Origins == nil {
|
||||
return nil, no("Origins")
|
||||
}
|
||||
for _, origin := range opts.Origins {
|
||||
if origin.Origin == "" {
|
||||
return nil, no("Origins[].Origin")
|
||||
}
|
||||
if origin.Rules == nil && len(opts.Origins) > 1 {
|
||||
return nil, no("Origins[].Rules")
|
||||
}
|
||||
for _, rule := range origin.Rules {
|
||||
if rule.Name == "" {
|
||||
return nil, no("Origins[].Rules[].Name")
|
||||
}
|
||||
if rule.RequestURL == "" {
|
||||
return nil, no("Origins[].Rules[].RequestURL")
|
||||
}
|
||||
}
|
||||
}
|
||||
s["origins"] = opts.Origins
|
||||
|
||||
if opts.FlavorID == "" {
|
||||
return nil, no("FlavorID")
|
||||
}
|
||||
s["flavor_id"] = opts.FlavorID
|
||||
|
||||
if opts.Caching != nil {
|
||||
for _, cache := range opts.Caching {
|
||||
if cache.Name == "" {
|
||||
return nil, no("Caching[].Name")
|
||||
}
|
||||
if cache.Rules != nil {
|
||||
for _, rule := range cache.Rules {
|
||||
if rule.Name == "" {
|
||||
return nil, no("Caching[].Rules[].Name")
|
||||
}
|
||||
if rule.RequestURL == "" {
|
||||
return nil, no("Caching[].Rules[].RequestURL")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
s["caching"] = opts.Caching
|
||||
}
|
||||
|
||||
if opts.Restrictions != nil {
|
||||
for _, restriction := range opts.Restrictions {
|
||||
if restriction.Name == "" {
|
||||
return nil, no("Restrictions[].Name")
|
||||
}
|
||||
if restriction.Rules != nil {
|
||||
for _, rule := range restriction.Rules {
|
||||
if rule.Name == "" {
|
||||
return nil, no("Restrictions[].Rules[].Name")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
s["restrictions"] = opts.Restrictions
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Create accepts a CreateOpts struct and creates a new CDN service using the
|
||||
// values provided.
|
||||
func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
||||
var res CreateResult
|
||||
|
||||
reqBody, err := opts.ToCDNServiceCreateMap()
|
||||
if err != nil {
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
// Send request to API
|
||||
resp, err := c.Post(createURL(c), &reqBody, nil, nil)
|
||||
res.Header = resp.Header
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
// Get retrieves a specific service based on its URL or its unique ID. For
|
||||
// example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and
|
||||
// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0"
|
||||
// are valid options for idOrURL.
|
||||
func Get(c *gophercloud.ServiceClient, idOrURL string) GetResult {
|
||||
var url string
|
||||
if strings.Contains(idOrURL, "/") {
|
||||
url = idOrURL
|
||||
} else {
|
||||
url = getURL(c, idOrURL)
|
||||
}
|
||||
|
||||
var res GetResult
|
||||
_, res.Err = c.Get(url, &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Path is a JSON pointer location that indicates which service parameter is being added, replaced,
|
||||
// or removed.
|
||||
type Path struct {
|
||||
baseElement string
|
||||
}
|
||||
|
||||
func (p Path) renderRoot() string {
|
||||
return "/" + p.baseElement
|
||||
}
|
||||
|
||||
func (p Path) renderDash() string {
|
||||
return fmt.Sprintf("/%s/-", p.baseElement)
|
||||
}
|
||||
|
||||
func (p Path) renderIndex(index int64) string {
|
||||
return fmt.Sprintf("/%s/%d", p.baseElement, index)
|
||||
}
|
||||
|
||||
var (
|
||||
// PathDomains indicates that an update operation is to be performed on a Domain.
|
||||
PathDomains = Path{baseElement: "domains"}
|
||||
|
||||
// PathOrigins indicates that an update operation is to be performed on an Origin.
|
||||
PathOrigins = Path{baseElement: "origins"}
|
||||
|
||||
// PathCaching indicates that an update operation is to be performed on a CacheRule.
|
||||
PathCaching = Path{baseElement: "caching"}
|
||||
)
|
||||
|
||||
type value interface {
|
||||
toPatchValue() interface{}
|
||||
appropriatePath() Path
|
||||
renderRootOr(func(p Path) string) string
|
||||
}
|
||||
|
||||
// Patch represents a single update to an existing Service. Multiple updates to a service can be
|
||||
// submitted at the same time.
|
||||
type Patch interface {
|
||||
ToCDNServiceUpdateMap() map[string]interface{}
|
||||
}
|
||||
|
||||
// Insertion is a Patch that requests the addition of a value (Domain, Origin, or CacheRule) to
|
||||
// a Service at a fixed index. Use an Append instead to append the new value to the end of its
|
||||
// collection. Pass it to the Update function as part of the Patch slice.
|
||||
type Insertion struct {
|
||||
Index int64
|
||||
Value value
|
||||
}
|
||||
|
||||
// ToCDNServiceUpdateMap converts an Insertion into a request body fragment suitable for the
|
||||
// Update call.
|
||||
func (i Insertion) ToCDNServiceUpdateMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"op": "add",
|
||||
"path": i.Value.renderRootOr(func(p Path) string { return p.renderIndex(i.Index) }),
|
||||
"value": i.Value.toPatchValue(),
|
||||
}
|
||||
}
|
||||
|
||||
// Append is a Patch that requests the addition of a value (Domain, Origin, or CacheRule) to a
|
||||
// Service at the end of its respective collection. Use an Insertion instead to insert the value
|
||||
// at a fixed index within the collection. Pass this to the Update function as part of its
|
||||
// Patch slice.
|
||||
type Append struct {
|
||||
Value value
|
||||
}
|
||||
|
||||
// ToCDNServiceUpdateMap converts an Append into a request body fragment suitable for the
|
||||
// Update call.
|
||||
func (a Append) ToCDNServiceUpdateMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"op": "add",
|
||||
"path": a.Value.renderRootOr(func(p Path) string { return p.renderDash() }),
|
||||
"value": a.Value.toPatchValue(),
|
||||
}
|
||||
}
|
||||
|
||||
// Replacement is a Patch that alters a specific service parameter (Domain, Origin, or CacheRule)
|
||||
// in-place by index. Pass it to the Update function as part of the Patch slice.
|
||||
type Replacement struct {
|
||||
Value value
|
||||
Index int64
|
||||
}
|
||||
|
||||
// ToCDNServiceUpdateMap converts a Replacement into a request body fragment suitable for the
|
||||
// Update call.
|
||||
func (r Replacement) ToCDNServiceUpdateMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"op": "replace",
|
||||
"path": r.Value.renderRootOr(func(p Path) string { return p.renderIndex(r.Index) }),
|
||||
"value": r.Value.toPatchValue(),
|
||||
}
|
||||
}
|
||||
|
||||
// NameReplacement specifically updates the Service name. Pass it to the Update function as part
|
||||
// of the Patch slice.
|
||||
type NameReplacement struct {
|
||||
NewName string
|
||||
}
|
||||
|
||||
// ToCDNServiceUpdateMap converts a NameReplacement into a request body fragment suitable for the
|
||||
// Update call.
|
||||
func (r NameReplacement) ToCDNServiceUpdateMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"op": "replace",
|
||||
"path": "/name",
|
||||
"value": r.NewName,
|
||||
}
|
||||
}
|
||||
|
||||
// Removal is a Patch that requests the removal of a service parameter (Domain, Origin, or
|
||||
// CacheRule) by index. Pass it to the Update function as part of the Patch slice.
|
||||
type Removal struct {
|
||||
Path Path
|
||||
Index int64
|
||||
All bool
|
||||
}
|
||||
|
||||
// ToCDNServiceUpdateMap converts a Removal into a request body fragment suitable for the
|
||||
// Update call.
|
||||
func (r Removal) ToCDNServiceUpdateMap() map[string]interface{} {
|
||||
result := map[string]interface{}{"op": "remove"}
|
||||
if r.All {
|
||||
result["path"] = r.Path.renderRoot()
|
||||
} else {
|
||||
result["path"] = r.Path.renderIndex(r.Index)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
type UpdateOpts []Patch
|
||||
|
||||
// Update accepts a slice of Patch operations (Insertion, Append, Replacement or Removal) and
|
||||
// updates an existing CDN service using the values provided. idOrURL can be either the service's
|
||||
// URL or its ID. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and
|
||||
// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0"
|
||||
// are valid options for idOrURL.
|
||||
func Update(c *gophercloud.ServiceClient, idOrURL string, opts UpdateOpts) UpdateResult {
|
||||
var url string
|
||||
if strings.Contains(idOrURL, "/") {
|
||||
url = idOrURL
|
||||
} else {
|
||||
url = updateURL(c, idOrURL)
|
||||
}
|
||||
|
||||
reqBody := make([]map[string]interface{}, len(opts))
|
||||
for i, patch := range opts {
|
||||
reqBody[i] = patch.ToCDNServiceUpdateMap()
|
||||
}
|
||||
|
||||
resp, err := c.Request("PATCH", url, gophercloud.RequestOpts{
|
||||
JSONBody: &reqBody,
|
||||
OkCodes: []int{202},
|
||||
})
|
||||
var result UpdateResult
|
||||
result.Header = resp.Header
|
||||
result.Err = err
|
||||
return result
|
||||
}
|
||||
|
||||
// Delete accepts a service's ID or its URL and deletes the CDN service
|
||||
// associated with it. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and
|
||||
// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0"
|
||||
// are valid options for idOrURL.
|
||||
func Delete(c *gophercloud.ServiceClient, idOrURL string) DeleteResult {
|
||||
var url string
|
||||
if strings.Contains(idOrURL, "/") {
|
||||
url = idOrURL
|
||||
} else {
|
||||
url = deleteURL(c, idOrURL)
|
||||
}
|
||||
|
||||
var res DeleteResult
|
||||
_, res.Err = c.Delete(url, nil)
|
||||
return res
|
||||
}
|
316
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/results.go
generated
vendored
316
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/results.go
generated
vendored
@@ -1,316 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// Domain represents a domain used by users to access their website.
|
||||
type Domain struct {
|
||||
// Specifies the domain used to access the assets on their website, for which
|
||||
// a CNAME is given to the CDN provider.
|
||||
Domain string `mapstructure:"domain" json:"domain"`
|
||||
// Specifies the protocol used to access the assets on this domain. Only "http"
|
||||
// or "https" are currently allowed. The default is "http".
|
||||
Protocol string `mapstructure:"protocol" json:"protocol,omitempty"`
|
||||
}
|
||||
|
||||
func (d Domain) toPatchValue() interface{} {
|
||||
r := make(map[string]interface{})
|
||||
r["domain"] = d.Domain
|
||||
if d.Protocol != "" {
|
||||
r["protocol"] = d.Protocol
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (d Domain) appropriatePath() Path {
|
||||
return PathDomains
|
||||
}
|
||||
|
||||
func (d Domain) renderRootOr(render func(p Path) string) string {
|
||||
return render(d.appropriatePath())
|
||||
}
|
||||
|
||||
// DomainList provides a useful way to perform bulk operations in a single Patch.
|
||||
type DomainList []Domain
|
||||
|
||||
func (list DomainList) toPatchValue() interface{} {
|
||||
r := make([]interface{}, len(list))
|
||||
for i, domain := range list {
|
||||
r[i] = domain.toPatchValue()
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (list DomainList) appropriatePath() Path {
|
||||
return PathDomains
|
||||
}
|
||||
|
||||
func (list DomainList) renderRootOr(_ func(p Path) string) string {
|
||||
return list.appropriatePath().renderRoot()
|
||||
}
|
||||
|
||||
// OriginRule represents a rule that defines when an origin should be accessed.
|
||||
type OriginRule struct {
|
||||
// Specifies the name of this rule.
|
||||
Name string `mapstructure:"name" json:"name"`
|
||||
// Specifies the request URL this rule should match for this origin to be used. Regex is supported.
|
||||
RequestURL string `mapstructure:"request_url" json:"request_url"`
|
||||
}
|
||||
|
||||
// Origin specifies a list of origin domains or IP addresses where the original assets are stored.
|
||||
type Origin struct {
|
||||
// Specifies the URL or IP address to pull origin content from.
|
||||
Origin string `mapstructure:"origin" json:"origin"`
|
||||
// Specifies the port used to access the origin. The default is port 80.
|
||||
Port int `mapstructure:"port" json:"port,omitempty"`
|
||||
// Specifies whether or not to use HTTPS to access the origin. The default
|
||||
// is false.
|
||||
SSL bool `mapstructure:"ssl" json:"ssl"`
|
||||
// Specifies a collection of rules that define the conditions when this origin
|
||||
// should be accessed. If there is more than one origin, the rules parameter is required.
|
||||
Rules []OriginRule `mapstructure:"rules" json:"rules,omitempty"`
|
||||
}
|
||||
|
||||
func (o Origin) toPatchValue() interface{} {
|
||||
r := make(map[string]interface{})
|
||||
r["origin"] = o.Origin
|
||||
r["port"] = o.Port
|
||||
r["ssl"] = o.SSL
|
||||
if len(o.Rules) > 0 {
|
||||
r["rules"] = make([]map[string]interface{}, len(o.Rules))
|
||||
for index, rule := range o.Rules {
|
||||
submap := r["rules"].([]map[string]interface{})[index]
|
||||
submap["name"] = rule.Name
|
||||
submap["request_url"] = rule.RequestURL
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (o Origin) appropriatePath() Path {
|
||||
return PathOrigins
|
||||
}
|
||||
|
||||
func (o Origin) renderRootOr(render func(p Path) string) string {
|
||||
return render(o.appropriatePath())
|
||||
}
|
||||
|
||||
// OriginList provides a useful way to perform bulk operations in a single Patch.
|
||||
type OriginList []Origin
|
||||
|
||||
func (list OriginList) toPatchValue() interface{} {
|
||||
r := make([]interface{}, len(list))
|
||||
for i, origin := range list {
|
||||
r[i] = origin.toPatchValue()
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (list OriginList) appropriatePath() Path {
|
||||
return PathOrigins
|
||||
}
|
||||
|
||||
func (list OriginList) renderRootOr(_ func(p Path) string) string {
|
||||
return list.appropriatePath().renderRoot()
|
||||
}
|
||||
|
||||
// TTLRule specifies a rule that determines if a TTL should be applied to an asset.
|
||||
type TTLRule struct {
|
||||
// Specifies the name of this rule.
|
||||
Name string `mapstructure:"name" json:"name"`
|
||||
// Specifies the request URL this rule should match for this TTL to be used. Regex is supported.
|
||||
RequestURL string `mapstructure:"request_url" json:"request_url"`
|
||||
}
|
||||
|
||||
// CacheRule specifies the TTL rules for the assets under this service.
|
||||
type CacheRule struct {
|
||||
// Specifies the name of this caching rule. Note: 'default' is a reserved name used for the default TTL setting.
|
||||
Name string `mapstructure:"name" json:"name"`
|
||||
// Specifies the TTL to apply.
|
||||
TTL int `mapstructure:"ttl" json:"ttl"`
|
||||
// Specifies a collection of rules that determine if this TTL should be applied to an asset.
|
||||
Rules []TTLRule `mapstructure:"rules" json:"rules,omitempty"`
|
||||
}
|
||||
|
||||
func (c CacheRule) toPatchValue() interface{} {
|
||||
r := make(map[string]interface{})
|
||||
r["name"] = c.Name
|
||||
r["ttl"] = c.TTL
|
||||
r["rules"] = make([]map[string]interface{}, len(c.Rules))
|
||||
for index, rule := range c.Rules {
|
||||
submap := r["rules"].([]map[string]interface{})[index]
|
||||
submap["name"] = rule.Name
|
||||
submap["request_url"] = rule.RequestURL
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (c CacheRule) appropriatePath() Path {
|
||||
return PathCaching
|
||||
}
|
||||
|
||||
func (c CacheRule) renderRootOr(render func(p Path) string) string {
|
||||
return render(c.appropriatePath())
|
||||
}
|
||||
|
||||
// CacheRuleList provides a useful way to perform bulk operations in a single Patch.
|
||||
type CacheRuleList []CacheRule
|
||||
|
||||
func (list CacheRuleList) toPatchValue() interface{} {
|
||||
r := make([]interface{}, len(list))
|
||||
for i, rule := range list {
|
||||
r[i] = rule.toPatchValue()
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (list CacheRuleList) appropriatePath() Path {
|
||||
return PathCaching
|
||||
}
|
||||
|
||||
func (list CacheRuleList) renderRootOr(_ func(p Path) string) string {
|
||||
return list.appropriatePath().renderRoot()
|
||||
}
|
||||
|
||||
// RestrictionRule specifies a rule that determines if this restriction should be applied to an asset.
|
||||
type RestrictionRule struct {
|
||||
// Specifies the name of this rule.
|
||||
Name string `mapstructure:"name" json:"name"`
|
||||
// Specifies the http host that requests must come from.
|
||||
Referrer string `mapstructure:"referrer" json:"referrer,omitempty"`
|
||||
}
|
||||
|
||||
// Restriction specifies a restriction that defines who can access assets (content from the CDN cache).
|
||||
type Restriction struct {
|
||||
// Specifies the name of this restriction.
|
||||
Name string `mapstructure:"name" json:"name"`
|
||||
// Specifies a collection of rules that determine if this TTL should be applied to an asset.
|
||||
Rules []RestrictionRule `mapstructure:"rules" json:"rules"`
|
||||
}
|
||||
|
||||
// Error specifies an error that occurred during the previous service action.
|
||||
type Error struct {
|
||||
// Specifies an error message detailing why there is an error.
|
||||
Message string `mapstructure:"message"`
|
||||
}
|
||||
|
||||
// Service represents a CDN service resource.
|
||||
type Service struct {
|
||||
// Specifies the service ID that represents distributed content. The value is
|
||||
// a UUID, such as 96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0, that is generated by the server.
|
||||
ID string `mapstructure:"id"`
|
||||
// Specifies the name of the service.
|
||||
Name string `mapstructure:"name"`
|
||||
// Specifies a list of domains used by users to access their website.
|
||||
Domains []Domain `mapstructure:"domains"`
|
||||
// Specifies a list of origin domains or IP addresses where the original assets are stored.
|
||||
Origins []Origin `mapstructure:"origins"`
|
||||
// Specifies the TTL rules for the assets under this service. Supports wildcards for fine grained control.
|
||||
Caching []CacheRule `mapstructure:"caching"`
|
||||
// Specifies the restrictions that define who can access assets (content from the CDN cache).
|
||||
Restrictions []Restriction `mapstructure:"restrictions" json:"restrictions,omitempty"`
|
||||
// Specifies the CDN provider flavor ID to use. For a list of flavors, see the operation to list the available flavors.
|
||||
FlavorID string `mapstructure:"flavor_id"`
|
||||
// Specifies the current status of the service.
|
||||
Status string `mapstructure:"status"`
|
||||
// Specifies the list of errors that occurred during the previous service action.
|
||||
Errors []Error `mapstructure:"errors"`
|
||||
// Specifies the self-navigating JSON document paths.
|
||||
Links []gophercloud.Link `mapstructure:"links"`
|
||||
}
|
||||
|
||||
// ServicePage is the page returned by a pager when traversing over a
|
||||
// collection of CDN services.
|
||||
type ServicePage struct {
|
||||
pagination.MarkerPageBase
|
||||
}
|
||||
|
||||
// IsEmpty returns true if a ListResult contains no services.
|
||||
func (r ServicePage) IsEmpty() (bool, error) {
|
||||
services, err := ExtractServices(r)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return len(services) == 0, nil
|
||||
}
|
||||
|
||||
// LastMarker returns the last service in a ListResult.
|
||||
func (r ServicePage) LastMarker() (string, error) {
|
||||
services, err := ExtractServices(r)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(services) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
return (services[len(services)-1]).ID, nil
|
||||
}
|
||||
|
||||
// ExtractServices is a function that takes a ListResult and returns the services' information.
|
||||
func ExtractServices(page pagination.Page) ([]Service, error) {
|
||||
var response struct {
|
||||
Services []Service `mapstructure:"services"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(page.(ServicePage).Body, &response)
|
||||
return response.Services, err
|
||||
}
|
||||
|
||||
// CreateResult represents the result of a Create operation.
|
||||
type CreateResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a method that extracts the location of a newly created service.
|
||||
func (r CreateResult) Extract() (string, error) {
|
||||
if r.Err != nil {
|
||||
return "", r.Err
|
||||
}
|
||||
if l, ok := r.Header["Location"]; ok && len(l) > 0 {
|
||||
return l[0], nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// GetResult represents the result of a get operation.
|
||||
type GetResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a function that extracts a service from a GetResult.
|
||||
func (r GetResult) Extract() (*Service, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
var res Service
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
|
||||
return &res, err
|
||||
}
|
||||
|
||||
// UpdateResult represents the result of a Update operation.
|
||||
type UpdateResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a method that extracts the location of an updated service.
|
||||
func (r UpdateResult) Extract() (string, error) {
|
||||
if r.Err != nil {
|
||||
return "", r.Err
|
||||
}
|
||||
if l, ok := r.Header["Location"]; ok && len(l) > 0 {
|
||||
return l[0], nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// DeleteResult represents the result of a Delete operation.
|
||||
type DeleteResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
23
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/urls.go
generated
vendored
23
vendor/github.com/rackspace/gophercloud/openstack/cdn/v1/services/urls.go
generated
vendored
@@ -1,23 +0,0 @@
|
||||
package services
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
func listURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL("services")
|
||||
}
|
||||
|
||||
func createURL(c *gophercloud.ServiceClient) string {
|
||||
return listURL(c)
|
||||
}
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL("services", id)
|
||||
}
|
||||
|
||||
func updateURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return getURL(c, id)
|
||||
}
|
||||
|
||||
func deleteURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return getURL(c, id)
|
||||
}
|
3
vendor/github.com/rackspace/gophercloud/openstack/common/README.md
generated
vendored
3
vendor/github.com/rackspace/gophercloud/openstack/common/README.md
generated
vendored
@@ -1,3 +0,0 @@
|
||||
# Common Resources
|
||||
|
||||
This directory is for resources that are shared by multiple services.
|
15
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/doc.go
generated
vendored
15
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/doc.go
generated
vendored
@@ -1,15 +0,0 @@
|
||||
// Package extensions provides information and interaction with the different extensions available
|
||||
// for an OpenStack service.
|
||||
//
|
||||
// The purpose of OpenStack API extensions is to:
|
||||
//
|
||||
// - Introduce new features in the API without requiring a version change.
|
||||
// - Introduce vendor-specific niche functionality.
|
||||
// - Act as a proving ground for experimental functionalities that might be included in a future
|
||||
// version of the API.
|
||||
//
|
||||
// Extensions usually have tags that prevent conflicts with other extensions that define attributes
|
||||
// or resources with the same names, and with core resources and attributes.
|
||||
// Because an extension might not be supported by all plug-ins, its availability varies with deployments
|
||||
// and the specific plug-in.
|
||||
package extensions
|
1
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/errors.go
generated
vendored
1
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/errors.go
generated
vendored
@@ -1 +0,0 @@
|
||||
package extensions
|
91
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/fixtures.go
generated
vendored
91
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/fixtures.go
generated
vendored
@@ -1,91 +0,0 @@
|
||||
// +build fixtures
|
||||
|
||||
package extensions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
"github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// ListOutput provides a single page of Extension results.
|
||||
const ListOutput = `
|
||||
{
|
||||
"extensions": [
|
||||
{
|
||||
"updated": "2013-01-20T00:00:00-00:00",
|
||||
"name": "Neutron Service Type Management",
|
||||
"links": [],
|
||||
"namespace": "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
|
||||
"alias": "service-type",
|
||||
"description": "API for retrieving service providers for Neutron advanced services"
|
||||
}
|
||||
]
|
||||
}`
|
||||
|
||||
// GetOutput provides a single Extension result.
|
||||
const GetOutput = `
|
||||
{
|
||||
"extension": {
|
||||
"updated": "2013-02-03T10:00:00-00:00",
|
||||
"name": "agent",
|
||||
"links": [],
|
||||
"namespace": "http://docs.openstack.org/ext/agent/api/v2.0",
|
||||
"alias": "agent",
|
||||
"description": "The agent management extension."
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// ListedExtension is the Extension that should be parsed from ListOutput.
|
||||
var ListedExtension = Extension{
|
||||
Updated: "2013-01-20T00:00:00-00:00",
|
||||
Name: "Neutron Service Type Management",
|
||||
Links: []interface{}{},
|
||||
Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
|
||||
Alias: "service-type",
|
||||
Description: "API for retrieving service providers for Neutron advanced services",
|
||||
}
|
||||
|
||||
// ExpectedExtensions is a slice containing the Extension that should be parsed from ListOutput.
|
||||
var ExpectedExtensions = []Extension{ListedExtension}
|
||||
|
||||
// SingleExtension is the Extension that should be parsed from GetOutput.
|
||||
var SingleExtension = &Extension{
|
||||
Updated: "2013-02-03T10:00:00-00:00",
|
||||
Name: "agent",
|
||||
Links: []interface{}{},
|
||||
Namespace: "http://docs.openstack.org/ext/agent/api/v2.0",
|
||||
Alias: "agent",
|
||||
Description: "The agent management extension.",
|
||||
}
|
||||
|
||||
// HandleListExtensionsSuccessfully creates an HTTP handler at `/extensions` on the test handler
|
||||
// mux that response with a list containing a single tenant.
|
||||
func HandleListExtensionsSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/extensions", 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)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleGetExtensionSuccessfully creates an HTTP handler at `/extensions/agent` that responds with
|
||||
// a JSON payload corresponding to SingleExtension.
|
||||
func HandleGetExtensionSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/extensions/agent", 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")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintf(w, GetOutput)
|
||||
})
|
||||
}
|
21
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/requests.go
generated
vendored
21
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/requests.go
generated
vendored
@@ -1,21 +0,0 @@
|
||||
package extensions
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// Get retrieves information for a specific extension using its alias.
|
||||
func Get(c *gophercloud.ServiceClient, alias string) GetResult {
|
||||
var res GetResult
|
||||
_, res.Err = c.Get(ExtensionURL(c, alias), &res.Body, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// List returns a Pager which allows you to iterate over the full collection of extensions.
|
||||
// It does not accept query parameters.
|
||||
func List(c *gophercloud.ServiceClient) pagination.Pager {
|
||||
return pagination.NewPager(c, ListExtensionURL(c), func(r pagination.PageResult) pagination.Page {
|
||||
return ExtensionPage{pagination.SinglePageBase(r)}
|
||||
})
|
||||
}
|
65
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/results.go
generated
vendored
65
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/results.go
generated
vendored
@@ -1,65 +0,0 @@
|
||||
package extensions
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// GetResult temporarily stores the result of a Get call.
|
||||
// Use its Extract() method to interpret it as an Extension.
|
||||
type GetResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract interprets a GetResult as an Extension.
|
||||
func (r GetResult) Extract() (*Extension, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
var res struct {
|
||||
Extension *Extension `json:"extension"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
|
||||
return res.Extension, err
|
||||
}
|
||||
|
||||
// Extension is a struct that represents an OpenStack extension.
|
||||
type Extension struct {
|
||||
Updated string `json:"updated" mapstructure:"updated"`
|
||||
Name string `json:"name" mapstructure:"name"`
|
||||
Links []interface{} `json:"links" mapstructure:"links"`
|
||||
Namespace string `json:"namespace" mapstructure:"namespace"`
|
||||
Alias string `json:"alias" mapstructure:"alias"`
|
||||
Description string `json:"description" mapstructure:"description"`
|
||||
}
|
||||
|
||||
// ExtensionPage is the page returned by a pager when traversing over a collection of extensions.
|
||||
type ExtensionPage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty checks whether an ExtensionPage struct is empty.
|
||||
func (r ExtensionPage) IsEmpty() (bool, error) {
|
||||
is, err := ExtractExtensions(r)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return len(is) == 0, nil
|
||||
}
|
||||
|
||||
// ExtractExtensions accepts a Page struct, specifically an ExtensionPage struct, and extracts the
|
||||
// elements into a slice of Extension structs.
|
||||
// In other words, a generic collection is mapped into a relevant slice.
|
||||
func ExtractExtensions(page pagination.Page) ([]Extension, error) {
|
||||
var resp struct {
|
||||
Extensions []Extension `mapstructure:"extensions"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(page.(ExtensionPage).Body, &resp)
|
||||
|
||||
return resp.Extensions, err
|
||||
}
|
13
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/urls.go
generated
vendored
13
vendor/github.com/rackspace/gophercloud/openstack/common/extensions/urls.go
generated
vendored
@@ -1,13 +0,0 @@
|
||||
package extensions
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
// ExtensionURL generates the URL for an extension resource by name.
|
||||
func ExtensionURL(c *gophercloud.ServiceClient, name string) string {
|
||||
return c.ServiceURL("extensions", name)
|
||||
}
|
||||
|
||||
// ListExtensionURL generates the URL for the extensions resource collection.
|
||||
func ListExtensionURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL("extensions")
|
||||
}
|
@@ -1 +0,0 @@
|
||||
package defsecrules
|
@@ -1,143 +0,0 @@
|
||||
package defsecrules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
fake "github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
const rootPath = "/os-security-group-default-rules"
|
||||
|
||||
func mockListRulesResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc(rootPath, 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")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"security_group_default_rules": [
|
||||
{
|
||||
"from_port": 80,
|
||||
"id": "{ruleID}",
|
||||
"ip_protocol": "TCP",
|
||||
"ip_range": {
|
||||
"cidr": "10.10.10.0/24"
|
||||
},
|
||||
"to_port": 80
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func mockCreateRuleResponse(t *testing.T) {
|
||||
th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"security_group_default_rule": {
|
||||
"ip_protocol": "TCP",
|
||||
"from_port": 80,
|
||||
"to_port": 80,
|
||||
"cidr": "10.10.12.0/24"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"security_group_default_rule": {
|
||||
"from_port": 80,
|
||||
"id": "{ruleID}",
|
||||
"ip_protocol": "TCP",
|
||||
"ip_range": {
|
||||
"cidr": "10.10.12.0/24"
|
||||
},
|
||||
"to_port": 80
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func mockCreateRuleResponseICMPZero(t *testing.T) {
|
||||
th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"security_group_default_rule": {
|
||||
"ip_protocol": "ICMP",
|
||||
"from_port": 0,
|
||||
"to_port": 0,
|
||||
"cidr": "10.10.12.0/24"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"security_group_default_rule": {
|
||||
"from_port": 0,
|
||||
"id": "{ruleID}",
|
||||
"ip_protocol": "ICMP",
|
||||
"ip_range": {
|
||||
"cidr": "10.10.12.0/24"
|
||||
},
|
||||
"to_port": 0
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func mockGetRuleResponse(t *testing.T, ruleID string) {
|
||||
url := rootPath + "/" + ruleID
|
||||
th.Mux.HandleFunc(url, 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")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
{
|
||||
"security_group_default_rule": {
|
||||
"id": "{ruleID}",
|
||||
"from_port": 80,
|
||||
"to_port": 80,
|
||||
"ip_protocol": "TCP",
|
||||
"ip_range": {
|
||||
"cidr": "10.10.12.0/24"
|
||||
}
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func mockDeleteRuleResponse(t *testing.T, ruleID string) {
|
||||
url := rootPath + "/" + ruleID
|
||||
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "DELETE")
|
||||
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
package defsecrules
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// List will return a collection of default rules.
|
||||
func List(client *gophercloud.ServiceClient) pagination.Pager {
|
||||
createPage := func(r pagination.PageResult) pagination.Page {
|
||||
return DefaultRulePage{pagination.SinglePageBase(r)}
|
||||
}
|
||||
|
||||
return pagination.NewPager(client, rootURL(client), createPage)
|
||||
}
|
||||
|
||||
// CreateOpts represents the configuration for adding a new default rule.
|
||||
type CreateOpts struct {
|
||||
// Required - the lower bound of the port range that will be opened.
|
||||
FromPort int `json:"from_port"`
|
||||
|
||||
// Required - the upper bound of the port range that will be opened.
|
||||
ToPort int `json:"to_port"`
|
||||
|
||||
// Required - the protocol type that will be allowed, e.g. TCP.
|
||||
IPProtocol string `json:"ip_protocol"`
|
||||
|
||||
// ONLY required if FromGroupID is blank. This represents the IP range that
|
||||
// will be the source of network traffic to your security group. Use
|
||||
// 0.0.0.0/0 to allow all IP addresses.
|
||||
CIDR string `json:"cidr,omitempty"`
|
||||
}
|
||||
|
||||
// CreateOptsBuilder builds the create rule options into a serializable format.
|
||||
type CreateOptsBuilder interface {
|
||||
ToRuleCreateMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// ToRuleCreateMap builds the create rule options into a serializable format.
|
||||
func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) {
|
||||
rule := make(map[string]interface{})
|
||||
|
||||
if opts.FromPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
|
||||
return rule, errors.New("A FromPort must be set")
|
||||
}
|
||||
if opts.ToPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
|
||||
return rule, errors.New("A ToPort must be set")
|
||||
}
|
||||
if opts.IPProtocol == "" {
|
||||
return rule, errors.New("A IPProtocol must be set")
|
||||
}
|
||||
if opts.CIDR == "" {
|
||||
return rule, errors.New("A CIDR must be set")
|
||||
}
|
||||
|
||||
rule["from_port"] = opts.FromPort
|
||||
rule["to_port"] = opts.ToPort
|
||||
rule["ip_protocol"] = opts.IPProtocol
|
||||
rule["cidr"] = opts.CIDR
|
||||
|
||||
return map[string]interface{}{"security_group_default_rule": rule}, nil
|
||||
}
|
||||
|
||||
// Create is the operation responsible for creating a new default rule.
|
||||
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
||||
var result CreateResult
|
||||
|
||||
reqBody, err := opts.ToRuleCreateMap()
|
||||
if err != nil {
|
||||
result.Err = err
|
||||
return result
|
||||
}
|
||||
|
||||
_, result.Err = client.Post(rootURL(client), reqBody, &result.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Get will return details for a particular default rule.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var result GetResult
|
||||
_, 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.Delete(resourceURL(client, id), nil)
|
||||
return result
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
package defsecrules
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// DefaultRule represents a default rule - which is identical to a
|
||||
// normal security rule.
|
||||
type DefaultRule secgroups.Rule
|
||||
|
||||
// DefaultRulePage is a single page of a DefaultRule collection.
|
||||
type DefaultRulePage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty determines whether or not a page of default rules contains any results.
|
||||
func (page DefaultRulePage) IsEmpty() (bool, error) {
|
||||
users, err := ExtractDefaultRules(page)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return len(users) == 0, nil
|
||||
}
|
||||
|
||||
// ExtractDefaultRules returns a slice of DefaultRules contained in a single
|
||||
// page of results.
|
||||
func ExtractDefaultRules(page pagination.Page) ([]DefaultRule, error) {
|
||||
casted := page.(DefaultRulePage).Body
|
||||
var response struct {
|
||||
Rules []DefaultRule `mapstructure:"security_group_default_rules"`
|
||||
}
|
||||
|
||||
err := mapstructure.WeakDecode(casted, &response)
|
||||
|
||||
return response.Rules, err
|
||||
}
|
||||
|
||||
type commonResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// CreateResult represents the result of a create operation.
|
||||
type CreateResult struct {
|
||||
commonResult
|
||||
}
|
||||
|
||||
// GetResult represents the result of a get operation.
|
||||
type GetResult struct {
|
||||
commonResult
|
||||
}
|
||||
|
||||
// Extract will extract a DefaultRule struct from most responses.
|
||||
func (r commonResult) Extract() (*DefaultRule, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
var response struct {
|
||||
Rule DefaultRule `mapstructure:"security_group_default_rule"`
|
||||
}
|
||||
|
||||
err := mapstructure.WeakDecode(r.Body, &response)
|
||||
|
||||
return &response.Rule, err
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
package defsecrules
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
const rulepath = "os-security-group-default-rules"
|
||||
|
||||
func resourceURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL(rulepath, id)
|
||||
}
|
||||
|
||||
func rootURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL(rulepath)
|
||||
}
|
23
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/delegate.go
generated
vendored
23
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/delegate.go
generated
vendored
@@ -1,23 +0,0 @@
|
||||
package extensions
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
common "github.com/rackspace/gophercloud/openstack/common/extensions"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// ExtractExtensions interprets a Page as a slice of Extensions.
|
||||
func ExtractExtensions(page pagination.Page) ([]common.Extension, error) {
|
||||
return common.ExtractExtensions(page)
|
||||
}
|
||||
|
||||
// Get retrieves information for a specific extension using its alias.
|
||||
func Get(c *gophercloud.ServiceClient, alias string) common.GetResult {
|
||||
return common.Get(c, alias)
|
||||
}
|
||||
|
||||
// List returns a Pager which allows you to iterate over the full collection of extensions.
|
||||
// It does not accept query parameters.
|
||||
func List(c *gophercloud.ServiceClient) pagination.Pager {
|
||||
return common.List(c)
|
||||
}
|
3
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/doc.go
generated
vendored
3
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/doc.go
generated
vendored
@@ -1,3 +0,0 @@
|
||||
// Package extensions provides information and interaction with the
|
||||
// different extensions available for the OpenStack Compute service.
|
||||
package extensions
|
@@ -1,3 +0,0 @@
|
||||
// Package floatingip provides the ability to manage floating ips through
|
||||
// nova-network
|
||||
package floatingip
|
@@ -1,193 +0,0 @@
|
||||
// +build fixtures
|
||||
|
||||
package floatingip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
"github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// ListOutput is a sample response to a List call.
|
||||
const ListOutput = `
|
||||
{
|
||||
"floating_ips": [
|
||||
{
|
||||
"fixed_ip": null,
|
||||
"id": 1,
|
||||
"instance_id": null,
|
||||
"ip": "10.10.10.1",
|
||||
"pool": "nova"
|
||||
},
|
||||
{
|
||||
"fixed_ip": "166.78.185.201",
|
||||
"id": 2,
|
||||
"instance_id": "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
|
||||
"ip": "10.10.10.2",
|
||||
"pool": "nova"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
// GetOutput is a sample response to a Get call.
|
||||
const GetOutput = `
|
||||
{
|
||||
"floating_ip": {
|
||||
"fixed_ip": "166.78.185.201",
|
||||
"id": 2,
|
||||
"instance_id": "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
|
||||
"ip": "10.10.10.2",
|
||||
"pool": "nova"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// CreateOutput is a sample response to a Post call
|
||||
const CreateOutput = `
|
||||
{
|
||||
"floating_ip": {
|
||||
"fixed_ip": null,
|
||||
"id": 1,
|
||||
"instance_id": null,
|
||||
"ip": "10.10.10.1",
|
||||
"pool": "nova"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// FirstFloatingIP is the first result in ListOutput.
|
||||
var FirstFloatingIP = FloatingIP{
|
||||
ID: "1",
|
||||
IP: "10.10.10.1",
|
||||
Pool: "nova",
|
||||
}
|
||||
|
||||
// SecondFloatingIP is the first result in ListOutput.
|
||||
var SecondFloatingIP = FloatingIP{
|
||||
FixedIP: "166.78.185.201",
|
||||
ID: "2",
|
||||
InstanceID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
|
||||
IP: "10.10.10.2",
|
||||
Pool: "nova",
|
||||
}
|
||||
|
||||
// ExpectedFloatingIPsSlice is the slice of results that should be parsed
|
||||
// from ListOutput, in the expected order.
|
||||
var ExpectedFloatingIPsSlice = []FloatingIP{FirstFloatingIP, SecondFloatingIP}
|
||||
|
||||
// CreatedFloatingIP is the parsed result from CreateOutput.
|
||||
var CreatedFloatingIP = FloatingIP{
|
||||
ID: "1",
|
||||
IP: "10.10.10.1",
|
||||
Pool: "nova",
|
||||
}
|
||||
|
||||
// HandleListSuccessfully configures the test server to respond to a List request.
|
||||
func HandleListSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-floating-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, ListOutput)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleGetSuccessfully configures the test server to respond to a Get request
|
||||
// for an existing floating ip
|
||||
func HandleGetSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-floating-ips/2", 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)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleCreateSuccessfully configures the test server to respond to a Create request
|
||||
// for a new floating ip
|
||||
func HandleCreateSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-floating-ips", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"pool": "nova"
|
||||
}
|
||||
`)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, CreateOutput)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleDeleteSuccessfully configures the test server to respond to a Delete request for a
|
||||
// an existing floating ip
|
||||
func HandleDeleteSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-floating-ips/1", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "DELETE")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleAssociateSuccessfully configures the test server to respond to a Post request
|
||||
// to associate an allocated floating IP
|
||||
func HandleAssociateSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/servers/4d8c3732-a248-40ed-bebc-539a6ffd25c0/action", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"addFloatingIp": {
|
||||
"address": "10.10.10.2"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleFixedAssociateSucessfully configures the test server to respond to a Post request
|
||||
// to associate an allocated floating IP with a specific fixed IP address
|
||||
func HandleAssociateFixedSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/servers/4d8c3732-a248-40ed-bebc-539a6ffd25c0/action", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"addFloatingIp": {
|
||||
"address": "10.10.10.2",
|
||||
"fixed_address": "166.78.185.201"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleDisassociateSuccessfully configures the test server to respond to a Post request
|
||||
// to disassociate an allocated floating IP
|
||||
func HandleDisassociateSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/servers/4d8c3732-a248-40ed-bebc-539a6ffd25c0/action", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"removeFloatingIp": {
|
||||
"address": "10.10.10.2"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
})
|
||||
}
|
@@ -1,171 +0,0 @@
|
||||
package floatingip
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// List returns a Pager that allows you to iterate over a collection of FloatingIPs.
|
||||
func List(client *gophercloud.ServiceClient) pagination.Pager {
|
||||
return pagination.NewPager(client, listURL(client), func(r pagination.PageResult) pagination.Page {
|
||||
return FloatingIPsPage{pagination.SinglePageBase(r)}
|
||||
})
|
||||
}
|
||||
|
||||
// CreateOptsBuilder describes struct types that can be accepted by the Create call. Notable, the
|
||||
// CreateOpts struct in this package does.
|
||||
type CreateOptsBuilder interface {
|
||||
ToFloatingIPCreateMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// CreateOpts specifies a Floating IP allocation request
|
||||
type CreateOpts struct {
|
||||
// Pool is the pool of floating IPs to allocate one from
|
||||
Pool string
|
||||
}
|
||||
|
||||
// AssociateOpts specifies the required information to associate or disassociate a floating IP to an instance
|
||||
type AssociateOpts struct {
|
||||
// ServerID is the UUID of the server
|
||||
ServerID string
|
||||
|
||||
// FixedIP is an optional fixed IP address of the server
|
||||
FixedIP string
|
||||
|
||||
// FloatingIP is the floating IP to associate with an instance
|
||||
FloatingIP string
|
||||
}
|
||||
|
||||
// ToFloatingIPCreateMap constructs a request body from CreateOpts.
|
||||
func (opts CreateOpts) ToFloatingIPCreateMap() (map[string]interface{}, error) {
|
||||
if opts.Pool == "" {
|
||||
return nil, errors.New("Missing field required for floating IP creation: Pool")
|
||||
}
|
||||
|
||||
return map[string]interface{}{"pool": opts.Pool}, nil
|
||||
}
|
||||
|
||||
// ToAssociateMap constructs a request body from AssociateOpts.
|
||||
func (opts AssociateOpts) ToAssociateMap() (map[string]interface{}, error) {
|
||||
if opts.ServerID == "" {
|
||||
return nil, errors.New("Required field missing for floating IP association: ServerID")
|
||||
}
|
||||
|
||||
if opts.FloatingIP == "" {
|
||||
return nil, errors.New("Required field missing for floating IP association: FloatingIP")
|
||||
}
|
||||
|
||||
associateInfo := map[string]interface{}{
|
||||
"serverId": opts.ServerID,
|
||||
"floatingIp": opts.FloatingIP,
|
||||
"fixedIp": opts.FixedIP,
|
||||
}
|
||||
|
||||
return associateInfo, nil
|
||||
|
||||
}
|
||||
|
||||
// Create requests the creation of a new floating IP
|
||||
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
||||
var res CreateResult
|
||||
|
||||
reqBody, err := opts.ToFloatingIPCreateMap()
|
||||
if err != nil {
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
// Get returns data about a previously created FloatingIP.
|
||||
func Get(client *gophercloud.ServiceClient, id string) GetResult {
|
||||
var res GetResult
|
||||
_, 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.Delete(deleteURL(client, id), nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// association / disassociation
|
||||
|
||||
// Associate pairs an allocated floating IP with an instance
|
||||
// Deprecated. Use AssociateInstance.
|
||||
func Associate(client *gophercloud.ServiceClient, serverId, fip string) AssociateResult {
|
||||
var res AssociateResult
|
||||
|
||||
addFloatingIp := make(map[string]interface{})
|
||||
addFloatingIp["address"] = fip
|
||||
reqBody := map[string]interface{}{"addFloatingIp": addFloatingIp}
|
||||
|
||||
_, res.Err = client.Post(associateURL(client, serverId), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// AssociateInstance pairs an allocated floating IP with an instance.
|
||||
func AssociateInstance(client *gophercloud.ServiceClient, opts AssociateOpts) AssociateResult {
|
||||
var res AssociateResult
|
||||
|
||||
associateInfo, err := opts.ToAssociateMap()
|
||||
if err != nil {
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
addFloatingIp := make(map[string]interface{})
|
||||
addFloatingIp["address"] = associateInfo["floatingIp"].(string)
|
||||
|
||||
// fixedIp is not required
|
||||
if associateInfo["fixedIp"] != "" {
|
||||
addFloatingIp["fixed_address"] = associateInfo["fixedIp"].(string)
|
||||
}
|
||||
|
||||
serverId := associateInfo["serverId"].(string)
|
||||
|
||||
reqBody := map[string]interface{}{"addFloatingIp": addFloatingIp}
|
||||
_, res.Err = client.Post(associateURL(client, serverId), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// Disassociate decouples an allocated floating IP from an instance
|
||||
// Deprecated. Use DisassociateInstance.
|
||||
func Disassociate(client *gophercloud.ServiceClient, serverId, fip string) DisassociateResult {
|
||||
var res DisassociateResult
|
||||
|
||||
removeFloatingIp := make(map[string]interface{})
|
||||
removeFloatingIp["address"] = fip
|
||||
reqBody := map[string]interface{}{"removeFloatingIp": removeFloatingIp}
|
||||
|
||||
_, res.Err = client.Post(disassociateURL(client, serverId), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
||||
|
||||
// DisassociateInstance decouples an allocated floating IP from an instance
|
||||
func DisassociateInstance(client *gophercloud.ServiceClient, opts AssociateOpts) DisassociateResult {
|
||||
var res DisassociateResult
|
||||
|
||||
associateInfo, err := opts.ToAssociateMap()
|
||||
if err != nil {
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
removeFloatingIp := make(map[string]interface{})
|
||||
removeFloatingIp["address"] = associateInfo["floatingIp"].(string)
|
||||
reqBody := map[string]interface{}{"removeFloatingIp": removeFloatingIp}
|
||||
|
||||
serverId := associateInfo["serverId"].(string)
|
||||
|
||||
_, res.Err = client.Post(disassociateURL(client, serverId), reqBody, nil, nil)
|
||||
return res
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
package floatingip
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// A FloatingIP is an IP that can be associated with an instance
|
||||
type FloatingIP struct {
|
||||
// ID is a unique ID of the Floating IP
|
||||
ID string `mapstructure:"id"`
|
||||
|
||||
// FixedIP is the IP of the instance related to the Floating IP
|
||||
FixedIP string `mapstructure:"fixed_ip,omitempty"`
|
||||
|
||||
// InstanceID is the ID of the instance that is using the Floating IP
|
||||
InstanceID string `mapstructure:"instance_id"`
|
||||
|
||||
// IP is the actual Floating IP
|
||||
IP string `mapstructure:"ip"`
|
||||
|
||||
// Pool is the pool of floating IPs that this floating IP belongs to
|
||||
Pool string `mapstructure:"pool"`
|
||||
}
|
||||
|
||||
// FloatingIPsPage stores a single, only page of FloatingIPs
|
||||
// results from a List call.
|
||||
type FloatingIPsPage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty determines whether or not a FloatingIPsPage is empty.
|
||||
func (page FloatingIPsPage) IsEmpty() (bool, error) {
|
||||
va, err := ExtractFloatingIPs(page)
|
||||
return len(va) == 0, err
|
||||
}
|
||||
|
||||
// ExtractFloatingIPs interprets a page of results as a slice of
|
||||
// FloatingIPs.
|
||||
func ExtractFloatingIPs(page pagination.Page) ([]FloatingIP, error) {
|
||||
casted := page.(FloatingIPsPage).Body
|
||||
var response struct {
|
||||
FloatingIPs []FloatingIP `mapstructure:"floating_ips"`
|
||||
}
|
||||
|
||||
err := mapstructure.WeakDecode(casted, &response)
|
||||
|
||||
return response.FloatingIPs, err
|
||||
}
|
||||
|
||||
type FloatingIPResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a method that attempts to interpret any FloatingIP resource
|
||||
// response as a FloatingIP struct.
|
||||
func (r FloatingIPResult) Extract() (*FloatingIP, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
var res struct {
|
||||
FloatingIP *FloatingIP `json:"floating_ip" mapstructure:"floating_ip"`
|
||||
}
|
||||
|
||||
err := mapstructure.WeakDecode(r.Body, &res)
|
||||
return res.FloatingIP, err
|
||||
}
|
||||
|
||||
// CreateResult is the response from a Create operation. Call its Extract method to interpret it
|
||||
// as a FloatingIP.
|
||||
type CreateResult struct {
|
||||
FloatingIPResult
|
||||
}
|
||||
|
||||
// GetResult is the response from a Get operation. Call its Extract method to interpret it
|
||||
// as a FloatingIP.
|
||||
type GetResult struct {
|
||||
FloatingIPResult
|
||||
}
|
||||
|
||||
// DeleteResult is the response from a Delete operation. Call its Extract method to determine if
|
||||
// the call succeeded or failed.
|
||||
type DeleteResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
||||
|
||||
// AssociateResult is the response from a Delete operation. Call its Extract method to determine if
|
||||
// the call succeeded or failed.
|
||||
type AssociateResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
||||
|
||||
// DisassociateResult is the response from a Delete operation. Call its Extract method to determine if
|
||||
// the call succeeded or failed.
|
||||
type DisassociateResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package floatingip
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
const resourcePath = "os-floating-ips"
|
||||
|
||||
func resourceURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL(resourcePath)
|
||||
}
|
||||
|
||||
func listURL(c *gophercloud.ServiceClient) string {
|
||||
return resourceURL(c)
|
||||
}
|
||||
|
||||
func createURL(c *gophercloud.ServiceClient) string {
|
||||
return resourceURL(c)
|
||||
}
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL(resourcePath, id)
|
||||
}
|
||||
|
||||
func deleteURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return getURL(c, id)
|
||||
}
|
||||
|
||||
func serverURL(c *gophercloud.ServiceClient, serverId string) string {
|
||||
return c.ServiceURL("servers/" + serverId + "/action")
|
||||
}
|
||||
|
||||
func associateURL(c *gophercloud.ServiceClient, serverId string) string {
|
||||
return serverURL(c, serverId)
|
||||
}
|
||||
|
||||
func disassociateURL(c *gophercloud.ServiceClient, serverId string) string {
|
||||
return serverURL(c, serverId)
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
// Package keypairs provides information and interaction with the Keypairs
|
||||
// extension for the OpenStack Compute service.
|
||||
package keypairs
|
171
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs/fixtures.go
generated
vendored
171
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs/fixtures.go
generated
vendored
@@ -1,171 +0,0 @@
|
||||
// +build fixtures
|
||||
|
||||
package keypairs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
"github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// ListOutput is a sample response to a List call.
|
||||
const ListOutput = `
|
||||
{
|
||||
"keypairs": [
|
||||
{
|
||||
"keypair": {
|
||||
"fingerprint": "15:b0:f8:b3:f9:48:63:71:cf:7b:5b:38:6d:44:2d:4a",
|
||||
"name": "firstkey",
|
||||
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC+Eo/RZRngaGTkFs7I62ZjsIlO79KklKbMXi8F+KITD4bVQHHn+kV+4gRgkgCRbdoDqoGfpaDFs877DYX9n4z6FrAIZ4PES8TNKhatifpn9NdQYWA+IkU8CuvlEKGuFpKRi/k7JLos/gHi2hy7QUwgtRvcefvD/vgQZOVw/mGR9Q== Generated by Nova\n"
|
||||
}
|
||||
},
|
||||
{
|
||||
"keypair": {
|
||||
"fingerprint": "35:9d:d0:c3:4a:80:d3:d8:86:f1:ca:f7:df:c4:f9:d8",
|
||||
"name": "secondkey",
|
||||
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7DUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5Q== Generated by Nova\n"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
// GetOutput is a sample response to a Get call.
|
||||
const GetOutput = `
|
||||
{
|
||||
"keypair": {
|
||||
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC+Eo/RZRngaGTkFs7I62ZjsIlO79KklKbMXi8F+KITD4bVQHHn+kV+4gRgkgCRbdoDqoGfpaDFs877DYX9n4z6FrAIZ4PES8TNKhatifpn9NdQYWA+IkU8CuvlEKGuFpKRi/k7JLos/gHi2hy7QUwgtRvcefvD/vgQZOVw/mGR9Q== Generated by Nova\n",
|
||||
"name": "firstkey",
|
||||
"fingerprint": "15:b0:f8:b3:f9:48:63:71:cf:7b:5b:38:6d:44:2d:4a"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// CreateOutput is a sample response to a Create call.
|
||||
const CreateOutput = `
|
||||
{
|
||||
"keypair": {
|
||||
"fingerprint": "35:9d:d0:c3:4a:80:d3:d8:86:f1:ca:f7:df:c4:f9:d8",
|
||||
"name": "createdkey",
|
||||
"private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7\nDUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ\n9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5QIDAQAB\nAoGAE5XO1mDhORy9COvsg+kYPUhB1GsCYxh+v88wG7HeFDKBY6KUc/Kxo6yoGn5T\nTjRjekyi2KoDZHz4VlIzyZPwFS4I1bf3oCunVoAKzgLdmnTtvRNMC5jFOGc2vUgP\n9bSyRj3S1R4ClVk2g0IDeagko/jc8zzLEYuIK+fbkds79YECQQDt3vcevgegnkga\ntF4NsDmmBPRkcSHCqrANP/7vFcBQN3czxeYYWX3DK07alu6GhH1Y4sHbdm616uU0\nll7xbDzxAkEAzAtN2IyftNygV2EGiaGgqLyo/tD9+Vui2qCQplqe4jvWh/5Sparl\nOjmKo+uAW+hLrLVMnHzRWxbWU8hirH5FNQJATO+ZxCK4etXXAnQmG41NCAqANWB2\nB+2HJbH2NcQ2QHvAHUm741JGn/KI/aBlo7KEjFRDWUVUB5ji64BbUwCsMQJBAIku\nLGcjnBf/oLk+XSPZC2eGd2Ph5G5qYmH0Q2vkTx+wtTn3DV+eNsDfgMtWAJVJ5t61\ngU1QSXyhLPVlKpnnxuUCQC+xvvWjWtsLaFtAsZywJiqLxQzHts8XLGZptYJ5tLWV\nrtmYtBcJCN48RrgQHry/xWYeA4K/AFQpXfNPgprQ96Q=\n-----END RSA PRIVATE KEY-----\n",
|
||||
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7DUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5Q== Generated by Nova\n",
|
||||
"user_id": "fake"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// ImportOutput is a sample response to a Create call that provides its own public key.
|
||||
const ImportOutput = `
|
||||
{
|
||||
"keypair": {
|
||||
"fingerprint": "1e:2c:9b:56:79:4b:45:77:f9:ca:7a:98:2c:b0:d5:3c",
|
||||
"name": "importedkey",
|
||||
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated by Nova",
|
||||
"user_id": "fake"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// FirstKeyPair is the first result in ListOutput.
|
||||
var FirstKeyPair = KeyPair{
|
||||
Name: "firstkey",
|
||||
Fingerprint: "15:b0:f8:b3:f9:48:63:71:cf:7b:5b:38:6d:44:2d:4a",
|
||||
PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC+Eo/RZRngaGTkFs7I62ZjsIlO79KklKbMXi8F+KITD4bVQHHn+kV+4gRgkgCRbdoDqoGfpaDFs877DYX9n4z6FrAIZ4PES8TNKhatifpn9NdQYWA+IkU8CuvlEKGuFpKRi/k7JLos/gHi2hy7QUwgtRvcefvD/vgQZOVw/mGR9Q== Generated by Nova\n",
|
||||
}
|
||||
|
||||
// SecondKeyPair is the second result in ListOutput.
|
||||
var SecondKeyPair = KeyPair{
|
||||
Name: "secondkey",
|
||||
Fingerprint: "35:9d:d0:c3:4a:80:d3:d8:86:f1:ca:f7:df:c4:f9:d8",
|
||||
PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7DUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5Q== Generated by Nova\n",
|
||||
}
|
||||
|
||||
// ExpectedKeyPairSlice is the slice of results that should be parsed from ListOutput, in the expected
|
||||
// order.
|
||||
var ExpectedKeyPairSlice = []KeyPair{FirstKeyPair, SecondKeyPair}
|
||||
|
||||
// CreatedKeyPair is the parsed result from CreatedOutput.
|
||||
var CreatedKeyPair = KeyPair{
|
||||
Name: "createdkey",
|
||||
Fingerprint: "35:9d:d0:c3:4a:80:d3:d8:86:f1:ca:f7:df:c4:f9:d8",
|
||||
PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7DUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5Q== Generated by Nova\n",
|
||||
PrivateKey: "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7\nDUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ\n9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5QIDAQAB\nAoGAE5XO1mDhORy9COvsg+kYPUhB1GsCYxh+v88wG7HeFDKBY6KUc/Kxo6yoGn5T\nTjRjekyi2KoDZHz4VlIzyZPwFS4I1bf3oCunVoAKzgLdmnTtvRNMC5jFOGc2vUgP\n9bSyRj3S1R4ClVk2g0IDeagko/jc8zzLEYuIK+fbkds79YECQQDt3vcevgegnkga\ntF4NsDmmBPRkcSHCqrANP/7vFcBQN3czxeYYWX3DK07alu6GhH1Y4sHbdm616uU0\nll7xbDzxAkEAzAtN2IyftNygV2EGiaGgqLyo/tD9+Vui2qCQplqe4jvWh/5Sparl\nOjmKo+uAW+hLrLVMnHzRWxbWU8hirH5FNQJATO+ZxCK4etXXAnQmG41NCAqANWB2\nB+2HJbH2NcQ2QHvAHUm741JGn/KI/aBlo7KEjFRDWUVUB5ji64BbUwCsMQJBAIku\nLGcjnBf/oLk+XSPZC2eGd2Ph5G5qYmH0Q2vkTx+wtTn3DV+eNsDfgMtWAJVJ5t61\ngU1QSXyhLPVlKpnnxuUCQC+xvvWjWtsLaFtAsZywJiqLxQzHts8XLGZptYJ5tLWV\nrtmYtBcJCN48RrgQHry/xWYeA4K/AFQpXfNPgprQ96Q=\n-----END RSA PRIVATE KEY-----\n",
|
||||
UserID: "fake",
|
||||
}
|
||||
|
||||
// ImportedKeyPair is the parsed result from ImportOutput.
|
||||
var ImportedKeyPair = KeyPair{
|
||||
Name: "importedkey",
|
||||
Fingerprint: "1e:2c:9b:56:79:4b:45:77:f9:ca:7a:98:2c:b0:d5:3c",
|
||||
PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated by Nova",
|
||||
UserID: "fake",
|
||||
}
|
||||
|
||||
// HandleListSuccessfully configures the test server to respond to a List request.
|
||||
func HandleListSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-keypairs", 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 "firstkey".
|
||||
func HandleGetSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-keypairs/firstkey", 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)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleCreateSuccessfully configures the test server to respond to a Create request for a new
|
||||
// keypair called "createdkey".
|
||||
func HandleCreateSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-keypairs", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
th.TestJSONRequest(t, r, `{ "keypair": { "name": "createdkey" } }`)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, CreateOutput)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleImportSuccessfully configures the test server to respond to an Import request for an
|
||||
// existing keypair called "importedkey".
|
||||
func HandleImportSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-keypairs", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "POST")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
th.TestJSONRequest(t, r, `
|
||||
{
|
||||
"keypair": {
|
||||
"name": "importedkey",
|
||||
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated by Nova"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, ImportOutput)
|
||||
})
|
||||
}
|
||||
|
||||
// HandleDeleteSuccessfully configures the test server to respond to a Delete request for a
|
||||
// keypair called "deletedkey".
|
||||
func HandleDeleteSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-keypairs/deletedkey", func(w http.ResponseWriter, r *http.Request) {
|
||||
th.TestMethod(t, r, "DELETE")
|
||||
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
})
|
||||
}
|
102
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs/requests.go
generated
vendored
102
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs/requests.go
generated
vendored
@@ -1,102 +0,0 @@
|
||||
package keypairs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// CreateOptsExt adds a KeyPair option to the base CreateOpts.
|
||||
type CreateOptsExt struct {
|
||||
servers.CreateOptsBuilder
|
||||
KeyName string `json:"key_name,omitempty"`
|
||||
}
|
||||
|
||||
// ToServerCreateMap adds the key_name and, optionally, key_data options to
|
||||
// the base server creation options.
|
||||
func (opts CreateOptsExt) ToServerCreateMap() (map[string]interface{}, error) {
|
||||
base, err := opts.CreateOptsBuilder.ToServerCreateMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if opts.KeyName == "" {
|
||||
return base, nil
|
||||
}
|
||||
|
||||
serverMap := base["server"].(map[string]interface{})
|
||||
serverMap["key_name"] = opts.KeyName
|
||||
|
||||
return base, nil
|
||||
}
|
||||
|
||||
// List returns a Pager that allows you to iterate over a collection of KeyPairs.
|
||||
func List(client *gophercloud.ServiceClient) pagination.Pager {
|
||||
return pagination.NewPager(client, listURL(client), func(r pagination.PageResult) pagination.Page {
|
||||
return KeyPairPage{pagination.SinglePageBase(r)}
|
||||
})
|
||||
}
|
||||
|
||||
// CreateOptsBuilder describes struct types that can be accepted by the Create call. Notable, the
|
||||
// CreateOpts struct in this package does.
|
||||
type CreateOptsBuilder interface {
|
||||
ToKeyPairCreateMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// CreateOpts specifies keypair creation or import parameters.
|
||||
type CreateOpts struct {
|
||||
// Name [required] is a friendly name to refer to this KeyPair in other services.
|
||||
Name string
|
||||
|
||||
// PublicKey [optional] is a pregenerated OpenSSH-formatted public key. If provided, this key
|
||||
// will be imported and no new key will be created.
|
||||
PublicKey string
|
||||
}
|
||||
|
||||
// ToKeyPairCreateMap constructs a request body from CreateOpts.
|
||||
func (opts CreateOpts) ToKeyPairCreateMap() (map[string]interface{}, error) {
|
||||
if opts.Name == "" {
|
||||
return nil, errors.New("Missing field required for keypair creation: Name")
|
||||
}
|
||||
|
||||
keypair := make(map[string]interface{})
|
||||
keypair["name"] = opts.Name
|
||||
if opts.PublicKey != "" {
|
||||
keypair["public_key"] = opts.PublicKey
|
||||
}
|
||||
|
||||
return map[string]interface{}{"keypair": keypair}, nil
|
||||
}
|
||||
|
||||
// Create requests the creation of a new keypair on the server, or to import a pre-existing
|
||||
// keypair.
|
||||
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
|
||||
var res CreateResult
|
||||
|
||||
reqBody, err := opts.ToKeyPairCreateMap()
|
||||
if err != nil {
|
||||
res.Err = err
|
||||
return res
|
||||
}
|
||||
|
||||
_, res.Err = client.Post(createURL(client), reqBody, &res.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
// Get returns public data about a previously uploaded KeyPair.
|
||||
func Get(client *gophercloud.ServiceClient, name string) GetResult {
|
||||
var res GetResult
|
||||
_, 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.Delete(deleteURL(client, name), nil)
|
||||
return res
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
package keypairs
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// KeyPair is an SSH key known to the OpenStack cluster that is available to be injected into
|
||||
// servers.
|
||||
type KeyPair struct {
|
||||
// Name is used to refer to this keypair from other services within this region.
|
||||
Name string `mapstructure:"name"`
|
||||
|
||||
// Fingerprint is a short sequence of bytes that can be used to authenticate or validate a longer
|
||||
// public key.
|
||||
Fingerprint string `mapstructure:"fingerprint"`
|
||||
|
||||
// PublicKey is the public key from this pair, in OpenSSH format. "ssh-rsa AAAAB3Nz..."
|
||||
PublicKey string `mapstructure:"public_key"`
|
||||
|
||||
// PrivateKey is the private key from this pair, in PEM format.
|
||||
// "-----BEGIN RSA PRIVATE KEY-----\nMIICXA..." It is only present if this keypair was just
|
||||
// returned from a Create call
|
||||
PrivateKey string `mapstructure:"private_key"`
|
||||
|
||||
// UserID is the user who owns this keypair.
|
||||
UserID string `mapstructure:"user_id"`
|
||||
}
|
||||
|
||||
// KeyPairPage stores a single, only page of KeyPair results from a List call.
|
||||
type KeyPairPage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty determines whether or not a KeyPairPage is empty.
|
||||
func (page KeyPairPage) IsEmpty() (bool, error) {
|
||||
ks, err := ExtractKeyPairs(page)
|
||||
return len(ks) == 0, err
|
||||
}
|
||||
|
||||
// ExtractKeyPairs interprets a page of results as a slice of KeyPairs.
|
||||
func ExtractKeyPairs(page pagination.Page) ([]KeyPair, error) {
|
||||
type pair struct {
|
||||
KeyPair KeyPair `mapstructure:"keypair"`
|
||||
}
|
||||
|
||||
var resp struct {
|
||||
KeyPairs []pair `mapstructure:"keypairs"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(page.(KeyPairPage).Body, &resp)
|
||||
results := make([]KeyPair, len(resp.KeyPairs))
|
||||
for i, pair := range resp.KeyPairs {
|
||||
results[i] = pair.KeyPair
|
||||
}
|
||||
return results, err
|
||||
}
|
||||
|
||||
type keyPairResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a method that attempts to interpret any KeyPair resource response as a KeyPair struct.
|
||||
func (r keyPairResult) Extract() (*KeyPair, error) {
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
var res struct {
|
||||
KeyPair *KeyPair `json:"keypair" mapstructure:"keypair"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(r.Body, &res)
|
||||
return res.KeyPair, err
|
||||
}
|
||||
|
||||
// CreateResult is the response from a Create operation. Call its Extract method to interpret it
|
||||
// as a KeyPair.
|
||||
type CreateResult struct {
|
||||
keyPairResult
|
||||
}
|
||||
|
||||
// GetResult is the response from a Get operation. Call its Extract method to interpret it
|
||||
// as a KeyPair.
|
||||
type GetResult struct {
|
||||
keyPairResult
|
||||
}
|
||||
|
||||
// DeleteResult is the response from a Delete operation. Call its Extract method to determine if
|
||||
// the call succeeded or failed.
|
||||
type DeleteResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
25
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs/urls.go
generated
vendored
25
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs/urls.go
generated
vendored
@@ -1,25 +0,0 @@
|
||||
package keypairs
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
const resourcePath = "os-keypairs"
|
||||
|
||||
func resourceURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL(resourcePath)
|
||||
}
|
||||
|
||||
func listURL(c *gophercloud.ServiceClient) string {
|
||||
return resourceURL(c)
|
||||
}
|
||||
|
||||
func createURL(c *gophercloud.ServiceClient) string {
|
||||
return resourceURL(c)
|
||||
}
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient, name string) string {
|
||||
return c.ServiceURL(resourcePath, name)
|
||||
}
|
||||
|
||||
func deleteURL(c *gophercloud.ServiceClient, name string) string {
|
||||
return getURL(c, name)
|
||||
}
|
@@ -1,2 +0,0 @@
|
||||
// Package network provides the ability to manage nova-networks
|
||||
package networks
|
209
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/networks/fixtures.go
generated
vendored
209
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/networks/fixtures.go
generated
vendored
@@ -1,209 +0,0 @@
|
||||
// +build fixtures
|
||||
|
||||
package networks
|
||||
|
||||
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": [
|
||||
{
|
||||
"bridge": "br100",
|
||||
"bridge_interface": "eth0",
|
||||
"broadcast": "10.0.0.7",
|
||||
"cidr": "10.0.0.0/29",
|
||||
"cidr_v6": null,
|
||||
"created_at": "2011-08-15 06:19:19.387525",
|
||||
"deleted": false,
|
||||
"deleted_at": null,
|
||||
"dhcp_start": "10.0.0.3",
|
||||
"dns1": null,
|
||||
"dns2": null,
|
||||
"gateway": "10.0.0.1",
|
||||
"gateway_v6": null,
|
||||
"host": "nsokolov-desktop",
|
||||
"id": "20c8acc0-f747-4d71-a389-46d078ebf047",
|
||||
"injected": false,
|
||||
"label": "mynet_0",
|
||||
"multi_host": false,
|
||||
"netmask": "255.255.255.248",
|
||||
"netmask_v6": null,
|
||||
"priority": null,
|
||||
"project_id": "1234",
|
||||
"rxtx_base": null,
|
||||
"updated_at": "2011-08-16 09:26:13.048257",
|
||||
"vlan": 100,
|
||||
"vpn_private_address": "10.0.0.2",
|
||||
"vpn_public_address": "127.0.0.1",
|
||||
"vpn_public_port": 1000
|
||||
},
|
||||
{
|
||||
"bridge": "br101",
|
||||
"bridge_interface": "eth0",
|
||||
"broadcast": "10.0.0.15",
|
||||
"cidr": "10.0.0.10/29",
|
||||
"cidr_v6": null,
|
||||
"created_at": "2011-08-15 06:19:19.885495",
|
||||
"deleted": false,
|
||||
"deleted_at": null,
|
||||
"dhcp_start": "10.0.0.11",
|
||||
"dns1": null,
|
||||
"dns2": null,
|
||||
"gateway": "10.0.0.9",
|
||||
"gateway_v6": null,
|
||||
"host": null,
|
||||
"id": "20c8acc0-f747-4d71-a389-46d078ebf000",
|
||||
"injected": false,
|
||||
"label": "mynet_1",
|
||||
"multi_host": false,
|
||||
"netmask": "255.255.255.248",
|
||||
"netmask_v6": null,
|
||||
"priority": null,
|
||||
"project_id": null,
|
||||
"rxtx_base": null,
|
||||
"updated_at": null,
|
||||
"vlan": 101,
|
||||
"vpn_private_address": "10.0.0.10",
|
||||
"vpn_public_address": null,
|
||||
"vpn_public_port": 1001
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
// GetOutput is a sample response to a Get call.
|
||||
const GetOutput = `
|
||||
{
|
||||
"network": {
|
||||
"bridge": "br101",
|
||||
"bridge_interface": "eth0",
|
||||
"broadcast": "10.0.0.15",
|
||||
"cidr": "10.0.0.10/29",
|
||||
"cidr_v6": null,
|
||||
"created_at": "2011-08-15 06:19:19.885495",
|
||||
"deleted": false,
|
||||
"deleted_at": null,
|
||||
"dhcp_start": "10.0.0.11",
|
||||
"dns1": null,
|
||||
"dns2": null,
|
||||
"gateway": "10.0.0.9",
|
||||
"gateway_v6": null,
|
||||
"host": null,
|
||||
"id": "20c8acc0-f747-4d71-a389-46d078ebf000",
|
||||
"injected": false,
|
||||
"label": "mynet_1",
|
||||
"multi_host": false,
|
||||
"netmask": "255.255.255.248",
|
||||
"netmask_v6": null,
|
||||
"priority": null,
|
||||
"project_id": null,
|
||||
"rxtx_base": null,
|
||||
"updated_at": null,
|
||||
"vlan": 101,
|
||||
"vpn_private_address": "10.0.0.10",
|
||||
"vpn_public_address": null,
|
||||
"vpn_public_port": 1001
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// FirstNetwork is the first result in ListOutput.
|
||||
var nilTime time.Time
|
||||
var FirstNetwork = Network{
|
||||
Bridge: "br100",
|
||||
BridgeInterface: "eth0",
|
||||
Broadcast: "10.0.0.7",
|
||||
CIDR: "10.0.0.0/29",
|
||||
CIDRv6: "",
|
||||
CreatedAt: time.Date(2011, 8, 15, 6, 19, 19, 387525000, time.UTC),
|
||||
Deleted: false,
|
||||
DeletedAt: nilTime,
|
||||
DHCPStart: "10.0.0.3",
|
||||
DNS1: "",
|
||||
DNS2: "",
|
||||
Gateway: "10.0.0.1",
|
||||
Gatewayv6: "",
|
||||
Host: "nsokolov-desktop",
|
||||
ID: "20c8acc0-f747-4d71-a389-46d078ebf047",
|
||||
Injected: false,
|
||||
Label: "mynet_0",
|
||||
MultiHost: false,
|
||||
Netmask: "255.255.255.248",
|
||||
Netmaskv6: "",
|
||||
Priority: 0,
|
||||
ProjectID: "1234",
|
||||
RXTXBase: 0,
|
||||
UpdatedAt: time.Date(2011, 8, 16, 9, 26, 13, 48257000, time.UTC),
|
||||
VLAN: 100,
|
||||
VPNPrivateAddress: "10.0.0.2",
|
||||
VPNPublicAddress: "127.0.0.1",
|
||||
VPNPublicPort: 1000,
|
||||
}
|
||||
|
||||
// SecondNetwork is the second result in ListOutput.
|
||||
var SecondNetwork = Network{
|
||||
Bridge: "br101",
|
||||
BridgeInterface: "eth0",
|
||||
Broadcast: "10.0.0.15",
|
||||
CIDR: "10.0.0.10/29",
|
||||
CIDRv6: "",
|
||||
CreatedAt: time.Date(2011, 8, 15, 6, 19, 19, 885495000, time.UTC),
|
||||
Deleted: false,
|
||||
DeletedAt: nilTime,
|
||||
DHCPStart: "10.0.0.11",
|
||||
DNS1: "",
|
||||
DNS2: "",
|
||||
Gateway: "10.0.0.9",
|
||||
Gatewayv6: "",
|
||||
Host: "",
|
||||
ID: "20c8acc0-f747-4d71-a389-46d078ebf000",
|
||||
Injected: false,
|
||||
Label: "mynet_1",
|
||||
MultiHost: false,
|
||||
Netmask: "255.255.255.248",
|
||||
Netmaskv6: "",
|
||||
Priority: 0,
|
||||
ProjectID: "",
|
||||
RXTXBase: 0,
|
||||
UpdatedAt: nilTime,
|
||||
VLAN: 101,
|
||||
VPNPrivateAddress: "10.0.0.10",
|
||||
VPNPublicAddress: "",
|
||||
VPNPublicPort: 1001,
|
||||
}
|
||||
|
||||
// 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-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-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)
|
||||
})
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
package networks
|
||||
|
||||
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
|
||||
}
|
222
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/networks/results.go
generated
vendored
222
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/networks/results.go
generated
vendored
@@ -1,222 +0,0 @@
|
||||
package networks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"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 {
|
||||
// The Bridge that VIFs on this network are connected to
|
||||
Bridge string `mapstructure:"bridge"`
|
||||
|
||||
// BridgeInterface is what interface is connected to the Bridge
|
||||
BridgeInterface string `mapstructure:"bridge_interface"`
|
||||
|
||||
// The Broadcast address of the network.
|
||||
Broadcast string `mapstructure:"broadcast"`
|
||||
|
||||
// CIDR is the IPv4 subnet.
|
||||
CIDR string `mapstructure:"cidr"`
|
||||
|
||||
// CIDRv6 is the IPv6 subnet.
|
||||
CIDRv6 string `mapstructure:"cidr_v6"`
|
||||
|
||||
// CreatedAt is when the network was created..
|
||||
CreatedAt time.Time `mapstructure:"-"`
|
||||
|
||||
// Deleted shows if the network has been deleted.
|
||||
Deleted bool `mapstructure:"deleted"`
|
||||
|
||||
// DeletedAt is the time when the network was deleted.
|
||||
DeletedAt time.Time `mapstructure:"-"`
|
||||
|
||||
// DHCPStart is the start of the DHCP address range.
|
||||
DHCPStart string `mapstructure:"dhcp_start"`
|
||||
|
||||
// DNS1 is the first DNS server to use through DHCP.
|
||||
DNS1 string `mapstructure:"dns_1"`
|
||||
|
||||
// DNS2 is the first DNS server to use through DHCP.
|
||||
DNS2 string `mapstructure:"dns_2"`
|
||||
|
||||
// Gateway is the network gateway.
|
||||
Gateway string `mapstructure:"gateway"`
|
||||
|
||||
// Gatewayv6 is the IPv6 network gateway.
|
||||
Gatewayv6 string `mapstructure:"gateway_v6"`
|
||||
|
||||
// Host is the host that the network service is running on.
|
||||
Host string `mapstructure:"host"`
|
||||
|
||||
// ID is the UUID of the network.
|
||||
ID string `mapstructure:"id"`
|
||||
|
||||
// Injected determines if network information is injected into the host.
|
||||
Injected bool `mapstructure:"injected"`
|
||||
|
||||
// Label is the common name that the network has..
|
||||
Label string `mapstructure:"label"`
|
||||
|
||||
// MultiHost is if multi-host networking is enablec..
|
||||
MultiHost bool `mapstructure:"multi_host"`
|
||||
|
||||
// Netmask is the network netmask.
|
||||
Netmask string `mapstructure:"netmask"`
|
||||
|
||||
// Netmaskv6 is the IPv6 netmask.
|
||||
Netmaskv6 string `mapstructure:"netmask_v6"`
|
||||
|
||||
// Priority is the network interface priority.
|
||||
Priority int `mapstructure:"priority"`
|
||||
|
||||
// ProjectID is the project associated with this network.
|
||||
ProjectID string `mapstructure:"project_id"`
|
||||
|
||||
// RXTXBase configures bandwidth entitlement.
|
||||
RXTXBase int `mapstructure:"rxtx_base"`
|
||||
|
||||
// UpdatedAt is the time when the network was last updated.
|
||||
UpdatedAt time.Time `mapstructure:"-"`
|
||||
|
||||
// VLAN is the vlan this network runs on.
|
||||
VLAN int `mapstructure:"vlan"`
|
||||
|
||||
// VPNPrivateAddress is the private address of the CloudPipe VPN.
|
||||
VPNPrivateAddress string `mapstructure:"vpn_private_address"`
|
||||
|
||||
// VPNPublicAddress is the public address of the CloudPipe VPN.
|
||||
VPNPublicAddress string `mapstructure:"vpn_public_address"`
|
||||
|
||||
// VPNPublicPort is the port of the CloudPipe VPN.
|
||||
VPNPublicPort int `mapstructure:"vpn_public_port"`
|
||||
}
|
||||
|
||||
// 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) {
|
||||
var res struct {
|
||||
Networks []Network `mapstructure:"networks"`
|
||||
}
|
||||
|
||||
err := mapstructure.Decode(page.(NetworkPage).Body, &res)
|
||||
|
||||
var rawNetworks []interface{}
|
||||
body := page.(NetworkPage).Body
|
||||
switch body.(type) {
|
||||
case map[string]interface{}:
|
||||
rawNetworks = body.(map[string]interface{})["networks"].([]interface{})
|
||||
case map[string][]interface{}:
|
||||
rawNetworks = body.(map[string][]interface{})["networks"]
|
||||
default:
|
||||
return res.Networks, fmt.Errorf("Unknown type")
|
||||
}
|
||||
|
||||
for i := range rawNetworks {
|
||||
thisNetwork := rawNetworks[i].(map[string]interface{})
|
||||
if t, ok := thisNetwork["created_at"].(string); ok && t != "" {
|
||||
createdAt, err := time.Parse("2006-01-02 15:04:05.000000", t)
|
||||
if err != nil {
|
||||
return res.Networks, err
|
||||
}
|
||||
res.Networks[i].CreatedAt = createdAt
|
||||
}
|
||||
|
||||
if t, ok := thisNetwork["updated_at"].(string); ok && t != "" {
|
||||
updatedAt, err := time.Parse("2006-01-02 15:04:05.000000", t)
|
||||
if err != nil {
|
||||
return res.Networks, err
|
||||
}
|
||||
res.Networks[i].UpdatedAt = updatedAt
|
||||
}
|
||||
|
||||
if t, ok := thisNetwork["deleted_at"].(string); ok && t != "" {
|
||||
deletedAt, err := time.Parse("2006-01-02 15:04:05.000000", t)
|
||||
if err != nil {
|
||||
return res.Networks, err
|
||||
}
|
||||
res.Networks[i].DeletedAt = deletedAt
|
||||
}
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
config := &mapstructure.DecoderConfig{
|
||||
Result: &res,
|
||||
WeaklyTypedInput: true,
|
||||
}
|
||||
decoder, err := mapstructure.NewDecoder(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := decoder.Decode(r.Body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b := r.Body.(map[string]interface{})["network"].(map[string]interface{})
|
||||
|
||||
if t, ok := b["created_at"].(string); ok && t != "" {
|
||||
createdAt, err := time.Parse("2006-01-02 15:04:05.000000", t)
|
||||
if err != nil {
|
||||
return res.Network, err
|
||||
}
|
||||
res.Network.CreatedAt = createdAt
|
||||
}
|
||||
|
||||
if t, ok := b["updated_at"].(string); ok && t != "" {
|
||||
updatedAt, err := time.Parse("2006-01-02 15:04:05.000000", t)
|
||||
if err != nil {
|
||||
return res.Network, err
|
||||
}
|
||||
res.Network.UpdatedAt = updatedAt
|
||||
}
|
||||
|
||||
if t, ok := b["deleted_at"].(string); ok && t != "" {
|
||||
deletedAt, err := time.Parse("2006-01-02 15:04:05.000000", t)
|
||||
if err != nil {
|
||||
return res.Network, err
|
||||
}
|
||||
res.Network.DeletedAt = deletedAt
|
||||
}
|
||||
|
||||
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
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/networks/urls.go
generated
vendored
17
vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/networks/urls.go
generated
vendored
@@ -1,17 +0,0 @@
|
||||
package networks
|
||||
|
||||
import "github.com/rackspace/gophercloud"
|
||||
|
||||
const resourcePath = "os-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)
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
// Package quotasets provides information and interaction with QuotaSet
|
||||
// extension for the OpenStack Compute service.
|
||||
package quotasets
|
@@ -1,59 +0,0 @@
|
||||
// +build fixtures
|
||||
|
||||
package quotasets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
th "github.com/rackspace/gophercloud/testhelper"
|
||||
"github.com/rackspace/gophercloud/testhelper/client"
|
||||
)
|
||||
|
||||
// GetOutput is a sample response to a Get call.
|
||||
const GetOutput = `
|
||||
{
|
||||
"quota_set" : {
|
||||
"instances" : 25,
|
||||
"security_groups" : 10,
|
||||
"security_group_rules" : 20,
|
||||
"cores" : 200,
|
||||
"injected_file_content_bytes" : 10240,
|
||||
"injected_files" : 5,
|
||||
"metadata_items" : 128,
|
||||
"ram" : 200000,
|
||||
"keypairs" : 10,
|
||||
"injected_file_path_bytes" : 255
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const FirstTenantID = "555544443333222211110000ffffeeee"
|
||||
|
||||
// FirstQuotaSet is the first result in ListOutput.
|
||||
var FirstQuotaSet = QuotaSet{
|
||||
FixedIps: 0,
|
||||
FloatingIps: 0,
|
||||
InjectedFileContentBytes: 10240,
|
||||
InjectedFilePathBytes: 255,
|
||||
InjectedFiles: 5,
|
||||
KeyPairs: 10,
|
||||
MetadataItems: 128,
|
||||
Ram: 200000,
|
||||
SecurityGroupRules: 20,
|
||||
SecurityGroups: 10,
|
||||
Cores: 200,
|
||||
Instances: 25,
|
||||
}
|
||||
|
||||
// HandleGetSuccessfully configures the test server to respond to a Get request for sample tenant
|
||||
func HandleGetSuccessfully(t *testing.T) {
|
||||
th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, 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)
|
||||
})
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user