Sha256: 7584715a3825cd76b69c1cde697ffff87edca3fe1ccb55f45f44f12e621ba848
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 KB
Contents
require 'util/miq-xml' require 'metadata/VmConfig/VmConfig' require 'awesome_spawn' class GetNativeCfg def self.new lshwXml = AwesomeSpawn.run!("lshw", :params => ["-xml"], :combined_output => true).output nodeHash = Hash.new { |h, k| h[k] = [] } doc = MiqXml.load(lshwXml) doc.find_match("//node").each { |n| nodeHash[n.attributes["id"].split(':', 2)[0]] << n } hardware = "" nodeHash["disk"].each do |d| diskid = d.find_first('businfo').get_text.to_s next unless diskid sn = d.find_first('size') # If there's no size node, assume it's a removable drive. next unless sn busType, busAddr = diskid.split('@', 2) if busType == "scsi" f1, f2 = busAddr.split(':', 2) f2 = f2.split('.')[1] busAddr = "#{f1}:#{f2}" else busAddr['.'] = ':' end diskid = busType + busAddr filename = d.find_first('logicalname').get_text.to_s hardware += "#{diskid}.present = \"TRUE\"\n" hardware += "#{diskid}.filename = \"#{filename}\"\n" end VmConfig.new(hardware) end end if __FILE__ == $0 cfg = GetNativeCfg.new cfg.getDiskFileHash.each { |dtag, df| puts "#{dtag}\t=> #{df}" } end
Version data entries
3 entries across 3 versions & 1 rubygems