Module: IDRAC::Boot

Included in:
Client
Defined in:
lib/idrac/boot.rb

Constant Summary collapse

STALE_UEFI_BOOT_ENTRY =

Stale UEFI boot placeholders a prior OS can leave behind. Dell names them "Unknown.Unknown.-"; left ENABLED they make UEFI loop over dead entries and can keep a node from ever reaching an install (this trapped n008: PXE plus five "Unknown.Unknown" ghosts, no disk entry). The default match targets exactly them.

/\AUnknown\.Unknown\./
BOOT_PROGRESS_STATES =

Redfish BootProgress.LastState mapped to the snake_case symbols radfish orders boots by (Radfish::Client::BOOT_PROGRESS_ORDER). Explicit so the acronym cases (PCI, OS) normalize correctly instead of through a naive underscore.

{
  "None" => :none,
  "PrimaryProcessorInitializationStarted" => :primary_processor_initialization_started,
  "BusInitializationStarted" => :bus_initialization_started,
  "MemoryInitializationStarted" => :memory_initialization_started,
  "SecondaryProcessorInitializationStarted" => :secondary_processor_initialization_started,
  "PCIResourceConfigStarted" => :pci_resource_config_started,
  "SystemHardwareInitializationComplete" => :system_hardware_initialization_complete,
  "SetupEntered" => :setup_entered,
  "OSBootStarted" => :os_boot_started,
  "OSRunning" => :os_running
}.freeze

Instance Method Summary collapse

Instance Method Details

#bios_error_prompt_disabled?Boolean

Check if BIOS error prompt is disabled

Returns:

  • (Boolean)


531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/idrac/boot.rb', line 531

def bios_error_prompt_disabled?
  response = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1/Bios")
  
  if response.status == 200
    begin
      data = JSON.parse(response.body)
      if data["Attributes"] && data["Attributes"].has_key?("ErrPrompt")
        current_value = data["Attributes"]["ErrPrompt"]
        debug "ErrPrompt current value: '#{current_value}' (checking if == 'Disabled')", 1, :cyan
        return current_value == "Disabled"
      else
        debug "ErrPrompt attribute not found in BIOS settings", 1, :yellow
        debug "Available BIOS attributes: #{data['Attributes']&.keys&.sort&.join(', ')}", 2, :yellow if data["Attributes"]
        return false
      end
    rescue JSON::ParserError
      debug "Failed to parse BIOS response", 0, :red
      return false
    end
  else
    debug "Failed to get BIOS information. Status code: #{response.status}", 0, :red
    return false
  end
end

#bios_hdd_placeholder_enabled?Boolean

Returns:

  • (Boolean)


556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/idrac/boot.rb', line 556

def bios_hdd_placeholder_enabled?
  case self.license_version.to_i
  when 8
    # scp = usable_scp(get_system_configuration_profile(target: "BIOS"))
    # scp["BIOS.Setup.1-1"]["HddPlaceholder"] == "Enabled"
    true
  else
    response = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1/Bios")
    json = JSON.parse(response.body)
    raise "Error reading HddPlaceholder setup" if json&.dig('Attributes','HddPlaceholder').blank?
    json["Attributes"]["HddPlaceholder"] == "Enabled"
  end
end

#bios_os_power_control_enabled?Boolean

Returns:

  • (Boolean)


570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/idrac/boot.rb', line 570

def bios_os_power_control_enabled?
  case self.license_version.to_i
  when 8
    scp = usable_scp(get_system_configuration_profile(target: "BIOS"))
    scp["BIOS.Setup.1-1"]["ProcCStates"] == "Enabled" &&
      scp["BIOS.Setup.1-1"]["SysProfile"] == "PerfPerWattOptimizedOs" &&
      scp["BIOS.Setup.1-1"]["ProcPwrPerf"] == "OsDbpm"
  else
    response = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1/Bios")
    json = JSON.parse(response.body)
    raise "Error reading PowerControl setup" if json&.dig('Attributes').blank?
    json["Attributes"]["ProcCStates"] == "Enabled" &&
      json["Attributes"]["SysProfile"] == "PerfPerWattOptimizedOs" &&
      json["Attributes"]["ProcPwrPerf"] == "OsDbpm"
  end
