From 53057d5c20b2abf7ffc672972cbc83018ba0ed6c Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Wed, 28 Apr 2021 14:18:28 -0400 Subject: Check if another VM is running on machine start Only one VM can be up at a time. If another VM is running, or the current VM is running, error out on a podman machine start [NO TESTS NEEDED] Signed-off-by: Ashley Cui --- cmd/podman/machine/start.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cmd/podman') diff --git a/cmd/podman/machine/start.go b/cmd/podman/machine/start.go index d06e04f41..4334cfc0f 100644 --- a/cmd/podman/machine/start.go +++ b/cmd/podman/machine/start.go @@ -7,6 +7,7 @@ import ( "github.com/containers/podman/v3/pkg/domain/entities" "github.com/containers/podman/v3/pkg/machine" "github.com/containers/podman/v3/pkg/machine/qemu" + "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -40,6 +41,18 @@ func start(cmd *cobra.Command, args []string) error { if len(args) > 0 && len(args[0]) > 0 { vmName = args[0] } + + // We only have qemu VM's for now + active, activeName, err := qemu.CheckActiveVM() + if err != nil { + return err + } + if active { + if vmName == activeName { + return errors.Wrapf(machine.ErrVMAlreadyRunning, "cannot start VM %s", vmName) + } + return errors.Wrapf(machine.ErrMultipleActiveVM, "cannot start VM %s. VM %s is currently running", vmName, activeName) + } switch vmType { default: vm, err = qemu.LoadVMByName(vmName) -- cgit v1.2.3-54-g00ecf