This commit is contained in:
asteam
2025-09-27 01:06:15 +03:00
parent 1ccc37a104
commit cf584c8123
1175 changed files with 11022 additions and 1832 deletions

View File

@@ -2,10 +2,11 @@ package compute
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v11/internal/validators"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
)
// MigrateRequest struct to migrate compute
@@ -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
}