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)
| 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. |
| 385 | func (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. |
| 410 | func (s *cliSession) findNodeByName(ctx context.Context, name string) (*api.Node, error) { |
no test coverage detected