module IDRAC::Storage

def create_virtual_disk_scp(controller_id:, drives:, name: "vssd0", raid_type: "RAID5", encrypt: true)

Create a RAID virtual disk using SCP for older iDRAC firmware
https://github.com/dell/iDRAC-Redfish-Scripting/blob/cc88a3db1bfb6cb5c6eea938ea6da67a84fb1dad/Redfish%20Python/CreateVirtualDiskREDFISH.py
Rest from:
create virtual disks with **strip size of 64 KB**.
(read/write), I/O size, and RAID type. For optimal solid-state drive performance,
This enables FastPath to use the proper data path through the controller based on command
cache policies of the RAID controller must be set to **write-through and no read ahead**.
The PERC 11 series of cards support FastPath. To enable FastPath on a virtual disk, the
[FastPath](https://www.dell.com/support/manuals/en-us/poweredge-r7525/perc11_ug/fastpath?guid=guid-a9e90946-a41f-48ab-88f1-9ce514b4c414&lang=en-us)
the create_vssd0_post method.
All we are doing here is manually setting WriteThrough. The rest is set correctly from
We want one volume -- vssd0, RAID5, NO READ AHEAD, WRITE THROUGH, 64K STRIPE, ALL DISKS
#######################################################
When we remove 630/730's, we can remove this.
nor encryption.
doesn't support the POST method with cache policies
This is required for older DELL iDRAC that
System Configuration Profile - based VSSD0
#######################################################
def create_virtual_disk_scp(controller_id:, drives:, name: "vssd0", raid_type: "RAID5", encrypt: true)
  # Extract the controller FQDD from controller_id
  controller_fqdd = controller_id.split("/").last
  
  # Get drive IDs in the required format
  drive_ids = drives.map do |drive_path|
    # Extract the disk FQDD from @odata.id
    drive_id = drive_path.split("/").last
    if drive_id.include?(":") # Already in FQDD format
      drive_id
    else
      # Need to convert to FQDD format
      "Disk.Bay.#{drive_id}:#{controller_fqdd}"
    end
  end
  
  # Map RAID type to proper format
  raid_level = case raid_type
               when "RAID0" then "0"
               when "RAID1" then "1"
               when "RAID5" then "5"
               when "RAID6" then "6"
               when "RAID10" then "10"
               else raid_type.gsub("RAID", "")
               end
  
  # Create the virtual disk component
  vd_component = {
    "FQDD" => "Disk.Virtual.0:#{controller_fqdd}",
    "Attributes" => [
      { "Name" => "RAIDaction", "Value" => "Create", "Set On Import" => "True" },
      { "Name" => "Name", "Value" => name, "Set On Import" => "True" },
      { "Name" => "RAIDTypes", "Value" => "RAID #{raid_level}", "Set On Import" => "True" },
      { "Name" => "StripeSize", "Value" => "64KB", "Set On Import" => "True" }, # 64KB needed for FastPath
      { "Name" => "RAIDdefaultWritePolicy", "Value" => "WriteThrough", "Set On Import" => "True" },
      { "Name" => "RAIDdefaultReadPolicy", "Value" => "NoReadAhead", "Set On Import" => "True" },
      { "Name" => "DiskCachePolicy", "Value" => "Enabled", "Set On Import" => "True" }
    ]
  }
  
  # Add encryption if requested
  if encrypt
    vd_component["Attributes"] << { "Name" => "LockStatus", "Value" => "Unlocked", "Set On Import" => "True" }
  end
  
  # Add the include physical disks
  drive_ids.each do |disk_id|
    vd_component["Attributes"] << { 
      "Name" => "IncludedPhysicalDiskID", 
      "Value" => disk_id, 
      "Set On Import" => "True" 
    }
  end
  
  # Create an SCP with the controller component that contains the VD component
  controller_component = {
    "FQDD" => controller_fqdd,
    "Components" => [vd_component]
  }
  
  # Apply the SCP
  scp = { "SystemConfiguration" => { "Components" => [controller_component] } }
  result = set_system_configuration_profile(scp, target: "RAID", reboot: false)
  
  if result[:status] == :success
    return { status: :success, job_id: result[:job_id] }
  else
    raise Error, "Failed to create virtual disk: #{result[:error] || 'Unknown error'}"
  end
end