(_ *cobra.Command, session *cliSession, vm *api.VM)
| 684 | } |
| 685 | |
| 686 | func runLXCShell(_ *cobra.Command, session *cliSession, vm *api.VM) error { |
| 687 | ctx := context.Background() |
| 688 | |
| 689 | nodeIP, err := session.findNodeIP(ctx, vm.Node) |
| 690 | if err != nil { |
| 691 | return printError(fmt.Errorf("cannot resolve node for guest %d: %w", vm.ID, err)) |
| 692 | } |
| 693 | |
| 694 | sshUser, jumpHost := session.resolveNodeSSHCreds(&api.Node{ |
| 695 | Name: vm.Node, |
| 696 | SourceProfile: vm.SourceProfile, |
| 697 | }) |
| 698 | if sshUser == "" { |
| 699 | return printError(fmt.Errorf("SSH user not configured; set ssh_user in config or use --ssh-user")) |
| 700 | } |
| 701 | |
| 702 | keyfile := session.resolveNodeSSHKeyfile(&api.Node{ |
| 703 | Name: vm.Node, |
| 704 | SourceProfile: vm.SourceProfile, |
| 705 | }) |
| 706 | |
| 707 | isNixOS := vm.OSType == "nixos" || vm.OSType == "nix" |
| 708 | |
| 709 | var pctCmd string |
| 710 | if isNixOS { |
| 711 | pctCmd = fmt.Sprintf("pct exec %d -- /bin/sh -c 'if [ -f /etc/set-environment ]; then . /etc/set-environment; fi; exec bash'", vm.ID) |
| 712 | } else { |
| 713 | pctCmd = fmt.Sprintf("pct enter %d", vm.ID) |
| 714 | } |
| 715 | |
| 716 | if !strings.EqualFold(sshUser, "root") { |
| 717 | pctCmd = "sudo " + pctCmd |
| 718 | } |
| 719 | |
| 720 | sshArgs := ssh.BuildSSHArgs(sshUser, nodeIP, jumpHost) |
| 721 | sshArgs = append(sshArgs, "-t", pctCmd) |
| 722 | |
| 723 | containerType := "LXC" |
| 724 | if isNixOS { |
| 725 | containerType = "NixOS LXC" |
| 726 | } |
| 727 | |
| 728 | fmt.Fprintf(os.Stderr, "Connecting to %s container %s (ID: %d) on node %s (%s)...\n", |
| 729 | containerType, vm.Name, vm.ID, vm.Node, nodeIP) |
| 730 | |
| 731 | if err := execInteractiveShell(sshArgs, keyfile); err != nil { |
| 732 | return printError(fmt.Errorf("shell session ended with error: %w", err)) |
| 733 | } |
| 734 | |
| 735 | return nil |
| 736 | } |
| 737 | |
| 738 | func runQEMUShell(_ *cobra.Command, session *cliSession, vm *api.VM) error { |
| 739 | if vm.IP == "" { |
no test coverage detected