tenantattr extension for cinder (#186)

* tenantattr extension for cinder; ExtractInto method for handling custom Volume objects

* make sure interface{} parameter is *struct

* ExtractInto*Ptr methods for Result

* use gophercloud.ExtractInto*Ptr for ExtractInto and ^CtractVolumesInto

* use type instead of struct literal in unit test

* comments for tenantattr pkg

* call volumes.ExtractInto from volumes.Extract

* clean up extractIntoPtr and add comments for new exported methods

* add comment about ExtractInto*Ptr being for internal use only

* check for http response error in ExtractInto*Ptr methods

rename tenantattr pkg to volumetenants

* rename tenantattr to volumetenants; remove commented code
diff --git a/acceptance/openstack/sharedfilesystems/v2/securityservices.go b/acceptance/openstack/sharedfilesystems/v2/securityservices.go
new file mode 100644
index 0000000..e9b5549
--- /dev/null
+++ b/acceptance/openstack/sharedfilesystems/v2/securityservices.go
@@ -0,0 +1,49 @@
+package v2
+
+import (
+	"testing"
+
+	"github.com/gophercloud/gophercloud"
+	"github.com/gophercloud/gophercloud/acceptance/tools"
+	"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices"
+)
+
+// CreateSecurityService will create a security service with a random name. An
+// error will be returned if the security service was unable to be created.
+func CreateSecurityService(t *testing.T, client *gophercloud.ServiceClient) (*securityservices.SecurityService, error) {
+	if testing.Short() {
+		t.Skip("Skipping test that requires share network creation in short mode.")
+	}
+
+	securityServiceName := tools.RandomString("ACPTTEST", 16)
+	t.Logf("Attempting to create security service: %s", securityServiceName)
+
+	createOpts := securityservices.CreateOpts{
+		Name: securityServiceName,
+		Type: "kerberos",
+	}
+
+	securityService, err := securityservices.Create(client, createOpts).Extract()
+	if err != nil {
+		return securityService, err
+	}
+
+	return securityService, nil
+}
+
+// PrintSecurityService will print a security service and all of its attributes.
+func PrintSecurityService(t *testing.T, securityService *securityservices.SecurityService) {
+	t.Logf("ID: %s", securityService.ID)
+	t.Logf("Project ID: %s", securityService.ProjectID)
+	t.Logf("Domain: %s", securityService.Domain)
+	t.Logf("Status: %s", securityService.Status)
+	t.Logf("Type: %s", securityService.Type)
+	t.Logf("Name: %s", securityService.Name)
+	t.Logf("Description: %s", securityService.Description)
+	t.Logf("DNS IP: %s", securityService.DNSIP)
+	t.Logf("User: %s", securityService.User)
+	t.Logf("Password: %s", securityService.Password)
+	t.Logf("Server: %s", securityService.Server)
+	t.Logf("Created at: %v", securityService.CreatedAt)
+	t.Logf("Updated at: %v", securityService.UpdatedAt)
+}
diff --git a/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go b/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go
new file mode 100644
index 0000000..8ef917c
--- /dev/null
+++ b/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go
@@ -0,0 +1,23 @@
+package v2
+
+import (
+	"testing"
+
+	"github.com/gophercloud/gophercloud/acceptance/clients"
+)
+
+func TestSecurityServiceCreate(t *testing.T) {
+	client, err := clients.NewSharedFileSystemV2Client()
+	if err != nil {
+		t.Fatalf("Unable to create shared file system client: %v", err)
+	}
+
+	securityService, err := CreateSecurityService(t, client)
+	if err != nil {
+		t.Fatalf("Unable to create security service: %v", err)
+	}
+
+	// TODO: Delete the security service once Delete is supported
+
+	PrintSecurityService(t, securityService)
+}
diff --git a/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go b/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go
index 8784764..e29e484 100644
--- a/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go
+++ b/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go
@@ -61,3 +61,28 @@
 
 	PrintShareType(t, shareType)
 }
