package compute import ( "context" "encoding/json" "net/http" "strconv" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" ) // MigrateRequest struct to migrate compute type MigrateRequest struct { // ID of compute instance // Required: true ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"` // Particular Stack ID to migrate this compute to // Required: false TargetStackID uint64 `url:"targetStackId,omitempty" json:"targetStackId,omitempty"` // If live migration fails, destroy compute // on source node and recreate on the target // Required: false 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) if err != nil { return false, validators.ValidationErrors(validators.GetErrors(err)) } url := "/cloudbroker/compute/migrate" syncReq := asyncWrapperMigrateRequest{MigrateRequest: req, SyncMode: true} res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, syncReq) if err != nil { return false, err } result, err := strconv.ParseBool(string(res)) if err != nil { return false, err } 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 }