This commit is contained in:
asteam
2025-07-15 17:39:18 +03:00
parent 1f8637400f
commit 7dacf35cd6
163 changed files with 4322 additions and 504 deletions

View File

@@ -2,6 +2,7 @@ package compute
import (
"context"
"encoding/json"
"net/http"
"strconv"
@@ -24,6 +25,11 @@ type MigrateRequest struct {
Force bool `url:"force,omitempty" json:"force,omitempty"`
}
type asyncWrapperMigrateRequest struct {
MigrateRequest
SyncMode bool `url:"sync"`
}
// Migrate migrates compute to another stack
func (c Compute) Migrate(ctx context.Context, req MigrateRequest) (bool, error) {
err := validators.ValidateRequest(req)
@@ -33,7 +39,9 @@ func (c Compute) Migrate(ctx context.Context, req MigrateRequest) (bool, error)
url := "/cloudbroker/compute/migrate"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
syncReq := asyncWrapperMigrateRequest{MigrateRequest: req, SyncMode: true}
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, syncReq)
if err != nil {
return false, err
}
@@ -45,3 +53,29 @@ func (c Compute) Migrate(ctx context.Context, req MigrateRequest) (bool, error)
return result, nil
}
// AsyncMigrate migrates compute to another stack in async mode
func (c Compute) AsyncMigrate(ctx context.Context, req MigrateRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/migrate"
asyncReq := asyncWrapperMigrateRequest{MigrateRequest: req, SyncMode: false}
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, asyncReq)
if err != nil {
return " ", err
}
var taskID string
err = json.Unmarshal(res, &taskID)
if err != nil {
return "", err
}
return taskID, nil
}