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

92 lines
2.4 KiB
Go
Raw Normal View History

2022-12-22 17:56:47 +03:00
package compute
import (
"context"
"net/http"
2026-10-09 16:23:35 +03:00
"strconv"
2022-12-22 17:56:47 +03:00
"strings"
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
// MigrateStorageRequest struct for migration
2022-12-22 17:56:47 +03:00
type MigrateStorageRequest 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
// SEP ID to migrate disks
// Required: true
2023-03-24 17:09:30 +03:00
SEPID uint64 `url:"sepId" json:"sepId" validate:"required"`
2022-12-22 17:56:47 +03:00
// SEP pool name to migrate disks
// Required: true
2023-03-24 17:09:30 +03:00
PoolName string `url:"poolName" json:"poolName" validate:"required"`
2022-12-22 17:56:47 +03:00
2025-12-08 16:16:35 +03:00
// Target node ID
2022-12-22 17:56:47 +03:00
// Required: true
2025-12-08 16:16:35 +03:00
NodeID uint64 `url:"node_id" json:"node_id" validate:"required"`
2026-10-09 16:23:35 +03:00
}
2022-12-22 17:56:47 +03:00
2026-10-09 16:23:35 +03:00
type wrapperMigrateStorageRequest struct {
MigrateStorageRequest
AsyncMode bool `url:"async_mode,omitempty"`
2022-12-22 17:56:47 +03:00
}
// MigrateStorage gets complex compute migration
2025-12-08 16:16:35 +03:00
// Compute will be migrated to specified node, and compute disks will
2022-12-22 17:56:47 +03:00
// be migrated to specified SEP to specified pool.
// This action can take up to 84 hours
2026-10-09 16:23:35 +03:00
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) {
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 "", validators.ValidationErrors(validators.GetErrors(err))
2022-12-22 17:56:47 +03:00
}
url := "/cloudbroker/compute/migrateStorage"
2026-10-09 16:23:35 +03:00
aReq := wrapperMigrateStorageRequest{
MigrateStorageRequest: req,
AsyncMode: true,
}
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
2022-12-22 17:56:47 +03:00
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}