-
Notifications
You must be signed in to change notification settings - Fork 9
/
machine.go
680 lines (597 loc) · 21.7 KB
/
machine.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
package metal
import (
"fmt"
"log/slog"
"net/netip"
"os"
"slices"
"strings"
"time"
"github.com/dustin/go-humanize"
mn "github.com/metal-stack/metal-lib/pkg/net"
)
// A MState is an enum which indicates the state of a machine
type MState string
// Role describes the role of a machine.
type Role string
const (
// AvailableState describes a machine state where a machine is available for an allocation
AvailableState MState = ""
// ReservedState describes a machine state where a machine is not being considered for random allocation
ReservedState MState = "RESERVED"
// LockedState describes a machine state where a machine cannot be deleted or allocated anymore
LockedState MState = "LOCKED"
)
var (
// RoleMachine is a role that indicates the allocated machine acts as a machine
RoleMachine Role = "machine"
// RoleFirewall is a role that indicates the allocated machine acts as a firewall
RoleFirewall Role = "firewall"
)
var (
// AllStates contains all possible values of a machine state
AllStates = []MState{AvailableState, ReservedState, LockedState}
// AllRoles contains all possible values of a role
AllRoles = map[Role]bool{
RoleMachine: true,
RoleFirewall: true,
}
)
// A MachineState describes the state of a machine. If the Value is AvailableState,
// the machine will be available for allocation. In all other cases the allocation
// must explicitly point to this machine.
type MachineState struct {
Value MState `rethinkdb:"value" json:"value"`
Description string `rethinkdb:"description" json:"description"`
Issuer string `rethinkdb:"issuer" json:"issuer,omitempty"`
MetalHammerVersion string `rethinkdb:"metal_hammer_version" json:"metal_hammer_version"`
}
// MachineStateFrom converts a machineState string to the type
func MachineStateFrom(name string) (MState, error) {
switch name {
case string(AvailableState):
return AvailableState, nil
case string(ReservedState):
return ReservedState, nil
case string(LockedState):
return LockedState, nil
default:
return "", fmt.Errorf("unknown MachineState:%s", name)
}
}
// LEDState is the state of the LED of the Machine
type LEDState string
const (
// LEDStateOn LED is on
LEDStateOn LEDState = "LED-ON"
// LEDStateOff LED is off
LEDStateOff LEDState = "LED-OFF"
)
// LEDStateFrom converts an LEDState string to the corresponding type
func LEDStateFrom(name string) (LEDState, error) {
switch name {
case string(LEDStateOff):
return LEDStateOff, nil
case string(LEDStateOn):
return LEDStateOn, nil
default:
return "", fmt.Errorf("unknown LEDState:%s", name)
}
}
// A ChassisIdentifyLEDState describes the state of a chassis identify LED, i.e. LED-ON/LED-OFF.
type ChassisIdentifyLEDState struct {
Value LEDState `rethinkdb:"value" json:"value"`
Description string `rethinkdb:"description" json:"description"`
}
// A Machine is a piece of metal which is under the control of our system. It registers itself
// and can be allocated or freed. If the machine is allocated, the substructure Allocation will
// be filled. Any unallocated (free) machine won't have such values.
type Machine struct {
Base
Allocation *MachineAllocation `rethinkdb:"allocation" json:"allocation"`
PartitionID string `rethinkdb:"partitionid" json:"partitionid"`
SizeID string `rethinkdb:"sizeid" json:"sizeid"`
RackID string `rethinkdb:"rackid" json:"rackid"`
Waiting bool `rethinkdb:"waiting" json:"waiting"`
PreAllocated bool `rethinkdb:"preallocated" json:"preallocated"`
Hardware MachineHardware `rethinkdb:"hardware" json:"hardware"`
State MachineState `rethinkdb:"state" json:"state"`
LEDState ChassisIdentifyLEDState `rethinkdb:"ledstate" json:"ledstate"`
Tags []string `rethinkdb:"tags" json:"tags"`
IPMI IPMI `rethinkdb:"ipmi" json:"ipmi"`
BIOS BIOS `rethinkdb:"bios" json:"bios"`
}
// Machines is a slice of Machine
type Machines []Machine
// IsFirewall returns true if this machine is a firewall machine.
func (m *Machine) IsFirewall() bool {
if m.Allocation == nil {
return false
}
if m.Allocation.Role == RoleFirewall {
return true
}
return false
}
// A MachineAllocation stores the data which are only present for allocated machines.
type MachineAllocation struct {
Creator string `rethinkdb:"creator" json:"creator"`
Created time.Time `rethinkdb:"created" json:"created"`
Name string `rethinkdb:"name" json:"name"`
Description string `rethinkdb:"description" json:"description"`
Project string `rethinkdb:"project" json:"project"`
ImageID string `rethinkdb:"imageid" json:"imageid"`
FilesystemLayout *FilesystemLayout `rethinkdb:"filesystemlayout" json:"filesystemlayout"`
MachineNetworks []*MachineNetwork `rethinkdb:"networks" json:"networks"`
Hostname string `rethinkdb:"hostname" json:"hostname"`
SSHPubKeys []string `rethinkdb:"sshPubKeys" json:"sshPubKeys"`
UserData string `rethinkdb:"userdata" json:"userdata"`
ConsolePassword string `rethinkdb:"console_password" json:"console_password"`
Succeeded bool `rethinkdb:"succeeded" json:"succeeded"`
Reinstall bool `rethinkdb:"reinstall" json:"reinstall"`
MachineSetup *MachineSetup `rethinkdb:"setup" json:"setup"`
Role Role `rethinkdb:"role" json:"role"`
VPN *MachineVPN `rethinkdb:"vpn" json:"vpn"`
UUID string `rethinkdb:"uuid" json:"uuid"`
FirewallRules *FirewallRules `rethinkdb:"firewall_rules" json:"firewall_rules"`
}
type FirewallRules struct {
Egress []EgressRule `rethinkdb:"egress" json:"egress"`
Ingress []IngressRule `rethinkdb:"ingress" json:"ingress"`
}
type EgressRule struct {
Protocol Protocol `rethinkdb:"protocol" json:"protocol"`
Ports []int `rethinkdb:"ports" json:"ports"`
To []string `rethinkdb:"to" json:"to"`
Comment string `rethinkdb:"comment" json:"comment"`
}
type IngressRule struct {
Protocol Protocol `rethinkdb:"protocol" json:"protocol"`
Ports []int `rethinkdb:"ports" json:"ports"`
To []string `rethinkdb:"to" json:"to"`
From []string `rethinkdb:"from" json:"from"`
Comment string `rethinkdb:"comment" json:"comment"`
}
type Protocol string
const (
ProtocolTCP Protocol = "TCP"
ProtocolUDP Protocol = "UDP"
)
func ProtocolFromString(s string) (Protocol, error) {
switch strings.ToLower(s) {
case "tcp":
return ProtocolTCP, nil
case "udp":
return ProtocolUDP, nil
default:
return Protocol(""), fmt.Errorf("no such protocol: %s", s)
}
}
func (r EgressRule) Validate() error {
switch r.Protocol {
case ProtocolTCP, ProtocolUDP:
// ok
default:
return fmt.Errorf("invalid protocol: %s", r.Protocol)
}
if err := validateComment(r.Comment); err != nil {
return err
}
if err := validatePorts(r.Ports); err != nil {
return err
}
if err := validateCIDRs(r.To); err != nil {
return err
}
return nil
}
func (r IngressRule) Validate() error {
switch r.Protocol {
case ProtocolTCP, ProtocolUDP:
// ok
default:
return fmt.Errorf("invalid protocol: %s", r.Protocol)
}
if err := validateComment(r.Comment); err != nil {
return err
}
if err := validatePorts(r.Ports); err != nil {
return err
}
if err := validateCIDRs(r.To); err != nil {
return err
}
if err := validateCIDRs(r.From); err != nil {
return err
}
if err := validateCIDRs(slices.Concat(r.From, r.To)); err != nil {
return err
}
return nil
}
const (
allowedCharacters = "abcdefghijklmnopqrstuvwxyz_- "
maxCommentLength = 100
)
func validateComment(comment string) error {
for _, c := range comment {
if !strings.Contains(allowedCharacters, strings.ToLower(string(c))) {
return fmt.Errorf("illegal character in comment found, only: %q allowed", allowedCharacters)
}
}
if len(comment) > maxCommentLength {
return fmt.Errorf("comments can not exceed %d characters", maxCommentLength)
}
return nil
}
func validatePorts(ports []int) error {
for _, port := range ports {
if port < 0 || port > 65535 {
return fmt.Errorf("port is out of range")
}
}
return nil
}
func validateCIDRs(cidrs []string) error {
af := ""
for _, cidr := range cidrs {
p, err := netip.ParsePrefix(cidr)
if err != nil {
return fmt.Errorf("invalid cidr: %w", err)
}
var newaf string
if p.Addr().Is4() {
newaf = "ipv4"
} else {
newaf = "ipv6"
}
if af != "" && af != newaf {
return fmt.Errorf("mixed address family in one rule is not supported:%v", cidrs)
}
af = newaf
}
return nil
}
// A MachineSetup stores the data used for machine reinstallations.
type MachineSetup struct {
ImageID string `rethinkdb:"imageid" json:"imageid"`
PrimaryDisk string `rethinkdb:"primarydisk" json:"primarydisk"`
OSPartition string `rethinkdb:"ospartition" json:"ospartition"`
Initrd string `rethinkdb:"initrd" json:"initrd"`
Cmdline string `rethinkdb:"cmdline" json:"cmdline"`
Kernel string `rethinkdb:"kernel" json:"kernel"`
BootloaderID string `rethinkdb:"bootloaderid" json:"bootloaderid"`
}
// ByProjectID creates a map of machines with the project id as the index.
func (ms Machines) ByProjectID() map[string]Machines {
res := make(map[string]Machines)
for i, m := range ms {
if m.Allocation != nil {
res[m.Allocation.Project] = append(res[m.Allocation.Project], ms[i])
}
}
return res
}
func (ms Machines) WithSize(id string) Machines {
var res Machines
for _, m := range ms {
m := m
if m.SizeID != id {
continue
}
res = append(res, m)
}
return res
}
func (ms Machines) WithPartition(id string) Machines {
var res Machines
for _, m := range ms {
m := m
if m.PartitionID != id {
continue
}
res = append(res, m)
}
return res
}
// MachineNetwork stores the Network details of the machine
type MachineNetwork struct {
NetworkID string `rethinkdb:"networkid" json:"networkid"`
Prefixes []string `rethinkdb:"prefixes" json:"prefixes"`
IPs []string `rethinkdb:"ips" json:"ips"`
DestinationPrefixes []string `rethinkdb:"destinationprefixes" json:"destinationprefixes"`
Vrf uint `rethinkdb:"vrf" json:"vrf"`
PrivatePrimary bool `rethinkdb:"privateprimary" json:"privateprimary"`
Private bool `rethinkdb:"private" json:"private"`
ASN uint32 `rethinkdb:"asn" json:"asn"`
Nat bool `rethinkdb:"nat" json:"nat"`
Underlay bool `rethinkdb:"underlay" json:"underlay"`
Shared bool `rethinkdb:"shared" json:"shared"`
}
// NetworkType represents the type of a network
type NetworkType struct {
Name string `json:"name,omitempty"`
Private bool `json:"private,omitempty"`
PrivatePrimary bool `json:"private_primary,omitempty"`
Shared bool `json:"shared,omitempty"`
Underlay bool `json:"underlay,omitempty"`
Supported bool `json:"-"`
}
var (
PrivatePrimaryUnshared = NetworkType{
Name: mn.PrivatePrimaryUnshared,
Private: true,
PrivatePrimary: true,
Shared: false,
Underlay: false,
Supported: true,
}
PrivatePrimaryShared = NetworkType{
Name: mn.PrivatePrimaryShared,
Private: true,
PrivatePrimary: true,
Shared: true,
Underlay: false,
Supported: true,
}
PrivateSecondaryShared = NetworkType{
Name: mn.PrivateSecondaryShared,
Private: true,
PrivatePrimary: false,
Shared: true,
Underlay: false,
Supported: true,
}
// PrivateSecondaryUnshared this case is not a valid configuration
PrivateSecondaryUnshared = NetworkType{
Name: mn.PrivateSecondaryUnshared,
Private: true,
PrivatePrimary: false,
Shared: false,
Underlay: false,
Supported: false,
}
External = NetworkType{
Name: mn.External,
Private: false,
PrivatePrimary: false,
Shared: false,
Underlay: false,
Supported: true,
}
Underlay = NetworkType{
Name: mn.Underlay,
Private: false,
PrivatePrimary: false,
Shared: false,
Underlay: true,
Supported: true,
}
AllNetworkTypes = []NetworkType{PrivatePrimaryUnshared, PrivatePrimaryShared, PrivateSecondaryShared, PrivateSecondaryUnshared, External, Underlay}
)
// Is checks whether the machine network has the given type
func (mn *MachineNetwork) Is(n NetworkType) bool {
return mn.Private == n.Private && mn.PrivatePrimary == n.PrivatePrimary && mn.Shared == n.Shared && mn.Underlay == n.Underlay
}
// NetworkType determines the network type based on the flags stored in the db entity.
func (mn *MachineNetwork) NetworkType() (*NetworkType, error) {
var nt *NetworkType
for i := range AllNetworkTypes {
t := AllNetworkTypes[i]
if mn.Is(t) {
nt = &t
break
}
}
if nt == nil {
return nil, fmt.Errorf("could not determine network type out of flags, underlay: %v, privateprimary: %v, private: %v, shared: %v", mn.Underlay, mn.PrivatePrimary, mn.Private, mn.Shared)
}
if nt.Supported {
return nt, nil
}
// This is for machineNetworks from an allocation which was before NetworkType was introduced.
// We guess based on unset fields not present at this time and therefore are set to false.
// TODO: This guess based approach can be removed in future releases.
if mn.Private && !mn.PrivatePrimary && !mn.Shared && !mn.Underlay {
return &PrivatePrimaryUnshared, nil
}
return nil, fmt.Errorf("determined network type out of flags, underlay: %v, privateprimary: %v, private: %v, shared: %v is unsupported", mn.Underlay, mn.PrivatePrimary, mn.Private, mn.Shared)
}
func (n NetworkType) String() string {
return n.Name
}
// MachineHardware stores the data which is collected by our system on the hardware when it registers itself.
type MachineHardware struct {
Memory uint64 `rethinkdb:"memory" json:"memory"`
CPUCores int `rethinkdb:"cpu_cores" json:"cpu_cores"`
Nics Nics `rethinkdb:"network_interfaces" json:"network_interfaces"`
Disks []BlockDevice `rethinkdb:"block_devices" json:"block_devices"`
MetalCPUs []MetalCPU `rethinkdb:"cpus" json:"cpus"`
MetalGPUs []MetalGPU `rethinkdb:"gpus" json:"gpus"`
}
type MetalCPU struct {
Vendor string `rethinkdb:"vendor" json:"vendor"`
Model string `rethinkdb:"model" json:"model"`
Cores uint32 `rethinkdb:"cores" json:"cores"`
Threads uint32 `rethinkdb:"threads" json:"threads"`
}
type MetalGPU struct {
Vendor string `rethinkdb:"vendor" json:"vendor"`
Model string `rethinkdb:"model" json:"model"`
}
// MachineLiveliness indicates the liveliness of a machine
type MachineLiveliness string
// The enums for the machine liveliness states.
const (
MachineLivelinessAlive MachineLiveliness = "Alive"
MachineLivelinessDead MachineLiveliness = "Dead"
MachineLivelinessUnknown MachineLiveliness = "Unknown"
MachineDeadAfter time.Duration = 5 * time.Minute
MachineResurrectAfter time.Duration = time.Hour
)
// DiskCapacity calculates the capacity of all disks.
func (hw *MachineHardware) DiskCapacity() uint64 {
var c uint64
for _, d := range hw.Disks {
c += d.Size
}
return c
}
func (hw *MachineHardware) GPUModels() map[string]uint64 {
models := make(map[string]uint64)
for _, gpu := range hw.MetalGPUs {
_, ok := models[gpu.Model]
if !ok {
models[gpu.Model] = 1
} else {
models[gpu.Model]++
}
}
return models
}
// ReadableSpec returns a human readable string for the hardware.
func (hw *MachineHardware) ReadableSpec() string {
return fmt.Sprintf("Cores: %d, Memory: %s, Storage: %s GPUs:%s", hw.CPUCores, humanize.Bytes(hw.Memory), humanize.Bytes(hw.DiskCapacity()), hw.MetalGPUs)
}
// BlockDevice information.
type BlockDevice struct {
Name string `rethinkdb:"name" json:"name"`
Size uint64 `rethinkdb:"size" json:"size"`
}
// Fru (Field Replaceable Unit) data
type Fru struct {
ChassisPartNumber string `rethinkdb:"chassis_part_number" json:"chassis_part_number"`
ChassisPartSerial string `rethinkdb:"chassis_part_serial" json:"chassis_part_serial"`
BoardMfg string `rethinkdb:"board_mfg" json:"board_mfg"`
BoardMfgSerial string `rethinkdb:"board_mfg_serial" json:"board_mfg_serial"`
BoardPartNumber string `rethinkdb:"board_part_number" json:"board_part_number"`
ProductManufacturer string `rethinkdb:"product_manufacturer" json:"product_manufacturer"`
ProductPartNumber string `rethinkdb:"product_part_number" json:"product_part_number"`
ProductSerial string `rethinkdb:"product_serial" json:"product_serial"`
}
// IPMI connection data
type IPMI struct {
// Address is host:port of the connection to the ipmi BMC, host can be either a ip address or a hostname
Address string `rethinkdb:"address" json:"address"`
MacAddress string `rethinkdb:"mac" json:"mac"`
User string `rethinkdb:"user" json:"user"`
Password string `rethinkdb:"password" json:"password"`
Interface string `rethinkdb:"interface" json:"interface"`
Fru Fru `rethinkdb:"fru" json:"fru"`
BMCVersion string `rethinkdb:"bmcversion" json:"bmcversion"`
PowerState string `rethinkdb:"powerstate" json:"powerstate"`
PowerMetric *PowerMetric `rethinkdb:"powermetric" json:"powermetric"`
LastUpdated time.Time `rethinkdb:"last_updated" json:"last_updated"`
}
type PowerMetric struct {
// AverageConsumedWatts shall represent the
// average power level that occurred averaged over the last IntervalInMin
// minutes.
AverageConsumedWatts float32 `rethinkdb:"averageconsumedwatts" json:"averageconsumedwatts"`
// IntervalInMin shall represent the time
// interval (or window), in minutes, in which the PowerMetrics properties
// are measured over.
// Should be an integer, but some Dell implementations return as a float.
IntervalInMin float32 `rethinkdb:"intervalinmin" json:"intervalinmin"`
// MaxConsumedWatts shall represent the
// maximum power level in watts that occurred within the last
// IntervalInMin minutes.
MaxConsumedWatts float32 `rethinkdb:"maxconsumedwatts" json:"maxconsumedwatts"`
// MinConsumedWatts shall represent the
// minimum power level in watts that occurred within the last
// IntervalInMin minutes.
MinConsumedWatts float32 `rethinkdb:"minconsumedwatts" json:"minconsumedwatts"`
}
// BIOS contains machine bios information
type BIOS struct {
Version string `rethinkdb:"version" json:"version"`
Vendor string `rethinkdb:"vendor" json:"vendor"`
Date string `rethinkdb:"date" json:"date"`
}
// HasMAC returns true if this machine has the given MAC.
func (m *Machine) HasMAC(mac string) bool {
for _, nic := range m.Hardware.Nics {
if string(nic.MacAddress) == mac {
return true
}
}
return false
}
// A MachineCommand is an alias of a string
type MachineCommand string
// our supported machines commands.
const (
MachineOnCmd MachineCommand = "ON"
MachineOffCmd MachineCommand = "OFF"
MachineResetCmd MachineCommand = "RESET"
MachineCycleCmd MachineCommand = "CYCLE"
MachineBiosCmd MachineCommand = "BIOS"
MachineDiskCmd MachineCommand = "DISK"
MachinePxeCmd MachineCommand = "PXE"
MachineReinstallCmd MachineCommand = "REINSTALL"
ChassisIdentifyLEDOnCmd MachineCommand = "LED-ON"
ChassisIdentifyLEDOffCmd MachineCommand = "LED-OFF"
UpdateFirmwareCmd MachineCommand = "UPDATE-FIRMWARE"
)
// A MachineExecCommand can be sent via a MachineEvent to execute
// the command against the specific machine. The specified command
// should be executed against the given target machine. The parameters
// is an optional array of strings which are implementation specific
// and dependent of the command.
type MachineExecCommand struct {
TargetMachineID string `json:"target,omitempty"`
Command MachineCommand `json:"cmd,omitempty"`
IPMI *IPMI `json:"ipmi,omitempty"`
FirmwareUpdate *FirmwareUpdate `json:"firmwareupdate,omitempty"`
}
// MachineEvent is propagated when a machine is create/updated/deleted.
type MachineEvent struct {
Type EventType `json:"type,omitempty"`
OldMachineID string `json:"old,omitempty"`
NewMachineID string `json:"new,omitempty"`
Cmd *MachineExecCommand `json:"cmd,omitempty"`
}
// AllocationEvent is propagated when a machine is allocated.
type AllocationEvent struct {
MachineID string `json:"old,omitempty"`
}
type FirmwareUpdate struct {
Kind FirmwareKind `json:"kind"`
URL string `json:"url"`
}
type MachineVPN struct {
ControlPlaneAddress string `rethinkdb:"address" json:"address"`
AuthKey string `rethinkdb:"auth_key" json:"auth_key"`
Connected bool `rethinkdb:"connected" json:"connected"`
}
type MachineIPMISuperUser struct {
password string
}
func NewIPMISuperUser(log *slog.Logger, path string) MachineIPMISuperUser {
password := ""
if raw, err := os.ReadFile(path); err == nil {
password = strings.TrimSpace(string(raw))
if password != "" {
log.Info("ipmi superuser password found, feature is enabled")
} else {
log.Warn("ipmi superuser password file found, but password is empty, feature is disabled")
}
} else {
log.Warn("ipmi superuser password could not be read, feature is disabled", "error", err)
}
return MachineIPMISuperUser{
password: password,
}
}
func (i *MachineIPMISuperUser) IsEnabled() bool {
return i.password != ""
}
func (i *MachineIPMISuperUser) Password() string {
return i.password
}
func (i *MachineIPMISuperUser) User() string {
return "root"
}
func DisabledIPMISuperUser() MachineIPMISuperUser {
return MachineIPMISuperUser{}
}