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

52 lines
1.2 KiB
Go
Raw Normal View History

2022-12-22 17:56:47 +03:00
package compute
import (
"context"
"net/http"
"strconv"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-12-22 17:56:47 +03:00
)
2025-12-08 16:16:35 +03:00
// PinToNodeRequest struct to pin compute to node
type PinToNodeRequest struct {
2022-12-22 17:56:47 +03:00
// ID of the compute instance
// Required: true
2023-03-24 17:09:30 +03:00
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
2022-12-22 17:56:47 +03:00
2025-12-08 16:16:35 +03:00
// Node ID to pin to
2024-11-12 12:51:21 +03:00
// Required: false
2025-12-08 16:16:35 +03:00
TargetNodeID uint64 `url:"targetNodeId" json:"targetNodeId"`
2022-12-22 17:56:47 +03:00
// Try to migrate or not if compute in running states
// Required: false
2023-03-01 19:05:53 +03:00
Force bool `url:"force" json:"force"`
2024-12-27 11:35:22 +03:00
// Auto start when node restarted
// Required: false
// Default: false
AutoStart bool `url:"autoStart" json:"autoStart"`
2022-12-22 17:56:47 +03:00
}
2025-12-08 16:16:35 +03:00
// PinToNode pins compute to current node
func (c Compute) PinToNode(ctx context.Context, req PinToNodeRequest) (uint64, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-12-22 17:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return 0, validators.ValidationErrors(validators.GetErrors(err))
2022-12-22 17:56:47 +03:00
}
2025-12-08 16:16:35 +03:00
url := "/cloudbroker/compute/pin_to_node"
2022-12-22 17:56:47 +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
}