1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-29 21:47:02 +03:00

Feature #3028: Add PCI dev checks to onedb fsck

This commit is contained in:
Carlos Martín 2015-08-25 13:17:42 +02:00
parent a2e7ccffe1
commit 18946ff3b8

View File

@ -938,7 +938,7 @@ EOT
# Calculate the host's xml and write them to host_pool_new
@db.transaction do
@db[:host_pool].each do |row|
host_doc = Document.new(row[:body])
host_doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
hid = row[:oid]
@ -949,54 +949,67 @@ EOT
mem_usage = counters_host[:memory]*1024
# rewrite running_vms
host_doc.root.each_element("HOST_SHARE/RUNNING_VMS") {|e|
host_doc.root.xpath("HOST_SHARE/RUNNING_VMS").each {|e|
if e.text != rvms.to_s
log_error(
"Host #{hid} RUNNING_VMS has #{e.text} \tis\t#{rvms}")
e.text = rvms
e.content = rvms
end
}
# re-do list of VM IDs
vms_elem = host_doc.root.elements.delete("VMS")
vms_elem = host_doc.root.at_xpath("VMS").remove
vms_new_elem = host_doc.root.add_element("VMS")
vms_new_elem = host_doc.create_element("VMS")
host_doc.root.add_child(vms_new_elem)
counters_host[:rvms].each do |id|
id_elem = vms_elem.elements.delete("ID[.=#{id}]")
id_elem = vms_elem.at_xpath("ID[.=#{id}]")
if id_elem.nil?
log_error(
"VM #{id} is missing from Host #{hid} VM id list")
else
id_elem.remove
end
vms_new_elem.add_element("ID").text = id.to_s
vms_new_elem.add_child(host_doc.create_element("ID")).content = id.to_s
end
vms_elem.each_element("ID") do |id_elem|
vms_elem.xpath("ID").each do |id_elem|
log_error(
"VM #{id_elem.text} is in Host #{hid} VM id list, "<<
"but it should not")
end
host_doc.root.xpath("HOST_SHARE/PCI_DEVICES/PCI").each do |pci|
if !pci.at_xpath("VMID").nil?
vmid = pci.at_xpath("VMID").text.to_i
if vmid != -1 && !counters_host[:rvms].include?(vmid)
log_error("VM #{vmid} has a PCI device assigned in host #{hid}, but it should not. Device: #{pci.at_xpath('DEVICE_NAME').text}")
pci.at_xpath("VMID").content = "-1"
end
end
end
# rewrite cpu
host_doc.root.each_element("HOST_SHARE/CPU_USAGE") {|e|
host_doc.root.xpath("HOST_SHARE/CPU_USAGE").each {|e|
if e.text != cpu_usage.to_s
log_error(
"Host #{hid} CPU_USAGE has #{e.text} "<<
"\tis\t#{cpu_usage}")
e.text = cpu_usage
e.content = cpu_usage
end
}
# rewrite memory
host_doc.root.each_element("HOST_SHARE/MEM_USAGE") {|e|
host_doc.root.xpath("HOST_SHARE/MEM_USAGE").each {|e|
if e.text != mem_usage.to_s
log_error("Host #{hid} MEM_USAGE has #{e.text} "<<
"\tis\t#{mem_usage}")
e.text = mem_usage
e.content = mem_usage
end
}