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

77 lines
1.7 KiB
Go
Raw Normal View History

2025-09-23 14:34:24 +03:00
package compute
import (
"context"
"net/http"
"strconv"
2026-06-05 17:30:36 +03:00
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/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-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
}
2026-06-05 17:30:36 +03:00
type wrapperPinToNodeRequest struct {
PinToNodeRequest
AsyncMode bool `url:"asyncMode"`
}
2025-12-08 16:30:08 +03:00
// PinToNode pin compute to current node
func (c Compute) PinToNode(ctx context.Context, req PinToNodeRequest) (bool, error) {
2025-09-23 14:34:24 +03:00
err := validators.ValidateRequest(req)
if err != nil {
2025-09-26 18:56:58 +03:00
return false, validators.ValidationErrors(validators.GetErrors(err))
2025-09-23 14:34:24 +03:00
}
2026-06-05 17:30:36 +03:00
reqWrapped := wrapperPinToNodeRequest{
PinToNodeRequest: req,
AsyncMode: false,
}
2025-12-08 16:30:08 +03:00
url := "/cloudapi/compute/pin_to_node"
2025-09-23 14:34:24 +03:00
2026-06-05 17:30:36 +03:00
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
2025-09-23 14:34:24 +03:00
if err != nil {
2025-09-26 18:56:58 +03:00
return false, err
2025-09-23 14:34:24 +03:00
}
2025-09-26 18:56:58 +03:00
result, err := strconv.ParseBool(string(res))
2025-09-23 14:34:24 +03:00
if err != nil {
2025-09-26 18:56:58 +03:00
return false, err
2025-09-23 14:34:24 +03:00
}
return result, nil
}
2026-06-05 17:30:36 +03:00
// PinToNodeAsync pins compute to current node with AsyncMode
func (c Compute) PinToNodeAsync(ctx context.Context, req PinToNodeRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperPinToNodeRequest{
PinToNodeRequest: req,
AsyncMode: true,
}
url := "/cloudapi/compute/pin_to_node"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
return string(res), nil
}