From 6dbf141197dae0a31943c92d9b7541da9fe1f87e Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 10 Jan 2025 09:13:59 -0700 Subject: [PATCH] Update virtual media ejecting: We weren't checking vm.Inserted and on some HP ILOs this caused failures to eject even when there was nothing to eject. This makes it so that this call won't fail when there is nothing to eject. Signed-off-by: Jacob Weinstock --- internal/redfishwrapper/virtual_media.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/redfishwrapper/virtual_media.go b/internal/redfishwrapper/virtual_media.go index 095b4861..00d4b945 100644 --- a/internal/redfishwrapper/virtual_media.go +++ b/internal/redfishwrapper/virtual_media.go @@ -43,23 +43,21 @@ func (c *Client) SetVirtualMedia(ctx context.Context, kind string, mediaURL stri } for _, vm := range virtualMedia { - var ejected bool - if vm.Inserted && vm.SupportsMediaEject { - 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 && vm.SupportsMediaEject { + if vm.Inserted && vm.SupportsMediaEject { if err := vm.EjectMedia(); err != nil { return false, err } } return true, nil } + if vm.Inserted && vm.SupportsMediaEject { + if err := vm.EjectMedia(); err != nil { + return false, err + } + } if !slices.Contains(vm.MediaTypes, mediaKind) { return false, fmt.Errorf("media kind %s not supported by BMC, supported media kinds %q", kind, vm.MediaTypes) }