Skip to content

Commit 41c3197

Browse files
authored
Core: set response headers for all requests (gophercloud#1942)
1 parent 21650dc commit 41c3197

File tree

180 files changed

+1488
-1149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+1488
-1149
lines changed

docs/contributor-tutorial/.template/requests.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pa
3838

3939
// Get retrieves details of a RESOURCE.
4040
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
41-
_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
41+
resp, err := client.Get(getURL(client, id), &r.Body, nil)
42+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
4243
return
4344
}
4445

@@ -64,15 +65,17 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r Create
6465
r.Err = err
6566
return
6667
}
67-
_, r.Err = client.Post(createURL(client), &b, &r.Body, &gophercloud.RequestOpts{
68+
resp, err := client.Post(createURL(client), &b, &r.Body, &gophercloud.RequestOpts{
6869
OkCodes: []int{201},
6970
})
71+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
7072
return
7173
}
7274

7375
// Delete deletes a RESOURCE.
7476
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
75-
_, r.Err = client.Delete(deleteURL(client, id), nil)
77+
resp, err := client.Delete(deleteURL(client, id), nil)
78+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
7679
return
7780
}
7881

@@ -98,8 +101,9 @@ func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder
98101
r.Err = err
99102
return
100103
}
101-
_, r.Err = client.Patch(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
104+
resp, err := client.Patch(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
102105
OkCodes: []int{200},
103106
})
107+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
104108
return
105109
}

openstack/baremetal/apiversions/requests.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66

77
// List lists all the API versions available to end users.
88
func List(client *gophercloud.ServiceClient) (r ListResult) {
9-
_, r.Err = client.Get(listURL(client), &r.Body, nil)
9+
resp, err := client.Get(listURL(client), &r.Body, nil)
10+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
1011
return
1112
}
1213

1314
// Get will get a specific API version, specified by major ID.
1415
func Get(client *gophercloud.ServiceClient, v string) (r GetResult) {
15-
_, r.Err = client.Get(getURL(client, v), &r.Body, nil)
16+
resp, err := client.Get(getURL(client, v), &r.Body, nil)
17+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
1618
return
1719
}

openstack/baremetal/v1/allocations/requests.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r Create
5050
return
5151
}
5252

53-
_, r.Err = client.Post(createURL(client), reqBody, &r.Body, nil)
53+
resp, err := client.Post(createURL(client), reqBody, &r.Body, nil)
54+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
5455
return
5556
}
5657

@@ -118,14 +119,16 @@ func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pa
118119

119120
// Get requests the details of an allocation by ID.
120121
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
121-
_, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{
122+
resp, err := client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{
122123
OkCodes: []int{200},
123124
})
125+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
124126
return
125127
}
126128

127129
// Delete requests the deletion of an allocation
128130
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
129-
_, r.Err = client.Delete(deleteURL(client, id), nil)
131+
resp, err := client.Delete(deleteURL(client, id), nil)
132+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
130133
return
131134
}

openstack/baremetal/v1/drivers/requests.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,31 @@ func ListDrivers(client *gophercloud.ServiceClient, opts ListDriversOptsBuilder)
4343

