Correct VM existance check on WSL

Replaces GetHyperVisorVMs() with Exists() to better abstract the underlying
use-case and slightly imrpove efficiency.

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
This commit is contained in:
Jason T. Greene
2024-02-13 21:37:56 -06:00
parent 07779e09f6
commit d23dd35dc1
6 changed files with 12 additions and 30 deletions

View File

@ -7,7 +7,6 @@ import (
"runtime"
"time"
"github.com/containers/common/pkg/util"
"github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/connection"
machineDefine "github.com/containers/podman/v5/pkg/machine/define"
@ -243,11 +242,11 @@ func VMExists(name string, vmstubbers []vmconfigs.VMProvider) (*vmconfigs.Machin
}
// Check with the provider hypervisor
for _, vmstubber := range vmstubbers {
vms, err := vmstubber.GetHyperVisorVMs()
exists, err := vmstubber.Exists(name)
if err != nil {
return nil, false, err
}
if util.StringInSlice(name, vms) { //nolint:staticcheck
if exists {
return nil, true, fmt.Errorf("vm %q already exists on hypervisor", name)
}
}