-
Notifications
You must be signed in to change notification settings - Fork 36
/
client.go
763 lines (623 loc) · 27.3 KB
/
client.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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
// Package bmclib client.go is intended to be the main public API.
// Its purpose is to make interacting with bmclib as friendly as possible.
package bmclib
import (
"context"
"fmt"
"io"
"net/http"
"os"
"strings"
"sync"
"time"
"dario.cat/mergo"
"github.com/bmc-toolbox/bmclib/v2/bmc"
"github.com/bmc-toolbox/bmclib/v2/constants"
"github.com/bmc-toolbox/bmclib/v2/internal/httpclient"
"github.com/bmc-toolbox/bmclib/v2/providers/asrockrack"
"github.com/bmc-toolbox/bmclib/v2/providers/dell"
"github.com/bmc-toolbox/bmclib/v2/providers/intelamt"
"github.com/bmc-toolbox/bmclib/v2/providers/ipmitool"
"github.com/bmc-toolbox/bmclib/v2/providers/openbmc"
"github.com/bmc-toolbox/bmclib/v2/providers/redfish"
"github.com/bmc-toolbox/bmclib/v2/providers/rpc"
"github.com/bmc-toolbox/bmclib/v2/providers/supermicro"
"github.com/bmc-toolbox/common"
"github.com/go-logr/logr"
"github.com/jacobweinstock/registrar"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"
tracenoop "go.opentelemetry.io/otel/trace/noop"
)
const (
// default connection timeout
defaultConnectTimeout = 30 * time.Second
pkgName = "github.com/bmc-toolbox/bmclib"
)
// Client for BMC interactions
type Client struct {
Auth Auth
Logger logr.Logger
Registry *registrar.Registry
httpClient *http.Client
httpClientSetupFuncs []func(*http.Client)
mdLock *sync.Mutex
metadata *bmc.Metadata
perProviderTimeout func(context.Context) time.Duration
oneTimeRegistry *registrar.Registry
oneTimeRegistryEnabled bool
providerConfig providerConfig
traceprovider oteltrace.TracerProvider
}
// Auth details for connecting to a BMC
type Auth struct {
Host string
User string
Pass string
}
// providerConfig contains per provider specific configuration.
type providerConfig struct {
ipmitool ipmitool.Config
asrock asrockrack.Config
gofish redfish.Config
intelamt intelamt.Config
dell dell.Config
supermicro supermicro.Config
rpc rpc.Provider
openbmc openbmc.Config
}
// NewClient returns a new Client struct
func NewClient(host, user, pass string, opts ...Option) *Client {
defaultClient := &Client{
Logger: logr.Discard(),
Registry: registrar.NewRegistry(),
oneTimeRegistryEnabled: false,
oneTimeRegistry: registrar.NewRegistry(),
httpClient: httpclient.Build(),
traceprovider: tracenoop.NewTracerProvider(),
providerConfig: providerConfig{
ipmitool: ipmitool.Config{
Port: "623",
},
asrock: asrockrack.Config{
Port: "443",
},
gofish: redfish.Config{
Port: "443",
VersionsNotCompatible: []string{},
},
intelamt: intelamt.Config{
HostScheme: "http",
Port: 16992,
},
dell: dell.Config{
Port: "443",
VersionsNotCompatible: []string{},
},
supermicro: supermicro.Config{
Port: "443",
},
rpc: rpc.Provider{},
openbmc: openbmc.Config{
Port: "443",
},
},
}
for _, opt := range opts {
opt(defaultClient)
}
for _, setupFunc := range defaultClient.httpClientSetupFuncs {
setupFunc(defaultClient.httpClient)
}
defaultClient.Registry.Logger = defaultClient.Logger
defaultClient.Auth.Host = host
defaultClient.Auth.User = user
defaultClient.Auth.Pass = pass
// len of 0 means that no Registry, with any registered providers, was passed in.
if len(defaultClient.Registry.Drivers) == 0 {
defaultClient.registerProviders()
}
defaultClient.mdLock = &sync.Mutex{}
if defaultClient.perProviderTimeout == nil {
defaultClient.perProviderTimeout = defaultClient.defaultTimeout
}
return defaultClient
}
func (c *Client) defaultTimeout(ctx context.Context) time.Duration {
deadline, ok := ctx.Deadline()
if !ok {
return defaultConnectTimeout
}
l := len(c.registry().Drivers)
if l == 0 {
return time.Until(deadline)
}
return time.Until(deadline) / time.Duration(l)
}
func (c *Client) registerRPCProvider() error {
driverRPC := rpc.New(c.providerConfig.rpc.ConsumerURL, c.Auth.Host, c.providerConfig.rpc.Opts.HMAC.Secrets)
c.providerConfig.rpc.Logger = c.Logger
httpClient := *c.httpClient
httpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone()
c.providerConfig.rpc.HTTPClient = &httpClient
if err := mergo.Merge(driverRPC, c.providerConfig.rpc, mergo.WithOverride, mergo.WithTransformers(&rpc.Provider{})); err != nil {
return fmt.Errorf("failed to merge user specified rpc config with the config defaults, rpc provider not available: %w", err)
}
c.Registry.Register(rpc.ProviderName, rpc.ProviderProtocol, rpc.Features, nil, driverRPC)
return nil
}
// register ipmitool provider
func (c *Client) registerIPMIProvider() error {
ipmiOpts := []ipmitool.Option{
ipmitool.WithLogger(c.Logger),
ipmitool.WithPort(c.providerConfig.ipmitool.Port),
ipmitool.WithCipherSuite(c.providerConfig.ipmitool.CipherSuite),
ipmitool.WithIpmitoolPath(c.providerConfig.ipmitool.IpmitoolPath),
}
driverIpmitool, err := ipmitool.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, ipmiOpts...)
if err != nil {
return err
}
c.Registry.Register(ipmitool.ProviderName, ipmitool.ProviderProtocol, ipmitool.Features, nil, driverIpmitool)
return nil
}
// register ASRR vendorapi provider
func (c *Client) registerASRRProvider() {
asrHttpClient := *c.httpClient
asrHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone()
driverAsrockrack := asrockrack.NewWithOptions(c.Auth.Host+":"+c.providerConfig.asrock.Port, c.Auth.User, c.Auth.Pass, c.Logger, asrockrack.WithHTTPClient(&asrHttpClient))
c.Registry.Register(asrockrack.ProviderName, asrockrack.ProviderProtocol, asrockrack.Features, nil, driverAsrockrack)
}
// register gofish provider
func (c *Client) registerGofishProvider() {
gfHttpClient := *c.httpClient
gfHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone()
gofishOpts := []redfish.Option{
redfish.WithHttpClient(&gfHttpClient),
redfish.WithVersionsNotCompatible(c.providerConfig.gofish.VersionsNotCompatible),
redfish.WithUseBasicAuth(c.providerConfig.gofish.UseBasicAuth),
redfish.WithPort(c.providerConfig.gofish.Port),
redfish.WithEtagMatchDisabled(c.providerConfig.gofish.DisableEtagMatch),
redfish.WithSystemName(c.providerConfig.gofish.SystemName),
}
driverGoFish := redfish.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, c.Logger, gofishOpts...)
c.Registry.Register(redfish.ProviderName, redfish.ProviderProtocol, redfish.Features, nil, driverGoFish)
}
// register Intel AMT provider
func (c *Client) registerIntelAMTProvider() {
iamtOpts := []intelamt.Option{
intelamt.WithLogger(c.Logger),
intelamt.WithHostScheme(c.providerConfig.intelamt.HostScheme),
intelamt.WithPort(c.providerConfig.intelamt.Port),
}
driverAMT := intelamt.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, iamtOpts...)
c.Registry.Register(intelamt.ProviderName, intelamt.ProviderProtocol, intelamt.Features, nil, driverAMT)
}
// register Dell gofish provider
func (c *Client) registerDellProvider() {
dellGofishHttpClient := *c.httpClient
//dellGofishHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone()
dellGofishOpts := []dell.Option{
dell.WithHttpClient(&dellGofishHttpClient),
dell.WithVersionsNotCompatible(c.providerConfig.dell.VersionsNotCompatible),
dell.WithUseBasicAuth(c.providerConfig.dell.UseBasicAuth),
dell.WithPort(c.providerConfig.dell.Port),
}
driverGoFishDell := dell.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, c.Logger, dellGofishOpts...)
c.Registry.Register(dell.ProviderName, redfish.ProviderProtocol, dell.Features, nil, driverGoFishDell)
}
// register supermicro vendorapi provider
func (c *Client) registerSupermicroProvider() {
smcHttpClient := *c.httpClient
smcHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone()
driverSupermicro := supermicro.NewClient(
c.Auth.Host,
c.Auth.User,
c.Auth.Pass,
c.Logger,
supermicro.WithHttpClient(&smcHttpClient),
supermicro.WithPort(c.providerConfig.supermicro.Port),
)
c.Registry.Register(supermicro.ProviderName, supermicro.ProviderProtocol, supermicro.Features, nil, driverSupermicro)
}
func (c *Client) registerOpenBMCProvider() {
httpClient := *c.httpClient
httpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone()
driver := openbmc.New(
c.Auth.Host,
c.Auth.User,
c.Auth.Pass,
c.Logger,
openbmc.WithHttpClient(&httpClient),
openbmc.WithPort(c.providerConfig.openbmc.Port),
)
c.Registry.Register(openbmc.ProviderName, openbmc.ProviderProtocol, openbmc.Features, nil, driver)
}
func (c *Client) registerProviders() {
// register the rpc provider
// without the consumer URL there is no way to send RPC requests.
if c.providerConfig.rpc.ConsumerURL != "" {
// when the rpc provider is to be used, we won't register any other providers.
err := c.registerRPCProvider()
if err == nil {
c.Logger.Info("note: with the rpc provider registered, no other providers will be registered and available")
return
}
c.Logger.Info("failed to register rpc provider, falling back to registering all other providers", "error", err.Error())
}
if err := c.registerIPMIProvider(); err != nil {
c.Logger.Info("ipmitool provider not available", "error", err.Error())
}
c.registerASRRProvider()
c.registerGofishProvider()
c.registerIntelAMTProvider()
c.registerDellProvider()
c.registerSupermicroProvider()
c.registerOpenBMCProvider()
}
// GetMetadata returns the metadata that is populated after each BMC function/method call
func (c *Client) GetMetadata() bmc.Metadata {
if c.metadata != nil {
return *c.metadata
}
return bmc.Metadata{}
}
// setMetadata wraps setting metadata with a mutex for cases where users are
// making calls to multiple *Client.X functions/methods across goroutines
func (c *Client) setMetadata(metadata bmc.Metadata) {
// a mutex is created with the NewClient func, in the case
// where a user doesn't call NewClient we handle by checking if
// the mutex is nil
if c.mdLock != nil {
c.mdLock.Lock()
defer c.mdLock.Unlock()
}
c.metadata = &metadata
}
// registry will return the oneTimeRegistry if the oneTimeRegistryEnabled is true.
func (c *Client) registry() *registrar.Registry {
if c.oneTimeRegistryEnabled {
c.oneTimeRegistryEnabled = false
return c.oneTimeRegistry
}
return c.Registry
}
func (c *Client) RegisterSpanAttributes(m bmc.Metadata, span oteltrace.Span) {
span.SetAttributes(attribute.String("host", c.Auth.Host))
span.SetAttributes(attribute.String("successful-provider", m.SuccessfulProvider))
span.SetAttributes(
attribute.String("successful-open-conns", strings.Join(m.SuccessfulOpenConns, ",")),
)
span.SetAttributes(
attribute.String("successful-close-conns", strings.Join(m.SuccessfulCloseConns, ",")),
)
span.SetAttributes(
attribute.String("attempted-providers", strings.Join(m.ProvidersAttempted, ",")),
)
for p, e := range m.FailedProviderDetail {
span.SetAttributes(
attribute.String("provider-errs-"+p, e),
)
}
}
// Open calls the OpenConnectionFromInterfaces library function
// Any providers/drivers that do not successfully connect are removed
// from the client.Registry.Drivers. If client.Registry.Drivers ends up
// being empty then we error.
func (c *Client) Open(ctx context.Context) error {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "Open")
defer span.End()
ifs, metadata, err := bmc.OpenConnectionFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
metadata.RegisterSpanAttributes(c.Auth.Host, span)
defer c.setMetadata(metadata)
if err != nil {
return err
}
var reg registrar.Drivers
for _, elem := range c.Registry.Drivers {
for _, em := range ifs {
if em == elem.DriverInterface {
elem.DriverInterface = em
reg = append(reg, elem)
}
}
}
c.Registry.Drivers = reg
return nil
}
// Close pass through to library function
func (c *Client) Close(ctx context.Context) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "Close")
defer span.End()
// Generally, we always want the close function to run.
// We don't want a context timeout or cancellation to prevent this.
// But because the current model is to pass just a single context to all
// functions, we need to create a new context here allowing closing connections.
// This is a short term solution, and we should consider a better/more holistic model.
if err := ctx.Err(); err != nil {
var done context.CancelFunc
ctx, done = context.WithTimeout(context.Background(), defaultConnectTimeout)
defer done()
}
metadata, err := bmc.CloseConnectionFromInterfaces(ctx, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return err
}
// FilterForCompatible removes any drivers/providers that are not compatible. It wraps the
// Client.Registry.FilterForCompatible func in order to provide a per provider timeout.
func (c *Client) FilterForCompatible(ctx context.Context) {
perProviderTimeout, cancel := context.WithTimeout(ctx, c.perProviderTimeout(ctx))
defer cancel()
reg := c.registry().FilterForCompatible(perProviderTimeout)
c.Registry.Drivers = reg
}
// GetPowerState pass through to library function
func (c *Client) GetPowerState(ctx context.Context) (state string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "GetPowerState")
defer span.End()
state, metadata, err := bmc.GetPowerStateFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return state, err
}
// SetPowerState pass through to library function
func (c *Client) SetPowerState(ctx context.Context, state string) (ok bool, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "SetPowerState")
defer span.End()
ok, metadata, err := bmc.SetPowerStateFromInterfaces(ctx, c.perProviderTimeout(ctx), state, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return ok, err
}
// CreateUser pass through to library function
func (c *Client) CreateUser(ctx context.Context, user, pass, role string) (ok bool, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "CreateUser")
defer span.End()
ok, metadata, err := bmc.CreateUserFromInterfaces(ctx, c.perProviderTimeout(ctx), user, pass, role, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return ok, err
}
// UpdateUser pass through to library function
func (c *Client) UpdateUser(ctx context.Context, user, pass, role string) (ok bool, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "UpdateUser")
defer span.End()
ok, metadata, err := bmc.UpdateUserFromInterfaces(ctx, c.perProviderTimeout(ctx), user, pass, role, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return ok, err
}
// DeleteUser pass through to library function
func (c *Client) DeleteUser(ctx context.Context, user string) (ok bool, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "DeleteUser")
defer span.End()
ok, metadata, err := bmc.DeleteUserFromInterfaces(ctx, c.perProviderTimeout(ctx), user, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return ok, err
}
// ReadUsers pass through to library function
func (c *Client) ReadUsers(ctx context.Context) (users []map[string]string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "ReadUsers")
defer span.End()
users, metadata, err := bmc.ReadUsersFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return users, err
}
// GetBootDeviceOverride pass through to library function
func (c *Client) GetBootDeviceOverride(ctx context.Context) (override bmc.BootDeviceOverride, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "GetBootDeviceOverride")
defer span.End()
override, metadata, err := bmc.GetBootDeviceOverrideFromInterface(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
return override, err
}
// SetBootDevice pass through to library function
func (c *Client) SetBootDevice(ctx context.Context, bootDevice string, setPersistent, efiBoot bool) (ok bool, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "SetBootDevice")
defer span.End()
ok, metadata, err := bmc.SetBootDeviceFromInterfaces(ctx, c.perProviderTimeout(ctx), bootDevice, setPersistent, efiBoot, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return ok, err
}
// SetVirtualMedia controls the virtual media simulated by the BMC as being connected to the
// server. Specifically, the method ejects any currently attached virtual media, and then if
// mediaURL isn't empty, attaches a virtual media device of type kind whose contents are
// streamed from the indicated URL.
func (c *Client) SetVirtualMedia(ctx context.Context, kind string, mediaURL string) (ok bool, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "SetVirtualMedia")
defer span.End()
ok, metadata, err := bmc.SetVirtualMediaFromInterfaces(ctx, kind, mediaURL, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return ok, err
}
// ResetBMC pass through to library function
func (c *Client) ResetBMC(ctx context.Context, resetType string) (ok bool, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "ResetBMC")
defer span.End()
ok, metadata, err := bmc.ResetBMCFromInterfaces(ctx, c.perProviderTimeout(ctx), resetType, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return ok, err
}
// DeactivateSOL pass through library function to deactivate active SOL sessions
func (c *Client) DeactivateSOL(ctx context.Context) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "DeactivateSOL")
defer span.End()
metadata, err := bmc.DeactivateSOLFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
return err
}
// Inventory pass through library function to collect hardware and firmware inventory
func (c *Client) Inventory(ctx context.Context) (device *common.Device, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "Inventory")
defer span.End()
device, metadata, err := bmc.GetInventoryFromInterfaces(ctx, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
return device, err
}
func (c *Client) GetBiosConfiguration(ctx context.Context) (biosConfig map[string]string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "GetBiosConfiguration")
defer span.End()
biosConfig, metadata, err := bmc.GetBiosConfigurationInterfaces(ctx, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return biosConfig, err
}
func (c *Client) SetBiosConfiguration(ctx context.Context, biosConfig map[string]string) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "SetBiosConfiguration")
defer span.End()
metadata, err := bmc.SetBiosConfigurationInterfaces(ctx, c.registry().GetDriverInterfaces(), biosConfig)
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return err
}
func (c *Client) SetBiosConfigurationFromFile(ctx context.Context, cfg string) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "SetBiosConfigurationFromFile")
defer span.End()
metadata, err := bmc.SetBiosConfigurationFromFileInterfaces(ctx, c.registry().GetDriverInterfaces(), cfg)
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return err
}
func (c *Client) ResetBiosConfiguration(ctx context.Context) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "ResetBiosConfiguration")
defer span.End()
metadata, err := bmc.ResetBiosConfigurationInterfaces(ctx, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return err
}
// FirmwareInstall pass through library function to upload firmware and install firmware
func (c *Client) FirmwareInstall(ctx context.Context, component string, operationApplyTime string, forceInstall bool, reader io.Reader) (taskID string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "FirmwareInstall")
defer span.End()
taskID, metadata, err := bmc.FirmwareInstallFromInterfaces(ctx, component, operationApplyTime, forceInstall, reader, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return taskID, err
}
// Note: this interface is to be deprecated in favour of a more generic FirmwareTaskStatus.
//
// FirmwareInstallStatus pass through library function to check firmware install status
func (c *Client) FirmwareInstallStatus(ctx context.Context, installVersion, component, taskID string) (status string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "FirmwareInstallStatus")
defer span.End()
status, metadata, err := bmc.FirmwareInstallStatusFromInterfaces(ctx, installVersion, component, taskID, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return status, err
}
// PostCodeGetter pass through library function to return the BIOS/UEFI POST code
func (c *Client) PostCode(ctx context.Context) (status string, code int, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "PostCode")
defer span.End()
status, code, metadata, err := bmc.GetPostCodeInterfaces(ctx, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return status, code, err
}
func (c *Client) Screenshot(ctx context.Context) (image []byte, fileType string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "Screenshot")
defer span.End()
image, fileType, metadata, err := bmc.ScreenshotFromInterfaces(ctx, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return image, fileType, err
}
func (c *Client) ClearSystemEventLog(ctx context.Context) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "ClearSystemEventLog")
defer span.End()
metadata, err := bmc.ClearSystemEventLogFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return err
}
func (c *Client) MountFloppyImage(ctx context.Context, image io.Reader) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "MountFloppyImage")
defer span.End()
metadata, err := bmc.MountFloppyImageFromInterfaces(ctx, image, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return err
}
func (c *Client) UnmountFloppyImage(ctx context.Context) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "UnmountFloppyImage")
defer span.End()
metadata, err := bmc.UnmountFloppyImageFromInterfaces(ctx, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return err
}
// FirmwareInstallSteps return the order of actions required install firmware for a component.
func (c *Client) FirmwareInstallSteps(ctx context.Context, component string) (actions []constants.FirmwareInstallStep, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "FirmwareInstallSteps")
defer span.End()
status, metadata, err := bmc.FirmwareInstallStepsFromInterfaces(ctx, component, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return status, err
}
// FirmwareUpload just uploads the firmware for install, it returns a task ID to verify the upload status.
func (c *Client) FirmwareUpload(ctx context.Context, component string, file *os.File) (uploadVerifyTaskID string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "FirmwareUpload")
defer span.End()
uploadVerifyTaskID, metadata, err := bmc.FirmwareUploadFromInterfaces(ctx, component, file, c.Registry.GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return uploadVerifyTaskID, err
}
// FirmwareTaskStatus pass through library function to check firmware task statuses
func (c *Client) FirmwareTaskStatus(ctx context.Context, kind constants.FirmwareInstallStep, component, taskID, installVersion string) (state constants.TaskState, status string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "FirmwareTaskStatus")
defer span.End()
state, status, metadata, err := bmc.FirmwareTaskStatusFromInterfaces(ctx, kind, component, taskID, installVersion, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return state, status, err
}
// FirmwareInstallUploaded kicks off firmware install for a firmware uploaded with FirmwareUpload.
func (c *Client) FirmwareInstallUploaded(ctx context.Context, component, uploadVerifyTaskID string) (installTaskID string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "FirmwareInstallUploaded")
defer span.End()
installTaskID, metadata, err := bmc.FirmwareInstallerUploadedFromInterfaces(ctx, component, uploadVerifyTaskID, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return installTaskID, err
}
func (c *Client) FirmwareInstallUploadAndInitiate(ctx context.Context, component string, file *os.File) (taskID string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "FirmwareInstallUploadAndInitiate")
defer span.End()
taskID, metadata, err := bmc.FirmwareInstallUploadAndInitiateFromInterfaces(ctx, component, file, c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)
return taskID, err
}
// GetSystemEventLog queries for the SEL and returns the entries in an opinionated format.
func (c *Client) GetSystemEventLog(ctx context.Context) (entries bmc.SystemEventLogEntries, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "GetSystemEventLog")
defer span.End()
entries, metadata, err := bmc.GetSystemEventLogFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
return entries, err
}
// GetSystemEventLogRaw queries for the SEL and returns the raw response.
func (c *Client) GetSystemEventLogRaw(ctx context.Context) (eventlog string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "GetSystemEventLogRaw")
defer span.End()
eventlog, metadata, err := bmc.GetSystemEventLogRawFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
return eventlog, err
}
// SendNMI tells the BMC to issue an NMI to the device
func (c *Client) SendNMI(ctx context.Context) error {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "SendNMI")
defer span.End()
metadata, err := bmc.SendNMIFromInterface(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
c.setMetadata(metadata)
return err
}