networks acceptance tests
diff --git a/acceptance/rackspace/networking/v2/common_test.go b/acceptance/rackspace/networking/v2/common_test.go
new file mode 100644
index 0000000..6356e96
--- /dev/null
+++ b/acceptance/rackspace/networking/v2/common_test.go
@@ -0,0 +1,40 @@
+// +build acceptance rackspace networking v2
+
+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{
+ Region: os.Getenv("RS_REGION_NAME"),
+ })
+}
+
+func Setup(t *testing.T) {
+ client, err := NewClient()
+ th.AssertNoErr(t, err)
+ Client = client
+}
+
+func Teardown() {
+ Client = nil
+}
diff --git a/acceptance/rackspace/networking/v2/networks_test.go b/acceptance/rackspace/networking/v2/networks_test.go
new file mode 100644
index 0000000..6621ded
--- /dev/null
+++ b/acceptance/rackspace/networking/v2/networks_test.go
@@ -0,0 +1,51 @@
+// +build acceptance rackspace networking v2
+
+package v2
+
+import (
+ "testing"
+
+ "github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/networking/v2/networks"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestNetworks(t *testing.T) {
+ Setup(t)
+ defer Teardown()
+
+ // Create a network
+ n, err := networks.Create(Client, networks.CreateOpts{Label: "sample_network", CIDR: "172.20.0.0/24"}).Extract()
+ th.AssertNoErr(t, err)
+ defer networks.Delete(Client, n.ID)
+ th.AssertEquals(t, n.Label, "sample_network")
+ th.AssertEquals(t, n.CIDR, "172.20.0.0/24")
+ networkID := n.ID
+
+ // List networks
+ pager := networks.List(Client)
+ err = pager.EachPage(func(page pagination.Page) (bool, error) {
+ t.Logf("--- Page ---")
+
+ networkList, err := networks.ExtractNetworks(page)
+ th.AssertNoErr(t, err)
+
+ for _, n := range networkList {
+ t.Logf("Network: ID [%s] Label [%s] CIDR [%s]",
+ n.ID, n.Label, n.CIDR)
+ }
+
+ return true, nil
+ })
+ th.CheckNoErr(t, err)
+
+ // Get a network
+ if networkID == "" {
+ t.Fatalf("In order to retrieve a network, the NetworkID must be set")
+ }
+ n, err = networks.Get(Client, networkID).Extract()
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, n.CIDR, "172.20.0.0/24")
+ th.AssertEquals(t, n.Label, "sample_network")
+ th.AssertEquals(t, n.ID, networkID)
+}
diff --git a/acceptance/rackspace/networking/v2/virtualinterfaces_test.go b/acceptance/rackspace/networking/v2/virtualinterfaces_test.go
new file mode 100644
index 0000000..1f2b4fd
--- /dev/null
+++ b/acceptance/rackspace/networking/v2/virtualinterfaces_test.go
@@ -0,0 +1,3 @@
+// +build acceptance rackspace networking v2
+
+package v2
diff --git a/rackspace/client.go b/rackspace/client.go
index 86a78a1..f0f8597 100644
--- a/rackspace/client.go
+++ b/rackspace/client.go
@@ -142,3 +142,8 @@
func NewObjectStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
return os.NewObjectStorageV1(client, eo)
}
+
+// NewNetworkV2 creates a ServiceClient that may be used with the Rackspace v2 networking package.
+func NewNetworkV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
+ return NewComputeV2(client, eo)
+}
diff --git a/rackspace/networking/v2/networks/requests.go b/rackspace/networking/v2/networks/requests.go
index 2327dff..d3c973e 100644
--- a/rackspace/networking/v2/networks/requests.go
+++ b/rackspace/networking/v2/networks/requests.go
@@ -85,7 +85,7 @@
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
- OkCodes: []int{201, 202},
+ OkCodes: []int{200, 201, 202},
})
return res
}