Module: IDRAC::Boot

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

Instance Method Summary collapse

Instance Method Details

#bios_error_prompt_disabled?Boolean

Check if BIOS error prompt is disabled

Returns:

  • (Boolean)


328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/idrac/boot.rb', line 328

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")
        return data["Attributes"]["ErrPrompt"] == "Disabled"
      else
        debug "ErrPrompt attribute not found in BIOS settings", 1, :yellow
        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)


350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/idrac/boot.rb', line 350

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('SystemConfiguration').blank?
    json["Attributes"]["HddPlaceholder"] == "Enabled"
  end
end

#bios_os_power_control_enabled?Boolean

Returns:

  • (Boolean)


364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/idrac/boot.rb', line 364

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('SystemConfiguration').blank?
    json["Attributes"]["ProcCStates"] == "Enabled" &&
      json["Attributes"]["SysProfile"] == "PerfPerWattOptimizedOs" &&
      json["Attributes"]["ProcPwrPerf"] == "OsDbpm"
  end
end

#configure_bios_settings(settings) ⇒ Object

Configure BIOS settings



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/idrac/boot.rb', line 273

def configure_bios_settings(settings)
  response = authenticated_request(
    :patch, 
    "/redfish/v1/Systems/System.Embedded.1/Bios/Settings",
    body: { "Attributes": settings }.to_json,
    headers: { 'Content-Type': 'application/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



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/idrac/boot.rb', line 415

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

#ensure_uefi_bootObject

Ensure UEFI boot mode



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/idrac/boot.rb', line 66

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,
          headers: { 'Content-Type': 'application/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

Get BIOS boot options



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

def get_bios_boot_options
  response = authenticated_request(:get, "/redfish/v1/Systems/System.Embedded.1/BootSources")
  
  if response.status == 200
    begin
      data = JSON.parse(response.body)
      
      if data["Attributes"]["UefiBootSeq"].blank?
        puts "Not in UEFI mode".red
        return false
      end
      
      boot_order = []
      boot_options = []
      
      data["Attributes"]["UefiBootSeq"].each do |seq|
        puts "#{seq["Name"]} > #{seq["Enabled"]}".yellow
        boot_options << seq["Name"]
        boot_order << seq["Name"] if seq["Enabled"]
      end
      
      return {
        boot_options: boot_options,
        boot_order: boot_order
      }
    rescue JSON::ParserError
      raise Error, "Failed to parse BIOS boot options response: #{response.body}"
    end
  else
    raise Error, "Failed to get BIOS boot options. Status code: #{response.status}"
  end
end

#get_idrac_versionObject

Get iDRAC version - needed for boot management differences



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

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



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/idrac/boot.rb', line 441

def import_system_configuration(scp, target: "ALL", reboot: false)
  params = {
    "ImportBuffer": JSON.pretty_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,
    headers: { 'Content-Type': 'application/json' }
  )
  
  task = wait_for_task(response.headers["location"])
  debugger
  return task
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



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/idrac/boot.rb', line 250

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

# Servers can boot in BIOS mode or in UEFI (modern, extensible BIOS replacement) mode.

# We use UEFI mode.
# self.get(path: "Systems/System.Embedded.1/Bios/Settings?$select=BootMode")
res = self.get(path: "Systems/System.Embedded.1/Bios")
if res["body"]["Attributes"]["BootMode"] == "Uefi"
  return { status: :success }
else
  res = self.set_system_configuration_profile(scp_boot_mode_uefi, reboot: true)
  # Then must power cycle the server
  self.power_on!(wait: true)
  self.power_off!(wait: true)
  return res
end


123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/idrac/boot.rb', line 123

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



137
138
139
140
141
142
143
144
# File 'lib/idrac/boot.rb', line 137

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



321
322
323
324
325
# File 'lib/idrac/boot.rb', line 321

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



309
310
311
312
313
314
315
316
317
318
# File 'lib/idrac/boot.rb', line 309

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_hd_firstObject

Set boot order (HD first)



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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/idrac/boot.rb', line 147

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,
        headers: { 'Content-Type': 'application/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_uefi_boot_cd_once_then_hdObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/idrac/boot.rb', line 208

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