Skip to content

Commit

Permalink
Add destination parameter to big storage backup revert
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordi Donadeu committed Nov 17, 2021
1 parent 23fde8c commit 403c1af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vps/bigstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,22 @@ func (r *BigStorageRepository) GetBackups(bigStorageName string) ([]BigStorageBa
}

// RevertBackup allows you to revert a bigstorage by bigstorage name and backupID
// if you want to revert a backup to a different big storage you can use the RevertBackupToOtherBigStorage method
func (r *BigStorageRepository) RevertBackup(bigStorageName string, backupID int64) error {
requestBody := actionWrapper{Action: "revert"}
restRequest := rest.Request{Endpoint: fmt.Sprintf("/big-storages/%s/backups/%d", bigStorageName, backupID), Body: &requestBody}

return r.Client.Patch(restRequest)
}

// RevertBackupToOtherBigStorage allows you to revert a backup to a different big storage
func (r *BigStorageRepository) RevertBackupToOtherBigStorage(bigStorageName string, backupID int64, destinationBigStorageName string) error {
requestBody := bigStorageRestoreBackupsWrapper{Action: "revert", DestinationBigStorageName: destinationBigStorageName}
restRequest := rest.Request{Endpoint: fmt.Sprintf("/big-storages/%s/backups/%d", bigStorageName, backupID), Body: &requestBody}

return r.Client.Patch(restRequest)
}

// GetUsage allows you to query your bigstorage usage within a certain period
func (r *BigStorageRepository) GetUsage(bigStorageName string, period UsagePeriod) ([]UsageDataDisk, error) {
var response usageDataDiskWrapper
Expand Down
11 changes: 11 additions & 0 deletions vps/bigstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ func TestBigStorageRepository_RevertBigStorageBackup(t *testing.T) {
require.NoError(t, err)
}

func TestBigStorageRepository_RevertBackupToOtherBigStorage(t *testing.T) {
const expectedRequest = `{"action":"revert","destinationBigStorageName":"example-bigStorage2"}`
server := mockServer{t: t, expectedURL: "/big-storages/example-bigstorage/backups/123", expectedMethod: "PATCH", statusCode: 204, expectedRequest: expectedRequest}
client, tearDown := server.getClient()
defer tearDown()
repo := BigStorageRepository{Client: *client}

err := repo.RevertBackupToOtherBigStorage("example-bigstorage", 123, "example-bigStorage2")
require.NoError(t, err)
}

func TestBigStorageRepository_GetBigStorageUsage(t *testing.T) {
const apiResponse = `{ "usage": [ { "iopsRead": 0.27, "iopsWrite": 0.13, "date": 1574783109 } ] }`

Expand Down
7 changes: 7 additions & 0 deletions vps/vps.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ type bigStorageBackupsWrapper struct {
BigStorageBackups []BigStorageBackup `json:"backups"`
}

// bigStorageRestoreBackupsWrapper is used to marshal a request for reverting a backup to a big storage
// this is solely used for unmarshalling
type bigStorageRestoreBackupsWrapper struct {
Action string `json:"action"`
DestinationBigStorageName string `json:"destinationBigStorageName"`
}

// usageDataDiskWrapper struct contains UsageDataDisk struct in it
type usageDataDiskWrapper struct {
Usage []UsageDataDisk `json:"usage"`
Expand Down

0 comments on commit 403c1af

Please sign in to comment.