mirror of https://github.com/containers/podman.git
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:
parent
07779e09f6
commit
d23dd35dc1
|
@ -74,9 +74,9 @@ func (a AppleHVStubber) CreateVM(opts define.CreateVMOpts, mc *vmconfigs.Machine
|
||||||
return resizeDisk(mc, strongunits.GiB(mc.Resources.DiskSize))
|
return resizeDisk(mc, strongunits.GiB(mc.Resources.DiskSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppleHVStubber) GetHyperVisorVMs() ([]string, error) {
|
func (a AppleHVStubber) Exists(name string) (bool, error) {
|
||||||
// not applicable for applehv
|
// not applicable for applehv
|
||||||
return nil, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppleHVStubber) MountType() vmconfigs.VolumeMountType {
|
func (a AppleHVStubber) MountType() vmconfigs.VolumeMountType {
|
||||||
|
|
|
@ -123,19 +123,10 @@ func (h HyperVStubber) CreateVM(opts define.CreateVMOpts, mc *vmconfigs.MachineC
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h HyperVStubber) GetHyperVisorVMs() ([]string, error) {
|
func (h HyperVStubber) Exists(name string) (bool, error) {
|
||||||
var (
|
|
||||||
vmNames []string
|
|
||||||
)
|
|
||||||
vmm := hypervctl.NewVirtualMachineManager()
|
vmm := hypervctl.NewVirtualMachineManager()
|
||||||
vms, err := vmm.GetAll()
|
exists, _, err := vmm.GetMachineExists(name)
|
||||||
if err != nil {
|
return exists, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, vm := range vms {
|
|
||||||
vmNames = append(vmNames, vm.ElementName) // Note: elementname is human-readable name
|
|
||||||
}
|
|
||||||
return vmNames, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h HyperVStubber) MountType() vmconfigs.VolumeMountType {
|
func (h HyperVStubber) MountType() vmconfigs.VolumeMountType {
|
||||||
|
|
|
@ -218,8 +218,8 @@ func waitForReady(readySocket *define.VMFile, pid int, stdErrBuffer *bytes.Buffe
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *QEMUStubber) GetHyperVisorVMs() ([]string, error) {
|
func (q *QEMUStubber) Exists(name string) (bool, error) {
|
||||||
return nil, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *QEMUStubber) VMType() define.VMType {
|
func (q *QEMUStubber) VMType() define.VMType {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/util"
|
|
||||||
"github.com/containers/podman/v5/pkg/machine"
|
"github.com/containers/podman/v5/pkg/machine"
|
||||||
"github.com/containers/podman/v5/pkg/machine/connection"
|
"github.com/containers/podman/v5/pkg/machine/connection"
|
||||||
machineDefine "github.com/containers/podman/v5/pkg/machine/define"
|
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
|
// Check with the provider hypervisor
|
||||||
for _, vmstubber := range vmstubbers {
|
for _, vmstubber := range vmstubbers {
|
||||||
vms, err := vmstubber.GetHyperVisorVMs()
|
exists, err := vmstubber.Exists(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
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)
|
return nil, true, fmt.Errorf("vm %q already exists on hypervisor", name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ type VMProvider interface { //nolint:interfacebloat
|
||||||
// Let's deprecate this ASAP
|
// Let's deprecate this ASAP
|
||||||
GetDisk(userInputPath string, dirs *define.MachineDirs, mc *MachineConfig) error
|
GetDisk(userInputPath string, dirs *define.MachineDirs, mc *MachineConfig) error
|
||||||
PrepareIgnition(mc *MachineConfig, ignBuilder *ignition.IgnitionBuilder) (*ignition.ReadyUnitOpts, error)
|
PrepareIgnition(mc *MachineConfig, ignBuilder *ignition.IgnitionBuilder) (*ignition.ReadyUnitOpts, error)
|
||||||
GetHyperVisorVMs() ([]string, error)
|
Exists(name string) (bool, error)
|
||||||
MountType() VolumeMountType
|
MountType() VolumeMountType
|
||||||
MountVolumesToVM(mc *MachineConfig, quiet bool) error
|
MountVolumesToVM(mc *MachineConfig, quiet bool) error
|
||||||
Remove(mc *MachineConfig) ([]string, func() error, error)
|
Remove(mc *MachineConfig) ([]string, func() error, error)
|
||||||
|
|
|
@ -94,16 +94,8 @@ func (w WSLStubber) PrepareIgnition(_ *vmconfigs.MachineConfig, _ *ignition.Igni
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w WSLStubber) GetHyperVisorVMs() ([]string, error) {
|
func (w WSLStubber) Exists(name string) (bool, error) {
|
||||||
vms, err := getAllWSLDistros(false)
|
return isWSLExist(machine.ToDist(name))
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
wslVMs := make([]string, 0)
|
|
||||||
for name := range vms {
|
|
||||||
wslVMs = append(wslVMs, name)
|
|
||||||
}
|
|
||||||
return wslVMs, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w WSLStubber) MountType() vmconfigs.VolumeMountType {
|
func (w WSLStubber) MountType() vmconfigs.VolumeMountType {
|
||||||
|
|
Loading…
Reference in New Issue