Adding configuration parameters :ok_hand:
diff --git a/rackspace/db/v1/configurations/fixtures.go b/rackspace/db/v1/configurations/fixtures.go
index df67e4c..c3723ab 100644
--- a/rackspace/db/v1/configurations/fixtures.go
+++ b/rackspace/db/v1/configurations/fixtures.go
@@ -77,6 +77,51 @@
}
`
+var listParamsJSON = `
+{
+ "configuration-parameters": [
+ {
+ "max": 1,
+ "min": 0,
+ "name": "innodb_file_per_table",
+ "restart_required": true,
+ "type": "integer"
+ },
+ {
+ "max": 4294967296,
+ "min": 0,
+ "name": "key_buffer_size",
+ "restart_required": false,
+ "type": "integer"
+ },
+ {
+ "max": 65535,
+ "min": 2,
+ "name": "connect_timeout",
+ "restart_required": false,
+ "type": "integer"
+ },
+ {
+ "max": 4294967296,
+ "min": 0,
+ "name": "join_buffer_size",
+ "restart_required": false,
+ "type": "integer"
+ }
+ ]
+}
+`
+
+var getParamJSON = `
+{
+ "max": 1,
+ "min": 0,
+ "name": "innodb_file_per_table",
+ "restart_required": true,
+ "type": "integer"
+}
+`
+
var exampleConfig = Config{
Created: "2014-07-31T18:56:09",
DatastoreName: "mysql",
diff --git a/rackspace/db/v1/configurations/requests.go b/rackspace/db/v1/configurations/requests.go
index 1dbee7a..726176a 100644
--- a/rackspace/db/v1/configurations/requests.go
+++ b/rackspace/db/v1/configurations/requests.go
@@ -190,6 +190,41 @@
pageFn := func(r pagination.PageResult) pagination.Page {
return instances.InstancePage{pagination.LinkedPageBase{PageResult: r}}
}
-
return pagination.NewPager(client, instancesURL(client, configID), pageFn)
}
+
+func ListDatastoreParams(client *gophercloud.ServiceClient, datastoreID, versionID string) pagination.Pager {
+ pageFn := func(r pagination.PageResult) pagination.Page {
+ return ParamPage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(client, listDSParamsURL(client, datastoreID, versionID), pageFn)
+}
+
+func GetDatastoreParam(client *gophercloud.ServiceClient, datastoreID, versionID, paramID string) ParamResult {
+ var res ParamResult
+
+ _, res.Err = client.Request("GET", getDSParamURL(client, datastoreID, versionID, paramID), gophercloud.RequestOpts{
+ OkCodes: []int{200},
+ JSONResponse: &res.Body,
+ })
+
+ return res
+}
+
+func ListGlobalParams(client *gophercloud.ServiceClient, versionID string) pagination.Pager {
+ pageFn := func(r pagination.PageResult) pagination.Page {
+ return ParamPage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(client, listGlobalParamsURL(client, versionID), pageFn)
+}
+
+func GetGlobalParam(client *gophercloud.ServiceClient, versionID, paramID string) ParamResult {
+ var res ParamResult
+
+ _, res.Err = client.Request("GET", getGlobalParamURL(client, versionID, paramID), gophercloud.RequestOpts{
+ OkCodes: []int{200},
+ JSONResponse: &res.Body,
+ })
+
+ return res
+}
diff --git a/rackspace/db/v1/configurations/requests_test.go b/rackspace/db/v1/configurations/requests_test.go
index 14120b3..29d1119 100644
--- a/rackspace/db/v1/configurations/requests_test.go
+++ b/rackspace/db/v1/configurations/requests_test.go
@@ -14,6 +14,14 @@
configID = "{configID}"
_baseURL = "/configurations"
resURL = _baseURL + "/" + configID
+
+ dsID = "{datastoreID}"
+ versionID = "{versionID}"
+ paramID = "{paramID}"
+ dsParamListURL = "/datastores/" + dsID + "/versions/" + versionID + "/parameters"
+ dsParamGetURL = "/datastores/" + dsID + "/versions/" + versionID + "/parameters/" + paramID
+ globalParamListURL = "/datastores/versions/" + versionID + "/parameters"
+ globalParamGetURL = "/datastores/versions/" + versionID + "/parameters/" + paramID
)
func TestList(t *testing.T) {
@@ -143,3 +151,97 @@
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, pages)
}
+
+func TestListDSParams(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ fixture.SetupHandler(t, dsParamListURL, "GET", "", listParamsJSON, 200)
+
+ pages := 0
+ err := ListDatastoreParams(fake.ServiceClient(), dsID, versionID).EachPage(func(page pagination.Page) (bool, error) {
+ pages++
+
+ actual, err := ExtractParams(page)
+ if err != nil {
+ return false, err
+ }
+
+ expected := []Param{
+ Param{Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
+ Param{Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
+ Param{Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
+ Param{Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
+ }
+
+ th.AssertDeepEquals(t, actual, expected)
+
+ return true, nil
+ })
+
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, 1, pages)
+}
+
+func TestGetDSParam(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ fixture.SetupHandler(t, dsParamGetURL, "GET", "", getParamJSON, 200)
+
+ param, err := GetDatastoreParam(fake.ServiceClient(), dsID, versionID, paramID).Extract()
+ th.AssertNoErr(t, err)
+
+ expected := &Param{
+ Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer",
+ }
+
+ th.AssertDeepEquals(t, expected, param)
+}
+
+func TestListGlobalParams(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ fixture.SetupHandler(t, globalParamListURL, "GET", "", listParamsJSON, 200)
+
+ pages := 0
+ err := ListGlobalParams(fake.ServiceClient(), versionID).EachPage(func(page pagination.Page) (bool, error) {
+ pages++
+
+ actual, err := ExtractParams(page)
+ if err != nil {
+ return false, err
+ }
+
+ expected := []Param{
+ Param{Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
+ Param{Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
+ Param{Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
+ Param{Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
+ }
+
+ th.AssertDeepEquals(t, actual, expected)
+
+ return true, nil
+ })
+
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, 1, pages)
+}
+
+func TestGetGlobalParam(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ fixture.SetupHandler(t, globalParamGetURL, "GET", "", getParamJSON, 200)
+
+ param, err := GetGlobalParam(fake.ServiceClient(), versionID, paramID).Extract()
+ th.AssertNoErr(t, err)
+
+ expected := &Param{
+ Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer",
+ }
+
+ th.AssertDeepEquals(t, expected, param)
+}
diff --git a/rackspace/db/v1/configurations/results.go b/rackspace/db/v1/configurations/results.go
index cd83d10..5c960b8 100644
--- a/rackspace/db/v1/configurations/results.go
+++ b/rackspace/db/v1/configurations/results.go
@@ -77,3 +77,49 @@
type DeleteResult struct {
gophercloud.ErrResult
}
+
+type Param struct {
+ Max int
+ Min int
+ Name string
+ RestartRequired bool `mapstructure:"restart_required" json:"restart_required"`
+ Type string
+}
+
+type ParamPage struct {
+ pagination.SinglePageBase
+}
+
+func (r ParamPage) IsEmpty() (bool, error) {
+ is, err := ExtractParams(r)
+ if err != nil {
+ return true, err
+ }
+ return len(is) == 0, nil
+}
+
+func ExtractParams(page pagination.Page) ([]Param, error) {
+ casted := page.(ParamPage).Body
+
+ var resp struct {
+ Params []Param `mapstructure:"configuration-parameters" json:"configuration-parameters"`
+ }
+
+ err := mapstructure.Decode(casted, &resp)
+ return resp.Params, err
+}
+
+type ParamResult struct {
+ gophercloud.Result
+}
+
+func (r ParamResult) Extract() (*Param, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+
+ var param Param
+
+ err := mapstructure.Decode(r.Body, ¶m)
+ return ¶m, err
+}
diff --git a/rackspace/db/v1/configurations/urls.go b/rackspace/db/v1/configurations/urls.go
index 9ac02e6..4d4c244 100644
--- a/rackspace/db/v1/configurations/urls.go
+++ b/rackspace/db/v1/configurations/urls.go
@@ -13,3 +13,19 @@
func instancesURL(c *gophercloud.ServiceClient, configID string) string {
return c.ServiceURL("configurations", configID, "instances")
}
+
+func listDSParamsURL(c *gophercloud.ServiceClient, datastoreID, versionID string) string {
+ return c.ServiceURL("datastores", dsID, "versions", versionID, "parameters")
+}
+
+func getDSParamURL(c *gophercloud.ServiceClient, datastoreID, versionID, paramID string) string {
+ return c.ServiceURL("datastores", dsID, "versions", versionID, "parameters", paramID)
+}
+
+func listGlobalParamsURL(c *gophercloud.ServiceClient, versionID string) string {
+ return c.ServiceURL("datastores", "versions", versionID, "parameters")
+}
+
+func getGlobalParamURL(c *gophercloud.ServiceClient, versionID, paramID string) string {
+ return c.ServiceURL("datastores", "versions", versionID, "parameters", paramID)
+}