-
Notifications
You must be signed in to change notification settings - Fork 4
/
constants.go
225 lines (212 loc) · 6.2 KB
/
constants.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package common
import "strings"
const (
VendorDell = "dell"
VendorMicron = "micron"
VendorAsrockrack = "asrockrack"
VendorSupermicro = "supermicro"
VendorHPE = "hp"
VendorQuanta = "quanta"
VendorGigabyte = "gigabyte"
VendorIntel = "intel"
VendorLSI = "lsi"
VendorHGST = "hgst"
VendorPacket = "packet"
VendorMellanox = "mellanox"
VendorToshiba = "toshiba"
VendorAmericanMegatrends = "american megatrends"
VendorBroadcom = "broadcom"
VendorInfineon = "infineon"
VendorAMD = "amd"
VendorHynix = "hynix"
VendorSamsung = "samsung"
VendorMarvell = "marvell"
SystemManufacturerUndefined = "To Be Filled By O.E.M."
// Generic component slugs
// Slugs are set on Device types to identify the type of component
//
// note: Enlist any new component types in the method further below.
SlugBackplaneExpander = "Backplane-Expander"
SlugChassis = "Chassis"
SlugTPM = "TPM"
SlugGPU = "GPU"
SlugCPU = "CPU"
SlugPhysicalMem = "PhysicalMemory"
SlugStorageController = "StorageController"
SlugStorageControllers = "StorageControllers"
SlugBMC = "BMC"
SlugBIOS = "BIOS"
SlugDrive = "Drive"
SlugDrives = "Drives"
SlugDriveTypePCIeNVMEeSSD = "NVMe-PCIe-SSD"
SlugDriveTypeSATASSD = "Sata-SSD"
SlugDriveTypeSATAHDD = "Sata-HDD"
SlugNIC = "NIC"
SlugNICs = "NICs"
SlugNICPort = "NICPort"
SlugNICPorts = "NICPorts"
SlugPSU = "Power-Supply"
SlugPSUs = "Power-Supplies"
SlugCPLD = "CPLD"
SlugEnclosure = "Enclosure"
SlugMainboard = "Mainboard"
SlugUnknown = "unknown"
// Smart status
SmartStatusOK = "ok"
SmartStatusFailed = "failed"
SmartStatusUnknown = "unknown"
VendorMarvellPciID = "1b4b"
// RAID implementations
SlugRAIDImplLinuxSoftware = "linuxsw"
SlugRAIDImplZFS = "zfs"
SlugRAIDImplHardware = "hardware"
)
func ComponentTypes() []string {
return []string{
SlugBackplaneExpander,
SlugChassis,
SlugTPM,
SlugGPU,
SlugCPU,
SlugPhysicalMem,
SlugStorageController,
SlugStorageControllers,
SlugBMC,
SlugBIOS,
SlugDrive,
SlugDrives,
SlugDriveTypePCIeNVMEeSSD,
SlugDriveTypeSATASSD,
SlugDriveTypeSATAHDD,
SlugNIC,
SlugNICs,
SlugNICPort,
SlugNICPorts,
SlugPSU,
SlugPSUs,
SlugCPLD,
SlugEnclosure,
SlugMainboard,
}
}
// FormatVendorName compares the given strings to identify and returned a known
// vendor name. When a match is not found, the string is returned as is.
//
// Note: This method will most likely return incorrect matches if the given
// vendor string is too short and or not unique enough.
//
// nolint:gocyclo // This list is expected to be long.
func FormatVendorName(name string) string {
v := strings.TrimSpace(strings.ToLower(name))
switch v {
case "hp", "hpe":
return VendorHPE
case "ami":
return VendorAmericanMegatrends
case "lsi":
return VendorLSI
case "amd":
return VendorAMD
}
switch {
case strings.Contains(v, VendorAMD):
return VendorAMD
case strings.Contains(v, VendorAsrockrack):
return VendorAsrockrack
case strings.Contains(v, VendorDell):
return VendorDell
case strings.Contains(v, VendorSupermicro):
return VendorSupermicro
case strings.Contains(v, VendorQuanta):
return VendorQuanta
case strings.Contains(v, VendorGigabyte):
return VendorGigabyte
case strings.Contains(v, VendorIntel):
return VendorIntel
case strings.Contains(v, VendorPacket):
return VendorPacket
case strings.Contains(v, VendorHynix):
return VendorHynix
case strings.Contains(v, VendorInfineon):
return VendorInfineon
case strings.Contains(v, VendorBroadcom):
return VendorBroadcom
case strings.Contains(v, VendorMellanox):
return VendorMellanox
case strings.Contains(v, VendorHGST):
return VendorHGST
case strings.Contains(v, VendorToshiba):
return VendorToshiba
case strings.Contains(v, VendorMicron):
return VendorMicron
case strings.Contains(v, VendorAmericanMegatrends):
return VendorAmericanMegatrends
case strings.Contains(v, VendorSamsung):
return VendorSamsung
case strings.Contains(v, VendorMarvell):
return VendorMarvell
default:
return name
}
}
// Return the product vendor name, given a product name/model string
func VendorFromString(s string) string {
s = strings.ToLower(s)
switch {
case strings.Contains(s, "dell"):
return VendorDell
case strings.Contains(s, "lsi3008-it"):
return VendorLSI
case strings.Contains(s, "hgst "):
return VendorHGST
case strings.Contains(s, "intel "):
return VendorIntel
case strings.Contains(s, "micron_"), strings.HasPrefix(s, "mtfd"):
return VendorMicron
case strings.Contains(s, "toshiba"):
return VendorToshiba
case strings.Contains(s, "connectx4lx"):
return VendorMellanox
case strings.Contains(s, "infineon"):
return VendorInfineon
case strings.Contains(s, VendorMarvell), strings.Contains(s, VendorMarvellPciID):
return VendorMarvell
default:
return ""
}
}
// Return a normalized product name given a product name
//
// nolint:gocyclo // This list is expected to be long.
func FormatProductName(s string) string {
switch s {
case "PowerEdge R6515":
return "r6515"
case "PowerEdge R640":
return "r640"
case "PowerEdge R6415":
return "r6415"
case "PowerEdge R750":
return "r750"
case "PowerEdge C6320":
return "c6320"
case "PIO-519C-MR-PH004":
return "x11sch-f"
case "SYS-5019C-MR-PH004", "SYS-5019C-MR":
return "x11scm-f"
case "SYS-5039MS-H12TRF":
return "x11sse-f"
case "SYS-510T-MR-EI018", "SYS-510T-MR1-EI018", "SYS-510T-MR2-EI018":
return "x12sth-sys"
case "SSG-6029P-E1CR12L-PH004", "SSG-6029P-E1CR12L":
return "x11dph-t"
case "SSG-110P-NTR10", "SSG-110P-NTR10-EI018", "SSG-110P-NTR10-2-EI018":
return "x12spo-ntf"
case "Micron_5200_MTFDDAK480TDN":
return "5200MAX"
case "SYS-221H-TN24R":
return "x13dem"
default:
return s
}
}