@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/lf-edge/eve/pkg/pillar/base"
13
13
"github.com/lf-edge/eve/pkg/pillar/types"
14
+ fileutils "github.com/lf-edge/eve/pkg/pillar/utils/file"
14
15
uuid "github.com/satori/go.uuid"
15
16
"github.com/shirou/gopsutil/cpu"
16
17
"github.com/shirou/gopsutil/mem"
@@ -38,17 +39,17 @@ type Hypervisor interface {
38
39
39
40
type hypervisorDesc struct {
40
41
constructor func () Hypervisor
41
- dom0handle string
42
+ enabled func () bool
42
43
hvTypeFileContent string
43
44
}
44
45
45
46
var knownHypervisors = map [string ]hypervisorDesc {
46
- XenHypervisorName : {constructor : newXen , dom0handle : "/proc/xen" , hvTypeFileContent : "xen" },
47
- KVMHypervisorName : {constructor : newKvm , dom0handle : "/dev/kvm" , hvTypeFileContent : "kvm" },
48
- KubevirtHypervisorName : {constructor : newKubevirt , dom0handle : "/dev/kvm" , hvTypeFileContent : "kubevirt" },
49
- ACRNHypervisorName : {constructor : newAcrn , dom0handle : "/dev/acrn" , hvTypeFileContent : "acrn" },
50
- ContainerdHypervisorName : {constructor : newContainerd , dom0handle : "/run/containerd/containerd.sock" },
51
- NullHypervisorName : {constructor : newNull , dom0handle : "/" },
47
+ XenHypervisorName : {constructor : newXen , enabled : func () bool { return fileutils . FileExists ( nil , "/proc/xen" ) } , hvTypeFileContent : "xen" },
48
+ KVMHypervisorName : {constructor : newKvm , enabled : func () bool { return fileutils . FileExists ( nil , "/dev/kvm" ) && ! base . IsHVTypeKube () } , hvTypeFileContent : "kvm" },
49
+ KubevirtHypervisorName : {constructor : newKubevirt , enabled : func () bool { return fileutils . FileExists ( nil , "/dev/kvm" ) && base . IsHVTypeKube () } , hvTypeFileContent : "kubevirt" },
50
+ ACRNHypervisorName : {constructor : newAcrn , enabled : func () bool { return fileutils . FileExists ( nil , "/dev/acrn" ) } , hvTypeFileContent : "acrn" },
51
+ ContainerdHypervisorName : {constructor : newContainerd , enabled : func () bool { return fileutils . FileExists ( nil , "/run/containerd/containerd.sock" ) } },
52
+ NullHypervisorName : {constructor : newNull , enabled : func () bool { return fileutils . DirExists ( nil , "/" ) } },
52
53
}
53
54
54
55
// this is a priority order to pick a default hypervisor if multiple are available (more to less likely)
@@ -96,18 +97,9 @@ func BootTimeHypervisor() Hypervisor {
96
97
// the advice of this function and always ask for the enabled one.
97
98
func GetAvailableHypervisors () (all []string , enabled []string ) {
98
99
all = hypervisorPriority
99
- isHVTypeKube := base .IsHVTypeKube ()
100
100
for _ , v := range all {
101
- if _ , err := os .Stat (knownHypervisors [v ].dom0handle ); err == nil {
102
- // Both Kubevirt and KVM use same dom0handle.
103
- // Lets differentiate by eve_flavor
104
- if isHVTypeKube && strings .Compare (v , KVMHypervisorName ) == 0 {
105
- continue // kubevirt image don't set kvm
106
- } else if ! isHVTypeKube && strings .Compare (v , KubevirtHypervisorName ) == 0 {
107
- continue // kvm image don't set kubevirt
108
- } else {
109
- enabled = append (enabled , v )
110
- }
101
+ if knownHypervisors [v ].enabled () {
102
+ enabled = append (enabled , v )
111
103
}
112
104
}
113
105
return
0 commit comments