2025-09-27 01:06:15 +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-27 01:06:15 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// GuestAgentEnableRequest struct to enable guest agent
|
|
|
|
|
type GuestAgentEnableRequest struct {
|
|
|
|
|
// ID of compute instance
|
|
|
|
|
// Required: true
|
|
|
|
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-05 17:30:36 +03:00
|
|
|
type wrapperGuestAgentEnableRequest struct {
|
|
|
|
|
GuestAgentEnableRequest
|
|
|
|
|
|
|
|
|
|
AsyncMode bool `url:"asyncMode"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-27 01:06:15 +03:00
|
|
|
// Enable guest agent at a specific compute
|
|
|
|
|
func (c Compute) GuestAgentEnable(ctx context.Context, req GuestAgentEnableRequest) (bool, error) {
|
|
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-05 17:30:36 +03:00
|
|
|
reqWrapped := wrapperGuestAgentEnableRequest{
|
|
|
|
|
GuestAgentEnableRequest: req,
|
|
|
|
|
AsyncMode: false,
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-27 01:06:15 +03:00
|
|
|
url := "/cloudapi/compute/guest_agent_enable"
|
|
|
|
|
|
2026-06-05 17:30:36 +03:00
|
|
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
2025-09-27 01:06:15 +03:00
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := strconv.ParseBool(string(res))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
2026-06-05 17:30:36 +03:00
|
|
|
|
|
|
|
|
// GuestAgentEnableAsync enables guest agent at a specific compute with AsyncMode
|
|
|
|
|
func (c Compute) GuestAgentEnableAsync(ctx context.Context, req GuestAgentEnableRequest) (string, error) {
|
|
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reqWrapped := wrapperGuestAgentEnableRequest{
|
|
|
|
|
GuestAgentEnableRequest: req,
|
|
|
|
|
AsyncMode: true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url := "/cloudapi/compute/guest_agent_enable"
|
|
|
|
|
|
|
|
|
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string(res), nil
|
|
|
|
|
}
|