Adding GetConfig operation for Rackspace provider
diff --git a/rackspace/db/v1/instances/fixtures.go b/rackspace/db/v1/instances/fixtures.go
index ac2471e..cbd18da 100644
--- a/rackspace/db/v1/instances/fixtures.go
+++ b/rackspace/db/v1/instances/fixtures.go
@@ -104,3 +104,63 @@
fmt.Fprintf(w, singleInstanceJson)
})
}
+
+func HandleGetConfigSuccessfully(t *testing.T, id string) {
+ th.Mux.HandleFunc("/instances/"+id+"/configuration", 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")
+
+ fmt.Fprintf(w, `
+{
+ "instance": {
+ "configuration": {
+ "basedir": "/usr",
+ "connect_timeout": "15",
+ "datadir": "/var/lib/mysql",
+ "default_storage_engine": "innodb",
+ "innodb_buffer_pool_instances": "1",
+ "innodb_buffer_pool_size": "175M",
+ "innodb_checksum_algorithm": "crc32",
+ "innodb_data_file_path": "ibdata1:10M:autoextend",
+ "innodb_file_per_table": "1",
+ "innodb_io_capacity": "200",
+ "innodb_log_file_size": "256M",
+ "innodb_log_files_in_group": "2",
+ "innodb_open_files": "8192",
+ "innodb_thread_concurrency": "0",
+ "join_buffer_size": "1M",
+ "key_buffer_size": "50M",
+ "local-infile": "0",
+ "log-error": "/var/log/mysql/mysqld.log",
+ "max_allowed_packet": "16M",
+ "max_connect_errors": "10000",
+ "max_connections": "40",
+ "max_heap_table_size": "16M",
+ "myisam-recover": "BACKUP",
+ "open_files_limit": "8192",
+ "performance_schema": "off",
+ "pid_file": "/var/run/mysqld/mysqld.pid",
+ "port": "3306",
+ "query_cache_limit": "1M",
+ "query_cache_size": "8M",
+ "query_cache_type": "1",
+ "read_buffer_size": "256K",
+ "read_rnd_buffer_size": "1M",
+ "server_id": "1",
+ "skip-external-locking": "1",
+ "skip_name_resolve": "1",
+ "sort_buffer_size": "256K",
+ "table_open_cache": "4096",
+ "thread_stack": "192K",
+ "tmp_table_size": "16M",
+ "tmpdir": "/var/tmp",
+ "user": "mysql",
+ "wait_timeout": "3600"
+ }
+ }
+}
+`)
+ })
+}
diff --git a/rackspace/db/v1/instances/requests.go b/rackspace/db/v1/instances/requests.go
new file mode 100644
index 0000000..a0ffcad
--- /dev/null
+++ b/rackspace/db/v1/instances/requests.go
@@ -0,0 +1,21 @@
+package instances
+
+import (
+ "github.com/racker/perigee"
+ "github.com/rackspace/gophercloud"
+)
+
+func GetDefaultConfig(client *gophercloud.ServiceClient, id string) ConfigResult {
+ var res ConfigResult
+
+ resp, err := perigee.Request("GET", configURL(client, id), perigee.Options{
+ MoreHeaders: client.AuthenticatedHeaders(),
+ Results: &res.Body,
+ OkCodes: []int{200},
+ })
+
+ res.Header = resp.HttpResponse.Header
+ res.Err = err
+
+ return res
+}
diff --git a/rackspace/db/v1/instances/requests_test.go b/rackspace/db/v1/instances/requests_test.go
new file mode 100644
index 0000000..e653c07
--- /dev/null
+++ b/rackspace/db/v1/instances/requests_test.go
@@ -0,0 +1,65 @@
+package instances
+
+import (
+ "testing"
+
+ th "github.com/rackspace/gophercloud/testhelper"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
+)
+
+func TestGetConfig(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ HandleGetConfigSuccessfully(t)
+
+ config, err := GetConfig(fake.ServiceClient(), opts).Extract()
+
+ expected := map[string]string{
+ "basedir": "/usr",
+ "connect_timeout": "15",
+ "datadir": "/var/lib/mysql",
+ "default_storage_engine": "innodb",
+ "innodb_buffer_pool_instances": "1",
+ "innodb_buffer_pool_size": "175M",
+ "innodb_checksum_algorithm": "crc32",
+ "innodb_data_file_path": "ibdata1:10M:autoextend",
+ "innodb_file_per_table": "1",
+ "innodb_io_capacity": "200",
+ "innodb_log_file_size": "256M",
+ "innodb_log_files_in_group": "2",
+ "innodb_open_files": "8192",
+ "innodb_thread_concurrency": "0",
+ "join_buffer_size": "1M",
+ "key_buffer_size": "50M",
+ "local-infile": "0",
+ "log-error": "/var/log/mysql/mysqld.log",
+ "max_allowed_packet": "16M",
+ "max_connect_errors": "10000",
+ "max_connections": "40",
+ "max_heap_table_size": "16M",
+ "myisam-recover": "BACKUP",
+ "open_files_limit": "8192",
+ "performance_schema": "off",
+ "pid_file": "/var/run/mysqld/mysqld.pid",
+ "port": "3306",
+ "query_cache_limit": "1M",
+ "query_cache_size": "8M",
+ "query_cache_type": "1",
+ "read_buffer_size": "256K",
+ "read_rnd_buffer_size": "1M",
+ "server_id": "1",
+ "skip-external-locking": "1",
+ "skip_name_resolve": "1",
+ "sort_buffer_size": "256K",
+ "table_open_cache": "4096",
+ "thread_stack": "192K",
+ "tmp_table_size": "16M",
+ "tmpdir": "/var/tmp",
+ "user": "mysql",
+ "wait_timeout": "3600",
+ }
+
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, expected, config)
+}
diff --git a/rackspace/db/v1/instances/results.go b/rackspace/db/v1/instances/results.go
index cab403a..2b7f4fd 100644
--- a/rackspace/db/v1/instances/results.go
+++ b/rackspace/db/v1/instances/results.go
@@ -53,3 +53,22 @@
func (r GetResult) Extract() (*Instance, error) {
return commonExtract(r.Err, r.Body)
}
+
+type ConfigResult struct {
+ gophercloud.Result
+}
+
+func (r ConfigResult) Extract() (map[string]string, error) {
+ if err != nil {
+ return nil, err
+ }
+
+ var response struct {
+ Instance struct {
+ Config map[string]string `mapstructure:"configuration"`
+ } `mapstructure:"instance"`
+ }
+
+ err = mapstructure.Decode(body, &response)
+ return &response.Instance, err
+}
diff --git a/rackspace/db/v1/instances/urls.go b/rackspace/db/v1/instances/urls.go
index bb6edf2..c0c1bad 100644
--- a/rackspace/db/v1/instances/urls.go
+++ b/rackspace/db/v1/instances/urls.go
@@ -9,3 +9,7 @@
func createURL(c *gophercloud.ServiceClient) string {
return baseURL(c)
}
+
+func configURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL("instances", id, "configuration")
+}