MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / execLXC

Method execLXC

internal/cli/cli_helpers.go:385–407  ·  view source on GitHub ↗

execLXC executes cmdParts inside an LXC container via SSH to its host node using pct exec. Returns stdout, stderr, exit code, and any transport error.

(ctx context.Context, vm *api.VM, cmdParts []string, timeout time.Duration)

Source from the content-addressed store, hash-verified

383// execLXC executes cmdParts inside an LXC container via SSH to its host node
384// using pct exec. Returns stdout, stderr, exit code, and any transport error.
385func (s *cliSession) execLXC(ctx context.Context, vm *api.VM, cmdParts []string, timeout time.Duration) (stdout, stderr string, exitCode int, err error) {
386 nodeIP, err := s.findNodeIP(ctx, vm.Node)
387 if err != nil {
388 return "", "", 0, fmt.Errorf("cannot resolve node for guest %d: %w", vm.ID, err)
389 }
390
391 sshUser, sshKeyfile, jumpHost := s.resolveSSHCreds(vm)
392
393 sshClient := commandrunner.NewSSHClient(commandrunner.SSHClientConfig{
394 Username: sshUser,
395 KeyPath: sshKeyfile,
396 Timeout: timeout,
397 Port: 22,
398 JumpHost: commandrunner.JumpHostConfig{
399 Addr: jumpHost.Addr,
400 User: jumpHost.User,
401 KeyPath: jumpHost.Keyfile,
402 Port: jumpHost.Port,
403 },
404 })
405
406 return sshClient.ExecuteContainerCommandDetailed(ctx, nodeIP, vm.ID, cmdParts)
407}
408
409// findNodeByName returns the node with the given name, or an error if not found.
410func (s *cliSession) findNodeByName(ctx context.Context, name string) (*api.Node, error) {

Callers 1

runGuestsExecFunction · 0.80

Calls 3

findNodeIPMethod · 0.95
resolveSSHCredsMethod · 0.95

Tested by

no test coverage detected