2026-01-16 17:05:59 +03:00
|
|
|
package disks
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-08-28 16:47:26 +03:00
|
|
|
"encoding/json"
|
2026-01-16 17:05:59 +03:00
|
|
|
"net/http"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
2026-08-21 18:12:55 +04:00
|
|
|
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators"
|
2026-01-16 17:05:59 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// UpdateRequest struct to update disk
|
|
|
|
|
type UpdateRequest struct {
|
|
|
|
|
// ID of the disk to update
|
|
|
|
|
// Required: true
|
|
|
|
|
DiskID uint64 `url:"disk_id" json:"disk_id" validate:"required"`
|
|
|
|
|
|
|
|
|
|
// Cache mode of disk
|
|
|
|
|
// Required: false
|
|
|
|
|
Cache string `url:"cache,omitempty" json:"cache,omitempty"`
|
2026-02-06 17:20:56 +03:00
|
|
|
|
2026-06-05 17:30:36 +03:00
|
|
|
// Discard
|
2026-02-06 17:20:56 +03:00
|
|
|
// Required: false
|
2026-06-05 17:30:36 +03:00
|
|
|
Discard string `url:"discard,omitempty" json:"discard,omitempty"`
|
2026-02-20 17:30:02 +03:00
|
|
|
|
|
|
|
|
// Block size of disk
|
|
|
|
|
// Required: false
|
|
|
|
|
BlockSize string `url:"block_size,omitempty" json:"block_size,omitempty"`
|
2026-01-16 17:05:59 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-28 16:47:26 +03:00
|
|
|
type wrapperUpdateRequest struct {
|
|
|
|
|
UpdateRequest
|
|
|
|
|
|
|
|
|
|
AsyncMode bool `url:"async_mode" json:"async_mode"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 17:05:59 +03:00
|
|
|
// Update updates disk
|
|
|
|
|
func (d Disks) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
|
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url := "/cloudbroker/disks/update"
|
|
|
|
|
|
2026-08-28 16:47:26 +03:00
|
|
|
wrappedReq := wrapperUpdateRequest{
|
|
|
|
|
UpdateRequest: req,
|
|
|
|
|
AsyncMode: false,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, wrappedReq)
|
2026-01-16 17:05:59 +03:00
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := strconv.ParseBool(string(res))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
2026-08-28 16:47:26 +03:00
|
|
|
|
|
|
|
|
// UpdateAsync updates disk in async mode
|
|
|
|
|
func (d Disks) UpdateAsync(ctx context.Context, req UpdateRequest) (string, error) {
|
|
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url := "/cloudbroker/disks/update"
|
|
|
|
|
|
|
|
|
|
wrappedReq := wrapperUpdateRequest{
|
|
|
|
|
UpdateRequest: req,
|
|
|
|
|
AsyncMode: true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, wrappedReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result string
|
|
|
|
|
if err := json.Unmarshal(res, &result); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|