Implement machine provider selection

GetSystemDefaultProvider reworked to fetch provider value from
the config file.

Additional environment variable CONTAINERS_MACHINE_PROVIDER is
supported to override the config for testing purposes.

Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
This commit is contained in:
Arthur Sengileyev
2023-01-15 19:12:37 +02:00
parent 19152fa349
commit b5ef9555ab
15 changed files with 118 additions and 22 deletions

View File

@ -10,6 +10,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"
"time"
"github.com/containers/storage/pkg/homedir"
@ -413,3 +414,20 @@ const (
MachineLocal
DockerGlobal
)
func ParseVMType(input string, emptyFallback VMType) (VMType, error) {
switch strings.TrimSpace(strings.ToLower(input)) {
case "qemu":
return QemuVirt, nil
case "wsl":
return WSLVirt, nil
case "applehv":
return AppleHvVirt, nil
case "hyperv":
return HyperVVirt, nil
case "":
return emptyFallback, nil
default:
return QemuVirt, fmt.Errorf("unknown VMType `%s`", input)
}
}