feature/shared file systems: show share details (#127)
* sfs/shares: get a share with details
* sfs/shares: use AssertDeepEquals in get share test
diff --git a/openstack/sharedfilesystems/v2/shares/requests.go b/openstack/sharedfilesystems/v2/shares/requests.go
index 292ea95..cfa8460 100644
--- a/openstack/sharedfilesystems/v2/shares/requests.go
+++ b/openstack/sharedfilesystems/v2/shares/requests.go
@@ -73,3 +73,9 @@
_, r.Err = client.Delete(deleteURL(client, id), nil)
return
}
+
+// Get will get a single share with given UUID
+func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
+ _, r.Err = client.Get(getURL(client, id), &r.Body, nil)
+ return
+}
diff --git a/openstack/sharedfilesystems/v2/shares/results.go b/openstack/sharedfilesystems/v2/shares/results.go
index 10d8129..aef9f9a 100644
--- a/openstack/sharedfilesystems/v2/shares/results.go
+++ b/openstack/sharedfilesystems/v2/shares/results.go
@@ -85,3 +85,8 @@
type DeleteResult struct {
gophercloud.ErrResult
}
+
+// GetResult contains the get result
+type GetResult struct {
+ commonResult
+}
diff --git a/openstack/sharedfilesystems/v2/shares/testing/fixtures.go b/openstack/sharedfilesystems/v2/shares/testing/fixtures.go
index 00bdfe0..83b174f 100644
--- a/openstack/sharedfilesystems/v2/shares/testing/fixtures.go
+++ b/openstack/sharedfilesystems/v2/shares/testing/fixtures.go
@@ -88,3 +88,55 @@
w.WriteHeader(http.StatusAccepted)
})
}
+
+var getResponse = `{
+ "share": {
+ "links": [
+ {
+ "href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
+ "rel": "self"
+ },
+ {
+ "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
+ "rel": "bookmark"
+ }
+ ],
+ "availability_zone": "nova",
+ "share_network_id": "713df749-aac0-4a54-af52-10f6c991e80c",
+ "share_server_id": "e268f4aa-d571-43dd-9ab3-f49ad06ffaef",
+ "snapshot_id": null,
+ "id": "011d21e2-fbc3-4e4a-9993-9ea223f73264",
+ "size": 1,
+ "share_type": "25747776-08e5-494f-ab40-a64b9d20d8f7",
+ "share_type_name": "default",
+ "consistency_group_id": "9397c191-8427-4661-a2e8-b23820dc01d4",
+ "project_id": "16e1ab15c35a457e9c2b2aa189f544e1",
+ "metadata": {
+ "project": "my_app",
+ "aim": "doc"
+ },
+ "status": "available",
+ "description": "My custom share London",
+ "host": "manila2@generic1#GENERIC1",
+ "has_replicas": false,
+ "replication_type": null,
+ "task_state": null,
+ "is_public": true,
+ "snapshot_support": true,
+ "name": "my_test_share",
+ "created_at": "2015-09-18T10:25:24.000000",
+ "share_proto": "NFS",
+ "volume_type": "default",
+ "source_cgsnapshot_member_id": null
+ }
+}`
+
+// MockGetResponse creates a mock get response
+func MockGetResponse(t *testing.T) {
+ th.Mux.HandleFunc(shareEndpoint+"/"+shareID, func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, getResponse)
+ })
+}
diff --git a/openstack/sharedfilesystems/v2/shares/testing/request_test.go b/openstack/sharedfilesystems/v2/shares/testing/request_test.go
index c4e811c..7735e02 100644
--- a/openstack/sharedfilesystems/v2/shares/testing/request_test.go
+++ b/openstack/sharedfilesystems/v2/shares/testing/request_test.go
@@ -1,10 +1,12 @@
package testing
import (
+ "github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
"testing"
+ "time"
)
func TestCreate(t *testing.T) {
@@ -31,3 +33,53 @@
result := shares.Delete(client.ServiceClient(), shareID)
th.AssertNoErr(t, result.Err)
}
+
+func TestGet(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockGetResponse(t)
+
+ s, err := shares.Get(client.ServiceClient(), shareID).Extract()
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, s, &shares.Share{
+ AvailabilityZone: "nova",
+ ShareNetworkID: "713df749-aac0-4a54-af52-10f6c991e80c",
+ ShareServerID: "e268f4aa-d571-43dd-9ab3-f49ad06ffaef",
+ SnapshotID: "",
+ ID: shareID,
+ Size: 1,
+ ShareType: "25747776-08e5-494f-ab40-a64b9d20d8f7",
+ ShareTypeName: "default",
+ ConsistencyGroupID: "9397c191-8427-4661-a2e8-b23820dc01d4",
+ ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
+ Metadata: map[string]string{
+ "project": "my_app",
+ "aim": "doc",
+ },
+ Status: "available",
+ Description: "My custom share London",
+ Host: "manila2@generic1#GENERIC1",
+ HasReplicas: false,
+ ReplicationType: "",
+ TaskState: "",
+ SnapshotSupport: true,
+ Name: "my_test_share",
+ CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(
+ 2015, time.September, 18, 10, 25, 24, 0, time.UTC)),
+ ShareProto: "NFS",
+ VolumeType: "default",
+ SourceCgsnapshotMemberID: "",
+ IsPublic: true,
+ Links: []map[string]string{
+ {
+ "href": "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
+ "rel": "self",
+ },
+ {
+ "href": "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/011d21e2-fbc3-4e4a-9993-9ea223f73264",
+ "rel": "bookmark",
+ },
+ },
+ })
+}
diff --git a/openstack/sharedfilesystems/v2/shares/urls.go b/openstack/sharedfilesystems/v2/shares/urls.go
index 7cb1c81..309f071 100644
--- a/openstack/sharedfilesystems/v2/shares/urls.go
+++ b/openstack/sharedfilesystems/v2/shares/urls.go
@@ -9,3 +9,7 @@
func deleteURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL("shares", id)
}
+
+func getURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("shares", id)
+}