Skip to content

Commit

Permalink
Merge pull request #11644 from rhatdan/now
Browse files Browse the repository at this point in the history
Add podman machine init --now option
  • Loading branch information
openshift-merge-robot authored Sep 20, 2021
2 parents 4cdffd0 + 74ad053 commit b700fe2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cmd/podman/machine/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package machine

import (
"fmt"

"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/pkg/machine"
Expand All @@ -26,6 +28,7 @@ var (
var (
initOpts = machine.InitOptions{}
defaultMachineName = "podman-machine-default"
now bool
)

func init() {
Expand Down Expand Up @@ -61,6 +64,12 @@ func init() {
)
_ = initCmd.RegisterFlagCompletionFunc(memoryFlagName, completion.AutocompleteNone)

flags.BoolVar(
&now,
"now", false,
"Start machine now",
)

ImagePathFlagName := "image-path"
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Engine.MachineImage, "Path to qcow image")
_ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
Expand Down Expand Up @@ -91,5 +100,15 @@ func initMachine(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
return vm.Init(initOpts)
err = vm.Init(initOpts)
if err != nil {
return err
}
if now {
err = vm.Start(initOpts.Name, machine.StartOptions{})
if err == nil {
fmt.Printf("Machine %q started successfully\n", initOpts.Name)
}
}
return err
}
4 changes: 4 additions & 0 deletions docs/source/markdown/podman-machine-init.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Defaults to `testing`.

Memory (in MB).

#### **--now**

Start the virtual machine immediately after it has been initialized.

#### **--help**

Print usage statement.
Expand Down

0 comments on commit b700fe2

Please sign in to comment.