Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eac5876
commit 2efa1fb
Showing
4 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ageiq/providers/lenovo/physical_infra_manager/parsers/components/storage_device_parser.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
require_relative 'component_parser' | ||
|
||
module ManageIQ::Providers::Lenovo | ||
module Parsers | ||
class StorageDeviceParser < ComponentParser | ||
class << self | ||
# | ||
# @param [XClarityClient::Node] component - component that has storage devices | ||
# | ||
def parse_storage_device(component) | ||
devices = select_storage_devices(component) | ||
|
||
devices.map! do |device| | ||
parse_device(device) | ||
end | ||
|
||
distinct_storage_devices(devices) | ||
end | ||
|
||
private | ||
|
||
# | ||
# Mount the storage device from a hash object | ||
# | ||
# @param [Hash] device - a hash containing the storage device informations | ||
# | ||
def parse_device(device) | ||
{ | ||
:uid_ems => mount_uuid(device), | ||
:device_name => device["productName"] ? device["productName"] : device["name"], | ||
:device_type => "storage", | ||
:firmwares => parse_device_firmware(device), | ||
:manufacturer => device["manufacturer"], | ||
:field_replaceable_unit => device["FRU"], | ||
:location => device['slotNumber'] ? "Bay #{device['slotNumber']}" : nil, | ||
:controller_type => device["class"], | ||
} | ||
end | ||
|
||
# | ||
# Selects all storage devices. | ||
# The storage devices could be in `pci_devices` or `addin_cards` prop | ||
# | ||
def select_storage_devices(component) | ||
pci_devices = component.try(:pciDevices).try(:select) { |device| storage_device?(device) } | ||
addin_cards = component.try(:addinCards).try(:select) { |device| storage_device?(device) } | ||
|
||
devices = [] | ||
devices.concat(pci_devices) if pci_devices.present? | ||
devices.concat(addin_cards) if addin_cards.present? | ||
devices | ||
end | ||
|
||
def distinct_storage_devices(devices) | ||
devices.uniq { |device| device[:uid_ems] } | ||
end | ||
|
||
def storage_device?(device) | ||
device_name = device["name"].try(:downcase) | ||
device["class"] == "Mass storage controller" || device_name =~ /serveraid/ || device_name =~ /sd media raid/ | ||
end | ||
|
||
def parse_device_firmware(device) | ||
device_fw = [] | ||
|
||
firmware = device["firmware"] | ||
unless firmware.nil? | ||
device_fw = firmware.map do |fw| | ||
parse_firmware(fw) | ||
end | ||
end | ||
|
||
device_fw | ||
end | ||
|
||
def parse_firmware(firmware) | ||
{ | ||
:name => "#{firmware["role"]} #{firmware["name"]}-#{firmware["status"]}", | ||
:build => firmware["build"], | ||
:version => firmware["version"], | ||
:release_date => firmware["date"], | ||
} | ||
end | ||
|
||
def mount_uuid(device) | ||
device["uuid"] || "#{device['pciBusNumber']}#{device['pciDeviceNumber']}#{device['pciFunctionNumber']}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters