MCPcopy Index your code
hub / github.com/devnullvoid/pvetui / ExecuteHostCommand

Method ExecuteHostCommand

internal/plugins/command-runner/executor.go:65–101  ·  view source on GitHub ↗

ExecuteHostCommand executes a command on a Proxmox host via SSH

(ctx context.Context, host, command string)

Source from the content-addressed store, hash-verified

63
64// ExecuteHostCommand executes a command on a Proxmox host via SSH
65func (e *Executor) ExecuteHostCommand(ctx context.Context, host, command string) ExecutionResult {
66 start := time.Now()
67
68 result := ExecutionResult{
69 Command: command,
70 }
71
72 // Validate command against whitelist
73 if err := e.validator.ValidateCommand(TargetHost, command); err != nil {
74 result.Error = err
75 result.Duration = time.Since(start)
76 return result
77 }
78
79 // Create context with timeout
80 ctx, cancel := context.WithTimeout(ctx, e.config.Timeout)
81 defer cancel()
82
83 // Execute command via SSH
84 output, err := e.sshClient.ExecuteCommand(ctx, host, command)
85 result.Duration = time.Since(start)
86
87 if err != nil {
88 result.Error = fmt.Errorf("execution failed: %w", err)
89 return result
90 }
91
92 // Enforce output size limit
93 if len(output) > e.config.MaxOutputSize {
94 result.Output = output[:e.config.MaxOutputSize]
95 result.Truncated = true
96 } else {
97 result.Output = output
98 }
99
100 return result
101}
102
103// ExecuteContainerCommand executes a command in an LXC container via SSH to the host.
104// It uses 'pct exec' to run the command inside the container.

Callers 3

Calls 2

ValidateCommandMethod · 0.80
ExecuteCommandMethod · 0.65

Tested by 2