@@ -2,6 +2,7 @@ package discover
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"encoding/xml"
6
7
"fmt"
7
8
"io"
@@ -18,7 +19,7 @@ import (
18
19
"github.com/bmc-toolbox/bmclib/providers/hp/c7000"
19
20
"github.com/bmc-toolbox/bmclib/providers/hp/ilo"
20
21
"github.com/bmc-toolbox/bmclib/providers/supermicro/supermicrox"
21
- log "github.com/sirupsen/logrus "
22
+ "github.com/go-logr/logr "
22
23
)
23
24
24
25
var (
@@ -34,7 +35,7 @@ type Probe struct {
34
35
password string
35
36
}
36
37
37
- func (p * Probe ) hpIlo () (bmcConnection interface {}, err error ) {
38
+ func (p * Probe ) hpIlo (ctx context. Context , log logr. Logger ) (bmcConnection interface {}, err error ) {
38
39
39
40
resp , err := p .client .Get (fmt .Sprintf ("https://%s/xmldata?item=all" , p .host ))
40
41
if err != nil {
@@ -68,7 +69,8 @@ func (p *Probe) hpIlo() (bmcConnection interface{}, err error) {
68
69
69
70
if iloXML .HSI != nil {
70
71
if strings .HasPrefix (iloXML .MP .Pn , "Integrated Lights-Out" ) {
71
- return ilo .New (p .host , p .username , p .password )
72
+ log .V (1 ).Info ("step" , "ScanAndConnect" , "host" , p .host , "vendor" , string (devices .HP ), "msg" , "it's a HP with iLo" )
73
+ return ilo .New (ctx , p .host , p .username , p .password , log )
72
74
}
73
75
74
76
return bmcConnection , fmt .Errorf ("it's an HP, but I cound't not identify the hardware type. Please verify" )
@@ -78,7 +80,7 @@ func (p *Probe) hpIlo() (bmcConnection interface{}, err error) {
78
80
return bmcConnection , errors .ErrDeviceNotMatched
79
81
}
80
82
81
- func (p * Probe ) hpC7000 () (bmcConnection interface {}, err error ) {
83
+ func (p * Probe ) hpC7000 (ctx context. Context , log logr. Logger ) (bmcConnection interface {}, err error ) {
82
84
83
85
resp , err := p .client .Get (fmt .Sprintf ("https://%s/xmldata?item=all" , p .host ))
84
86
if err != nil {
@@ -106,16 +108,16 @@ func (p *Probe) hpC7000() (bmcConnection interface{}, err error) {
106
108
}
107
109
108
110
if iloXMLC .Infra2 != nil {
109
- log .WithFields (log. Fields { "step" : "ScanAndConnect" , "host" : p .host , "vendor" : devices .HP }). Debug ( "it's a chassis" )
110
- return c7000 .New (p .host , p .username , p .password )
111
+ log .V ( 1 ). Info ( "step" , "ScanAndConnect" , "host" , p .host , "vendor" , string ( devices .HP ), "msg" , "it's a chassis" )
112
+ return c7000 .New (ctx , p .host , p .username , p .password , log )
111
113
}
112
114
113
115
}
114
116
return bmcConnection , errors .ErrDeviceNotMatched
115
117
}
116
118
117
119
// hpCl100 attempts to identify a cloudline device
118
- func (p * Probe ) hpCl100 () (bmcConnection interface {}, err error ) {
120
+ func (p * Probe ) hpCl100 (ctx context. Context , log logr. Logger ) (bmcConnection interface {}, err error ) {
119
121
120
122
// HPE Cloudline CL100
121
123
resp , err := p .client .Get (fmt .Sprintf ("https://%s/res/ok.png" , p .host ))
@@ -133,15 +135,15 @@ func (p *Probe) hpCl100() (bmcConnection interface{}, err error) {
133
135
}
134
136
// ensure the response we got included a png
135
137
if resp .StatusCode == 200 && bytes .Contains (firstBytes , []byte ("PNG" )) {
136
- log .WithFields (log. Fields { "step" : "ScanAndConnect" , "host" : p .host , "vendor" : devices .Cloudline }). Debug ( "it's a discrete" )
138
+ log .V ( 1 ). Info ( "step" , "ScanAndConnect" , "host" , p .host , "vendor" , string ( devices .Cloudline ), "msg" , "it's a discrete" )
137
139
return bmcConnection , errors .NewErrUnsupportedHardware ("hpe cl100 not supported" )
138
140
}
139
141
140
142
return bmcConnection , errors .ErrDeviceNotMatched
141
143
142
144
}
143
145
144
- func (p * Probe ) idrac8 () (bmcConnection interface {}, err error ) {
146
+ func (p * Probe ) idrac8 (ctx context. Context , log logr. Logger ) (bmcConnection interface {}, err error ) {
145
147
146
148
resp , err := p .client .Get (fmt .Sprintf ("https://%s/session?aimGetProp=hostname,gui_str_title_bar,OEMHostName,fwVersion,sysDesc" , p .host ))
147
149
if err != nil {
@@ -157,14 +159,14 @@ func (p *Probe) idrac8() (bmcConnection interface{}, err error) {
157
159
}
158
160
159
161
if resp .StatusCode == 200 && containsAnySubStr (payload , idrac8SysDesc ) {
160
- log .WithFields (log. Fields { "step" : "connection" , "host" : p .host , "vendor" : devices .Dell }). Debug ( "it's a idrac8" )
161
- return idrac8 .New (p .host , p .username , p .password )
162
+ log .V ( 1 ). Info ( "step" , "connection" , "host" , p .host , "vendor" , string ( devices .Dell ), "msg" , "it's a idrac8" )
163
+ return idrac8 .New (ctx , p .host , p .username , p .password , log )
162
164
}
163
165
164
166
return bmcConnection , errors .ErrDeviceNotMatched
165
167
}
166
168
167
- func (p * Probe ) idrac9 () (bmcConnection interface {}, err error ) {
169
+ func (p * Probe ) idrac9 (ctx context. Context , log logr. Logger ) (bmcConnection interface {}, err error ) {
168
170
169
171
resp , err := p .client .Get (fmt .Sprintf ("https://%s/sysmgmt/2015/bmc/info" , p .host ))
170
172
if err != nil {
@@ -180,14 +182,14 @@ func (p *Probe) idrac9() (bmcConnection interface{}, err error) {
180
182
}
181
183
182
184
if resp .StatusCode == 200 && containsAnySubStr (payload , idrac9SysDesc ) {
183
- log .WithFields (log. Fields { "step" : "connection" , "host" : p .host , "vendor" : devices .Dell }). Debug ( "it's a idrac9" )
184
- return idrac9 .New (p .host , p .username , p .password )
185
+ log .V ( 1 ). Info ( "step" , "connection" , "host" , p .host , "vendor" , string ( devices .Dell ), "msg" , "it's a idrac9" )
186
+ return idrac9 .New (ctx , p .host , p .username , p .password , log )
185
187
}
186
188
187
189
return bmcConnection , errors .ErrDeviceNotMatched
188
190
}
189
191
190
- func (p * Probe ) m1000e () (bmcConnection interface {}, err error ) {
192
+ func (p * Probe ) m1000e (ctx context. Context , log logr. Logger ) (bmcConnection interface {}, err error ) {
191
193
resp , err := p .client .Get (fmt .Sprintf ("https://%s/cgi-bin/webcgi/login" , p .host ))
192
194
if err != nil {
193
195
return bmcConnection , err
@@ -202,14 +204,14 @@ func (p *Probe) m1000e() (bmcConnection interface{}, err error) {
202
204
}
203
205
204
206
if resp .StatusCode == 200 && containsAnySubStr (payload , m1000eSysDesc ) {
205
- log .WithFields (log. Fields { "step" : "connection" , "host" : p .host , "vendor" : devices .Dell }). Debug ( "it's a m1000e chassis" )
206
- return m1000e .New (p .host , p .username , p .password )
207
+ log .V ( 1 ). Info ( "step" , "connection" , "host" , p .host , "vendor" , string ( devices .Dell ), "msg" , "it's a m1000e chassis" )
208
+ return m1000e .New (ctx , p .host , p .username , p .password , log )
207
209
}
208
210
209
211
return bmcConnection , errors .ErrDeviceNotMatched
210
212
}
211
213
212
- func (p * Probe ) supermicrox () (bmcConnection interface {}, err error ) {
214
+ func (p * Probe ) supermicrox (ctx context. Context , log logr. Logger ) (bmcConnection interface {}, err error ) {
213
215
resp , err := p .client .Get (fmt .Sprintf ("https://%s/cgi/login.cgi" , p .host ))
214
216
if err != nil {
215
217
return bmcConnection , err
@@ -225,14 +227,14 @@ func (p *Probe) supermicrox() (bmcConnection interface{}, err error) {
225
227
226
228
// looking for ATEN in the response payload isn't the most ideal way, although it is unique to Supermicros
227
229
if resp .StatusCode == 200 && bytes .Contains (payload , []byte ("ATEN International" )) {
228
- log .WithFields (log. Fields { "step" : "connection" , "host" : p .host , "vendor" : devices .Supermicro }). Debug ( "it's a supermicro" )
229
- return supermicrox .New (p .host , p .username , p .password )
230
+ log .V ( 1 ). Info ( "step" , "connection" , "host" , p .host , "vendor" , string ( devices .Supermicro ), "msg" , "it's a supermicro" )
231
+ return supermicrox .New (ctx , p .host , p .username , p .password , log )
230
232
}
231
233
232
234
return bmcConnection , errors .ErrDeviceNotMatched
233
235
}
234
236
235
- func (p * Probe ) quanta () (bmcConnection interface {}, err error ) {
237
+ func (p * Probe ) quanta (ctx context. Context , log logr. Logger ) (bmcConnection interface {}, err error ) {
236
238
resp , err := p .client .Get (fmt .Sprintf ("https://%s/page/login.html" , p .host ))
237
239
if err != nil {
238
240
return bmcConnection , err
@@ -248,7 +250,7 @@ func (p *Probe) quanta() (bmcConnection interface{}, err error) {
248
250
249
251
// ensure the response we got included a png
250
252
if resp .StatusCode == 200 && bytes .Contains (payload , []byte ("Quanta" )) {
251
- log .WithFields (log. Fields { "step" : "ScanAndConnect" , "host" : p .host , "vendor" : devices .Quanta }). Debug ( "it's a quanta" )
253
+ log .V ( 1 ). Info ( "step" , "ScanAndConnect" , "host" , p .host , "vendor" , string ( devices .Quanta ), "msg" , "it's a quanta" )
252
254
return bmcConnection , errors .NewErrUnsupportedHardware ("quanta hardware not supported" )
253
255
}
254
256
0 commit comments