-
Notifications
You must be signed in to change notification settings - Fork 3
/
hal.go
183 lines (155 loc) · 5.06 KB
/
hal.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
package hal
import (
"github.com/gliderlabs/ssh"
"strings"
"github.com/google/uuid"
"github.com/metal-stack/go-hal/pkg/api"
)
type (
// PowerState state of the power of a server
PowerState int
// BootTarget defines the way the server should boot
BootTarget int
// IdentifyLEDState the state of the LED to identify the server
IdentifyLEDState int
// FirmwareMode the Firmware mode of the server, either Legacy, Dual or Uefi
FirmwareMode int
)
const (
// PowerUnknownState the server power state is not known
PowerUnknownState PowerState = iota
// PowerOnState the server is powered on
PowerOnState
// PowerOffState the server is powered off
PowerOffState
)
const (
// BootTargetPXE the server boots via PXE
BootTargetPXE BootTarget = iota + 1
// BootTargetDisk the server boots from disk
BootTargetDisk
// BootTargetBIOS the server boots into Bios
BootTargetBIOS
)
const (
// IdentifyLEDStateUnknown the LED is unknown
IdentifyLEDStateUnknown IdentifyLEDState = iota
// IdentifyLEDStateOn the LED is on
IdentifyLEDStateOn
// IdentifyLEDStateOff the LED is off
IdentifyLEDStateOff
)
const (
// FirmwareModeUnknown server is in unknown firmware state
FirmwareModeUnknown FirmwareMode = iota
// FirmwareModeLegacy or BIOS
FirmwareModeLegacy
// FirmwareModeUEFI the server boots in uefi mode
FirmwareModeUEFI
)
var (
powerStates = [...]string{
PowerOnState: "ON",
PowerOffState: "OFF",
PowerUnknownState: "UNKNOWN",
}
bootTargets = [...]string{
BootTargetPXE: "PXE",
BootTargetDisk: "DISK",
BootTargetBIOS: "BIOS",
}
ledStates = [...]string{
IdentifyLEDStateOn: "ON",
IdentifyLEDStateOff: "OFF",
IdentifyLEDStateUnknown: "UNKNOWN",
}
firmwareModes = [...]string{
FirmwareModeLegacy: "LEGACY",
FirmwareModeUEFI: "UEFI",
FirmwareModeUnknown: "UNKNOWN",
}
)
// Stringer
func (p PowerState) String() string { return powerStates[p] }
func (b BootTarget) String() string { return bootTargets[b] }
func (i IdentifyLEDState) String() string { return ledStates[i] }
func (f FirmwareMode) String() string { return firmwareModes[f] }
// GuessPowerState try to figure out the power state of the server
func GuessPowerState(powerState string) PowerState {
for i, p := range powerStates {
if strings.Contains(strings.ToLower(p), strings.ToLower(powerState)) {
return PowerState(i)
}
}
return PowerUnknownState
}
// InBand get and set settings from the server via the inband interface.
type InBand interface {
// Board return board information of the current connection
Board() *api.Board
// UUID get the machine UUID
// current usage in metal-hammer
UUID() (*uuid.UUID, error)
// PowerOff set power state of the server to off
PowerOff() error
// PowerReset reset the power state of the server
PowerReset() error
// PowerCycle cycle the power state of the server
PowerCycle() error
// IdentifyLEDState get the identify LED state
IdentifyLEDState(IdentifyLEDState) error
// IdentifyLEDOn set the identify LED to on
IdentifyLEDOn() error
// IdentifyLEDOff set the identify LED to off
IdentifyLEDOff() error
// BootFrom set the boot order of the server to the specified target
BootFrom(BootTarget) error
// Firmware get the FirmwareMode of the server
Firmware() (FirmwareMode, error)
// SetFirmware set the FirmwareMode of the server
SetFirmware(FirmwareMode) error
// Describe print a basic information about this connection
Describe() string
// TODO add MachineFRU, BiosVersion, BMCVersion, BMC{IP, MAC, Interface}
// BMCConnection returns a connection to the BMC
BMCConnection() api.BMCConnection
// ConfigureBIOS configures the BIOS regarding certain required options.
// It returns whether the system needs to be rebooted afterwards
ConfigureBIOS() (bool, error)
// EnsureBootOrder ensures the boot order
EnsureBootOrder(bootloaderID string) error
}
// OutBand get and set settings from the server via the out of band interface.
type OutBand interface {
// Board return board information of the current connection
Board() *api.Board
// UUID get the machine uuid
// current usage in ipmi-catcher
UUID() (*uuid.UUID, error)
// PowerState returns the power state of the server
PowerState() (PowerState, error)
// PowerOff set power state of the server to off
PowerOff() error
// PowerOn set power state of the server to on
PowerOn() error
// PowerReset reset the power state of the server
PowerReset() error
// PowerCycle cycle the power state of the server
PowerCycle() error
// IdentifyLEDState get the identify LED state
IdentifyLEDState(IdentifyLEDState) error
// IdentifyLEDOn set the identify LED to on
IdentifyLEDOn() error
// IdentifyLEDOff set the identify LED to off
IdentifyLEDOff() error
// BootFrom set the boot order of the server to the specified target
BootFrom(BootTarget) error
// Describe print a basic information about this connection
Describe() string
IPMIConnection() (ip string, port int, user, password string)
Console(ssh.Session) error
UpdateBIOS(url string) error
UpdateBMC(url string) error
// Returns a connection to the BMC
BMCConnection() api.OutBandBMCConnection
}