-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlenovo.go
250 lines (204 loc) · 5.92 KB
/
lenovo.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
package lenovo
import (
"fmt"
"github.com/gliderlabs/ssh"
"github.com/google/uuid"
"github.com/metal-stack/go-hal"
"github.com/metal-stack/go-hal/internal/inband"
"github.com/metal-stack/go-hal/internal/ipmi"
"github.com/metal-stack/go-hal/internal/outband"
"github.com/metal-stack/go-hal/internal/redfish"
"github.com/metal-stack/go-hal/pkg/api"
"github.com/metal-stack/go-hal/pkg/logger"
)
var (
// errorNotImplemented for all functions that are not implemented yet
errorNotImplemented = fmt.Errorf("not implemented yet")
)
const (
vendor = api.VendorLenovo
)
type (
inBand struct {
*inband.InBand
}
outBand struct {
*outband.OutBand
}
bmcConnection struct {
*inBand
}
bmcConnectionOutBand struct {
*outBand
}
)
// InBand creates an inband connection to a Lenovo server.
func InBand(board *api.Board, log logger.Logger) (hal.InBand, error) {
ib, err := inband.New(board, true, log)
if err != nil {
return nil, err
}
return &inBand{
InBand: ib,
}, nil
}
// OutBand creates an outband connection to a Lenovo server.
func OutBand(r *redfish.APIClient, board *api.Board) hal.OutBand {
return &outBand{
OutBand: outband.ViaRedfish(r, board),
}
}
func (ob *outBand) Close() {
ob.Redfish.Gofish.Logout()
}
// InBand
// PowerState implements hal.InBand.
func (ib *inBand) PowerState() (hal.PowerState, error) {
return hal.PowerOnState, nil
}
func (ib *inBand) PowerOn() error {
return ib.IpmiTool.SetChassisControl(ipmi.ChassisControlPowerDown)
}
func (ib *inBand) PowerOff() error {
return ib.IpmiTool.SetChassisControl(ipmi.ChassisControlPowerDown)
}
func (ib *inBand) PowerCycle() error {
return ib.IpmiTool.SetChassisControl(ipmi.ChassisControlPowerCycle)
}
func (ib *inBand) PowerReset() error {
return ib.IpmiTool.SetChassisControl(ipmi.ChassisControlHardReset)
}
func (ib *inBand) IdentifyLEDState(state hal.IdentifyLEDState) error {
return ib.IpmiTool.SetChassisIdentifyLEDState(state)
}
func (ib *inBand) IdentifyLEDOn() error {
return ib.IpmiTool.SetChassisIdentifyLEDOn()
}
func (ib *inBand) IdentifyLEDOff() error {
return ib.IpmiTool.SetChassisIdentifyLEDOff()
}
func (ib *inBand) BootFrom(bootTarget hal.BootTarget) error {
return ib.IpmiTool.SetBootOrder(bootTarget, vendor)
}
func (ib *inBand) SetFirmware(hal.FirmwareMode) error {
return errorNotImplemented //TODO
}
func (ib *inBand) Describe() string {
return "InBand connected to Lenovo"
}
func (ib *inBand) BMCConnection() api.BMCConnection {
return &bmcConnection{
inBand: ib,
}
}
func (c *bmcConnection) BMC() (*api.BMC, error) {
return c.IpmiTool.BMC()
}
func (c *bmcConnection) PresentSuperUser() api.BMCUser {
return api.BMCUser{
Name: "USERID",
Id: "2",
ChannelNumber: 1,
}
}
func (c *bmcConnection) SuperUser() api.BMCUser {
return api.BMCUser{
Name: "root",
Id: "4",
ChannelNumber: 1,
}
}
func (c *bmcConnection) User() api.BMCUser {
return api.BMCUser{
Name: "metal",
Id: "3",
ChannelNumber: 1,
}
}
func (c *bmcConnection) Present() bool {
return c.IpmiTool.DevicePresent()
}
func (c *bmcConnection) CreateUserAndPassword(user api.BMCUser, privilege api.IpmiPrivilege) (string, error) {
board, err := c.Board()
if err != nil {
return "", err
}
return c.IpmiTool.CreateUser(user, privilege, "", board.Vendor.PasswordConstraints(), ipmi.LowLevel)
}
func (c *bmcConnection) CreateUser(user api.BMCUser, privilege api.IpmiPrivilege, password string) error {
_, err := c.IpmiTool.CreateUser(user, privilege, password, nil, ipmi.LowLevel)
return err
}
func (c *bmcConnection) ChangePassword(user api.BMCUser, newPassword string) error {
return c.IpmiTool.ChangePassword(user, newPassword, ipmi.LowLevel)
}
func (c *bmcConnection) SetUserEnabled(user api.BMCUser, enabled bool) error {
return c.IpmiTool.SetUserEnabled(user, enabled, ipmi.LowLevel)
}
func (ib *inBand) ConfigureBIOS() (bool, error) {
//return false, errorNotImplemented // do not throw an error to not break manual tests
return false, nil //TODO https://github.com/metal-stack/go-hal/issues/11
}
func (ib *inBand) EnsureBootOrder(bootloaderID string) error {
//return errorNotImplemented // do not throw an error to not break manual tests
return nil //TODO https://github.com/metal-stack/go-hal/issues/11
}
// OutBand
func (ob *outBand) UUID() (*uuid.UUID, error) {
u, err := ob.Redfish.MachineUUID()
if err != nil {
return nil, err
}
us, err := uuid.Parse(u)
if err != nil {
return nil, err
}
return &us, nil
}
func (ob *outBand) PowerState() (hal.PowerState, error) {
return ob.Redfish.PowerState()
}
func (ob *outBand) PowerOff() error {
return ob.Redfish.PowerOff()
}
func (ob *outBand) PowerOn() error {
return ob.Redfish.PowerReset() // PowerOn is not supported
}
func (ob *outBand) PowerReset() error {
return ob.Redfish.PowerReset()
}
func (ob *outBand) PowerCycle() error {
return ob.Redfish.PowerReset() // PowerCycle is not supported
}
func (ob *outBand) IdentifyLEDState(state hal.IdentifyLEDState) error {
return errorNotImplemented //TODO https://github.com/metal-stack/go-hal/issues/11
}
func (ob *outBand) IdentifyLEDOn() error {
return errorNotImplemented //TODO https://github.com/metal-stack/go-hal/issues/11
}
func (ob *outBand) IdentifyLEDOff() error {
return errorNotImplemented //TODO https://github.com/metal-stack/go-hal/issues/11
}
func (ob *outBand) BootFrom(target hal.BootTarget) error {
return ob.Redfish.SetBootOrder(target, vendor)
}
func (ob *outBand) Describe() string {
return "OutBand connected to Lenovo"
}
func (ob *outBand) Console(s ssh.Session) error {
return errorNotImplemented // https://github.com/metal-stack/go-hal/issues/11
}
func (ob *outBand) UpdateBIOS(url string) error {
return nil
}
func (ob *outBand) UpdateBMC(url string) error {
return nil
}
func (ob *outBand) BMCConnection() api.OutBandBMCConnection {
return &bmcConnectionOutBand{
outBand: ob,
}
}
func (c *bmcConnectionOutBand) BMC() (*api.BMC, error) {
return c.Redfish.BMC()
}