Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 05665d6

Browse files
author
Jamie Hannaford
committed
add delegates for rackspace configurations
1 parent 52dbcee commit 05665d6

File tree

3 files changed

+317
-0
lines changed

3 files changed

+317
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package configurations
2+
3+
import (
4+
"github.com/rackspace/gophercloud"
5+
os "github.com/rackspace/gophercloud/openstack/db/v1/configurations"
6+
"github.com/rackspace/gophercloud/pagination"
7+
)
8+
9+
// List will list all of the available configurations.
10+
func List(client *gophercloud.ServiceClient) pagination.Pager {
11+
return os.List(client)
12+
}
13+
14+
// Create will create a new configuration group.
15+
func Create(client *gophercloud.ServiceClient, opts os.CreateOptsBuilder) os.CreateResult {
16+
return os.Create(client, opts)
17+
}
18+
19+
// Get will retrieve the details for a specified configuration group.
20+
func Get(client *gophercloud.ServiceClient, configID string) os.GetResult {
21+
return os.Get(client, configID)
22+
}
23+
24+
// Update will modify an existing configuration group by performing a merge
25+
// between new and existing values. If the key already exists, the new value
26+
// will overwrite. All other keys will remain unaffected.
27+
func Update(client *gophercloud.ServiceClient, configID string, opts os.UpdateOptsBuilder) os.UpdateResult {
28+
return os.Update(client, configID, opts)
29+
}
30+
31+
// Replace will modify an existing configuration group by overwriting the
32+
// entire parameter group with the new values provided. Any existing keys not
33+
// included in UpdateOptsBuilder will be deleted.
34+
func Replace(client *gophercloud.ServiceClient, configID string, opts os.UpdateOptsBuilder) os.ReplaceResult {
35+
return os.Replace(client, configID, opts)
36+
}
37+
38+
// Delete will permanently delete a configuration group. Please note that
39+
// config groups cannot be deleted whilst still attached to running instances -
40+
// you must detach and then delete them.
41+
func Delete(client *gophercloud.ServiceClient, configID string) os.DeleteResult {
42+
return os.Delete(client, configID)
43+
}
44+
45+
// ListInstances will list all the instances associated with a particular
46+
// configuration group.
47+
func ListInstances(client *gophercloud.ServiceClient, configID string) pagination.Pager {
48+
return os.ListInstances(client, configID)
49+
}
50+
51+
// ListDatastoreParams will list all the available and supported parameters
52+
// that can be used for a particular datastore ID and a particular version.
53+
// For example, if you are wondering how you can configure a MySQL 5.6 instance,
54+
// you can use this operation (you will need to retrieve the MySQL datastore ID
55+
// by using the datastores API).
56+
func ListDatastoreParams(client *gophercloud.ServiceClient, datastoreID, versionID string) pagination.Pager {
57+
return os.ListDatastoreParams(client, datastoreID, versionID)
58+
}
59+
60+
// GetDatastoreParam will retrieve information about a specific configuration
61+
// parameter. For example, you can use this operation to understand more about
62+
// "innodb_file_per_table" configuration param for MySQL datastores. You will
63+
// need the param's ID first, which can be attained by using the ListDatastoreParams
64+
// operation.
65+
func GetDatastoreParam(client *gophercloud.ServiceClient, datastoreID, versionID, paramID string) os.ParamResult {
66+
return os.GetDatastoreParam(client, datastoreID, versionID, paramID)
67+
}
68+
69+
// ListGlobalParams is similar to ListDatastoreParams but does not require a
70+
// DatastoreID.
71+
func ListGlobalParams(client *gophercloud.ServiceClient, versionID string) pagination.Pager {
72+
return os.ListGlobalParams(client, versionID)
73+
}
74+
75+
// GetGlobalParam is similar to GetDatastoreParam but does not require a
76+
// DatastoreID.
77+
func GetGlobalParam(client *gophercloud.ServiceClient, versionID, paramID string) os.ParamResult {
78+
return os.GetGlobalParam(client, versionID, paramID)
79+
}
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
package configurations
2+
3+
import (
4+
"testing"
5+
6+
os "github.com/rackspace/gophercloud/openstack/db/v1/configurations"
7+
"github.com/rackspace/gophercloud/pagination"
8+
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
9+
th "github.com/rackspace/gophercloud/testhelper"
10+
fake "github.com/rackspace/gophercloud/testhelper/client"
11+
"github.com/rackspace/gophercloud/testhelper/fixture"
12+
)
13+
14+
var (
15+
configID = "{configID}"
16+
_baseURL = "/configurations"
17+
resURL = _baseURL + "/" + configID
18+
19+
dsID = "{datastoreID}"
20+
versionID = "{versionID}"
21+
paramID = "{paramID}"
22+
dsParamListURL = "/datastores/" + dsID + "/versions/" + versionID + "/parameters"
23+
dsParamGetURL = "/datastores/" + dsID + "/versions/" + versionID + "/parameters/" + paramID
24+
globalParamListURL = "/datastores/versions/" + versionID + "/parameters"
25+
globalParamGetURL = "/datastores/versions/" + versionID + "/parameters/" + paramID
26+
)
27+
28+
func TestList(t *testing.T) {
29+
th.SetupHTTP()
30+
defer th.TeardownHTTP()
31+
fixture.SetupHandler(t, _baseURL, "GET", "", os.ListConfigsJSON, 200)
32+
33+
count := 0
34+
err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
35+
count++
36+
actual, err := os.ExtractConfigs(page)
37+
th.AssertNoErr(t, err)
38+
39+
expected := []os.Config{os.ExampleConfig}
40+
th.AssertDeepEquals(t, expected, actual)
41+
42+
return true, nil
43+
})
44+
45+
th.AssertEquals(t, 1, count)
46+
th.AssertNoErr(t, err)
47+
}
48+
49+
func TestGet(t *testing.T) {
50+
th.SetupHTTP()
51+
defer th.TeardownHTTP()
52+
fixture.SetupHandler(t, resURL, "GET", "", os.GetConfigJSON, 200)
53+
54+
config, err := Get(fake.ServiceClient(), configID).Extract()
55+
th.AssertNoErr(t, err)
56+
th.AssertDeepEquals(t, &os.ExampleConfig, config)
57+
}
58+
59+
func TestCreate(t *testing.T) {
60+
th.SetupHTTP()
61+
defer th.TeardownHTTP()
62+
fixture.SetupHandler(t, _baseURL, "POST", os.CreateReq, os.CreateConfigJSON, 200)
63+
64+
opts := os.CreateOpts{
65+
Datastore: &os.DatastoreOpts{
66+
Type: "a00000a0-00a0-0a00-00a0-000a000000aa",
67+
Version: "b00000b0-00b0-0b00-00b0-000b000000bb",
68+
},
69+
Description: "example description",
70+
Name: "example-configuration-name",
71+
Values: map[string]interface{}{
72+
"collation_server": "latin1_swedish_ci",
73+
"connect_timeout": 120,
74+
},
75+
}
76+
77+
config, err := Create(fake.ServiceClient(), opts).Extract()
78+
th.AssertNoErr(t, err)
79+
th.AssertDeepEquals(t, &os.ExampleConfigWithValues, config)
80+
}
81+
82+
func TestUpdate(t *testing.T) {
83+
th.SetupHTTP()
84+
defer th.TeardownHTTP()
85+
fixture.SetupHandler(t, resURL, "PATCH", os.UpdateReq, "", 200)
86+
87+
opts := os.UpdateOpts{
88+
Values: map[string]interface{}{
89+
"connect_timeout": 300,
90+
},
91+
}
92+
93+
err := Update(fake.ServiceClient(), configID, opts).ExtractErr()
94+
th.AssertNoErr(t, err)
95+
}
96+
97+
func TestReplace(t *testing.T) {
98+
th.SetupHTTP()
99+
defer th.TeardownHTTP()
100+
fixture.SetupHandler(t, resURL, "PUT", os.UpdateReq, "", 202)
101+
102+
opts := os.UpdateOpts{
103+
Values: map[string]interface{}{
104+
"connect_timeout": 300,
105+
},
106+
}
107+
108+
err := Replace(fake.ServiceClient(), configID, opts).ExtractErr()
109+
th.AssertNoErr(t, err)
110+
}
111+
112+
func TestDelete(t *testing.T) {
113+
th.SetupHTTP()
114+
defer th.TeardownHTTP()
115+
fixture.SetupHandler(t, resURL, "DELETE", "", "", 202)
116+
117+
err := Delete(fake.ServiceClient(), configID).ExtractErr()
118+
th.AssertNoErr(t, err)
119+
}
120+
121+
func TestListInstances(t *testing.T) {
122+
th.SetupHTTP()
123+
defer th.TeardownHTTP()
124+
fixture.SetupHandler(t, resURL+"/instances", "GET", "", os.ListInstancesJSON, 200)
125+
126+
expectedInstance := instances.Instance{
127+
ID: "d4603f69-ec7e-4e9b-803f-600b9205576f",
128+
Name: "json_rack_instance",
129+
}
130+
131+
pages := 0
132+
err := ListInstances(fake.ServiceClient(), configID).EachPage(func(page pagination.Page) (bool, error) {
133+
pages++
134+
135+
actual, err := instances.ExtractInstances(page)
136+
if err != nil {
137+
return false, err
138+
}
139+
140+
th.AssertDeepEquals(t, actual, []instances.Instance{expectedInstance})
141+
142+
return true, nil
143+
})
144+
145+
th.AssertNoErr(t, err)
146+
th.AssertEquals(t, 1, pages)
147+
}
148+
149+
func TestListDSParams(t *testing.T) {
150+
th.SetupHTTP()
151+
defer th.TeardownHTTP()
152+
fixture.SetupHandler(t, dsParamListURL, "GET", "", os.ListParamsJSON, 200)
153+
154+
pages := 0
155+
err := ListDatastoreParams(fake.ServiceClient(), dsID, versionID).EachPage(func(page pagination.Page) (bool, error) {
156+
pages++
157+
158+
actual, err := os.ExtractParams(page)
159+
if err != nil {
160+
return false, err
161+
}
162+
163+
expected := []os.Param{
164+
os.Param{Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
165+
os.Param{Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
166+
os.Param{Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
167+
os.Param{Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
168+
}
169+
170+
th.AssertDeepEquals(t, actual, expected)
171+
172+
return true, nil
173+
})
174+
175+
th.AssertNoErr(t, err)
176+
th.AssertEquals(t, 1, pages)
177+
}
178+
179+
func TestGetDSParam(t *testing.T) {
180+
th.SetupHTTP()
181+
defer th.TeardownHTTP()
182+
fixture.SetupHandler(t, dsParamGetURL, "GET", "", os.GetParamJSON, 200)
183+
184+
param, err := GetDatastoreParam(fake.ServiceClient(), dsID, versionID, paramID).Extract()
185+
th.AssertNoErr(t, err)
186+
187+
expected := &os.Param{
188+
Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer",
189+
}
190+
191+
th.AssertDeepEquals(t, expected, param)
192+
}
193+
194+
func TestListGlobalParams(t *testing.T) {
195+
th.SetupHTTP()
196+
defer th.TeardownHTTP()
197+
fixture.SetupHandler(t, globalParamListURL, "GET", "", os.ListParamsJSON, 200)
198+
199+
pages := 0
200+
err := ListGlobalParams(fake.ServiceClient(), versionID).EachPage(func(page pagination.Page) (bool, error) {
201+
pages++
202+
203+
actual, err := os.ExtractParams(page)
204+
if err != nil {
205+
return false, err
206+
}
207+
208+
expected := []os.Param{
209+
os.Param{Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
210+
os.Param{Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
211+
os.Param{Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
212+
os.Param{Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
213+
}
214+
215+
th.AssertDeepEquals(t, actual, expected)
216+
217+
return true, nil
218+
})
219+
220+
th.AssertNoErr(t, err)
221+
th.AssertEquals(t, 1, pages)
222+
}
223+
224+
func TestGetGlobalParam(t *testing.T) {
225+
th.SetupHTTP()
226+
defer th.TeardownHTTP()
227+
fixture.SetupHandler(t, globalParamGetURL, "GET", "", os.GetParamJSON, 200)
228+
229+
param, err := GetGlobalParam(fake.ServiceClient(), versionID, paramID).Extract()
230+
th.AssertNoErr(t, err)
231+
232+
expected := &os.Param{
233+
Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer",
234+
}
235+
236+
th.AssertDeepEquals(t, expected, param)
237+
}

rackspace/db/v1/configurations/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package configurations

0 commit comments

Comments
 (0)