Files
dynamix-golang-sdk/pkg/cloudbroker/compute/pin_to_node.go

52 lines
1.2 KiB
Go
Raw Normal View History

2025-09-23 14:34:24 +03:00
package compute
import (
"context"
"net/http"
"strconv"
2025-12-08 16:30:08 +03:00
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v13/internal/validators"
2025-09-23 14:34:24 +03:00
)
2025-12-08 16:30:08 +03:00
// PinToNodeRequest struct to pin compute to node
type PinToNodeRequest struct {
2025-09-23 14:34:24 +03:00
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
2025-12-08 16:30:08 +03:00
// Node ID to pin to
2025-09-23 14:34:24 +03:00
// Required: false
2025-12-08 16:30:08 +03:00
TargetNodeID uint64 `url:"targetNodeId" json:"targetNodeId"`
2025-09-23 14:34:24 +03:00
// Try to migrate or not if compute in running states
// Required: false
Force bool `url:"force" json:"force"`
2025-09-26 18:56:58 +03:00
// Auto start when node restarted
// Required: false
// Default: false
AutoStart bool `url:"autoStart" json:"autoStart"`
2025-09-23 14:34:24 +03:00
}
2025-12-08 16:30:08 +03:00
// PinToNode pins compute to current node
func (c Compute) PinToNode(ctx context.Context, req PinToNodeRequest) (uint64, error) {
2025-09-23 14:34:24 +03:00
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
2025-12-08 16:30:08 +03:00
url := "/cloudbroker/compute/pin_to_node"
2025-09-23 14:34:24 +03:00
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}