-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_platform.go
More file actions
100 lines (88 loc) · 2.28 KB
/
detect_platform.go
File metadata and controls
100 lines (88 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"log"
"net/http"
"os"
"strings"
"time"
)
func DetectPlatform() (bool, string) {
if IsProxmox() {
return true, "proxmox"
}
if IsOpenStack() {
return true, "openstack"
}
if IsSolusVM() {
return true, "solusvm"
}
return false, ""
}
func IsProxmox() bool {
// Check for Proxmox-specific MAC address prefix BC:24:11
entries, err := os.ReadDir("/sys/class/net")
if err == nil {
for _, entry := range entries {
if entry.Name() == "lo" {
continue
}
if data, err := os.ReadFile("/sys/class/net/" + entry.Name() + "/address"); err == nil {
mac := strings.ToUpper(strings.TrimSpace(string(data)))
if strings.HasPrefix(mac, "BC:24:11") {
log.Println("[Platform][Proxmox] Found default Proxmox MAC prefix (heuristic)")
return true
}
}
}
}
return false
}
func IsSolusVM() bool {
// Check for "Generated by SolusVM" comments in common config files
filesToCheck := []string{
"/etc/sysconfig/network",
"/etc/sysconfig/network-scripts/ifcfg-eth0",
"/etc/hosts",
"/etc/network/interfaces",
"/etc/hostname",
}
for _, file := range filesToCheck {
if data, err := os.ReadFile(file); err == nil {
content := string(data)
if strings.Contains(content, "Generated by SolusVM") ||
strings.Contains(content, "SolusVM") {
log.Println("[Platform][SolusVM] Found SolusVM signature in", file)
return true
}
}
}
return false
}
func IsOpenStack() bool {
// Try to reach OpenStack metadata service (with timeout)
client := http.Client{Timeout: 5 * time.Second}
resp, err := client.Get("http://169.254.169.254/openstack/")
if err == nil {
resp.Body.Close()
log.Println("[Platform][OpenStack] Metadata endpoint found: http://169.254.169.254 ")
return true
}
// Check for config drive
if _, err := os.Stat("/dev/disk/by-label/config-2"); err == nil {
log.Println("[Platform][OpenStack] Config drive found /dev/disk/by-label/config-2")
return true
}
dmiPaths := []string{
"/sys/class/dmi/id/product_name",
"/sys/class/dmi/id/chassis_asset_tag",
}
for _, path := range dmiPaths {
if data, err := os.ReadFile(path); err == nil {
if strings.Contains(strings.ToLower(string(data)), "openstack") {
log.Println("[Platform][OpenStack] DMI contains openstack")
return true
}
}
}
return false
}