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

82 lines
2.0 KiB
Go
Raw Normal View History

2025-09-27 01:06:15 +03:00
package compute
import (
"context"
"encoding/json"
"net/http"
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
)
// GuestAgentExecuteRequest struct to execute command from user to agent
type GuestAgentExecuteRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
// Custom command from user to agent
// Required: true
Command string `url:"command" json:"command" validate:"required"`
// Arguments to command
// Required: true
Arguments string `url:"arguments" json:"arguments" validate:"required"`
}
2026-06-05 17:30:36 +03:00
type wrapperGuestAgentExecuteRequest struct {
GuestAgentExecuteRequest
AsyncMode bool `url:"asyncMode"`
}
2025-09-27 01:06:15 +03:00
// Execute guest agent command
func (c Compute) GuestAgentExecuteRequest(ctx context.Context, req GuestAgentExecuteRequest) (map[string]interface{}, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
2026-06-05 17:30:36 +03:00
reqWrapped := wrapperGuestAgentExecuteRequest{
GuestAgentExecuteRequest: req,
AsyncMode: false,
}
2025-09-27 01:06:15 +03:00
url := "/cloudapi/compute/guest_agent_execute"
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 nil, err
}
var result map[string]interface{}
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return result, nil
}
2026-06-05 17:30:36 +03:00
// GuestAgentExecuteRequestAsync executes guest agent command with AsyncMode
func (c Compute) GuestAgentExecuteRequestAsync(ctx context.Context, req GuestAgentExecuteRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperGuestAgentExecuteRequest{
GuestAgentExecuteRequest: req,
AsyncMode: true,
}
url := "/cloudapi/compute/guest_agent_execute"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
return string(res), nil
}