Skip to content

feat(instance): use generated UpdateVolume #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions api/instance/v1/instance_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,10 @@ type UpdateServerResponse struct {
Server *Server `json:"server"`
}

type UpdateVolumeResponse struct {
Volume *Volume `json:"volume"`
}

// Volume: volume
type Volume struct {
// ID: the volumes unique ID
Expand Down Expand Up @@ -2727,6 +2731,55 @@ func (s *API) GetVolume(req *GetVolumeRequest, opts ...scw.RequestOption) (*GetV
return &resp, nil
}

type UpdateVolumeRequest struct {
Zone scw.Zone `json:"-"`
// VolumeID: UUID of the volume
VolumeID string `json:"-"`
// Name: the volume name
Name *string `json:"name,omitempty"`
// Size: the volume disk size
Size *scw.Size `json:"size,omitempty"`
}

// UpdateVolume: update volume
//
// Replace name and/or size properties of given ID volume with the given value(s). Any volume name can be changed while, for now, only `b_ssd` volume growing is supported.
func (s *API) UpdateVolume(req *UpdateVolumeRequest, opts ...scw.RequestOption) (*UpdateVolumeResponse, error) {
var err error

if req.Zone == "" {
defaultZone, _ := s.client.GetDefaultZone()
req.Zone = defaultZone
}

if fmt.Sprint(req.Zone) == "" {
return nil, errors.New("field Zone cannot be empty in request")
}

if fmt.Sprint(req.VolumeID) == "" {
return nil, errors.New("field VolumeID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "PATCH",
Path: "/instance/v1/zones/" + fmt.Sprint(req.Zone) + "/volumes/" + fmt.Sprint(req.VolumeID) + "",
Headers: http.Header{},
}

err = scwReq.SetBody(req)
if err != nil {
return nil, err
}

var resp UpdateVolumeResponse

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

type DeleteVolumeRequest struct {
Zone scw.Zone `json:"-"`

Expand Down
88 changes: 30 additions & 58 deletions api/instance/v1/testdata/volume-utils-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
version: 1
interactions:
- request:
body: '{"name":"test volume","organization":"d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3","volume_type":"l_ssd","size":20000000000}'
body: '{"name":"test volume","organization":"951df375-e094-4d26-97c1-ba548eeb9c42","volume_type":"l_ssd","size":20000000000}'
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- scaleway-sdk-go/0.0.0 (go1.12.5; darwin; amd64)
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.3; darwin; amd64)
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/volumes
method: POST
response:
body: '{"volume": {"size": 20000000000, "state": "available", "name": "test volume",
"modification_date": "2019-06-19T15:22:50.083278+00:00", "organization": "d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3",
"export_uri": null, "creation_date": "2019-06-19T15:22:50.083278+00:00", "id":
"f5f47e99-c0dc-40c9-be24-c3fc8294af08", "volume_type": "l_ssd", "server": null}}'
body: '{"volume": {"id": "fd5ad3da-3123-4726-9a2b-c7647bc89b04", "name": "test
volume", "volume_type": "l_ssd", "export_uri": null, "organization": "951df375-e094-4d26-97c1-ba548eeb9c42",
"server": null, "size": 20000000000, "state": "available", "creation_date":
"2020-05-20T12:39:42.548392+00:00", "modification_date": "2020-05-20T12:39:42.548392+00:00",
"zone": "fr-par-1"}}'
headers:
Cache-Control:
- no-cache
Content-Length:
- "350"
- "370"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Wed, 19 Jun 2019 15:22:50 GMT
- Wed, 20 May 2020 12:39:42 GMT
Location:
- https://cp-par1.scaleway.com/volumes/f5f47e99-c0dc-40c9-be24-c3fc8294af08
- https://cp-par1.scaleway.com/volumes/fd5ad3da-3123-4726-9a2b-c7647bc89b04
Server:
- scaleway_api
Strict-Transport-Security:
Expand All @@ -37,71 +38,38 @@ interactions:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 6fb1b944-1ad1-417e-8568-ad7dbeb80dde
status: 201 Created
code: 201
duration: ""
- request:
body: ""
form: {}
headers:
User-Agent:
- scaleway-sdk-go/0.0.0 (go1.12.5; darwin; amd64)
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/volumes/f5f47e99-c0dc-40c9-be24-c3fc8294af08
method: GET
response:
body: '{"volume": {"size": 20000000000, "state": "available", "name": "test volume",
"modification_date": "2019-06-19T15:22:50.083278+00:00", "organization": "d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3",
"export_uri": null, "creation_date": "2019-06-19T15:22:50.083278+00:00", "id":
"f5f47e99-c0dc-40c9-be24-c3fc8294af08", "volume_type": "l_ssd", "server": null}}'
headers:
Cache-Control:
- no-cache
Content-Length:
- "350"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Wed, 19 Jun 2019 15:22:50 GMT
Server:
- scaleway_api
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status: 200 OK
code: 200
duration: ""
- request:
body: '{"id":"f5f47e99-c0dc-40c9-be24-c3fc8294af08","name":"some new volume name","export_uri":"","size":20000000000,"volume_type":"l_ssd","creation_date":"2019-06-19T15:22:50.083278Z","modification_date":"2019-06-19T15:22:50.083278Z","organization":"d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3","server":null}'
body: '{"name":"some new volume name"}'
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- scaleway-sdk-go/0.0.0 (go1.12.5; darwin; amd64)
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/volumes/f5f47e99-c0dc-40c9-be24-c3fc8294af08
method: PUT
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.3; darwin; amd64)
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/volumes/fd5ad3da-3123-4726-9a2b-c7647bc89b04
method: PATCH
response:
body: '{"volume": {"size": 20000000000, "state": "available", "name": "some new
volume name", "modification_date": "2019-06-19T15:22:50.083278+00:00", "organization":
"d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3", "export_uri": null, "creation_date":
"2019-06-19T15:22:50.083278+00:00", "id": "f5f47e99-c0dc-40c9-be24-c3fc8294af08",
"volume_type": "l_ssd", "server": null}}'
body: '{"volume": {"id": "fd5ad3da-3123-4726-9a2b-c7647bc89b04", "name": "some
new volume name", "volume_type": "l_ssd", "export_uri": null, "organization":
"951df375-e094-4d26-97c1-ba548eeb9c42", "server": null, "size": 20000000000,
"state": "available", "creation_date": "2020-05-20T12:39:42.548392+00:00", "modification_date":
"2020-05-20T12:39:42.548392+00:00", "zone": "fr-par-1"}}'
headers:
Cache-Control:
- no-cache
Content-Length:
- "359"
- "379"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Wed, 19 Jun 2019 15:22:50 GMT
- Wed, 20 May 2020 12:39:42 GMT
Server:
- scaleway_api
Strict-Transport-Security:
Expand All @@ -110,6 +78,8 @@ interactions:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- aa94c984-91fe-4d9e-a504-725b6c87ede0
status: 200 OK
code: 200
duration: ""
Expand All @@ -118,8 +88,8 @@ interactions:
form: {}
headers:
User-Agent:
- scaleway-sdk-go/0.0.0 (go1.12.5; darwin; amd64)
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/volumes/f5f47e99-c0dc-40c9-be24-c3fc8294af08
- scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.3; darwin; amd64)
url: https://api.scaleway.com/instance/v1/zones/fr-par-1/volumes/fd5ad3da-3123-4726-9a2b-c7647bc89b04
method: DELETE
response:
body: ""
Expand All @@ -131,7 +101,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 19 Jun 2019 15:22:50 GMT
- Wed, 20 May 2020 12:39:42 GMT
Server:
- scaleway_api
Strict-Transport-Security:
Expand All @@ -140,6 +110,8 @@ interactions:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- f031e794-2e6c-4ac9-ade2-01e3d13c3a36
status: 204 No Content
code: 204
duration: ""
113 changes: 0 additions & 113 deletions api/instance/v1/volume_utils.go

This file was deleted.

2 changes: 1 addition & 1 deletion api/instance/v1/volume_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestUpdateVolume(t *testing.T) {

var (
zone = scw.ZoneFrPar1
organization = "d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3"
organization = "951df375-e094-4d26-97c1-ba548eeb9c42"
volumeName = "test volume"
volumeSize = 20 * scw.GB
volumeType = VolumeTypeLSSD
Expand Down