+
+func TestShareTypeExtraSpecs(t *testing.T) {
+	client, err := clients.NewSharedFileSystemV2Client()
+	if err != nil {
+		t.Fatalf("Unable to create shared file system client: %v", err)
+	}
+
+	shareType, err := CreateShareType(t, client)
+	if err != nil {
+		t.Fatalf("Unable to create share type: %v", err)
+	}
+
+	extraSpecs, err := sharetypes.GetExtraSpecs(client, shareType.ID).Extract()
+	if err != nil {
+		t.Fatalf("Unable to retrieve share type: %s", shareType.Name)
+	}
+
+	if extraSpecs["driver_handles_share_servers"] != "True" {
+		t.Fatal("driver_handles_share_servers was expected to be true")
+	}
+
+	PrintShareType(t, shareType)
+
+	defer DeleteShareType(t, client, shareType)
+}
diff --git a/openstack/sharedfilesystems/v2/securityservices/requests.go b/openstack/sharedfilesystems/v2/securityservices/requests.go
new file mode 100644
index 0000000..eca9fe5
--- /dev/null
+++ b/openstack/sharedfilesystems/v2/securityservices/requests.go
@@ -0,0 +1,61 @@
+package securityservices
+
+import "github.com/gophercloud/gophercloud"
+
+type SecurityServiceType string
+
+// Valid security service types
+const (
+	LDAP            SecurityServiceType = "ldap"
+	Kerberos        SecurityServiceType = "kerberos"
+	ActiveDirectory SecurityServiceType = "active_directory"
+)
+
+// CreateOptsBuilder allows extensions to add additional parameters to the
+// Create request.
+type CreateOptsBuilder interface {
+	ToSecurityServiceCreateMap() (map[string]interface{}, error)
+}
+
+// CreateOpts contains options for creating a SecurityService. This object is
+// passed to the securityservices.Create function. For more information about
+// these parameters, see the SecurityService object.
+type CreateOpts struct {
+	// The security service type. A valid value is ldap, kerberos, or active_directory
+	Type SecurityServiceType `json:"type" required:"true"`
+	// The security service name
+	Name string `json:"name,omitempty"`
+	// The security service description
+	Description string `json:"description,omitempty"`
+	// The DNS IP address that is used inside the tenant network
+	DNSIP string `json:"dns_ip,omitempty"`
+	// The security service user or group name that is used by the tenant
+	User string `json:"user,omitempty"`
+	// The user password, if you specify a user
+	Password string `json:"password,omitempty"`
+	// The security service domain
+	Domain string `json:"domain,omitempty"`
+	// The security service host name or IP address
+	Server string `json:"server,omitempty"`
+}
+
+// ToSecurityServicesCreateMap assembles a request body based on the contents of a
+// CreateOpts.
+func (opts CreateOpts) ToSecurityServiceCreateMap() (map[string]interface{}, error) {
+	return gophercloud.BuildRequestBody(opts, "security_service")
+}
+
+// Create will create a new SecurityService based on the values in CreateOpts. To
+// extract the SecurityService object from the response, call the Extract method
+// on the CreateResult.
+func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
+	b, err := opts.ToSecurityServiceCreateMap()
+	if err != nil {
+		r.Err = err
+		return
+	}
+	_, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
+		OkCodes: []int{200},
+	})
+	return
+}
diff --git a/openstack/sharedfilesystems/v2/securityservices/results.go b/openstack/sharedfilesystems/v2/securityservices/results.go
new file mode 100644
index 0000000..e34692d
--- /dev/null
+++ b/openstack/sharedfilesystems/v2/securityservices/results.go
@@ -0,0 +1,52 @@
+package securityservices
+
+import "github.com/gophercloud/gophercloud"
+
+// SecurityService contains all the information associated with an OpenStack
+// SecurityService.
+type SecurityService struct {
+	// The security service ID
+	ID string `json:"id"`
+	// The UUID of the project where the security service was created
+	ProjectID string `json:"project_id"`
+	// The security service domain
+	Domain string `json:"domain"`
+	// The security service status
+	Status string `json:"status"`
+	// The security service type. A valid value is ldap, kerberos, or active_directory
+	Type string `json:"type"`
+	// The security service name
+	Name string `json:"name"`
+	// The security service description
+	Description string `json:"description"`
+	// The DNS IP address that is used inside the tenant network
+	DNSIP string `json:"dns_ip"`
+	// The security service user or group name that is used by the tenant
+	User string `json:"user"`
+	// The user password, if you specify a user
+	Password string `json:"password"`
+	// The security service host name or IP address
+	Server string `json:"server"`
+	// The date and time stamp when the security service was created
+	CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
+	// The date and time stamp when the security service was updated
+	UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
+}
+
+type commonResult struct {
+	gophercloud.Result
+}
+
+// Extract will get the SecurityService object out of the commonResult object.
+func (r commonResult) Extract() (*SecurityService, error) {
+	var s struct {
+		SecurityService *SecurityService `json:"security_service"`
+	}
+	err := r.ExtractInto(&s)
+	return s.SecurityService, err
+}
+
+// CreateResult contains the response body and error from a Create request.
+type CreateResult struct {
+	commonResult
+}
diff --git a/openstack/sharedfilesystems/v2/securityservices/testing/fixtures.go b/openstack/sharedfilesystems/v2/securityservices/testing/fixtures.go
new file mode 100644
index 0000000..78adc48
--- /dev/null
+++ b/openstack/sharedfilesystems/v2/securityservices/testing/fixtures.go
@@ -0,0 +1,52 @@
+package testing
+
+import (
+	"fmt"
+	"net/http"
+	"testing"
+
+	th "github.com/gophercloud/gophercloud/testhelper"
+	fake "github.com/gophercloud/gophercloud/testhelper/client"
+)
+
+func MockCreateResponse(t *testing.T) {
+	th.Mux.HandleFunc("/security-services", 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, `
+        {
+            "security_service": {
+                "description": "Creating my first Security Service",
+                "dns_ip": "10.0.0.0/24",
+                "user": "demo",
+                "password": "***",
+                "type": "kerberos",
+                "name": "SecServ1"
+            }
+        }`)
+
+		w.Header().Add("Content-Type", "application/json")
+		w.WriteHeader(http.StatusOK)
+
+		fmt.Fprintf(w, `
+        {
+            "security_service": {
+                "status": "new",
+                "domain": null,
+                "project_id": "16e1ab15c35a457e9c2b2aa189f544e1",
+                "name": "SecServ1",
+                "created_at": "2015-09-07T12:19:10.695211",
+                "updated_at": null,
+                "server": null,
+                "dns_ip": "10.0.0.0/24",
+                "user": "demo",
+                "password": "supersecret",
+                "type": "kerberos",
+                "id": "3c829734-0679-4c17-9637-801da48c0d5f",
+                "description": "Creating my first Security Service"
+            }
+        }`)
+	})
+}
diff --git a/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go b/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go
new file mode 100644
index 0000000..2b3325e
--- /dev/null
+++ b/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go
@@ -0,0 +1,53 @@
+package testing
+
+import (
+	"testing"
+
+	"github.com/gophercloud/gophercloud"
+	"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices"
+	th "github.com/gophercloud/gophercloud/testhelper"
+	"github.com/gophercloud/gophercloud/testhelper/client"
+)
+
+// Verifies that a security service can be created correctly
+func TestCreate(t *testing.T) {
+	th.SetupHTTP()
+	defer th.TeardownHTTP()
+
+	MockCreateResponse(t)
+
+	options := &securityservices.CreateOpts{
+		Name:        "SecServ1",
+		Description: "Creating my first Security Service",
+		DNSIP:       "10.0.0.0/24",
+		User:        "demo",
+		Password:    "***",
+		Type:        "kerberos",
+	}
+
+	s, err := securityservices.Create(client.ServiceClient(), options).Extract()
+	th.AssertNoErr(t, err)
+
+	th.AssertEquals(t, s.Name, "SecServ1")
+	th.AssertEquals(t, s.Description, "Creating my first Security Service")
+	th.AssertEquals(t, s.User, "demo")
+	th.AssertEquals(t, s.DNSIP, "10.0.0.0/24")
+	th.AssertEquals(t, s.Password, "supersecret")
+	th.AssertEquals(t, s.Type, "kerberos")
+}
+
+// Verifies that a security service cannot be created without a type
+func TestCreateFails(t *testing.T) {
+	options := &securityservices.CreateOpts{
+		Name:        "SecServ1",
+		Description: "Creating my first Security Service",
+		DNSIP:       "10.0.0.0/24",
+		User:        "demo",
+		Password:    "***",
+	}
+
+	_, err := securityservices.Create(client.ServiceClient(), options).Extract()
+	if _, ok := err.(gophercloud.ErrMissingInput); !ok {
+		t.Fatal("ErrMissingInput was expected to occur")
+	}
+}
diff --git a/openstack/sharedfilesystems/v2/securityservices/urls.go b/openstack/sharedfilesystems/v2/securityservices/urls.go
new file mode 100644
index 0000000..ba0ae6d
--- /dev/null
+++ b/openstack/sharedfilesystems/v2/securityservices/urls.go
@@ -0,0 +1,7 @@
+package securityservices
+
+import "github.com/gophercloud/gophercloud"
+
+func createURL(c *gophercloud.ServiceClient) string {
+	return c.ServiceURL("security-services")
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/requests.go b/openstack/sharedfilesystems/v2/sharetypes/requests.go
index 38174fe..94f84b6 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/requests.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/requests.go
@@ -98,3 +98,9 @@
 	_, r.Err = client.Get(getDefaultURL(client), &r.Body, nil)
 	return
 }
