mirror of
https://github.com/containers/podman.git
synced 2026-03-13 08:01:19 +08:00
Merge pull request #10170 from ashley-cui/machineone
[NO TESTS NEEDED] Check if another VM is running on machine start
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user