Skip to content

Commit afec93a

Browse files
committed
Support deletion of servers including all attached storages, fixes #43
1 parent 8cbc8bc commit afec93a

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

upcloud/request/server.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package request
33
import (
44
"encoding/xml"
55
"fmt"
6-
"github.com/UpCloudLtd/upcloud-go-api/upcloud"
76
"strings"
87
"time"
8+
9+
"github.com/UpCloudLtd/upcloud-go-api/upcloud"
910
)
1011

1112
// Constants
@@ -192,6 +193,16 @@ func (r *DeleteServerRequest) RequestURL() string {
192193
return fmt.Sprintf("/server/%s", r.UUID)
193194
}
194195

196+
// DeleteServerAndStoragesRequest represents a request to delete a server and all attached storages
197+
type DeleteServerAndStoragesRequest struct {
198+
UUID string
199+
}
200+
201+
// RequestURL implements the Request interface
202+
func (r *DeleteServerAndStoragesRequest) RequestURL() string {
203+
return fmt.Sprintf("/server/%s/?storages=1", r.UUID)
204+
}
205+
195206
// TagServerRequest represents a request to tag a server with one or more tags
196207
type TagServerRequest struct {
197208
UUID string

upcloud/request/server_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package request
22

33
import (
44
"encoding/xml"
5-
"github.com/UpCloudLtd/upcloud-go-api/upcloud"
6-
"github.com/stretchr/testify/assert"
75
"testing"
86
"time"
7+
8+
"github.com/UpCloudLtd/upcloud-go-api/upcloud"
9+
"github.com/stretchr/testify/assert"
910
)
1011

1112
// TestGetServerDetailsRequest tests that GetServerDetailsRequest objects behave correctly
@@ -127,6 +128,15 @@ func TestDeleteServerRequest(t *testing.T) {
127128
assert.Equal(t, "/server/foo", request.RequestURL())
128129
}
129130

131+
// TestDeleteServerAndStoragesRequest tests that DeleteServerAndStoragesRequest objects behave correctly
132+
func TestDeleteServerAndStoragesRequest(t *testing.T) {
133+
request := DeleteServerAndStoragesRequest{
134+
UUID: "foo",
135+
}
136+
137+
assert.Equal(t, "/server/foo/?storages=1", request.RequestURL())
138+
}
139+
130140
// TestTagServerRequest tests that TestTagServer behaves correctly
131141
func TestTagServerRequest(t *testing.T) {
132142
// Test with multiple tags

upcloud/service/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,17 @@ func (s *Service) DeleteServer(r *request.DeleteServerRequest) error {
270270
return nil
271271
}
272272

273+
// DeleteServerAndStorages deletes the specified server and all attached storages
274+
func (s *Service) DeleteServerAndStorages(r *request.DeleteServerAndStoragesRequest) error {
275+
err := s.client.PerformDeleteRequest(s.client.CreateRequestUrl(r.RequestURL()))
276+
277+
if err != nil {
278+
return parseServiceError(err)
279+
}
280+
281+
return nil
282+
}
283+
273284
// TagServer tags a server with with one or more tags
274285
func (s *Service) TagServer(r *request.TagServerRequest) (*upcloud.ServerDetails, error) {
275286
serverDetails := upcloud.ServerDetails{}

0 commit comments

Comments
 (0)