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

48 lines
1.2 KiB
Go
Raw Normal View History

2022-12-22 17:56:47 +03:00
package compute
import (
"context"
"encoding/json"
"net/http"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-12-22 17:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// SnapshotUsageRequest struct tto get compute snapshot real size on storage
2022-12-22 17:56:47 +03:00
type SnapshotUsageRequest struct {
// ID of the compute instance
// Required: true
2023-03-24 17:09:30 +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-12-22 17: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) (ListSnapshotUsage, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-12-22 17:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return nil, validators.ValidationErrors(validators.GetErrors(err))
2022-12-22 17:56:47 +03:00
}
url := "/cloudbroker/compute/snapshotUsage"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListSnapshotUsage{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}