From 26229cf1e493b380ec93354abd87e46b9dc4800b Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 25 Oct 2024 14:46:50 -0600 Subject: [PATCH 1/2] Add system name checking to the Managers helper method: This allows the systemName struct field to filter the managers. Needed for things like inserting and ejecting virtual media. Signed-off-by: Jacob Weinstock --- internal/redfishwrapper/system.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/redfishwrapper/system.go b/internal/redfishwrapper/system.go index 4e50e908..5fa10863 100644 --- a/internal/redfishwrapper/system.go +++ b/internal/redfishwrapper/system.go @@ -49,7 +49,24 @@ func (c *Client) Managers(ctx context.Context) ([]*redfish.Manager, error) { return nil, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - return c.client.Service.Managers() + ms, err := c.client.Service.Managers() + if err != nil { + return nil, err + } + + for _, m := range ms { + sys, err := m.ManagerForServers() + if err != nil { + continue + } + for _, s := range sys { + if s.Name == c.systemName { + return []*redfish.Manager{m}, nil + } + } + } + + return ms, nil } // Chassis gets the chassis instances managed by this service. From 53911d926e493f994b0ff9df3ca54fd2790fdd51 Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 25 Oct 2024 14:48:30 -0600 Subject: [PATCH 2/2] Make sure the System helper method is used: Many of the existing redfish feature methods weren't using the System helper that filtered for system name. Also, for virtual media ejecting, handle BMC's that don't support the "inserted" property. Signed-off-by: Jacob Weinstock --- internal/redfishwrapper/boot_device.go | 4 ++-- internal/redfishwrapper/power.go | 22 ++++++++-------------- internal/redfishwrapper/virtual_media.go | 8 ++++++++ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/internal/redfishwrapper/boot_device.go b/internal/redfishwrapper/boot_device.go index 5a674294..91b7b5fd 100644 --- a/internal/redfishwrapper/boot_device.go +++ b/internal/redfishwrapper/boot_device.go @@ -89,7 +89,7 @@ func (c *Client) SystemBootDeviceSet(_ context.Context, bootDevice string, setPe return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - systems, err := c.client.Service.Systems() + systems, err := c.Systems() if err != nil { return false, err } @@ -136,7 +136,7 @@ func (c *Client) GetBootDeviceOverride(_ context.Context) (override bmc.BootDevi return override, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - systems, err := c.client.Service.Systems() + systems, err := c.Systems() if err != nil { return override, err } diff --git a/internal/redfishwrapper/power.go b/internal/redfishwrapper/power.go index 0a700871..f08b6e03 100644 --- a/internal/redfishwrapper/power.go +++ b/internal/redfishwrapper/power.go @@ -36,7 +36,7 @@ func (c *Client) BMCReset(ctx context.Context, resetType string) (ok bool, err e return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - managers, err := c.client.Service.Managers() + managers, err := c.Managers(ctx) if err != nil { return false, err } @@ -57,8 +57,7 @@ func (c *Client) SystemPowerOn(ctx context.Context) (ok bool, err error) { return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - service := c.client.Service - ss, err := service.Systems() + ss, err := c.Systems() if err != nil { return false, err } @@ -84,8 +83,7 @@ func (c *Client) SystemPowerOff(ctx context.Context) (ok bool, err error) { return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - service := c.client.Service - ss, err := service.Systems() + ss, err := c.Systems() if err != nil { return false, err } @@ -112,8 +110,7 @@ func (c *Client) SystemReset(ctx context.Context) (ok bool, err error) { return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - service := c.client.Service - ss, err := service.Systems() + ss, err := c.Systems() if err != nil { return false, err } @@ -147,8 +144,7 @@ func (c *Client) SystemPowerCycle(ctx context.Context) (ok bool, err error) { return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - service := c.client.Service - ss, err := service.Systems() + ss, err := c.Systems() if err != nil { return false, err } @@ -180,8 +176,7 @@ func (c *Client) SystemPowerStatus(ctx context.Context) (result string, err erro return result, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - service := c.client.Service - ss, err := service.Systems() + ss, err := c.Systems() if err != nil { return "", err } @@ -199,8 +194,7 @@ func (c *Client) SystemForceOff(ctx context.Context) (ok bool, err error) { return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - service := c.client.Service - ss, err := service.Systems() + ss, err := c.Systems() if err != nil { return false, err } @@ -227,7 +221,7 @@ func (c *Client) SendNMI(_ context.Context) error { return errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } - ss, err := c.client.Service.Systems() + ss, err := c.Systems() if err != nil { return err } diff --git a/internal/redfishwrapper/virtual_media.go b/internal/redfishwrapper/virtual_media.go index 5ec83a90..f214bffc 100644 --- a/internal/redfishwrapper/virtual_media.go +++ b/internal/redfishwrapper/virtual_media.go @@ -43,13 +43,21 @@ func (c *Client) SetVirtualMedia(ctx context.Context, kind string, mediaURL stri } for _, vm := range virtualMedia { + var ejected bool if vm.Inserted { if err := vm.EjectMedia(); err != nil { return false, err } + ejected = true } if mediaURL == "" { // Only ejecting the media was requested. + // For BMC's that don't support the "inserted" property, we need to eject the media if it's not already ejected. + if !ejected { + if err := vm.EjectMedia(); err != nil { + return false, err + } + } return true, nil } if !slices.Contains(vm.MediaTypes, mediaKind) {