This commit is contained in:
2025-11-18 15:27:53 +03:00
parent e3a65c0f33
commit 06992b8949
10 changed files with 291 additions and 10 deletions

42
samples/client/client.go Normal file
View File

@@ -0,0 +1,42 @@
package client
import (
"context"
"fmt"
"errors"
decortsdk "repository.basistech.ru/BASIS/dynamix-golang-sdk/v12"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/pkg/cloudbroker/compute"
)
type Migrator interface {
Migrate(ctxOrigin context.Context, vmUUID, to uint64) (bool, error)
}
type migrator struct {
cfg *Config
client decortsdk.ClientInterface
}
func NewMigrator(cfg *Config, c decortsdk.ClientInterface) Migrator {
return &migrator{
cfg: cfg,
client: c,
}
}
func (m *migrator) Migrate(ctxOrigin context.Context, dxVMID, stackID uint64) (bool, error) {
req := compute.MigrateRequest{
ComputeID: dxVMID,
TargetStackID: stackID,
Force: false,
}
ctx, cancel := context.WithTimeout(ctxOrigin, m.cfg.QueryTimeout)
ok, err := m.client.CloudBroker().Compute().Migrate(ctx, req)
cancel()
if err != nil {
return false, errors.Join(err, fmt.Errorf("Migrate VM %d to Node %d", dxVMID, stackID))
}
return ok, nil
}