2025-09-23 14:34:24 +03:00
|
|
|
package compute
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"net/http"
|
2026-06-05 17:30:36 +03:00
|
|
|
"strconv"
|
2025-09-23 14:34:24 +03:00
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// MigrateStorageCleanUpRequest struct to cleanup resources after finished migration
|
|
|
|
|
type MigrateStorageCleanUpRequest struct {
|
|
|
|
|
// ID of the compute instance
|
|
|
|
|
// Required: true
|
|
|
|
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-05 17:30:36 +03:00
|
|
|
type wrapperMigrateStorageCleanUpRequest struct {
|
|
|
|
|
MigrateStorageCleanUpRequest
|
|
|
|
|
|
|
|
|
|
AsyncMode bool `url:"asyncMode"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 14:34:24 +03:00
|
|
|
// MigrateStorageCleanUp cleanup resources after finished (success of failed) complex compute migration.
|
|
|
|
|
// If the migration was successful, then old disks will be removed, else new (target) disks will be removed.
|
|
|
|
|
// Do it wisely!
|
2026-06-05 17:30:36 +03:00
|
|
|
func (c Compute) MigrateStorageCleanUp(ctx context.Context, req MigrateStorageCleanUpRequest) (bool, error) {
|
2025-09-23 14:34:24 +03:00
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
2026-06-05 17:30:36 +03:00
|
|
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reqWrapped := wrapperMigrateStorageCleanUpRequest{
|
|
|
|
|
MigrateStorageCleanUpRequest: req,
|
|
|
|
|
AsyncMode: false,
|
2025-09-23 14:34:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url := "/cloudbroker/compute/migrateStorageCleanup"
|
|
|
|
|
|
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 {
|
2026-06-05 17:30:36 +03:00
|
|
|
return false, err
|
2025-09-23 14:34:24 +03:00
|
|
|
}
|
|
|
|
|
|
2026-06-05 17:30:36 +03:00
|
|
|
result, err := strconv.ParseBool(string(res))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
2025-09-23 14:34:24 +03:00
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
2026-06-05 17:30:36 +03:00
|
|
|
|
|
|
|
|
// MigrateStorageCleanUpAsync cleanup resources after finished migration with AsyncMode
|
|
|
|
|
func (c Compute) MigrateStorageCleanUpAsync(ctx context.Context, req MigrateStorageCleanUpRequest) (string, error) {
|
|
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reqWrapped := wrapperMigrateStorageCleanUpRequest{
|
|
|
|
|
MigrateStorageCleanUpRequest: req,
|
|
|
|
|
AsyncMode: true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url := "/cloudbroker/compute/migrateStorageCleanup"
|
|
|
|
|
|
|
|
|
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string(res), nil
|
|
|
|
|
}
|