summaryrefslogtreecommitdiff
path: root/cmd/podman/machine/init.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/machine/init.go')
-rw-r--r--cmd/podman/machine/init.go48
1 files changed, 35 insertions, 13 deletions
diff --git a/cmd/podman/machine/init.go b/cmd/podman/machine/init.go
index bee6844df..14e87c201 100644
--- a/cmd/podman/machine/init.go
+++ b/cmd/podman/machine/init.go
@@ -1,4 +1,4 @@
-// +build amd64,!windows arm64,!windows
+// +build amd64 arm64
package machine
@@ -8,7 +8,6 @@ import (
"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/pkg/machine"
- "github.com/containers/podman/v3/pkg/machine/qemu"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -38,6 +37,8 @@ func init() {
})
flags := initCmd.Flags()
cfg := registry.PodmanConfig()
+ initOpts.Username = cfg.Config.Machine.User
+
cpusFlagName := "cpus"
flags.Uint64Var(
&initOpts.CPUS,
@@ -76,6 +77,13 @@ func init() {
flags.StringVar(&initOpts.TimeZone, timezoneFlagName, defaultTz, "Set timezone")
_ = initCmd.RegisterFlagCompletionFunc(timezoneFlagName, completion.AutocompleteDefault)
+ flags.BoolVar(
+ &initOpts.ReExec,
+ "reexec", false,
+ "process was rexeced",
+ )
+ flags.MarkHidden("reexec")
+
ImagePathFlagName := "image-path"
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Machine.Image, "Path to qcow image")
_ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
@@ -88,33 +96,47 @@ func init() {
// TODO should we allow for a users to append to the qemu cmdline?
func initMachine(cmd *cobra.Command, args []string) error {
var (
- vm machine.VM
- vmType string
- err error
+ vm machine.VM
+ err error
)
+
+ provider := getSystemDefaultProvider()
initOpts.Name = defaultMachineName
if len(args) > 0 {
initOpts.Name = args[0]
}
- switch vmType {
- default: // qemu is the default
- if _, err := qemu.LoadVMByName(initOpts.Name); err == nil {
- return errors.Wrap(machine.ErrVMAlreadyExists, initOpts.Name)
- }
- vm, err = qemu.NewMachine(initOpts)
+ if _, err := provider.LoadVMByName(initOpts.Name); err == nil {
+ return errors.Wrap(machine.ErrVMAlreadyExists, initOpts.Name)
}
+
+ vm, err = provider.NewMachine(initOpts)
if err != nil {
return err
}
- err = vm.Init(initOpts)
- if err != nil {
+
+ if finished, err := vm.Init(initOpts); err != nil || !finished {
+ // Finished = true, err = nil - Success! Log a message with further instructions
+ // Finished = false, err = nil - The installation is partially complete and podman should
+ // exit gracefully with no error and no success message.
+ // Examples:
+ // - a user has chosen to perform their own reboot
+ // - reexec for limited admin operations, returning to parent
+ // Finished = *, err != nil - Exit with an error message
+
return err
}
+ fmt.Println("Machine init complete")
if now {
err = vm.Start(initOpts.Name, machine.StartOptions{})
if err == nil {
fmt.Printf("Machine %q started successfully\n", initOpts.Name)
}
+ } else {
+ extra := ""
+ if initOpts.Name != defaultMachineName {
+ extra = " " + initOpts.Name
+ }
+ fmt.Printf("To start your machine run:\n\n\tpodman machine start%s\n\n", extra)
}
return err
}