diff options
author | Ashley Cui <acui@redhat.com> | 2021-04-28 14:18:28 -0400 |
---|---|---|
committer | Ashley Cui <acui@redhat.com> | 2021-04-28 15:09:10 -0400 |
commit | 53057d5c20b2abf7ffc672972cbc83018ba0ed6c (patch) | |
tree | e0dbb98e5d80dc8726d5bf5ad8640be5edc60f02 /cmd/podman/machine/start.go | |
parent | 476c76f580d5cd092ff958765af36857b2a68d6c (diff) | |
download | podman-53057d5c20b2abf7ffc672972cbc83018ba0ed6c.tar.gz podman-53057d5c20b2abf7ffc672972cbc83018ba0ed6c.tar.bz2 podman-53057d5c20b2abf7ffc672972cbc83018ba0ed6c.zip |
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 <acui@redhat.com>
Diffstat (limited to 'cmd/podman/machine/start.go')
-rw-r--r-- | cmd/podman/machine/start.go | 13 |
1 files changed, 13 insertions, 0 deletions
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) |