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

Commit a50d135

Browse files
author
Jamie Hannaford
committed
Refactor to use new client.Request
1 parent c1c6bf8 commit a50d135

File tree

13 files changed

+92
-144
lines changed

13 files changed

+92
-144
lines changed

openstack/db/v1/databases/requests.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package databases
33
import (
44
"fmt"
55

6-
"github.com/racker/perigee"
76
"github.com/rackspace/gophercloud"
87
"github.com/rackspace/gophercloud/pagination"
98
)
@@ -68,16 +67,12 @@ func Create(client *gophercloud.ServiceClient, instanceID string, opts CreateOpt
6867
return res
6968
}
7069

71-
resp, err := perigee.Request("POST", baseURL(client, instanceID), perigee.Options{
72-
MoreHeaders: client.AuthenticatedHeaders(),
73-
ReqBody: &reqBody,
74-
Results: &res.Body,
75-
OkCodes: []int{202},
70+
_, res.Err = client.Request("POST", baseURL(client, instanceID), gophercloud.RequestOpts{
71+
JSONBody: &reqBody,
72+
JSONResponse: &res.Body,
73+
OkCodes: []int{202},
7674
})
7775

78-
res.Header = resp.HttpResponse.Header
79-
res.Err = err
80-
8176
return res
8277
}
8378

@@ -92,14 +87,10 @@ func List(client *gophercloud.ServiceClient, instanceID string) pagination.Pager
9287
func Delete(client *gophercloud.ServiceClient, instanceID, dbName string) DeleteResult {
9388
var res DeleteResult
9489

95-
resp, err := perigee.Request("DELETE", dbURL(client, instanceID, dbName), perigee.Options{
96-
MoreHeaders: client.AuthenticatedHeaders(),
97-
Results: &res.Body,
98-
OkCodes: []int{202},
90+
_, res.Err = client.Request("DELETE", dbURL(client, instanceID, dbName), gophercloud.RequestOpts{
91+
JSONBody: &res.Body,
92+
OkCodes: []int{202},
9993
})
10094

101-
res.Header = resp.HttpResponse.Header
102-
res.Err = err
103-
10495
return res
10596
}

openstack/db/v1/flavors/requests.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package flavors
22

33
import (
4-
"github.com/racker/perigee"
54
"github.com/rackspace/gophercloud"
65
"github.com/rackspace/gophercloud/pagination"
76
)
@@ -16,9 +15,11 @@ func List(client *gophercloud.ServiceClient) pagination.Pager {
1615

1716
func Get(client *gophercloud.ServiceClient, id string) GetResult {
1817
var gr GetResult
19-
gr.Err = perigee.Get(getURL(client, id), perigee.Options{
20-
Results: &gr.Body,
21-
MoreHeaders: client.AuthenticatedHeaders(),
18+
19+
_, gr.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
20+
JSONResponse: &gr.Body,
21+
OkCodes: []int{200},
2222
})
23+
2324
return gr
2425
}

openstack/db/v1/instances/requests.go

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package instances
33
import (
44
"fmt"
55

6-
"github.com/racker/perigee"
76
"github.com/rackspace/gophercloud"
87
db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
98
"github.com/rackspace/gophercloud/openstack/db/v1/users"
@@ -87,16 +86,12 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
8786
return res
8887
}
8988

90-
resp, err := perigee.Request("POST", baseURL(client), perigee.Options{
91-
MoreHeaders: client.AuthenticatedHeaders(),
92-
ReqBody: &reqBody,
93-
Results: &res.Body,
94-
OkCodes: []int{200},
89+
_, res.Err = client.Request("POST", baseURL(client), gophercloud.RequestOpts{
90+
JSONBody: &reqBody,
91+
JSONResponse: &res.Body,
92+
OkCodes: []int{200},
9593
})
9694

97-
res.Header = resp.HttpResponse.Header
98-
res.Err = err
99-
10095
return res
10196
}
10297

@@ -113,30 +108,22 @@ func List(client *gophercloud.ServiceClient) pagination.Pager {
113108
func Get(client *gophercloud.ServiceClient, id string) GetResult {
114109
var res GetResult
115110

116-
resp, err := perigee.Request("GET", resourceURL(client, id), perigee.Options{
117-
MoreHeaders: client.AuthenticatedHeaders(),
118-
Results: &res.Body,
119-
OkCodes: []int{200},
111+
_, res.Err = client.Request("GET", resourceURL(client, id), gophercloud.RequestOpts{
112+
JSONResponse: &res.Body,
113+
OkCodes: []int{200},
120114
})
121115

122-
res.Header = resp.HttpResponse.Header
123-
res.Err = err
124-
125116
return res
126117
}
127118

128119
// Delete permanently destroys the database instance.
129120
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
130121
var res DeleteResult
131122

132-
resp, err := perigee.Request("DELETE", resourceURL(client, id), perigee.Options{
133-
MoreHeaders: client.AuthenticatedHeaders(),
134-
OkCodes: []int{202},
123+
_, res.Err = client.Request("DELETE", resourceURL(client, id), gophercloud.RequestOpts{
124+
OkCodes: []int{202},
135125
})
136126

137-
res.Header = resp.HttpResponse.Header
138-
res.Err = err
139-
140127
return res
141128
}
142129

@@ -145,15 +132,11 @@ func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
145132
func EnableRootUser(client *gophercloud.ServiceClient, id string) UserRootResult {
146133
var res UserRootResult
147134

148-
resp, err := perigee.Request("POST", userRootURL(client, id), perigee.Options{
149-
MoreHeaders: client.AuthenticatedHeaders(),
150-
Results: &res.Body,
151-
OkCodes: []int{200},
135+
_, res.Err = client.Request("POST", userRootURL(client, id), gophercloud.RequestOpts{
136+
JSONResponse: &res.Body,
137+
OkCodes: []int{200},
152138
})
153139

154-
res.Header = resp.HttpResponse.Header
155-
res.Err = err
156-
157140
return res
158141
}
159142

@@ -163,10 +146,9 @@ func EnableRootUser(client *gophercloud.ServiceClient, id string) UserRootResult
163146
func IsRootEnabled(client *gophercloud.ServiceClient, id string) (bool, error) {
164147
var res gophercloud.Result
165148

166-
_, err := perigee.Request("GET", userRootURL(client, id), perigee.Options{
167-
MoreHeaders: client.AuthenticatedHeaders(),
168-
Results: &res.Body,
169-
OkCodes: []int{200},
149+
_, err := client.Request("GET", userRootURL(client, id), gophercloud.RequestOpts{
150+
JSONResponse: &res.Body,
151+
OkCodes: []int{200},
170152
})
171153

172154
return res.Body.(map[string]interface{})["rootEnabled"] == true, err
@@ -178,15 +160,11 @@ func IsRootEnabled(client *gophercloud.ServiceClient, id string) (bool, error) {
178160
func RestartService(client *gophercloud.ServiceClient, id string) ActionResult {
179161
var res ActionResult
180162

181-
resp, err := perigee.Request("POST", actionURL(client, id), perigee.Options{
182-
MoreHeaders: client.AuthenticatedHeaders(),
183-
ReqBody: map[string]bool{"restart": true},
184-
OkCodes: []int{202},
163+
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
164+
JSONBody: map[string]bool{"restart": true},
165+
OkCodes: []int{202},
185166
})
186167

187-
res.Header = resp.HttpResponse.Header
188-
res.Err = err
189-
190168
return res
191169
}
192170

@@ -201,15 +179,11 @@ func ResizeInstance(client *gophercloud.ServiceClient, id, flavorRef string) Act
201179
},
202180
}
203181

204-
resp, err := perigee.Request("POST", actionURL(client, id), perigee.Options{
205-
MoreHeaders: client.AuthenticatedHeaders(),
206-
ReqBody: reqBody,
207-
OkCodes: []int{202},
182+
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
183+
JSONBody: reqBody,
184+
OkCodes: []int{202},
208185
})
209186

210-
res.Header = resp.HttpResponse.Header
211-
res.Err = err
212-
213187
return res
214188
}
215189

@@ -225,14 +199,10 @@ func ResizeVolume(client *gophercloud.ServiceClient, id string, size int) Action
225199
},
226200
}
227201

228-
resp, err := perigee.Request("POST", actionURL(client, id), perigee.Options{
229-
MoreHeaders: client.AuthenticatedHeaders(),
230-
ReqBody: reqBody,
231-
OkCodes: []int{202},
202+
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
203+
JSONBody: reqBody,
204+
OkCodes: []int{202},
232205
})
233206

234-
res.Header = resp.HttpResponse.Header
235-
res.Err = err
236-
237207
return res
238208
}

openstack/db/v1/users/requests.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package users
22

33
import (
4-
"github.com/racker/perigee"
54
"github.com/rackspace/gophercloud"
65
db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
76
"github.com/rackspace/gophercloud/pagination"
@@ -77,15 +76,11 @@ func Create(client *gophercloud.ServiceClient, instanceID string, opts CreateOpt
7776
return res
7877
}
7978

80-
resp, err := perigee.Request("POST", baseURL(client, instanceID), perigee.Options{
81-
MoreHeaders: client.AuthenticatedHeaders(),
82-
ReqBody: &reqBody,
83-
OkCodes: []int{202},
79+
_, res.Err = client.Request("POST", baseURL(client, instanceID), gophercloud.RequestOpts{
80+
JSONBody: &reqBody,
81+
OkCodes: []int{202},
8482
})
8583

86-
res.Header = resp.HttpResponse.Header
87-
res.Err = err
88-
8984
return res
9085
}
9186

@@ -100,13 +95,9 @@ func List(client *gophercloud.ServiceClient, instanceID string) pagination.Pager
10095
func Delete(client *gophercloud.ServiceClient, instanceID, userName string) DeleteResult {
10196
var res DeleteResult
10297

103-
resp, err := perigee.Request("DELETE", userURL(client, instanceID, userName), perigee.Options{
104-
MoreHeaders: client.AuthenticatedHeaders(),
105-
OkCodes: []int{202},
98+
_, res.Err = client.Request("DELETE", userURL(client, instanceID, userName), gophercloud.RequestOpts{
99+
OkCodes: []int{202},
106100
})
107101

108-
res.Header = resp.HttpResponse.Header
109-
res.Err = err
110-
111102
return res
112103
}

rackspace/db/v1/backups/requests.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package backups
33
import (
44
"errors"
55

6-
"github.com/racker/perigee"
76
"github.com/rackspace/gophercloud"
87
"github.com/rackspace/gophercloud/pagination"
98
)
@@ -49,11 +48,10 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateRes
4948
return res
5049
}
5150

52-
_, res.Err = perigee.Request("POST", baseURL(client), perigee.Options{
53-
MoreHeaders: client.AuthenticatedHeaders(),
54-
ReqBody: &reqBody,
55-
Results: &res.Body,
56-
OkCodes: []int{202},
51+
_, res.Err = client.Request("POST", baseURL(client), gophercloud.RequestOpts{
52+
JSONBody: &reqBody,
53+
JSONResponse: &res.Body,
54+
OkCodes: []int{202},
5755
})
5856

5957
return res
@@ -96,10 +94,9 @@ func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pa
9694
func Get(client *gophercloud.ServiceClient, id string) GetResult {
9795
var res GetResult
9896

99-
_, res.Err = perigee.Request("GET", resourceURL(client, id), perigee.Options{
100-
MoreHeaders: client.AuthenticatedHeaders(),
101-
Results: &res.Body,
102-
OkCodes: []int{200},
97+
_, res.Err = client.Request("GET", resourceURL(client, id), gophercloud.RequestOpts{
98+
JSONResponse: &res.Body,
99+
OkCodes: []int{200},
103100
})
104101

105102
return res
@@ -108,9 +105,8 @@ func Get(client *gophercloud.ServiceClient, id string) GetResult {
108105
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
109106
var res DeleteResult
110107

111-
_, res.Err = perigee.Request("DELETE", resourceURL(client, id), perigee.Options{
112-
MoreHeaders: client.AuthenticatedHeaders(),
113-
OkCodes: []int{202},
108+
_, res.Err = client.Request("DELETE", resourceURL(client, id), gophercloud.RequestOpts{
109+
OkCodes: []int{202},
114110
})
115111

116112
return res

rackspace/db/v1/backups/requests_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"github.com/rackspace/gophercloud/pagination"
7+
"github.com/rackspace/gophercloud/rackspace/db/v1/datastores"
78
th "github.com/rackspace/gophercloud/testhelper"
89
fake "github.com/rackspace/gophercloud/testhelper/client"
910
)
@@ -36,7 +37,7 @@ func TestCreate(t *testing.T) {
3637
Size: 100,
3738
Status: "NEW",
3839
Updated: "2014-02-13T21:47:16",
39-
Datastore: datastores.Datastore{
40+
Datastore: datastores.DatastorePartial{
4041
Version: "5.1",
4142
Type: "MySQL",
4243
VersionID: "20000000-0000-0000-0000-000000000002",
@@ -71,7 +72,7 @@ func TestList(t *testing.T) {
7172
Size: 0.141026,
7273
Status: "COMPLETED",
7374
Updated: "2014-06-18T21:24:39",
74-
Datastore: datastores.Datastore{
75+
Datastore: datastores.DatastorePartial{
7576
Version: "5.1",
7677
Type: "MySQL",
7778
VersionID: "20000000-0000-0000-0000-000000000002",
@@ -109,7 +110,7 @@ func TestGet(t *testing.T) {
109110
Size: 100,
110111
Status: "NEW",
111112
Updated: "2014-02-13T21:47:16",
112-
Datastore: datastores.Datastore{
113+
Datastore: datastores.DatastorePartial{
113114
Version: "5.1",
114115
Type: "MySQL",
115116
VersionID: "20000000-0000-0000-0000-000000000002",

rackspace/db/v1/backups/results.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Backup struct {
1818
Status string
1919
Created string
2020
Updated string
21-
Datastore datastores.Datastore
21+
Datastore datastores.DatastorePartial
2222
}
2323

2424
type CreateResult struct {

rackspace/db/v1/datastores/results.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ type Datastore struct {
2020
Versions []Version
2121
}
2222

23+
type DatastorePartial struct {
24+
Version string
25+
Type string
26+
VersionID string `json:"version_id" mapstructure:"version_id"`
27+
}
28+
2329
type GetResult struct {
2430
gophercloud.Result
2531
}

rackspace/db/v1/instances/delegate_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases"
88
os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
99
osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users"
10+
"github.com/rackspace/gophercloud/rackspace/db/v1/datastores"
1011
th "github.com/rackspace/gophercloud/testhelper"
1112
fake "github.com/rackspace/gophercloud/testhelper/client"
1213
)
@@ -16,7 +17,7 @@ var instanceID = "d4603f69-ec7e-4e9b-803f-600b9205576f"
1617
var expectedInstance = &Instance{
1718
Created: "2014-02-13T21:47:13",
1819
Updated: "2014-02-13T21:47:13",
19-
Datastore: Datastore{Type: "mysql", Version: "5.6"},
20+
Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"},
2021
Flavor: os.Flavor{
2122
ID: "1",
2223
Links: []gophercloud.Link{

0 commit comments

Comments
 (0)