shirou / gopsutil

psutil for golang
Other
10.47k stars 1.58k forks source link

Report a bare-meteral machine as KVM at host.Info #1568

Closed wwng2333 closed 8 months ago

wwng2333 commented 8 months ago

Describe the bug Report a bare-meteral machine as KVM at host.Info

To Reproduce

package main

import (
    "fmt"
    "github.com/shirou/gopsutil/v3/host"
)

func main() {
    hi, _ := host.Info()
    fmt.Printf("cpuType: %v", hi.VirtualizationSystem)
}

Expected behavior My host is running kvm for guest vm, but it's not a real vm.

➜  ~ virt-what 
# return nothing here.
➜  ~ lsmod | grep kvm
kvm_intel             458752  4
kvm                  1327104  1 kvm_intel
irqbypass              16384  11 kvm
➜  ~ lspci   
00:00.0 Host bridge: Intel Corporation 8th Gen Core Processor Host Bridge/DRAM Registers (rev 07)
00:01.0 PCI bridge: Intel Corporation 6th-10th Gen Core Processor PCIe Controller (x16) (rev 07)
00:02.0 VGA compatible controller: Intel Corporation CoffeeLake-H GT2 [UHD Graphics 630]
00:08.0 System peripheral: Intel Corporation Xeon E3-1200 v5/v6 / E3-1500 v5 / 6th/7th/8th Gen Core Processor Gaussian Mixture Model
00:14.0 USB controller: Intel Corporation 100 Series/C230 Series Chipset Family USB 3.0 xHCI Controller (rev 31)
00:14.2 Signal processing controller: Intel Corporation 100 Series/C230 Series Chipset Family Thermal Subsystem (rev 31)
00:15.0 Signal processing controller: Intel Corporation 100 Series/C230 Series Chipset Family Serial IO I2C Controller #0 (rev 31)
00:15.1 Signal processing controller: Intel Corporation 100 Series/C230 Series Chipset Family Serial IO I2C Controller #1 (rev 31)
00:17.0 SATA controller: Intel Corporation Q170/Q150/B150/H170/H110/Z170/CM236 Chipset SATA Controller [AHCI Mode] (rev 31)
00:1c.0 PCI bridge: Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #5 (rev f1)
00:1c.5 PCI bridge: Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #6 (rev f1)
00:1f.0 ISA bridge: Intel Corporation H110 Chipset LPC/eSPI Controller (rev 31)
00:1f.2 Memory controller: Intel Corporation 100 Series/C230 Series Chipset Family Power Management Controller (rev 31)
00:1f.3 Audio device: Intel Corporation 100 Series/C230 Series Chipset Family HD Audio Controller (rev 31)
00:1f.4 SMBus: Intel Corporation 100 Series/C230 Series Chipset Family SMBus (rev 31)
01:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
01:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
01:00.2 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
01:00.3 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL810xE PCI Express Fast Ethernet controller (rev 05)
03:00.0 Non-Volatile memory controller: KIOXIA Corporation NVMe SSD (rev 01)
➜  ~ virsh list   
Authorization not available. Check if polkit service is running or see debug message for more information.
 Id   Name                 State
------------------------------------
 4    debian12-2023-10-1   running
 6    win10-2023-3-14      running

Environment (please complete the following information):

/etc/os-release:

➜  ~ cat /etc/os-release
NAME="Fedora Linux"
VERSION="37 (Server Edition)"
ID=fedora
VERSION_ID=37
VERSION_CODENAME=""
PLATFORM_ID="platform:f37"
PRETTY_NAME="Fedora Linux 37 (Server Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:37"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f37/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=37
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=37
SUPPORT_END=2023-11-14
VARIANT="Server Edition"
VARIANT_ID=server
➜  ~ uname -a
Linux crazy 6.3.12-100.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul  5 20:09:58 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Additional context [Cross-compiling? Paste the command you are using to cross-compile and the result of the corresponding go env]

wwng2333 commented 8 months ago
package main

import (
    "fmt"
    "github.com/shirou/gopsutil/v3/host"
)

func main() {
    hi, _ := host.Info()
    fmt.Printf("cpuType: %v\r\n", hi.VirtualizationSystem)
    fmt.Println(hi)
}

After print virtualizationRole, i know it's a host.