Class: IDRAC::FirmwareCatalog
- Inherits:
-
Object
- Object
- IDRAC::FirmwareCatalog
- Defined in:
- lib/idrac/firmware_catalog.rb
Constant Summary collapse
- DELL_CATALOG_BASE =
'https://downloads.dell.com'- DELL_CATALOG_URL =
"#{DELL_CATALOG_BASE}/catalog/Catalog.xml.gz"
Instance Attribute Summary collapse
-
#catalog_path ⇒ Object
readonly
Returns the value of attribute catalog_path.
Instance Method Summary collapse
- #compare_versions(current_version, available_version) ⇒ Object
- #download(output_dir = nil) ⇒ Object
- #extract_identifiers(name) ⇒ Object
- #find_system_models(model_name) ⇒ Object
- #find_updates_for_system(system_id) ⇒ Object
-
#initialize(catalog_path = nil) ⇒ FirmwareCatalog
constructor
A new instance of FirmwareCatalog.
- #match_component(firmware_name, catalog_name) ⇒ Object
- #parse ⇒ Object
-
#pci_key(vendor_id, device_id, sub_vendor_id, sub_device_id) ⇒ Object
Normalize one PCI ID quad to a comparable key.
-
#updates_for_component(catalog_updates, fw) ⇒ Object
Select the catalog DUPs that apply to one installed component (
fwfrom the iDRAC inventory), most specific key first. -
#version_key(version) ⇒ Object
Sortable key for a Dell version string (e.g. "25.5.9.0001", "22.00.6").
Constructor Details
#initialize(catalog_path = nil) ⇒ FirmwareCatalog
Returns a new instance of FirmwareCatalog.
15 16 17 |
# File 'lib/idrac/firmware_catalog.rb', line 15 def initialize(catalog_path = nil) @catalog_path = catalog_path end |
Instance Attribute Details
#catalog_path ⇒ Object (readonly)
Returns the value of attribute catalog_path.
13 14 15 |
# File 'lib/idrac/firmware_catalog.rb', line 13 def catalog_path @catalog_path end |
Instance Method Details
#compare_versions(current_version, available_version) ⇒ Object
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 |
# File 'lib/idrac/firmware_catalog.rb', line 359 def compare_versions(current_version, available_version) # If versions are identical, no update needed return false if current_version == available_version # If either version is N/A, no update available return false if current_version == "N/A" || available_version == "N/A" # Try to handle Dell's version format (e.g., A00, A01, etc.) if available_version.match?(/^[A-Z]\d+$/) # If current version doesn't match Dell's format, assume update is needed return true unless current_version.match?(/^[A-Z]\d+$/) # Compare Dell version format (A00 < A01 < A02 < ... < B00 < B01 ...) available_letter = available_version[0] available_number = available_version[1..-1].to_i current_letter = current_version[0] current_number = current_version[1..-1].to_i return true if current_letter < available_letter return true if current_letter == available_letter && current_number < available_number return false end # For numeric versions, try to compare them if current_version.match?(/^[\d\.]+$/) && available_version.match?(/^[\d\.]+$/) current_parts = current_version.split('.').map(&:to_i) available_parts = available_version.split('.').map(&:to_i) # Compare each part of the version max_length = [current_parts.length, available_parts.length].max max_length.times do |i| current_part = current_parts[i] || 0 available_part = available_parts[i] || 0 return true if current_part < available_part return false if current_part > available_part end # If we get here, versions are equal return false end # If we can't determine, assume update is needed true end |
#download(output_dir = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/idrac/firmware_catalog.rb', line 19 def download(output_dir = nil) # Default to ~/.idrac directory output_dir ||= File.('~/.idrac') FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir) catalog_gz = File.join(output_dir, 'Catalog.xml.gz') catalog_xml = File.join(output_dir, 'Catalog.xml') puts "Downloading Dell catalog from #{DELL_CATALOG_URL}...".light_cyan begin # Download the catalog URI.open(DELL_CATALOG_URL) do |remote_file| File.open(catalog_gz, 'wb') do |local_file| local_file.write(remote_file.read) end end puts "Extracting catalog...".light_cyan # Extract the catalog system("gunzip -f #{catalog_gz}") if File.exist?(catalog_xml) puts "Catalog downloaded and extracted to #{catalog_xml}".green @catalog_path = catalog_xml return catalog_xml else raise Error, "Failed to extract catalog" end rescue => e puts "Error downloading catalog: #{e.}".red.bold raise Error, "Failed to download Dell catalog: #{e.}" end end |
#extract_identifiers(name) ⇒ Object
284 285 286 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 327 328 329 330 |
# File 'lib/idrac/firmware_catalog.rb', line 284 def extract_identifiers(name) return [] unless name identifiers = [] # Extract model numbers like X520, I350, etc. model_matches = name.scan(/[IX]\d{3,4}/) identifiers.concat(model_matches) # Extract PERC model like H730 perc_matches = name.scan(/[HP]\d{3,4}/) identifiers.concat(perc_matches) # Extract other common identifiers if name.include?("NIC") || name.include?("Ethernet") || name.include?("Network") identifiers << "NIC" end if name.include?("PERC") || name.include?("RAID") identifiers << "PERC" # Extract PERC model like H730 perc_match = name.match(/PERC\s+([A-Z]\d{3})/) identifiers << perc_match[1] if perc_match end if name.include?("BIOS") identifiers << "BIOS" end if name.include?("iDRAC") || name.include?("IDRAC") || name.include?("Remote Access Controller") identifiers << "iDRAC" end if name.include?("Power Supply") || name.include?("PSU") identifiers << "PSU" end if name.include?("Lifecycle Controller") identifiers << "LC" end if name.include?("CPLD") identifiers << "CPLD" end identifiers end |
#find_system_models(model_name) ⇒ Object
62 63 64 65 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 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 132 133 134 135 136 137 138 139 140 |
# File 'lib/idrac/firmware_catalog.rb', line 62 def find_system_models(model_name) doc = parse models = [] # Extract model code from full model name (e.g., "PowerEdge R640" -> "R640") model_code = nil if model_name.include?("PowerEdge") model_code = model_name.split.last else model_code = model_name end puts "Searching for model: #{model_name} (code: #{model_code})" # Build a mapping of model names to system IDs model_to_system_id = {} doc.xpath('//SupportedSystems/Brand/Model').each do |model| system_id = model['systemID'] || model['id'] name = model.at_xpath('Display')&.text code = model.at_xpath('Code')&.text if name && system_id model_to_system_id[name] = { name: name, code: code, id: system_id } # Also map just the model number (R640, etc.) if name =~ /[RT]\d+/ model_short = name.match(/([RT]\d+\w*)/)[1] model_to_system_id[model_short] = { name: name, code: code, id: system_id } end end end # Try exact match first if model_to_system_id[model_name] models << model_to_system_id[model_name] end # Try model code match if model_to_system_id[model_code] models << model_to_system_id[model_code] end # If we still don't have a match, try a more flexible approach if models.empty? model_to_system_id.each do |name, model_info| if name.include?(model_code) || model_code.include?(name) models << model_info end end end # If still no match, try matching by systemID directly if models.empty? doc.xpath('//SupportedSystems/Brand/Model').each do |model| system_id = model['systemID'] || model['id'] name = model.at_xpath('Display')&.text code = model.at_xpath('Code')&.text if code && code.downcase == model_code.downcase models << { name: name, code: code, id: system_id } end end end models.uniq { |m| m[:id] } end |
#find_updates_for_system(system_id) ⇒ Object
142 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 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 207 208 209 210 211 212 |
# File 'lib/idrac/firmware_catalog.rb', line 142 def find_updates_for_system(system_id) doc = parse updates = [] # Find all SoftwareComponents doc.xpath("//SoftwareComponent").each do |component| # Check if this component supports our system ID supported_system_ids = component.xpath(".//SupportedSystems/Brand/Model/@systemID | .//SupportedSystems/Brand/Model/@id").map(&:value) next unless supported_system_ids.include?(system_id) # Get component details name_node = component.xpath("./Name/Display[@lang='en']").first name = name_node ? name_node.text.strip : "" component_type_node = component.xpath("./ComponentType/Display[@lang='en']").first component_type = component_type_node ? component_type_node.text.strip : "" path = component['path'] || "" category_node = component.xpath("./Category/Display[@lang='en']").first category = category_node ? category_node.text.strip : "" # Prefer the numeric vendorVersion (e.g. "25.5.9.0001") over dellVersion, # which is just the package revision label ("A17"). Comparing that label # against an installed numeric version falsely flags every component. version = component['vendorVersion'] || component['dellVersion'] || "" # Dell componentIDs this DUP actually flashes. This is the reliable key # for matching a DUP to an installed component (see #check_updates) — # names are ambiguous (every NIC DUP says "Ethernet"), so name-matching # picks wrong DUPs and iDRAC rejects them (RED097 / "not compatible"). component_ids = component.xpath(".//SupportedDevices/Device/@componentID").map(&:value).uniq # The PCI IDs this DUP declares it can flash. The PCIe/storage half of # the iDRAC inventory reports componentID "0" (measured on an R6525: # every NIC, the PERC and all 8 NVMe drives), so componentID alone # cannot match them and the old name heuristic guessed — it offered a # Broadcom LOM an Intel package. PCI IDs are the identity both sides # publish, so a cross-vendor match becomes impossible. pci_ids = component.xpath(".//SupportedDevices/Device/PCIInfo").map { |p| pci_key(p["vendorID"], p["deviceID"], p["subVendorID"], p["subDeviceID"]) }.compact.uniq # Skip if missing essential information next if name.empty? || path.empty? || version.empty? # Only include firmware updates if component_type.include?("Firmware") || category.include?("BIOS") || category.include?("Firmware") || category.include?("iDRAC") || name.include?("BIOS") || name.include?("Firmware") || name.include?("iDRAC") updates << { name: name, version: version, path: path, component_type: component_type, category: category, component_ids: component_ids, pci_ids: pci_ids, download_url: "https://downloads.dell.com/#{path}" } end end puts "Found #{updates.size} firmware updates for system ID #{system_id}" updates end |
#match_component(firmware_name, catalog_name) ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/idrac/firmware_catalog.rb', line 332 def match_component(firmware_name, catalog_name) # Normalize names for comparison catalog_name_lower = catalog_name.downcase.strip firmware_name_lower = firmware_name.downcase.strip # 1. Direct substring match return true if catalog_name_lower.include?(firmware_name_lower) || firmware_name_lower.include?(catalog_name_lower) # 2. Special case for BIOS return true if catalog_name_lower.include?("bios") && firmware_name_lower.include?("bios") # 3. Check identifiers firmware_identifiers = extract_identifiers(firmware_name) catalog_identifiers = extract_identifiers(catalog_name) return true if (firmware_identifiers & catalog_identifiers).any? # 4. Special case for network adapters if (firmware_name_lower.include?("ethernet") || firmware_name_lower.include?("network")) && (catalog_name_lower.include?("ethernet") || catalog_name_lower.include?("network")) return true end # No match found false end |
#parse ⇒ Object
55 56 57 58 59 60 |
# File 'lib/idrac/firmware_catalog.rb', line 55 def parse raise Error, "No catalog path specified" unless @catalog_path raise Error, "Catalog file not found: #{@catalog_path}" unless File.exist?(@catalog_path) File.open(@catalog_path) { |f| Nokogiri::XML(f) } end |
#pci_key(vendor_id, device_id, sub_vendor_id, sub_device_id) ⇒ Object
Normalize one PCI ID quad to a comparable key. Dell publishes the same
four IDs on both sides but spells them differently: the catalog writes
bare uppercase hex (
220 221 222 223 224 225 226 227 |
# File 'lib/idrac/firmware_catalog.rb', line 220 def pci_key(vendor_id, device_id, sub_vendor_id, sub_device_id) parts = [vendor_id, device_id, sub_vendor_id, sub_device_id].map do |id| id.to_s.strip.sub(/\A0x/i, "").upcase end return nil if parts.any?(&:empty?) parts.map { |p| p.rjust(4, "0") }.join("/") end |
#updates_for_component(catalog_updates, fw) ⇒ Object
Select the catalog DUPs that apply to one installed component (fw from
the iDRAC inventory), most specific key first.
- Dell componentID, when the inventory gives a real one. Exact and unambiguous; unchanged.
- PCI IDs, for the entries that report componentID "0" — on an R6525 that is every NIC, the PERC and every drive. The full quad first, then vendor+device if the catalog lists no package for that exact subsystem ID. Both tiers pin the vendor, which is the whole point: name matching reduced any NIC to the token "NIC" and any RAID device to "PERC", then substring-matched the DUP's package name, so a "Broadcom NetXtreme Gigabit Ethernet" LOM was offered "Intel NIC Family Version 25.0.0 Firmware for Intel I350 and X550 Adapters" — wrong vendor — and a "PERC H755N Front" was offered the H355 package. It was also unstable: the same tool offered two identical PERCs different packages, because the winner depended on catalog order.
- The name heuristic, only when the inventory gave neither key. When PCI IDs are present they are the answer: if nothing matches them, the catalog has no package for this device, and guessing by name is how the wrong-vendor DUPs got offered in the first place.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/idrac/firmware_catalog.rb', line 249 def updates_for_component(catalog_updates, fw) component_id = fw[:component_id] if component_id && component_id != "0" return catalog_updates.select { |u| Array(u[:component_ids]).include?(component_id) } end key = pci_key(fw[:vendor_id], fw[:device_id], fw[:sub_vendor_id], fw[:sub_device_id]) if key exact = catalog_updates.select { |u| Array(u[:pci_ids]).include?(key) } return exact if exact.any? chip = key.split("/").first(2).join("/") return catalog_updates.select do |u| Array(u[:pci_ids]).any? { |k| k.start_with?("#{chip}/") } end end name = fw[:name] || "" ids = extract_identifiers(name) catalog_updates.select do |u| un = u[:name] || "" ids.any? { |id| un.downcase.include?(id.downcase) } || un.downcase.include?(name.downcase) || name.downcase.include?(un.downcase) end end |
#version_key(version) ⇒ Object
Sortable key for a Dell version string (e.g. "25.5.9.0001", "22.00.6"). Non-numeric/odd versions sort lowest rather than raising.
278 279 280 281 282 |
# File 'lib/idrac/firmware_catalog.rb', line 278 def version_key(version) Gem::Version.new(version.to_s[/\d[\d.]*/] || "0") rescue ArgumentError Gem::Version.new("0") end |