package compute import ( "context" "encoding/json" "net/http" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" ) // Target describes a target for migration type Target struct { // SEP ID // Required: true SepID uint64 `url:"sep_id" json:"sep_id" validate:"required"` // Name of a pool // Required: true PoolName string `url:"pool_name" json:"pool_name" validate:"required"` // Storage policy ID // Required: false StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"` // Disk IDs // Required: false DiskIDs []uint64 `url:"disk_ids,omitempty" json:"disk_ids,omitempty"` } // Storage describes a destination for a disk type Storage struct { // Target for migration // Required: false Targets []Target `url:"targets,omitempty" json:"targets,omitempty"` // Whether a separate source-disk cleanup job should be started after full success // Required: false AutoCleanup interface{} `url:"auto_cleanup,omitempty" json:"auto_cleanup,omitempty" validate:"omitempty,isBool"` } // MigrateV2Request to start a migration of a compute or a disk type MigrateV2Request struct { // ID of compute to migrate // Required: true ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"` // Stateless load balancers support only compute mode, including their local system disk. // Required: false Mode string `url:"mode,omitempty" json:"mode,omitempty" validate:"omitempty,migrateV2Mode"` // ID of node to migrate to // Required: false TargetNodeID uint64 `url:"target_node_id,omitempty" json:"target_node_id,omitempty"` // Destination for a disk // Required: false Storage Storage `url:"storage,omitempty" json:"storage,omitempty"` } // MigrateV2 starts a migration of a compute or a disk func (c Compute) MigrateV2(ctx context.Context, req MigrateV2Request) (string, error) { err := validators.ValidateRequest(req) if err != nil { return "", validators.ValidationErrors(validators.GetErrors(err)) } url := "/cloudbroker/compute/migrate_v2" res, err := c.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req) if err != nil { return "", err } var resp string err = json.Unmarshal(res, &resp) if err != nil { return "", err } return resp, nil }