machine: Add -all-providers flag to machine list

Podman machine list now supports a new option, --all-providers, which lists all machines from all providers.

Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
Ashley Cui
2024-08-21 09:30:46 -04:00
parent 43fe3ebaf3
commit 41f945fc24
12 changed files with 261 additions and 128 deletions

View File

@@ -42,11 +42,11 @@ func Get() (vmconfigs.VMProvider, error) {
}
}
func GetAll(_ bool) ([]vmconfigs.VMProvider, error) {
func GetAll() []vmconfigs.VMProvider {
return []vmconfigs.VMProvider{
new(applehv.AppleHVStubber),
new(libkrun.LibKrunStubber),
}, nil
}
}
// SupportedProviders returns the providers that are supported on the host operating system
@@ -58,27 +58,23 @@ func SupportedProviders() []define.VMType {
return supported
}
// InstalledProviders returns the supported providers that are installed on the host
func InstalledProviders() ([]define.VMType, error) {
installed := []define.VMType{}
appleHvInstalled, err := appleHvInstalled()
if err != nil {
return nil, err
func IsInstalled(provider define.VMType) (bool, error) {
switch provider {
case define.AppleHvVirt:
ahv, err := appleHvInstalled()
if err != nil {
return false, err
}
return ahv, nil
case define.LibKrun:
lkr, err := libKrunInstalled()
if err != nil {
return false, err
}
return lkr, nil
default:
return false, nil
}
if appleHvInstalled {
installed = append(installed, define.AppleHvVirt)
}
libKrunInstalled, err := libKrunInstalled()
if err != nil {
return nil, err
}
if libKrunInstalled {
installed = append(installed, define.LibKrun)
}
return installed, nil
}
func appleHvInstalled() (bool, error) {