mirror of
https://github.com/oneclickvirt/basics.git
synced 2025-10-08 10:00:29 +08:00
update
This commit is contained in:
138
system/host.go
138
system/host.go
@@ -15,48 +15,54 @@ import (
|
|||||||
"github.com/shirou/gopsutil/v4/host"
|
"github.com/shirou/gopsutil/v4/host"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// getVmType maps the VM type string to a more readable format.
|
||||||
|
func getVmType(vmType string) string {
|
||||||
|
switch strings.TrimSpace(vmType) {
|
||||||
|
case "kvm":
|
||||||
|
return "KVM"
|
||||||
|
case "xen":
|
||||||
|
return "Xen Hypervisor"
|
||||||
|
case "microsoft":
|
||||||
|
return "Microsoft Hyper-V"
|
||||||
|
case "vmware":
|
||||||
|
return "VMware"
|
||||||
|
case "oracle":
|
||||||
|
return "Oracle VirtualBox"
|
||||||
|
case "parallels":
|
||||||
|
return "Parallels"
|
||||||
|
case "qemu":
|
||||||
|
return "QEMU"
|
||||||
|
case "amazon":
|
||||||
|
return "Amazon Virtualization"
|
||||||
|
case "docker":
|
||||||
|
return "Docker"
|
||||||
|
case "openvz":
|
||||||
|
return "OpenVZ (Virutozzo)"
|
||||||
|
case "lxc":
|
||||||
|
return "LXC"
|
||||||
|
case "lxc-libvirt":
|
||||||
|
return "LXC (Based on libvirt)"
|
||||||
|
case "uml":
|
||||||
|
return "User-mode Linux"
|
||||||
|
case "systemd-nspawn":
|
||||||
|
return "Systemd nspawn"
|
||||||
|
case "bochs":
|
||||||
|
return "BOCHS"
|
||||||
|
case "rkt":
|
||||||
|
return "RKT"
|
||||||
|
case "zvm":
|
||||||
|
return "S390 Z/VM"
|
||||||
|
case "none":
|
||||||
|
return "Dedicated"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func getVmTypeFromSDV(path string) string {
|
func getVmTypeFromSDV(path string) string {
|
||||||
cmd := exec.Command(path)
|
cmd := exec.Command(path)
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
switch strings.TrimSpace(strings.ReplaceAll(string(output), "\n", "")) {
|
return getVmType(strings.ReplaceAll(string(output), "\n", ""))
|
||||||
case "kvm":
|
|
||||||
return "KVM"
|
|
||||||
case "xen":
|
|
||||||
return "Xen Hypervisor"
|
|
||||||
case "microsoft":
|
|
||||||
return "Microsoft Hyper-V"
|
|
||||||
case "vmware":
|
|
||||||
return "VMware"
|
|
||||||
case "oracle":
|
|
||||||
return "Oracle VirtualBox"
|
|
||||||
case "parallels":
|
|
||||||
return "Parallels"
|
|
||||||
case "qemu":
|
|
||||||
return "QEMU"
|
|
||||||
case "amazon":
|
|
||||||
return "Amazon Virtualization"
|
|
||||||
case "docker":
|
|
||||||
return "Docker"
|
|
||||||
case "openvz":
|
|
||||||
return "OpenVZ (Virutozzo)"
|
|
||||||
case "lxc":
|
|
||||||
return "LXC"
|
|
||||||
case "lxc-libvirt":
|
|
||||||
return "LXC (Based on libvirt)"
|
|
||||||
case "uml":
|
|
||||||
return "User-mode Linux"
|
|
||||||
case "systemd-nspawn":
|
|
||||||
return "Systemd nspawn"
|
|
||||||
case "bochs":
|
|
||||||
return "BOCHS"
|
|
||||||
case "rkt":
|
|
||||||
return "RKT"
|
|
||||||
case "zvm":
|
|
||||||
return "S390 Z/VM"
|
|
||||||
case "none":
|
|
||||||
return "Dedicated"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -64,65 +70,25 @@ func getVmTypeFromSDV(path string) string {
|
|||||||
func getVmTypeFromDMI(path string) string {
|
func getVmTypeFromDMI(path string) string {
|
||||||
cmd := exec.Command(path, "-t", "system")
|
cmd := exec.Command(path, "-t", "system")
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err == nil && strings.Contains(strings.ToLower(string(output)), "family") {
|
if err == nil {
|
||||||
var familyLine string
|
// Check for 'family'
|
||||||
for _, line := range strings.Split(strings.ToLower(string(output)), "\n") {
|
for _, line := range strings.Split(strings.ToLower(string(output)), "\n") {
|
||||||
if strings.Contains(line, "family") {
|
if strings.Contains(line, "family") {
|
||||||
familyLine = strings.ReplaceAll(line, "family", "")
|
familyLine := strings.ReplaceAll(line, "family", "")
|
||||||
break
|
if vmType := getVmType(strings.TrimSpace(strings.ReplaceAll(familyLine, ":", ""))); vmType != "" {
|
||||||
|
return vmType
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch strings.TrimSpace(strings.ReplaceAll(familyLine, ":", "")) {
|
// Fallback to 'manufacturer'
|
||||||
case "kvm":
|
|
||||||
return "KVM"
|
|
||||||
case "xen":
|
|
||||||
return "Xen Hypervisor"
|
|
||||||
case "microsoft":
|
|
||||||
return "Microsoft Hyper-V"
|
|
||||||
case "vmware":
|
|
||||||
return "VMware"
|
|
||||||
case "oracle":
|
|
||||||
return "Oracle VirtualBox"
|
|
||||||
case "parallels":
|
|
||||||
return "Parallels"
|
|
||||||
case "qemu":
|
|
||||||
return "QEMU"
|
|
||||||
case "amazon":
|
|
||||||
return "Amazon Virtualization"
|
|
||||||
case "docker":
|
|
||||||
return "Docker"
|
|
||||||
case "openvz":
|
|
||||||
return "OpenVZ (Virutozzo)"
|
|
||||||
case "lxc":
|
|
||||||
return "LXC"
|
|
||||||
case "lxc-libvirt":
|
|
||||||
return "LXC (Based on libvirt)"
|
|
||||||
case "uml":
|
|
||||||
return "User-mode Linux"
|
|
||||||
case "systemd-nspawn":
|
|
||||||
return "Systemd nspawn"
|
|
||||||
case "bochs":
|
|
||||||
return "BOCHS"
|
|
||||||
case "rkt":
|
|
||||||
return "RKT"
|
|
||||||
case "zvm":
|
|
||||||
return "S390 Z/VM"
|
|
||||||
case "none":
|
|
||||||
return "Dedicated"
|
|
||||||
}
|
|
||||||
var manuFacturer string
|
|
||||||
for _, line := range strings.Split(strings.ToLower(string(output)), "\n") {
|
for _, line := range strings.Split(strings.ToLower(string(output)), "\n") {
|
||||||
if strings.Contains(line, "manufacturer") {
|
if strings.Contains(line, "manufacturer") {
|
||||||
tempL := strings.Split(line, ":")
|
tempL := strings.Split(line, ":")
|
||||||
if len(tempL) == 2 {
|
if len(tempL) == 2 {
|
||||||
manuFacturer = strings.TrimSpace(tempL[1])
|
return strings.TrimSpace(tempL[1])
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if manuFacturer != "" {
|
|
||||||
return manuFacturer
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user