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

48 lines
1.2 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package compute
import (
"context"
"encoding/json"
"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
// SnapshotUsageRequest struct to get compute snapshot real size on storage
2022-10-03 16:56:47 +03:00
type SnapshotUsageRequest 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
// Specify to show usage exact for this snapshot.
// Leave empty for get usage for all compute snapshots
// Required: false
2023-03-01 19:05:53 +03:00
Label string `url:"label,omitempty" json:"label,omitempty"`
2022-10-03 16:56:47 +03:00
}
2023-10-25 17:37:18 +03:00
// SnapshotUsage gets compute snapshot real size on storage.
2022-12-22 17:56:47 +03:00
// Always returns list of json objects, and first json object contains summary about all related
// snapshots.
func (c Compute) SnapshotUsage(ctx context.Context, req SnapshotUsageRequest) (ListUsageSnapshots, error) {
2023-03-17 12:54:34 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return nil, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/compute/snapshotUsage"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
2022-12-22 17:56:47 +03:00
list := ListUsageSnapshots{}
2022-10-03 16:56:47 +03:00
2022-12-22 17:56:47 +03:00
err = json.Unmarshal(res, &list)
2022-10-03 16:56:47 +03:00
if err != nil {
return nil, err
}
2022-12-22 17:56:47 +03:00
return list, nil
2022-10-03 16:56:47 +03:00
}