v12.9.0
This commit is contained in:
42
samples/client/client.go
Normal file
42
samples/client/client.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user