@@ -65,14 +65,9 @@ type RedfishBaseBMC struct {
6565 manufacturer string
6666}
6767
68- var pxeBootWithSettingUEFIBootMode = schemas.Boot {
69- BootSourceOverrideEnabled : schemas .OnceBootSourceOverrideEnabled ,
70- BootSourceOverrideMode : schemas .UEFIBootSourceOverrideMode ,
71- BootSourceOverrideTarget : schemas .PxeBootSource ,
72- }
73- var pxeBootWithoutSettingUEFIBootMode = schemas.Boot {
74- BootSourceOverrideEnabled : schemas .OnceBootSourceOverrideEnabled ,
75- BootSourceOverrideTarget : schemas .PxeBootSource ,
68+ var clearedBootOverride = schemas.Boot {
69+ BootSourceOverrideEnabled : schemas .DisabledBootSourceOverrideEnabled ,
70+ BootSourceOverrideTarget : schemas .NoneBootSource ,
7671}
7772
7873type InvalidBIOSSettingsError struct {
@@ -231,26 +226,65 @@ func (r *RedfishBaseBMC) GetSystems(ctx context.Context) ([]Server, error) {
231226 return servers , nil
232227}
233228
234- // SetPXEBootOnce sets the boot device for the next system boot using Redfish.
235- func (r * RedfishBaseBMC ) SetPXEBootOnce (ctx context.Context , systemURI string ) error {
229+ // SetBootOverride sets a Redfish boot source override targeting network boot.
230+ // With persistent=false it sets BootSourceOverrideEnabled=Once; with
231+ // persistent=true it sets Continuous, which is preserved across power cycles.
232+ // When the requested persistent override already matches the current state
233+ // the call is a no-op.
234+ func (r * RedfishBaseBMC ) SetBootOverride (ctx context.Context , systemURI string , persistent bool ) error {
236235 system , err := r .getSystemFromUri (ctx , systemURI )
237236 if err != nil {
238237 return fmt .Errorf ("failed to get systems: %w" , err )
239238 }
240- var setBoot schemas.Boot
239+ wantEnabled := schemas .OnceBootSourceOverrideEnabled
240+ if persistent {
241+ wantEnabled = schemas .ContinuousBootSourceOverrideEnabled
242+ if system .Boot .BootSourceOverrideEnabled == schemas .ContinuousBootSourceOverrideEnabled &&
243+ system .Boot .BootSourceOverrideTarget == schemas .PxeBootSource &&
244+ (system .Boot .BootSourceOverrideMode == "" ||
245+ system .Boot .BootSourceOverrideMode == schemas .UEFIBootSourceOverrideMode ) {
246+ return nil
247+ }
248+ }
249+
250+ setBoot := schemas.Boot {
251+ BootSourceOverrideEnabled : wantEnabled ,
252+ BootSourceOverrideTarget : schemas .PxeBootSource ,
253+ }
241254 // TODO: cover setting BootSourceOverrideMode with BIOS settings profile
242- // Only skip setting BootSourceOverrideMode for older BMCs that don't report it
255+ // Only set BootSourceOverrideMode when the BMC reports it; older BMCs that
256+ // don't expose it will reject the field.
243257 if system .Boot .BootSourceOverrideMode != "" && system .Boot .BootSourceOverrideMode != schemas .UEFIBootSourceOverrideMode {
244- setBoot = pxeBootWithSettingUEFIBootMode
245- } else {
246- setBoot = pxeBootWithoutSettingUEFIBootMode
258+ setBoot .BootSourceOverrideMode = schemas .UEFIBootSourceOverrideMode
247259 }
248260
249261 // TODO: pass logging context from caller
250262 log := ctrl .LoggerFrom (ctx )
251- log .V (2 ).Info ("Setting PXE boot once" , "SystemURI" , systemURI , "Boot settings" , setBoot )
263+ log .V (2 ).Info ("Setting boot override" , "SystemURI" , systemURI , "Boot settings" , setBoot )
264+ if err := system .SetBoot (& setBoot ); err != nil {
265+ return fmt .Errorf ("failed to set boot override: %w" , err )
266+ }
267+ return nil
268+ }
269+
270+ // ClearBootOverride disables any active Redfish boot source override so the
271+ // system uses its persistent boot order on the next power-on. No SetBoot call
272+ // is issued when the override is already disabled.
273+ func (r * RedfishBaseBMC ) ClearBootOverride (ctx context.Context , systemURI string ) error {
274+ system , err := r .getSystemFromUri (ctx , systemURI )
275+ if err != nil {
276+ return fmt .Errorf ("failed to get systems: %w" , err )
277+ }
278+ if system .Boot .BootSourceOverrideEnabled == "" ||
279+ system .Boot .BootSourceOverrideEnabled == schemas .DisabledBootSourceOverrideEnabled {
280+ return nil
281+ }
282+
283+ setBoot := clearedBootOverride
284+ log := ctrl .LoggerFrom (ctx )
285+ log .V (2 ).Info ("Clearing boot override" , "SystemURI" , systemURI , "Boot settings" , setBoot )
252286 if err := system .SetBoot (& setBoot ); err != nil {
253- return fmt .Errorf ("failed to set the boot order : %w" , err )
287+ return fmt .Errorf ("failed to clear boot override : %w" , err )
254288 }
255289 return nil
256290}
0 commit comments