diff --git a/client.go b/client.go index 437a919d..51b23801 100644 --- a/client.go +++ b/client.go @@ -145,38 +145,37 @@ func (c *Client) registerRPCProvider() error { return nil } -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()) - } - // register ipmitool provider +// 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), } - if driverIpmitool, err := ipmitool.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, ipmiOpts...); err == nil { - c.Registry.Register(ipmitool.ProviderName, ipmitool.ProviderProtocol, ipmitool.Features, nil, driverIpmitool) - } else { - c.Logger.Info("ipmitool provider not available", "error", err.Error()) + + driverIpmitool, err := ipmitool.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, ipmiOpts...) + if err != nil { + return err } - // register ASRR vendorapi provider + c.Registry.Register(ipmitool.ProviderName, ipmitool.ProviderProtocol, ipmitool.Features, nil, driverIpmitool) + + return nil +} + +// register ASRR vendorapi provider +func (c *Client) registerASRRProvider() error { 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 + return nil +} + +// register gofish provider +func (c *Client) registerGofishProvider() error { gfHttpClient := *c.httpClient gfHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone() gofishOpts := []redfish.Option{ @@ -184,11 +183,18 @@ func (c *Client) registerProviders() { redfish.WithVersionsNotCompatible(c.providerConfig.gofish.VersionsNotCompatible), redfish.WithUseBasicAuth(c.providerConfig.gofish.UseBasicAuth), redfish.WithPort(c.providerConfig.gofish.Port), + redfish.WithEtagMatchDisabled(c.providerConfig.gofish.DisableEtagMatch), } + 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 + return nil +} + +// register Intel AMT provider +func (c *Client) registerIntelAMTProvider() error { + iamtOpts := []intelamt.Option{ intelamt.WithLogger(c.Logger), intelamt.WithHostScheme(c.providerConfig.intelamt.HostScheme), @@ -197,7 +203,11 @@ func (c *Client) registerProviders() { 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 + return nil +} + +// register Dell gofish provider +func (c *Client) registerDellProvider() error { dellGofishHttpClient := *c.httpClient //dellGofishHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone() dellGofishOpts := []dell.Option{ @@ -209,11 +219,64 @@ func (c *Client) registerProviders() { 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 + return nil +} + +// register supermicro vendorapi provider +func (c *Client) registerSupermicroProvider() error { 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)) + 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) + + return nil +} + +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()) + } + + if err := c.registerASRRProvider(); err != nil { + c.Logger.Info("ASRR provider not available", "error", err.Error()) + } + + if err := c.registerGofishProvider(); err != nil { + c.Logger.Info("Gofish provider not available", "error", err.Error()) + } + + if err := c.registerIntelAMTProvider(); err != nil { + c.Logger.Info("Intel AMT provider not available", "error", err.Error()) + } + + if err := c.registerDellProvider(); err != nil { + c.Logger.Info("Dell provider not available", "error", err.Error()) + } + + if err := c.registerSupermicroProvider(); err != nil { + c.Logger.Info("Supermicro provider not available", "error", err.Error()) + } + } // GetMetadata returns the metadata that is populated after each BMC function/method call