Skip to content

Commit

Permalink
Block storage methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordi Donadeu committed Oct 10, 2023
1 parent 234db10 commit 432f8e3
Show file tree
Hide file tree
Showing 6 changed files with 586 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ these are subpackages under the gotransip package:
test.Repository
traffic.Repository
vps.BigstorageRepository
vps.BlockstorageRepository
vps.PrivateNetworkRepository
vps.Repository
Expand Down
2 changes: 2 additions & 0 deletions product/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type productsResponse struct {
type Products struct {
// A list of big storage products
BigStorage []Product `json:"bigStorage,omitempty"`
// A list of block storage products
BlockStorage []Product `json:"blockStorage,omitempty"`
// A list of haip products
Haip []Product `json:"haip,omitempty"`
// A list of private network products
Expand Down
20 changes: 20 additions & 0 deletions vps/bigstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type BigStorageBackup struct {
}

// GetAll returns a list of your bigstorages
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) GetAll() ([]BigStorage, error) {
var response bigStoragesWrapper
restRequest := rest.Request{Endpoint: "/big-storages"}
Expand All @@ -93,6 +94,7 @@ func (r *BigStorageRepository) GetAll() ([]BigStorage, error) {

// GetSelection returns a limited list of bigstorages,
// specify how many and which page/chunk of your bigstorage you want to retrieve
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) GetSelection(page int, itemsPerPage int) ([]BigStorage, error) {
var response bigStoragesWrapper
params := url.Values{
Expand All @@ -107,6 +109,7 @@ func (r *BigStorageRepository) GetSelection(page int, itemsPerPage int) ([]BigSt
}

// GetByName returns a specific BigStorage struct by name
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) GetByName(bigStorageName string) (BigStorage, error) {
var response bigStorageWrapper
restRequest := rest.Request{Endpoint: fmt.Sprintf("/big-storages/%s", bigStorageName)}
Expand All @@ -116,20 +119,23 @@ func (r *BigStorageRepository) GetByName(bigStorageName string) (BigStorage, err
}

// Order allows you to order a new bigstorage
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) Order(order BigStorageOrder) error {
restRequest := rest.Request{Endpoint: "/big-storages", Body: &order}

return r.Client.Post(restRequest)
}

// OrderWithResponse allows you to order a new bigstorage and returns a response
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) OrderWithResponse(order BigStorageOrder) (rest.Response, error) {
restRequest := rest.Request{Endpoint: "/big-storages", Body: &order}

return r.Client.PostWithResponse(restRequest)
}

// Upgrade allows you to upgrade a BigStorage's size or/and to enable off-site backups
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) Upgrade(bigStorageName string, size int, offsiteBackups bool) error {
requestBody := bigStorageUpgradeRequest{BigStorageName: bigStorageName, Size: size, OffsiteBackups: offsiteBackups}
restRequest := rest.Request{Endpoint: "/big-storages", Body: &requestBody}
Expand All @@ -143,6 +149,8 @@ func (r *BigStorageRepository) Upgrade(bigStorageName string, size int, offsiteB
// - One VPS can have a maximum of 10 bigstorages attached;
// - Set the vpsName property to the VPS name to attach to for attaching Big Storage;
// - Set the vpsName property to null to detach the Big Storage from the currently attached VPS.
//
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) Update(bigStorage BigStorage) error {
requestBody := bigStorageWrapper{BigStorage: bigStorage}
restRequest := rest.Request{Endpoint: fmt.Sprintf("/big-storages/%s", bigStorage.Name), Body: &requestBody}
Expand All @@ -151,6 +159,7 @@ func (r *BigStorageRepository) Update(bigStorage BigStorage) error {
}

// UpdateWithResponse returns a response
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) UpdateWithResponse(bigStorage BigStorage) (rest.Response, error) {
requestBody := bigStorageWrapper{BigStorage: bigStorage}
restRequest := rest.Request{Endpoint: fmt.Sprintf("/big-storages/%s", bigStorage.Name), Body: &requestBody}
Expand All @@ -159,13 +168,15 @@ func (r *BigStorageRepository) UpdateWithResponse(bigStorage BigStorage) (rest.R
}

// DetachFromVps allows you to detach a bigstorage from the vps it is attached to
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) DetachFromVps(bigStorage BigStorage) error {
bigStorage.VpsName = ""

return r.Update(bigStorage)
}

// AttachToVps allows you to attach a given VPS by name to a BigStorage
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) AttachToVps(vpsName string, bigStorage BigStorage) error {
bigStorage.VpsName = vpsName

Expand All @@ -177,6 +188,8 @@ func (r *BigStorageRepository) AttachToVps(vpsName string, bigStorage BigStorage
//
// - end: The Big Storage will be terminated from the end date of the agreement as can be found in the applicable quote;
// - immediately: The Big Storage will be terminated immediately.
//
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) Cancel(bigStorageName string, endTime gotransip.CancellationTime) error {
requestBody := gotransip.CancellationRequest{EndTime: endTime}
restRequest := rest.Request{Endpoint: fmt.Sprintf("/big-storages/%s", bigStorageName), Body: &requestBody}
Expand All @@ -185,6 +198,7 @@ func (r *BigStorageRepository) Cancel(bigStorageName string, endTime gotransip.C
}

// GetBackups returns a list of backups for a specific bigstorage
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) GetBackups(bigStorageName string) ([]BigStorageBackup, error) {
var response bigStorageBackupsWrapper
restRequest := rest.Request{Endpoint: fmt.Sprintf("/big-storages/%s/backups", bigStorageName)}
Expand All @@ -195,6 +209,7 @@ 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
// Deprecated: Use block storage resource instead
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}
Expand All @@ -204,6 +219,7 @@ func (r *BigStorageRepository) RevertBackup(bigStorageName string, backupID int6

// RevertBackupWithResponse allows you to revert a bigstorage by bigstorage name and backupID and returns a response
// if you want to revert a backup to a different big storage you can use the RevertBackupToOtherBigStorage method
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) RevertBackupWithResponse(bigStorageName string, backupID int64) (rest.Response, error) {
requestBody := actionWrapper{Action: "revert"}
restRequest := rest.Request{Endpoint: fmt.Sprintf("/big-storages/%s/backups/%d", bigStorageName, backupID), Body: &requestBody}
Expand All @@ -212,6 +228,7 @@ func (r *BigStorageRepository) RevertBackupWithResponse(bigStorageName string, b
}

// RevertBackupToOtherBigStorage allows you to revert a backup to a different big storage
// Deprecated: Use block storage resource instead
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}
Expand All @@ -220,6 +237,7 @@ func (r *BigStorageRepository) RevertBackupToOtherBigStorage(bigStorageName stri
}

// RevertBackupToOtherBigStorageWithResponse allows you to revert a backup to a different big storage and returns a response
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) RevertBackupToOtherBigStorageWithResponse(
bigStorageName string,
backupID int64,
Expand All @@ -232,6 +250,7 @@ func (r *BigStorageRepository) RevertBackupToOtherBigStorageWithResponse(
}

// GetUsage allows you to query your bigstorage usage within a certain period
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) GetUsage(bigStorageName string, period UsagePeriod) ([]UsageDataDisk, error) {
var response usageDataDiskWrapper
parameters := url.Values{
Expand All @@ -246,6 +265,7 @@ func (r *BigStorageRepository) GetUsage(bigStorageName string, period UsagePerio
}

// GetUsageLast24Hours allows you to get usage statistics for a given bigstorage within the last 24 hours
// Deprecated: Use block storage resource instead
func (r *BigStorageRepository) GetUsageLast24Hours(bigStorageName string) ([]UsageDataDisk, error) {
// always define a period body, this way we don't have to depend on the empty body logic on the api server
period := UsagePeriod{TimeStart: time.Now().Add(-24 * time.Hour).Unix(), TimeEnd: time.Now().Unix()}
Expand Down
Loading

0 comments on commit 432f8e3

Please sign in to comment.