+
+// GetExtraSpecs will retrieve the extra specifications for a given ShareType.
+func GetExtraSpecs(client *gophercloud.ServiceClient, id string) (r GetExtraSpecsResult) {
+	_, r.Err = client.Get(getExtraSpecsURL(client, id), &r.Body, nil)
+	return
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/results.go b/openstack/sharedfilesystems/v2/sharetypes/results.go
index fa3a4e1..f4de532 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/results.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/results.go
@@ -68,3 +68,25 @@
 type GetDefaultResult struct {
 	commonResult
 }
+
+// ExtraSpecs contains all the information associated with extra specifications
+// for an Openstack ShareType.
+type ExtraSpecs map[string]interface{}
+
+type extraSpecsResult struct {
+	gophercloud.Result
+}
+
+// Extract will get the ExtraSpecs object out of the commonResult object.
+func (r extraSpecsResult) Extract() (ExtraSpecs, error) {
+	var s struct {
+		Specs ExtraSpecs `json:"extra_specs"`
+	}
+	err := r.ExtractInto(&s)
+	return s.Specs, err
+}
+
+// GetExtraSpecsResult contains the response body and error from a Get Extra Specs request.
+type GetExtraSpecsResult struct {
+	extraSpecsResult
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go b/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go
index 58d9bb3..1666d11 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go
@@ -164,3 +164,21 @@
         }`)
 	})
 }
+
+func MockGetExtraSpecsResponse(t *testing.T) {
+	th.Mux.HandleFunc("/types/shareTypeID/extra_specs", 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, `
+        {
+            "extra_specs": {
+                "snapshot_support": "True",
+                "driver_handles_share_servers": "True",
+				"my_custom_extra_spec": "False"
+            }
+        }`)
+	})
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go b/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go
index 0518c02..ad1ad15 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go
@@ -119,3 +119,18 @@
 	th.AssertNoErr(t, err)
 	th.CheckDeepEquals(t, &expected, actual)
 }
+
+// Verifies that it is possible to get the extra specifications for a share type
+func TestGetExtraSpecs(t *testing.T) {
+	th.SetupHTTP()
+	defer th.TeardownHTTP()
+
+	MockGetExtraSpecsResponse(t)
+
+	st, err := sharetypes.GetExtraSpecs(client.ServiceClient(), "shareTypeID").Extract()
+	th.AssertNoErr(t, err)
+
+	th.AssertEquals(t, st["snapshot_support"], "True")
+	th.AssertEquals(t, st["driver_handles_share_servers"], "True")
+	th.AssertEquals(t, st["my_custom_extra_spec"], "False")
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/urls.go b/openstack/sharedfilesystems/v2/sharetypes/urls.go
index 7b1d2ca..ecd159e 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/urls.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/urls.go
@@ -17,3 +17,7 @@
 func getDefaultURL(c *gophercloud.ServiceClient) string {
 	return c.ServiceURL("types", "default")
 }
+
+func getExtraSpecsURL(c *gophercloud.ServiceClient, id string) string {
+	return c.ServiceURL("types", id, "extra_specs")
+}