summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-04-29 09:52:14 -0400
committerGitHub <noreply@github.com>2021-04-29 09:52:14 -0400
commitc01b1cbfcd205678af820d43b1966025e9c463e7 (patch)
tree0930fc2f331c00cc4564071326bb2121371388ae /pkg
parente7e97956b4a0ab66e1f1f2b453745b38d21f0703 (diff)
parent53057d5c20b2abf7ffc672972cbc83018ba0ed6c (diff)
downloadpodman-c01b1cbfcd205678af820d43b1966025e9c463e7.tar.gz
podman-c01b1cbfcd205678af820d43b1966025e9c463e7.tar.bz2
podman-c01b1cbfcd205678af820d43b1966025e9c463e7.zip
Merge pull request #10170 from ashley-cui/machineone
[NO TESTS NEEDED] Check if another VM is running on machine start
Diffstat (limited to 'pkg')
-rw-r--r--pkg/machine/config.go2
-rw-r--r--pkg/machine/qemu/machine.go14
2 files changed, 16 insertions, 0 deletions
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 32b3b5c2b..652229963 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -30,6 +30,8 @@ var (
DefaultIgnitionUserName = "core"
ErrNoSuchVM = errors.New("VM does not exist")
ErrVMAlreadyExists = errors.New("VM already exists")
+ ErrVMAlreadyRunning = errors.New("VM already running")
+ ErrMultipleActiveVM = errors.New("only one VM can be active at a time")
)
type Download struct {
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index fd22f465b..269a2a2da 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -519,3 +519,17 @@ func IsValidVMName(name string) (bool, error) {
}
return false, nil
}
+
+// CheckActiveVM checks if there is a VM already running
+func CheckActiveVM() (bool, string, error) {
+ vms, err := GetVMInfos()
+ if err != nil {
+ return false, "", errors.Wrap(err, "error checking VM active")
+ }
+ for _, vm := range vms {
+ if vm.Running {
+ return true, vm.Name, nil
+ }
+ }
+ return false, "", nil
+}