end

#bootObject

Shorter alias for convenience



100
101
102
# File 'lib/idrac/boot.rb', line 100

def boot
  boot_config
end

#boot_configObject

Get boot configuration with snake_case fields



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
# File 'lib/idrac/boot.rb', line 32

def boot_config
  response = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1")
  
  if response.status == 200
    begin
      data = JSON.parse(response.body)
      boot_data = data["Boot"] || {}
      
      # Get boot options for resolving references
      options_map = {}
      begin
        options = boot_options
        options.each do |opt|
          options_map[opt["id"]] = opt["display_name"] || opt["name"]
        end
      rescue
        # Ignore errors fetching boot options
      end
      
      # Build boot order with resolved names
      boot_order = (boot_data["BootOrder"] || []).map do |ref|
        {
          "reference" => ref,
          "name" => options_map[ref] || ref
        }
      end
      
      # Return hash with snake_case fields
      {
        # Boot override settings (for one-time or continuous boot)
        "boot_source_override_enabled" => boot_data["BootSourceOverrideEnabled"],     # Disabled/Once/Continuous
        "boot_source_override_target" => boot_data["BootSourceOverrideTarget"],       # None/Pxe/Hdd/Cd/etc
        "boot_source_override_mode" => boot_data["BootSourceOverrideMode"],           # UEFI/Legacy
        "allowed_override_targets" => boot_data["[email protected]"] || [],
        
        # Permanent boot order with resolved names
        "boot_order" => boot_order,                                                    # [{reference: "Boot0001", name: "Ubuntu"}]
        "boot_order_refs" => boot_data["BootOrder"] || [],                            # Raw references for set_boot_order
        
        # UEFI specific fields
        "uefi_target_boot_source_override" => boot_data["UefiTargetBootSourceOverride"],
        "stop_boot_on_fault" => boot_data["StopBootOnFault"],
        
        # References to other resources
        "boot_options_uri" => boot_data.dig("BootOptions", "@odata.id"),
        "certificates_uri" => boot_data.dig("Certificates", "@odata.id")
      }.compact
    rescue JSON::ParserError
      raise Error, "Failed to parse boot response: #{response.body}"
    end
  else
    raise Error, "Failed to get boot configuration. Status code: #{response.status}"
  end
end

#boot_optionsObject

Get boot options collection - the actual boot devices present in the system This is different from boot_config which returns the boot configuration settings



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
# File 'lib/idrac/boot.rb', line 106

def boot_options
  response = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1/BootOptions?$expand=*($levels=1)")
  
  if response.status == 200
    begin
      data = JSON.parse(response.body)
      
      # Return the BootOption objects with snake_case
      data["Members"]&.map do |member|
        {
          "id" => member["Id"],                                           # Boot0001
          "boot_option_reference" => member["BootOptionReference"],       # Boot0001  
          "display_name" => member["DisplayName"],                        # "Integrated RAID Controller 1: Ubuntu"
          "name" => member["DisplayName"] || member["Name"],              # Alias for display_name
          "enabled" => member["BootOptionEnabled"],                       # true/false
          "uefi_device_path" => member["UefiDevicePath"],                 # UEFI device path
          "description" => member["Description"]
        }.compact
      end || []
    rescue JSON::ParserError
      raise Error, "Failed to parse boot options response: #{response.body}"
    end
  else
    []
  end
end

#boot_progressObject

Normalized last BootProgress state (a snake_case Symbol from BOOT_PROGRESS_STATES), or nil when the BMC does not report BootProgress at all (iDRAC8 omits it). nil means "cannot observe", never "not running" -- callers fall back to other signals.



752
753
754
755
756
757
758
# File 'lib/idrac/boot.rb', line 752

