mirror of
https://github.com/containers/podman.git
synced 2025-11-13 09:38:05 +08:00
Update to use new common machine API
Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
This commit is contained in:
70
vendor/github.com/containers/common/pkg/machine/machine.go
generated
vendored
Normal file
70
vendor/github.com/containers/common/pkg/machine/machine.go
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type MachineMarker struct {
|
||||
Enabled bool
|
||||
Type string
|
||||
}
|
||||
|
||||
const (
|
||||
markerFile = "/etc/containers/podman-machine"
|
||||
Wsl = "wsl"
|
||||
Qemu = "qemu"
|
||||
)
|
||||
|
||||
var (
|
||||
markerSync sync.Once
|
||||
machineMarker *MachineMarker
|
||||
)
|
||||
|
||||
func loadMachineMarker(file string) {
|
||||
var kind string
|
||||
|
||||
// Support deprecated config value for compatibility
|
||||
enabled := isLegacyConfigSet()
|
||||
|
||||
if content, err := os.ReadFile(file); err == nil {
|
||||
enabled = true
|
||||
kind = strings.TrimSpace(string(content))
|
||||
}
|
||||
|
||||
machineMarker = &MachineMarker{enabled, kind}
|
||||
}
|
||||
|
||||
func isLegacyConfigSet() bool {
|
||||
config, err := config.Default()
|
||||
if err != nil {
|
||||
logrus.Warnf("could not obtain container configuration")
|
||||
return false
|
||||
}
|
||||
|
||||
//nolint:staticcheck //lint:ignore SA1019 deprecated call
|
||||
return config.Engine.MachineEnabled
|
||||
}
|
||||
|
||||
func IsPodmanMachine() bool {
|
||||
return GetMachineMarker().Enabled
|
||||
}
|
||||
|
||||
func MachineHostType() string {
|
||||
return GetMachineMarker().Type
|
||||
}
|
||||
|
||||
func IsGvProxyBased() bool {
|
||||
return IsPodmanMachine() && MachineHostType() != Wsl
|
||||
}
|
||||
|
||||
func GetMachineMarker() *MachineMarker {
|
||||
markerSync.Do(func() {
|
||||
loadMachineMarker(markerFile)
|
||||
})
|
||||
return machineMarker
|
||||
}
|
||||
Reference in New Issue
Block a user