Skip to content

Commit

Permalink
Add support for resizing volumes.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething committed Jul 17, 2016
1 parent e03ac28 commit 33bae1f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions storage_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "fmt"
type StorageActionsService interface {
Attach(volumeID string, dropletID int) (*Action, *Response, error)
Detach(volumeID string) (*Action, *Response, error)
Resize(volumeID string, sizeGigabytes int, regionSlug string) (*Action, *Response, error)
}

// StorageActionsServiceOp handles communication with the floating IPs
Expand Down Expand Up @@ -39,6 +40,16 @@ func (s *StorageActionsServiceOp) Detach(volumeID string) (*Action, *Response, e
return s.doAction(volumeID, request)
}

// Resize a storage volume.
func (s *StorageActionsServiceOp) Resize(volumeID string, sizeGigabytes int, regionSlug string) (*Action, *Response, error) {
request := &ActionRequest{
"type": "resize",
"size_gigabytes": sizeGigabytes,
"region": regionSlug,
}
return s.doAction(volumeID, request)
}

func (s *StorageActionsServiceOp) doAction(volumeID string, request *ActionRequest) (*Action, *Response, error) {
path := storageAllocationActionPath(volumeID)

Expand Down
32 changes: 32 additions & 0 deletions storage_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,35 @@ func TestStoragesActions_Detach(t *testing.T) {
t.Errorf("StoragesActions.Detach returned error: %v", err)
}
}

func TestStoragesActions_Resize(t *testing.T) {
setup()
defer teardown()
volumeID := "98d414c6-295e-4e3a-ac58-eb9456c1e1d1"

resizeRequest := &ActionRequest{
"type": "resize",
"size_gigabytes": float64(500),
"region": "nyc1",
}

mux.HandleFunc("/v2/volumes/"+volumeID+"/actions", func(w http.ResponseWriter, r *http.Request) {
v := new(ActionRequest)
err := json.NewDecoder(r.Body).Decode(v)
if err != nil {
t.Fatalf("decode json: %v", err)
}

testMethod(t, r, "POST")
if !reflect.DeepEqual(v, resizeRequest) {
t.Errorf("want=%#v", resizeRequest)
t.Errorf("got=%#v", v)
}
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
})

_, _, err := client.StorageActions.Resize(volumeID, 500, "nyc1")
if err != nil {
t.Errorf("StoragesActions.Resize returned error: %v", err)
}
}

0 comments on commit 33bae1f

Please sign in to comment.