def boot_progress
  res = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1?$select=BootProgress")
  body = res.body.is_a?(String) ? JSON.parse(res.body) : res.body
  last = body.is_a?(Hash) ? body.dig("BootProgress", "LastState") : nil
  return nil if last.nil? || last.to_s.empty?
  BOOT_PROGRESS_STATES[last] || last.to_s.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase.to_sym
end

#boot_rawObject

Get raw Redfish boot data (CamelCase)



88
89
90
91
92
93
94
95
96
97
# File 'lib/idrac/boot.rb', line 88

def boot_raw
  response = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1")
  
  if response.status == 200
    data = JSON.parse(response.body)
    data["Boot"] || {}
  else
    raise Error, "Failed to get boot configuration. Status code: #{response.status}"
  end
end

#boot_to_bios_setup(persistence: nil, mode: nil) ⇒ Object



245
246
247
# File 'lib/idrac/boot.rb', line 245

def boot_to_bios_setup(persistence: nil, mode: nil)
  set_boot_override("BiosSetup", persistence: persistence, mode: mode)
end

#boot_to_cd(persistence: nil, mode: nil) ⇒ Object



237
238
239
# File 'lib/idrac/boot.rb', line 237

def boot_to_cd(persistence: nil, mode: nil)
  set_boot_override("Cd", persistence: persistence, mode: mode)
end

#boot_to_disk(persistence: nil, mode: nil) ⇒ Object



233
234
235
# File 'lib/idrac/boot.rb', line 233

def boot_to_disk(persistence: nil, mode: nil)
  set_boot_override("Hdd", persistence: persistence, mode: mode)
end

#boot_to_pxe(persistence: nil, mode: nil) ⇒ Object

Convenience methods for common boot targets



229
230
231
# File 'lib/idrac/boot.rb', line 229

def boot_to_pxe(persistence: nil, mode: nil)
  set_boot_override("Pxe", persistence: persistence, mode: mode)
end

#boot_to_usb(persistence: nil, mode: nil) ⇒ Object



241
242
243
# File 'lib/idrac/boot.rb', line 241

def boot_to_usb(persistence: nil, mode: nil)
  set_boot_override("Usb", persistence: persistence, mode: mode)
end

#clear_boot_overrideObject

Clear boot override settings



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/idrac/boot.rb', line 181

def clear_boot_override
  debug "Clearing boot override...", 1, :yellow
  
  body = {
    "Boot" => {
      "BootSourceOverrideEnabled" => "Disabled"
    }
  }
  
  response = authenticated_request(
    :patch,
    "/redfish/v1/Systems/System.Embedded.1",
    body: body.to_json
  )
  
  if response.status.between?(200, 299)
    debug "Boot override cleared successfully.", 1, :green
    return true
  else
    raise Error, "Failed to clear boot override: #{response.status} - #{response.body}"
  end
end

#configure_bios_settings(settings) ⇒ Object

Configure BIOS settings



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
# File 'lib/idrac/boot.rb', line 477

def configure_bios_settings(settings)
  response = authenticated_request(
    :patch,
    "/redfish/v1/Systems/System.Embedded.1/Bios/Settings",
    body: { "Attributes": settings }.to_json
  )
  
  if response.status.between?(200, 299)
    puts "BIOS settings configured. A system reboot is required for changes to take effect.".green
    
    # Check if we need to wait for a job
    if response.headers["Location"]
      job_id = response.headers["Location"].split("/").last
      wait_for_job(job_id)
    end
    
    return true
  else
    error_message = "Failed to configure BIOS settings. Status code: #{response.status}"
    
    begin
      error_data = JSON.parse(response.body)
      if error_data["error"] && error_data["error"]["@Message.ExtendedInfo"]
        error_info = error_data["error"]["@Message.ExtendedInfo"].first
        error_message += ", Message: #{error_info['Message']}"
      end
    rescue
      # Ignore JSON parsing errors
    end
    
    raise Error, error_message
  end
end

#create_scp_for_bios(settings) ⇒ Object

Create System Configuration Profile for BIOS settings



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/idrac/boot.rb', line 621

