Files
decort-golang-sdk/pkg/cloudapi/compute/snapshot_delete.go

70 lines
1.7 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package compute
import (
"context"
"net/http"
2023-03-17 12:54:34 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// SnapshotDeleteRequest struct to delete snapshot
2022-10-03 16:56:47 +03:00
type SnapshotDeleteRequest struct {
2022-12-22 17:56:47 +03:00
// ID of the compute instance
// Required: true
2023-03-17 12:54:34 +03:00
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Text label of snapshot to delete
// Required: true
2023-03-17 12:54:34 +03:00
Label string `url:"label" json:"label" validate:"required"`
2022-10-03 16:56:47 +03:00
}
2024-11-12 12:51:21 +03:00
type wrapperSnapshotDeleteRequeststruct struct {
SnapshotDeleteRequest
AsyncMode bool `url:"asyncMode"`
}
2023-10-25 17:37:18 +03:00
// SnapshotDelete deletes specified compute snapshot
2024-11-12 12:51:21 +03:00
func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (string, error) {
2023-03-17 12:54:34 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2024-11-12 12:51:21 +03:00
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperSnapshotDeleteRequeststruct{
SnapshotDeleteRequest: req,
AsyncMode: false,
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/compute/snapshotDelete"
2024-11-12 12:51:21 +03:00
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
2022-10-03 16:56:47 +03:00
if err != nil {
2024-11-12 12:51:21 +03:00
return "", err
2022-10-03 16:56:47 +03:00
}
2024-11-12 12:51:21 +03:00
return string(res), nil
}
// SnapshotDeleteAsync deletes specified compute snapshot
func (c Compute) SnapshotDeleteAsync(ctx context.Context, req SnapshotDeleteRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperSnapshotDeleteRequeststruct{
SnapshotDeleteRequest: req,
AsyncMode: true,
}
url := "/cloudapi/compute/snapshotDelete"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
2022-10-03 16:56:47 +03:00
if err != nil {
2024-11-12 12:51:21 +03:00
return "", err
2022-10-03 16:56:47 +03:00
}
2024-11-12 12:51:21 +03:00
return string(res), nil
2022-10-03 16:56:47 +03:00
}