rescue Errno::ENOENT, Errno::EINVAL
end
+ def parse_disk_size(size)
+ if size =~ /^(\d+(?:\.\d+))?\s*TB/i
+ sprintf "%dTB", $1.to_f * 2**40 / 1000000000000
+ elsif size =~ /^(\d+(?:\.\d+))?\s*GB/i
+ sprintf "%dGB", $1.to_f * 2**30 / 1000000000
+ end
+ end
+
def pci_devices
device = nil
when "Device Id" then disk[:smart_devlce] = "megaraid,#{Regexp.last_match(2)}"
when "WWN" then disk[:wwn] = Regexp.last_match(2)
when "PD Type" then disk[:interface] = Regexp.last_match(2)
- when "Raw Size" then disk[:size] = Regexp.last_match(2).sub(/\s*\[.*\]$/, "")
+ when "Raw Size" then disk[:size] = parse_disk_size(Regexp.last_match(2).sub(/\s*\[.*\]$/, ""))
when "Inquiry Data" then disk[:vendor], disk[:model], disk[:serial] = Regexp.last_match(2).split
end
elsif array && line =~ /^(\S.*\S)\s*:\s+(\S.*)$/
when "Device Id" then disk[:smart_devlce] = "megaraid,#{Regexp.last_match(2)}"
when "WWN" then disk[:wwn] = Regexp.last_match(2)
when "PD Type" then disk[:interface] = Regexp.last_match(2)
- when "Raw Size" then disk[:size] = Regexp.last_match(2).sub(/\s*\[.*\]$/, "")
+ when "Raw Size" then disk[:size] = parse_disk_size(Regexp.last_match(2).sub(/\s*\[.*\]$/, ""))
when "Inquiry Data" then disk[:vendor], disk[:model], disk[:serial] = Regexp.last_match(2).split
end
end