def create_scp_for_bios(settings)
  attributes = []
  
  settings.each do |key, value|
    attributes << {
      "Name" => key.to_s,
      "Value" => value,
      "Set On Import" => "True"
    }
  end
  
  scp = {
    "SystemConfiguration" => {
      "Components" => [
        {
          "FQDD" => "BIOS.Setup.1-1",
          "Attributes" => attributes
        }
      ]
    }
  }
  
  return scp
end

#disable_boot_entries(match: STALE_UEFI_BOOT_ENTRY, wait: false, timeout: 900) ⇒ Object

Disable the UEFI boot entries whose Name matches match (default: the stale "Unknown.Unknown.*" placeholders) and return the NAMES disabled ([] when there was nothing to do). Drains any pending Lifecycle Controller config job FIRST so scheduling ours never trips LC068, then PATCHes BootSources/Settings and POSTs the BIOS config job that applies the change. The disable is applied by a reboot -- the LifecycleController runs the pending job during POST -- so by default this only SCHEDULES it and the caller owns power. Pass wait: true to poll the scheduled BIOS config job to a terminal state here (via wait_config_job) before returning.

Raises:



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
# File 'lib/idrac/boot.rb', line 697

def disable_boot_entries(match: STALE_UEFI_BOOT_ENTRY, wait: false, timeout: 900)
  res = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1/BootSources")
  body = res.body.is_a?(String) ? JSON.parse(res.body) : res.body
  seq = body.dig("Attributes", "UefiBootSeq") || []
  stale = seq.select { |e| e["Name"].to_s.match?(match) && e["Enabled"] != false }
  return [] if stale.empty?

  # A stale pending job would make the config-job POST below hard-fail with LC068; drain first.
  drain_pending_config_jobs!

  newseq = seq.each_with_index.map do |e, i|
    off = e["Name"].to_s.match?(match)
    { "Enabled" => (off ? false : e["Enabled"]), "Id" => e["Id"], "Index" => i, "Name" => e["Name"] }
  end
  patch = authenticated_request(:patch, "/redfish/v1/Systems/System.Embedded.1/BootSources/Settings",
                                body: JSON.generate("Attributes" => { "UefiBootSeq" => newseq }))
  raise Error, "Disabling stale boot sources failed (HTTP #{patch.status}): #{patch.body}" unless patch.status.between?(200, 299)

  job = authenticated_request(:post, "/redfish/v1/Managers/iDRAC.Embedded.1/Jobs",
                              body: JSON.generate("TargetSettingsURI" => "/redfish/v1/Systems/System.Embedded.1/BootSources/Settings"))
  raise Error, "BIOS config job for boot sources failed (HTTP #{job.status}): #{job.body}" unless job.status.between?(200, 299)

  # Default: the caller's reboot applies the change (LC runs the pending job during POST). With
  # wait: true, poll the scheduled config job to a terminal state -- reuse Jobs#wait_config_job.
  if wait
    headers = job.respond_to?(:headers) ? (job.headers || {}) : {}
    jid = (headers["location"] || headers["Location"]).to_s[/(JID_\w+)/, 1] || job.body.to_s[/(JID_\w+)/, 1]
    wait_config_job(jid, timeout: timeout) if jid
  end

  names = stale.map { |e| e["Name"] }
  puts "Disabled #{names.size} stale UEFI boot #{names.size == 1 ? 'entry' : 'entries'} " \
       "(#{names.join(', ')}); a BIOS config job applies it at the next boot.".green
  names
end

#ensure_uefi_bootObject

Ensure UEFI boot mode



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
# File 'lib/idrac/boot.rb', line 287

def ensure_uefi_boot
  response = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1/Bios")
  
  if response.status == 200
    begin
      data = JSON.parse(response.body)
      
      if data["Attributes"]["BootMode"] == "Uefi"
        puts "System is already in UEFI boot mode".green
        return true
      else
        puts "System is not in UEFI boot mode. Setting to UEFI...".yellow
        
        # Create payload for UEFI boot mode
        payload = {
          "Attributes": {
            "BootMode": "Uefi"
          }
        }
        
        # If iDRAC 9, we need to enable HddPlaceholder
        if get_idrac_version == 9
          payload[:Attributes][:HddPlaceholder] = "Enabled"
        end
        
        response = authenticated_request(
          :patch,
          "/redfish/v1/Systems/System.Embedded.1/Bios/Settings",
          body: payload.to_json
        )
        
        wait_for_job(response.headers["location"])
      end
    rescue JSON::ParserError
      raise Error, "Failed to parse BIOS response: #{response.body}"
    end
  else
    raise Error, "Failed to get BIOS information. Status code: #{response.status}"
  end
end

#get_bios_boot_optionsObject

Legacy method names for backward compatibility



134
135
136
# File 'lib/idrac/boot.rb', line 134

def get_bios_boot_options
  get_bios_boot_sources
end

#get_boot_devicesObject



138
139
140
# File 'lib/idrac/boot.rb', line 138

def get_boot_devices
  boot_options
end

#get_idrac_versionObject

Get iDRAC version - needed for boot management differences



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
# File 'lib/idrac/boot.rb', line 588

def get_idrac_version
  response = authenticated_request(:get, "/redfish/v1")
  
  if response.status == 200
    begin
      data = JSON.parse(response.body)
      redfish = data["RedfishVersion"]
      server = response.headers["server"]
      
      case server.to_s.downcase
      when /appweb\/4.5.4/, /idrac\/8/
        return 8
      when /apache/, /idrac\/9/
        return 9
      else
        # Try to determine by RedfishVersion as fallback
        if redfish == "1.4.0"
          return 8
        elsif redfish == "1.18.0"
          return 9
        else
          raise Error, "Unknown iDRAC version: #{server} / #{redfish}"
        end
      end
    rescue JSON::ParserError
      raise Error, "Failed to parse iDRAC response: #{response.body}"
    end
  else
    raise Error, "Failed to get iDRAC information. Status code: #{response.status}"
  end
end

#import_system_configuration(scp, target: "ALL", reboot: false) ⇒ Object

Import System Configuration Profile for advanced configurations



647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/idrac/boot.rb', line 647

def import_system_configuration(scp, target: "ALL", reboot: false)
  params = {
    "ImportBuffer" => JSON.generate(scp),
    "ShareParameters" => {
      "Target" => target
    }
  }
  # Configure shutdown behavior
  params["ShutdownType"] = "Forced"
  params["HostPowerState"] = reboot ? "On" : "Off"
  
  response = authenticated_request(
    :post,
    "/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/EID_674_Manager.ImportSystemConfiguration",
    body: params.to_json
  )
  
  # Same operation as set_system_configuration_profile: wait on the import JOB.
  return wait_for_scp_import(response.headers["location"])
end

#override_boot_sourceObject

This sets boot to HD but before that it sets the one-time boot to CD Different approach for iDRAC 8 vs 9



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/idrac/boot.rb', line 454

