You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
package compute
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// 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"`
|
|
}
|
|
|
|
// 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))
|
|
}
|
|
|
|
url := "/cloudapi/compute/guest_agent_execute"
|
|
|
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
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
|
|
}
|