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

44 lines
992 B
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-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 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
}
2025-12-08 16:30:08 +03:00
url := "/cloudapi/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 {
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
}