4444
// GetDriverDetails Shows details for a driver
4545
func GetDriverDetails(client *gophercloud.ServiceClient, driverName string) (r GetDriverResult) {
46-
_, r.Err = client.Get(driverDetailsURL(client, driverName), &r.Body, &gophercloud.RequestOpts{
46+
resp, err := client.Get(driverDetailsURL(client, driverName), &r.Body, &gophercloud.RequestOpts{
4747
OkCodes: []int{200},
4848
})
49+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
4950
return
5051
}
5152

5253
// GetDriverProperties Shows the required and optional parameters that
5354
// driverName expects to be supplied in the driver_info field for every
5455
// Node it manages
5556
func GetDriverProperties(client *gophercloud.ServiceClient, driverName string) (r GetPropertiesResult) {
56-
_, r.Err = client.Get(driverPropertiesURL(client, driverName), &r.Body, &gophercloud.RequestOpts{
57+
resp, err := client.Get(driverPropertiesURL(client, driverName), &r.Body, &gophercloud.RequestOpts{
5758
OkCodes: []int{200},
5859
})
60+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
5961
return
6062
}
6163

6264
// GetDriverDiskProperties Show the required and optional parameters that
6365
// driverName expects to be supplied in the node’s raid_config field, if a
6466
// RAID configuration change is requested.
6567
func GetDriverDiskProperties(client *gophercloud.ServiceClient, driverName string) (r GetDiskPropertiesResult) {
66-
_, r.Err = client.Get(driverDiskPropertiesURL(client, driverName), &r.Body, &gophercloud.RequestOpts{
68+
resp, err := client.Get(driverDiskPropertiesURL(client, driverName), &r.Body, &gophercloud.RequestOpts{
6769
OkCodes: []int{200},
6870
})
71+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
6972
return
7073
}

openstack/baremetal/v1/nodes/requests.go

+25-14
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) paginat
164164

165165
// Get requests details on a single node, by ID.
166166
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
167-
_, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{
167+
resp, err := client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{
168168
OkCodes: []int{200},
169169
})
170+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
170171
return
171172
}
172173

@@ -260,7 +261,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r Create
260261
return
261262
}
262263

263-
_, r.Err = client.Post(createURL(client), reqBody, &r.Body, nil)
264+
resp, err := client.Post(createURL(client), reqBody, &r.Body, nil)
265+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
264266
return
265267
}
266268

@@ -301,34 +303,37 @@ func Update(client *gophercloud.ServiceClient, id string, opts UpdateOpts) (r Up
301303

302304
body[i] = result
303305
}
304-
_, r.Err = client.Patch(updateURL(client, id), body, &r.Body, &gophercloud.RequestOpts{
305-
JSONBody: &body,
306-
OkCodes: []int{200},
306+
resp, err := client.Patch(updateURL(client, id), body, &r.Body, &gophercloud.RequestOpts{
307+
OkCodes: []int{200},
307308
})
309+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
308310
return
309311
}
310312

311313
// Delete requests that a node be removed
312314
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
313-
_, r.Err = client.Delete(deleteURL(client, id), nil)
315+
resp, err := client.Delete(deleteURL(client, id), nil)
316+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
314317
return
315318
}
316319

317320
// Request that Ironic validate whether the Node’s driver has enough information to manage the Node. This polls each
318321
// interface on the driver, and returns the status of that interface.
319322
func Validate(client *gophercloud.ServiceClient, id string) (r ValidateResult) {
320-
_, r.Err = client.Get(validateURL(client, id), &r.Body, &gophercloud.RequestOpts{
323+
resp, err := client.Get(validateURL(client, id), &r.Body, &gophercloud.RequestOpts{
321324
OkCodes: []int{200},
322325
})
326+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
323327
return
324328
}
325329

326330
// Inject NMI (Non-Masking Interrupts) for the given Node. This feature can be used for hardware diagnostics, and
327331
// actual support depends on a driver.
328332
func InjectNMI(client *gophercloud.ServiceClient, id string) (r InjectNMIResult) {
329-
_, r.Err = client.Put(injectNMIURL(client, id), map[string]string{}, nil, &gophercloud.RequestOpts{
333+
resp, err := client.Put(injectNMIURL(client, id), map[string]string{}, nil, &gophercloud.RequestOpts{
330334
OkCodes: []int{204},
331335
})
336+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
332337
return
333338
}
334339

@@ -362,25 +367,28 @@ func SetBootDevice(client *gophercloud.ServiceClient, id string, bootDevice Boot
362367
return
363368
}
364369

365-
_, r.Err = client.Put(bootDeviceURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
370+
resp, err := client.Put(bootDeviceURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
366371
OkCodes: []int{204},
367372
})
373+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
368374
return
369375
}
370376

371377
// Get the current boot device for the given Node.
372378
func GetBootDevice(client *gophercloud.ServiceClient, id string) (r BootDeviceResult) {
373-
_, r.Err = client.Get(bootDeviceURL(client, id), &r.Body, &gophercloud.RequestOpts{
379+
resp, err := client.Get(bootDeviceURL(client, id), &r.Body, &gophercloud.RequestOpts{
374380
OkCodes: []int{200},
375381
})
382+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
376383
return
377384
}
378385

379386
// Retrieve the acceptable set of supported boot devices for a specific Node.
380387
func GetSupportedBootDevices(client *gophercloud.ServiceClient, id string) (r SupportedBootDeviceResult) {
381-
_, r.Err = client.Get(supportedBootDeviceURL(client, id), &r.Body, &gophercloud.RequestOpts{
388+
resp, err := client.Get(supportedBootDeviceURL(client, id), &r.Body, &gophercloud.RequestOpts{
382389
OkCodes: []int{200},
383390
})
391+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
384392
return
385393
}
386394

@@ -435,9 +443,10 @@ func ChangeProvisionState(client *gophercloud.ServiceClient, id string, opts Pro
435443
return
436444
}
437445

438-
_, r.Err = client.Put(provisionStateURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
446+
resp, err := client.Put(provisionStateURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
439447
OkCodes: []int{202},
440448
})
449+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
441450
return
442451
}
443452

@@ -481,9 +490,10 @@ func ChangePowerState(client *gophercloud.ServiceClient, id string, opts PowerSt
481490
return
482491
}
483492

484-
_, r.Err = client.Put(powerStateURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
493+
resp, err := client.Put(powerStateURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
485494
OkCodes: []int{202},
486495
})
496+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
487497
return
488498
}
489499

@@ -586,8 +596,9 @@ func SetRAIDConfig(client *gophercloud.ServiceClient, id string, raidConfigOptsB
586596
return
587597
}
588598

589-
_, r.Err = client.Put(raidConfigURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
599+
resp, err := client.Put(raidConfigURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
590600
OkCodes: []int{204},
591601
})
602+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
592603
return
593604
}

openstack/baremetal/v1/ports/requests.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) paginat
9999

100100
// Get - requests the details off a port, by ID.
101101
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
102-
_, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{
102+
resp, err := client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{
103103
OkCodes: []int{200},
104104
})
105+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
105106
return
106107
}
107108

@@ -161,7 +162,8 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r Create
161162
return
162163
}
163164

164-
_, r.Err = client.Post(createURL(client), reqBody, &r.Body, nil)
165+
resp, err := client.Post(createURL(client), reqBody, &r.Body, nil)
166+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
165167
return
166168
}
167169

@@ -202,15 +204,16 @@ func Update(client *gophercloud.ServiceClient, id string, opts UpdateOpts) (r Up
202204
body[i] = patch.ToPortUpdateMap()
203205
}
204206

205-
_, r.Err = client.Patch(updateURL(client, id), body, &r.Body, &gophercloud.RequestOpts{
206-
JSONBody: &body,
207-
OkCodes: []int{200},
207+
resp, err := client.Patch(updateURL(client, id), body, &r.Body, &gophercloud.RequestOpts{
208+
OkCodes: []int{200},
208209
})
210+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
209211
return
210212
}
211213

212214
// Delete - requests the deletion of a port
213215
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
214-
_, r.Err = client.Delete(deleteURL(client, id), nil)
216+
resp, err := client.Delete(deleteURL(client, id), nil)
217+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
215218
return
216219
}

openstack/baremetalintrospection/v1/introspection/requests.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ func ListIntrospections(client *gophercloud.ServiceClient, opts ListIntrospectio
4848
// GetIntrospectionStatus makes a request against the Inspector API to get the
4949
// status of a single introspection.
5050
func GetIntrospectionStatus(client *gophercloud.ServiceClient, nodeID string) (r GetIntrospectionStatusResult) {
51-
_, r.Err = client.Get(introspectionURL(client, nodeID), &r.Body, &gophercloud.RequestOpts{
51+
resp, err := client.Get(introspectionURL(client, nodeID), &r.Body, &gophercloud.RequestOpts{
5252
OkCodes: []int{200},
5353
})
54+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
5455
return
5556
}
5657

@@ -81,36 +82,37 @@ func StartIntrospection(client *gophercloud.ServiceClient, nodeID string, opts S
8182
return
8283
}
8384

84-
_, r.Err = client.Post(introspectionURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{
85+
resp, err := client.Post(introspectionURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{
8586
OkCodes: []int{202},
8687
})
87-
88+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
8889
return
8990
}
9091

9192
// AbortIntrospection abort running introspection.
9293
func AbortIntrospection(client *gophercloud.ServiceClient, nodeID string) (r AbortResult) {
93-
_, r.Err = client.Post(abortIntrospectionURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{
94+
resp, err := client.Post(abortIntrospectionURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{
9495
OkCodes: []int{202},
9596
})
96-
97+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
9798
return
9899
}
99100

100101
// GetIntrospectionData return stored data from successful introspection.
101102
func GetIntrospectionData(client *gophercloud.ServiceClient, nodeID string) (r DataResult) {
102-
_, r.Err = client.Get(introspectionDataURL(client, nodeID), &r.Body, &gophercloud.RequestOpts{
103+
resp, err := client.Get(introspectionDataURL(client, nodeID), &r.Body, &gophercloud.RequestOpts{
103104
OkCodes: []int{200},
104105
})
106+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
105107
return
106108
}
107109

108110
// ReApplyIntrospection triggers introspection on stored unprocessed data.
109111
// No data is allowed to be sent along with the request.
110112
func ReApplyIntrospection(client *gophercloud.ServiceClient, nodeID string) (r ApplyDataResult) {
111-
_, r.Err = client.Post(introspectionUnprocessedDataURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{
113+
resp, err := client.Post(introspectionUnprocessedDataURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{
112114
OkCodes: []int{202},
113115
})
114-
116+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
115117
return
116118
}

0 commit comments

Comments
 (0)