Adding get extension operation
diff --git a/acceptance/openstack/networking/v2/network_test.go b/acceptance/openstack/networking/v2/network_test.go
index b1d02b5..209a68c 100644
--- a/acceptance/openstack/networking/v2/network_test.go
+++ b/acceptance/openstack/networking/v2/network_test.go
@@ -44,6 +44,12 @@
Client = nil
}
+func Equals(t *testing.T, actual interface{}, expected interface{}) {
+ if expected != actual {
+ t.Fatalf("Expected %#v but got %#v", expected, actual)
+ }
+}
+
func TestListAPIVersions(t *testing.T) {
Setup(t)
defer Teardown()
@@ -91,7 +97,19 @@
}
func TestGetExt(t *testing.T) {
- //networks.Extension()
+ Setup(t)
+ defer Teardown()
+
+ ext, err := networks.GetExtension(Client, "service-type")
+ if err != nil {
+ t.Fatalf("Unexpected error when getting extension: %#v", err)
+ }
+
+ Equals(t, ext.Updated, "2013-01-20T00:00:00-00:00")
+ Equals(t, ext.Name, "Neutron Service Type Management")
+ Equals(t, ext.Namespace, "http://docs.openstack.org/ext/neutron/service-type/api/v1.0")
+ Equals(t, ext.Alias, "service-type")
+ Equals(t, ext.Description, "API for retrieving service providers for Neutron advanced services")
}
func TestListNetworks(t *testing.T) {
diff --git a/openstack/networking/v2/networks/requests.go b/openstack/networking/v2/networks/requests.go
index 21055a8..cc57540 100644
--- a/openstack/networking/v2/networks/requests.go
+++ b/openstack/networking/v2/networks/requests.go
@@ -48,3 +48,19 @@
return &resp, nil
}
+
+func GetExtension(c *gophercloud.ServiceClient, name string) (*Extension, error) {
+ var ext Extension
+ _, err := perigee.Request("GET", ExtensionURL(c, name), perigee.Options{
+ MoreHeaders: c.Provider.AuthenticatedHeaders(),
+ Results: &struct {
+ Extension *Extension `json:"extension"`
+ }{&ext},
+ OkCodes: []int{200},
+ })
+
+ if err != nil {
+ return nil, err
+ }
+ return &ext, nil
+}
diff --git a/openstack/networking/v2/networks/requests_test.go b/openstack/networking/v2/networks/requests_test.go
index 4d4bfe1..85e3ce0 100644
--- a/openstack/networking/v2/networks/requests_test.go
+++ b/openstack/networking/v2/networks/requests_test.go
@@ -21,6 +21,18 @@
}
}
+func Equals(t *testing.T, actual interface{}, expected interface{}) {
+ if expected != actual {
+ t.Fatalf("Expected %#v but got %#v", expected, actual)
+ }
+}
+
+func CheckErr(t *testing.T, e error) {
+ if e != nil {
+ t.Fatalf("An error occurred: %#v", e)
+ }
+}
+
func TestListAPIVersions(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -151,3 +163,44 @@
t.Errorf("Expected %#v, got %#v", expected, actual)
}
}
+
+func TestListingExtensions(t *testing.T) {
+
+}
+
+func TestGettingExtension(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ th.Mux.HandleFunc("/v2.0/extension/agent", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", TokenID)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+
+ fmt.Fprintf(w, `
+{
+ "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."
+ }
+}
+ `)
+
+ c := ServiceClient()
+
+ ext, err := GetExtension(c, "agent")
+ CheckErr(t, err)
+
+ Equals(t, ext.Updated, "2013-02-03T10:00:00-00:00")
+ Equals(t, ext.Name, "agent")
+ Equals(t, ext.Namespace, "http://docs.openstack.org/ext/agent/api/v2.0")
+ Equals(t, ext.Alias, "agent")
+ Equals(t, ext.Description, "The agent management extension.")
+ })
+}
diff --git a/openstack/networking/v2/networks/results.go b/openstack/networking/v2/networks/results.go
index e601c57..61d51b0 100644
--- a/openstack/networking/v2/networks/results.go
+++ b/openstack/networking/v2/networks/results.go
@@ -128,3 +128,12 @@
func ToAPIResource(results gophercloud.Collection) []APIResource {
return results.(*APIInfoList).APIResources
}
+
+type Extension struct {
+ Updated string `json:"updated"`
+ Name string `json:"name"`
+ Links []interface{} `json:"links"`
+ Namespace string `json:"namespace"`
+ Alias string `json:"alias"`
+ Description string `json:"description"`
+}
diff --git a/openstack/networking/v2/networks/urls.go b/openstack/networking/v2/networks/urls.go
index 3f49261..8d350b1 100644
--- a/openstack/networking/v2/networks/urls.go
+++ b/openstack/networking/v2/networks/urls.go
@@ -6,6 +6,8 @@
"github.com/rackspace/gophercloud"
)
+const Version = "v2.0"
+
func APIVersionsURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL("")
}
@@ -13,3 +15,7 @@
func APIInfoURL(c *gophercloud.ServiceClient, version string) string {
return c.ServiceURL(strings.TrimRight(version, "/") + "/")
}
+
+func ExtensionURL(c *gophercloud.ServiceClient, name string) string {
+ return c.ServiceURL(Version, "extensions", name)
+}
diff --git a/openstack/networking/v2/networks/urls_test.go b/openstack/networking/v2/networks/urls_test.go
index a6c57e2..34009ed 100644
--- a/openstack/networking/v2/networks/urls_test.go
+++ b/openstack/networking/v2/networks/urls_test.go
@@ -6,7 +6,7 @@
"github.com/rackspace/gophercloud"
)
-const Endpoint = "http://localhost:57909/v3/"
+const Endpoint = "http://localhost:57909/"
func EndpointClient() *gophercloud.ServiceClient {
return &gophercloud.ServiceClient{Endpoint: Endpoint}
@@ -27,3 +27,11 @@
t.Fatalf("[%s] does not match expected [%s]", actual, expected)
}
}
+
+func TestExtensionURL(t *testing.T) {
+ actual := ExtensionURL(EndpointClient(), "agent")
+ expected := Endpoint + "v2.0/extensions/agent"
+ if expected != actual {
+ t.Fatalf("[%s] does not match expected [%s]", actual, expected)
+ }
+}