DNS Zones: List / Get (#271)
* Add Zone List / Get Support
* Addressing code review comments
* Adding v2 to DNS client
* List / Get unit tests plus updates to results for unit tests to work.
* DNS v2 List acceptance tests
* add failing unit test for dns v2 allpages
* Changing acceptance test for DNS v2 to use AllPages
* Adding empty zones.go file for package requirements
* Change ttl back to int
* DNS v2 Zones ListOpts
diff --git a/acceptance/clients/clients.go b/acceptance/clients/clients.go
index 8bf4aa3..aa57497 100644
--- a/acceptance/clients/clients.go
+++ b/acceptance/clients/clients.go
@@ -174,6 +174,25 @@
})
}
+// NewDNSV2Client returns a *ServiceClient for making calls
+// to the OpenStack Compute v2 API. An error will be returned
+// if authentication or client creation was not possible.
+func NewDNSV2Client() (*gophercloud.ServiceClient, error) {
+ ao, err := openstack.AuthOptionsFromEnv()
+ if err != nil {
+ return nil, err
+ }
+
+ client, err := openstack.AuthenticatedClient(ao)
+ if err != nil {
+ return nil, err
+ }
+
+ return openstack.NewDNSV2(client, gophercloud.EndpointOpts{
+ Region: os.Getenv("OS_REGION_NAME"),
+ })
+}
+
// NewIdentityV2Client returns a *ServiceClient for making calls
// to the OpenStack Identity v2 API. An error will be returned
// if authentication or client creation was not possible.
diff --git a/acceptance/openstack/dns/v2/zones.go b/acceptance/openstack/dns/v2/zones.go
new file mode 100644
index 0000000..5ec3cc8
--- /dev/null
+++ b/acceptance/openstack/dns/v2/zones.go
@@ -0,0 +1 @@
+package v2
diff --git a/acceptance/openstack/dns/v2/zones_test.go b/acceptance/openstack/dns/v2/zones_test.go
new file mode 100644
index 0000000..add964d
--- /dev/null
+++ b/acceptance/openstack/dns/v2/zones_test.go
@@ -0,0 +1,33 @@
+// +build acceptance dns zones
+
+package v2
+
+import (
+ "testing"
+
+ "github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
+ "github.com/gophercloud/gophercloud/openstack/dns/v2/zones"
+)
+
+func TestZonesList(t *testing.T) {
+ client, err := clients.NewDNSV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create a DNS client: %v", err)
+ }
+
+ var allZones []zones.Zone
+ allPages, err := zones.List(client, nil).AllPages()
+ if err != nil {
+ t.Fatalf("Unable to retrieve zones: %v", err)
+ }
+
+ allZones, err = zones.ExtractZones(allPages)
+ if err != nil {
+ t.Fatalf("Unable to extract zones: %v", err)
+ }
+
+ for _, zone := range allZones {
+ tools.PrintResource(t, &zone)
+ }
+}