Files
dynamix-golang-sdk/pkg/cloudapi/compute/disk_resize.go

80 lines
1.8 KiB
Go
Raw Normal View History

2025-09-23 14:34:24 +03:00
package compute
import (
"context"
"net/http"
"strconv"
2026-06-05 17:30:36 +03:00
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
2025-09-23 14:34:24 +03:00
)
// DiskResizeRequest struct to change disk size
type DiskResizeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to resize
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// New disk size
// Required: true
Size uint64 `url:"size" json:"size" validate:"required"`
}
2026-06-05 17:30:36 +03:00
type wrapperDiskResizeRequest struct {
DiskResizeRequest
AsyncMode bool `url:"asyncMode"`
}
2025-09-23 14:34:24 +03:00
// DiskResize change disk size
func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
2026-06-05 17:30:36 +03:00
reqWrapped := wrapperDiskResizeRequest{
DiskResizeRequest: req,
AsyncMode: false,
}
2025-09-23 14:34:24 +03:00
url := "/cloudapi/compute/diskResize"
2026-06-05 17:30:36 +03:00
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
2025-09-23 14:34:24 +03:00
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
2026-06-05 17:30:36 +03:00
// DiskResizeAsync changes disk size with AsyncMode
func (c Compute) DiskResizeAsync(ctx context.Context, req DiskResizeRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperDiskResizeRequest{
DiskResizeRequest: req,
AsyncMode: true,
}
url := "/cloudapi/compute/diskResize"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
return string(res), nil
}