Skip to content

Make running in the background the default #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type osVmConfig struct {
User string
CloudInitDir string
KsFile string
Background bool
Interactive bool
NoCredentials bool
RemoveVm bool // Kill the running VM when it exits
RemoveDiskImage bool // After exit of the VM, remove the disk image
Expand Down Expand Up @@ -53,7 +53,7 @@ func init() {

runCmd.Flags().StringVar(&diskImageConfigInstance.Filesystem, "filesystem", "", "Override the root filesystem (e.g. xfs, btrfs, ext4)")
runCmd.Flags().BoolVar(&vmConfig.NoCredentials, "no-creds", false, "Do not inject default SSH key via credentials; also implies --background")
runCmd.Flags().BoolVarP(&vmConfig.Background, "background", "B", false, "Do not spawn SSH, run in background")
runCmd.Flags().BoolVarP(&vmConfig.Interactive, "interactive,", "i", false, "Start an SSH session")
runCmd.Flags().BoolVar(&vmConfig.RemoveVm, "rm", false, "Remove the VM and it's disk when the SSH session exits. Cannot be used with --background")
runCmd.Flags().BoolVar(&vmConfig.Quiet, "quiet", false, "Suppress output from bootc disk creation and VM boot console")
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func doRun(flags *cobra.Command, args []string) error {
NoCredentials: vmConfig.NoCredentials,
CloudInitData: flags.Flags().Changed("cloudinit"),
RemoveVm: vmConfig.RemoveVm,
Background: vmConfig.Background,
Interactive: vmConfig.Interactive,
SSHPort: sshPort,
SSHIdentity: machineInfo.SSHIdentityPath,
VMUser: vmConfig.User,
Expand All @@ -155,7 +155,7 @@ func doRun(flags *cobra.Command, args []string) error {
return err
}

if !vmConfig.Background {
if vmConfig.Interactive {
if !vmConfig.Quiet {
var vmConsoleWg sync.WaitGroup
vmConsoleWg.Add(1)
Expand Down
4 changes: 2 additions & 2 deletions pkg/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type RunVMParameters struct {
SSHPort int
Cmd []string
RemoveVm bool
Background bool
Interactive bool
}

type BootcVM interface {
Expand All @@ -88,7 +88,7 @@ type BootcVMCommon struct {
sshIdentity string
sshPort int
removeVm bool
background bool
interactive bool
cmd []string
pidFile string
imageID string
Expand Down
8 changes: 4 additions & 4 deletions pkg/vm/vm_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (b *BootcVMMac) GetConfig() (cfg *BootcVMConfig, err error) {
func (b *BootcVMMac) Run(params RunVMParameters) (err error) {
b.sshPort = params.SSHPort
b.removeVm = params.RemoveVm
b.background = params.Background
b.interactive = params.Interactive
b.cmd = params.Cmd
b.hasCloudInit = params.CloudInitData
b.cloudInitDir = params.CloudInitDir
Expand All @@ -112,9 +112,9 @@ func (b *BootcVMMac) Run(params RunVMParameters) (err error) {

if params.NoCredentials {
b.sshIdentity = ""
if !b.background {
fmt.Print("No credentials provided for SSH, using --background by default")
b.background = true
if b.interactive {
fmt.Print("No credentials provided for SSH, running the VM in the background")
b.interactive = false
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/vm/vm_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (v *BootcVMLinux) PrintConsole() (err error) {
func (v *BootcVMLinux) Run(params RunVMParameters) (err error) {
v.sshPort = params.SSHPort
v.removeVm = params.RemoveVm
v.background = params.Background
v.interactive = params.Interactive
v.cmd = params.Cmd
v.hasCloudInit = params.CloudInitData
v.cloudInitDir = params.CloudInitDir
Expand All @@ -125,9 +125,9 @@ func (v *BootcVMLinux) Run(params RunVMParameters) (err error) {

if params.NoCredentials {
v.sshIdentity = ""
if !v.background {
fmt.Print("No credentials provided for SSH, using --background by default")
v.background = true
if v.interactive {
fmt.Print("No credentials provided for SSH, running the VM in the background")
v.interactive = false
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func runTestVM(bootcVM vm.BootcVM) {
SSHPort: 22,
Cmd: []string{},
RemoveVm: false,
Background: false,
Interactive: true,
SSHIdentity: testUserSSHKey,
})
Expect(err).To(Not(HaveOccurred()))
Expand Down