Files
decort-golang-sdk/pkg/cloudbroker/compute/migrate_storage.go
dayterr 8cde0e9371 v1.16.7
v1.16.7
2026-10-09 16:23:35 +03:00

92 lines
2.4 KiB
Go

package compute
import (
"context"
"net/http"
"strconv"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// MigrateStorageRequest struct for migration
type MigrateStorageRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// SEP ID to migrate disks
// Required: true
SEPID uint64 `url:"sepId" json:"sepId" validate:"required"`
// SEP pool name to migrate disks
// Required: true
PoolName string `url:"poolName" json:"poolName" validate:"required"`
// Target node ID
// Required: true
NodeID uint64 `url:"node_id" json:"node_id" validate:"required"`
}
type wrapperMigrateStorageRequest struct {
MigrateStorageRequest
AsyncMode bool `url:"async_mode,omitempty"`
}
// MigrateStorage gets complex compute migration
// Compute will be migrated to specified node, and compute disks will
// be migrated to specified SEP to specified pool.
// This action can take up to 84 hours
func (c Compute) MigrateStorage(ctx context.Context, req MigrateStorageRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/migrateStorage"
aReq := wrapperMigrateStorageRequest{
MigrateStorageRequest: req,
AsyncMode: false,
}
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
// MigrateStorageAsync gets complex compute migration in async mode
// Compute will be migrated to specified node, and compute disks will
// be migrated to specified SEP to specified pool.
// This action can take up to 84 hours
func (c Compute) MigrateStorageAsync(ctx context.Context, req MigrateStorageRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/migrateStorage"
aReq := wrapperMigrateStorageRequest{
MigrateStorageRequest: req,
AsyncMode: true,
}
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}