def override_boot_source
  # For now try with all iDRAC versions
  if self.license_version.to_i == 9
    set_boot_order_hd_first()
    set_one_time_virtual_media_boot()
  else
    scp = {"FQDD"=>"iDRAC.Embedded.1", "Attributes"=> [{"Name"=>"ServerBoot.1#BootOnce", "Value"=>"Enabled", "Set On Import"=>"True"}, {"Name"=>"ServerBoot.1#FirstBootDevice", "Value"=>"VCD-DVD", "Set On Import"=>"True"}]}
    # set_uefi_boot_cd_once_then_hd
    # scp = self.set_bios_boot_cd_first
    # get_bios_boot_options # Make sure we know if the OS is calling it Unknown or RAID
    # {"FQDD"=>"BIOS.Setup.1-1", "Attributes"=>
    # [{"Name"=>"ServerBoot.1#BootOnce",       "Value"=>"Enabled", "Set On Import"=>"True"},
    # {"Name"=>"ServerBoot.1#FirstBootDevice", "Value"=>"VCD-DVD", "Set On Import"=>"True"},
    # {"Name"=>"BootSeqRetry",                 "Value"=>"Disabled", "Set On Import"=>"True"},
    # {"Name"=>"UefiBootSeq",                  "Value"=>"Unknown.Unknown.1-1,NIC.PxeDevice.1-1,Floppy.iDRACVirtual.1-1,Optical.iDRACVirtual.1-1",
    #  "Set On Import"=>"True"}]}

    # 3.3.0 :018 > scp1 = {"FQDD"=>"BIOS.Setup.1-1", "Attributes"=> [{"Name"=>"OneTimeUefiBootSeq", "Value"=>"VCD-DVD", "Set On Import"=>"True"}, {"Name"=>"BootSeqRetry", "Value"=>"Disabled", "Set On Import"=>"True"}, {"Name"=>"UefiBootSeq", "Value"=>"Unknown.Unknown.1-1,NIC.PxeDevice.1-1", "Set On Import"=>"True"}]}
    set_system_configuration_profile(scp) # This will cycle power and leave the device off.
  end
end

#scp_boot_mode_uefi(idrac_license_version: 9) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/idrac/boot.rb', line 328

def scp_boot_mode_uefi(idrac_license_version: 9)
  opts = { "BootMode" => 'Uefi' }
  # If we're iDRAC 9, we need enable a placeholder, otherwise we can't order the
  # boot order until we've switched to UEFI mode.
  # Read [about it](https://dl.dell.com/manuals/all-products/esuprt_software/esuprt_it_ops_datcentr_mgmt/dell-management-solution-resources_white-papers12_en-us.pdf).
  # ...administrators may wish to reserve a boot entry for a fixed disk in the UEFI Boot Sequence before an OS is installed or before a physical or
  # virtual drive has been formatted. When a HardDisk Drive Placeholder is set to Enabled, the BIOS will create a boot option for the PERC RAID
  # (Integrated or in a PCIe slot) disk if a partition is found, even if there is no FAT filesystem present... this allows the Integrated RAID controller
  # to be moved in the UEFI Boot Sequence prior to the OS installation
  opts["HddPlaceholder"] = "Enabled" if idrac_license_version.to_i == 9
  self.make_scp(fqdd: "BIOS.Setup.1-1", attributes: opts)
end

#set_bios(hash) ⇒ Object



342
343
344
345
346
347
348
349
# File 'lib/idrac/boot.rb', line 342

def set_bios(hash)
  scp = self.make_scp(fqdd: "BIOS.Setup.1-1", attributes: hash)
  res = self.set_system_configuration_profile(scp)
  if res[:status] == :success
    self.get_bios_boot_options
  end
  res
end

#set_bios_ignore_errors(value = true) ⇒ Object

Configure BIOS to ignore boot errors



524
525
526
527
528
# File 'lib/idrac/boot.rb', line 524

def set_bios_ignore_errors(value = true)
  configure_bios_settings({
    "ErrPrompt": value ? "Disabled" : "Enabled"
  })
end

#set_bios_os_power_controlObject

Configure BIOS to optimize for OS power management



512
513
514
515
516
517
518
519
520
521
# File 'lib/idrac/boot.rb', line 512

def set_bios_os_power_control
  settings = {
    "ProcCStates": "Enabled",      # Processor C-States
    "SysProfile": "PerfPerWattOptimizedOs",
    "ProcPwrPerf": "OsDbpm",       # OS Power Management
    "PcieAspmL1": "Enabled"        # PCIe Active State Power Management
  }
  
  configure_bios_settings(settings)
end

#set_boot_order(devices) ⇒ Object

Set the permanent boot order



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/idrac/boot.rb', line 205

def set_boot_order(devices)
  debug "Setting boot order...", 1, :yellow
  
  body = {
    "Boot" => {
      "BootOrder" => devices
    }
  }
  
  response = authenticated_request(
    :patch,
    "/redfish/v1/Systems/System.Embedded.1",
    body: body.to_json
  )
  
  if response.status.between?(200, 299)
    debug "Boot order set successfully.", 1, :green
    return true
  else
    raise Error, "Failed to set boot order: #{response.status} - #{response.body}"
  end
end

#set_boot_order_hd_firstObject

Set boot order (HD first)



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
# File 'lib/idrac/boot.rb', line 352

def set_boot_order_hd_first
  # First ensure we're in UEFI mode
  ensure_uefi_boot
  
  # Get available boot options
  boot_options_response = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1/BootOptions?$expand=*($levels=1)")
  
  if boot_options_response.status == 200
    begin
      data = JSON.parse(boot_options_response.body)
      
      puts "Available boot options:"
      data["Members"].each { |m| puts "\t#{m['DisplayName']} -> #{m['Id']}" }
      
      # Find RAID controller or HD
      device = data["Members"].find { |m| m["DisplayName"] =~ /RAID Controller/ }
      # Sometimes it's named differently
      device ||= data["Members"].find { |m| m["DisplayName"] =~ /ubuntu/i }
      device ||= data["Members"].find { |m| m["DisplayName"] =~ /UEFI Hard Drive/i }
      device ||= data["Members"].find { |m| m["DisplayName"] =~ /Hard Drive/i }
      
      if device.nil?
        raise Error, "No bootable hard drive or RAID controller found in boot options"
      end
      
      boot_id = device["Id"]
      
      # Set boot order
      response = authenticated_request(
        :patch,
        "/redfish/v1/Systems/System.Embedded.1",
        body: { "Boot": { "BootOrder": [boot_id] } }.to_json
      )
      
      if response.status.between?(200, 299)
        puts "Boot order set to HD first".green
        return true
      else
        error_message = "Failed to set boot order. Status code: #{response.status}"
        
        begin
          error_data = JSON.parse(response.body)
          if error_data["error"] && error_data["error"]["@Message.ExtendedInfo"]
            error_info = error_data["error"]["@Message.ExtendedInfo"].first
            error_message += ", Message: #{error_info['Message']}"
          end
        rescue
          # Ignore JSON parsing errors
        end
        
        raise Error, error_message
      end
    rescue JSON::ParserError
      raise Error, "Failed to parse boot options response: #{response.body}"
    end
  else
    raise Error, "Failed to get boot options. Status code: #{boot_options_response.status}"
  end
end

#set_boot_override(target, persistence: nil, mode: nil) ⇒ Object

Set boot override for next boot



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
# File 'lib/idrac/boot.rb', line 143

def set_boot_override(target, persistence: nil, mode: nil)
  persistence = "Once" unless persistence
  # Validate target against allowed values
  boot_data = boot
  valid_targets = boot_data["allowed_override_targets"]
  
  if valid_targets && !valid_targets.include?(target)
    debug "Invalid boot target '#{target}'. Allowed values: #{valid_targets.join(', ')}", 1, :red
    raise Error, "Invalid boot target: #{target}"
  end
  
  debug "Setting boot override to #{target} (#{persistence})...", 1, :yellow
  
  body = {
    "Boot" => {
      "BootSourceOverrideEnabled" => persistence,  # Disabled/Once/Continuous
      "BootSourceOverrideTarget" => target     # None/Pxe/Hdd/Cd/etc
    }
  }
  
  # Add boot mode if specified
  body["Boot"]["BootSourceOverrideMode"] = mode if mode
  
  response = authenticated_request(
    :patch,
    "/redfish/v1/Systems/System.Embedded.1",
    body: body.to_json
  )
  
  if response.status.between?(200, 299)
    debug "Boot override set successfully.", 1, :green
    return true
  else
    raise Error, "Failed to set boot override: #{response.status} - #{response.body}"
  end
end

#set_one_time_cd_boot(reboot: false) ⇒ Object

Dell one-time boot to the virtual CD via an SCP import (the reliable path on this fleet). Drains any pending Lifecycle Controller config job first (a stale one makes the import hard-fail with LC068 "a configuration job is already scheduled"), then imports ServerBoot.1#BootOnce + FirstBootDevice=VCD-DVD. BootOnce makes the BIOS fall back to the standing order after one boot, so no boot-order reorder is needed here. Raises on a failed import; returns the import result hash.



765
766
767
768
769
770
771
772
773
774
775
# File 'lib/idrac/boot.rb', line 765

def set_one_time_cd_boot(reboot: false)
  drain_pending_config_jobs!
  scp = { "FQDD" => "iDRAC.Embedded.1", "Attributes" => [
    { "Name" => "ServerBoot.1#BootOnce", "Value" => "Enabled", "Set On Import" => "True" },
    { "Name" => "ServerBoot.1#FirstBootDevice", "Value" => "VCD-DVD", "Set On Import" => "True" } ] }
  res = set_system_configuration_profile(scp, target: "ALL", reboot: reboot)
  unless res.is_a?(Hash) && res[:status] == :success
    raise Error, "SCP one-time vCD boot failed: #{res[:job_state]} #{res[:error] || res[:message]} (job #{res[:job_id]})"
  end
  res
end

#set_uefi_boot_cd_once_then_hdObject



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
# File 'lib/idrac/boot.rb', line 412

def set_uefi_boot_cd_once_then_hd
  boot_options = get_bios_boot_options[:boot_options]
  # Note may have to put device into
  # self.set_bios( { "BootMode" => 'Uefi' } )
  # self.reboot!
  # And then reboot before you can make the following call:
  raid_name = boot_options.include?("RAID.Integrated.1-1") ? "RAID.Integrated.1-1" : "Unknown.Unknown.1-1"
  raise "No RAID HD in boot options" unless boot_options.include?(raid_name)
  bios = {
      "BootMode" => 'Uefi',
      "BootSeqRetry" => "Disabled",

      # "UefiTargetBootSourceOverride" => 'Cd',
      # "BootSourceOverrideTarget" => 'UefiTarget',
      # "OneTimeBootMode"       => "OneTimeUefiBootSeq",

      # One time boot order
      # "OneTimeHddSeqDev"      => "Optical.iDRACVirtual.1-1",
      # "OneTimeBiosBootSeqDev" => "Optical.iDRACVirtual.1-1",
      # "OneTimeUefiBootSeqDev" => "Optical.iDRACVirtual.1-1",

      # Enabled/Disabled Options
      # "SetBootOrderDis" => "Disk.USBBack.1-1",  # Don't boot to USB if it is plugged in
      "SetBootOrderEn"    => raid_name,
      # "SetBootOrderFqdd1" => raid_name,
      # "SetLegacyHddOrderFqdd1" => raid_name,
      # "SetBootOrderFqdd2" => "Optical.iDRACVirtual.1-1",

      # Permanent Boot Order
      "HddSeq"      => raid_name,
      "BiosBootSeq" => raid_name,
      "UefiBootSeq" => raid_name # This is likely redundant...
    }
  # The usb device will have 'usb' in it:
  usb_name = boot_options.select { |b| b =~ /usb/i }
  bios["SetBootOrderDis"] = usb_name if usb_name.present?

  set_bios(bios)
end

#stale_uefi_boot_entries(match: STALE_UEFI_BOOT_ENTRY) ⇒ Object

The still-ENABLED UEFI boot entries whose Name matches match (default: the stale "Unknown.Unknown.*" placeholders). Returns the raw BootSources entry hashes so callers can read Name/Id/Index; [] when there are none. Read-only.



683
684
685
686
687
688
# File 'lib/idrac/boot.rb', line 683

def stale_uefi_boot_entries(match: STALE_UEFI_BOOT_ENTRY)
  res = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1/BootSources")
  body = res.body.is_a?(String) ? JSON.parse(res.body) : res.body
  seq = body.dig("Attributes", "UefiBootSeq") || []
  seq.select { |e| e["Name"].to_s.match?(match) && e["Enabled"] != false }
end