mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
M #-: Linting monitor probes (#1259)
(cherry picked from commit a47ef89286ee3ee1c09ae1e291f648cc57607bc5)
This commit is contained in:
parent
a9cdd05cd5
commit
05848db905
@ -21,11 +21,9 @@ require 'open3'
|
||||
ENV['LANG'] = 'C'
|
||||
ENV['LC_ALL'] = 'C'
|
||||
|
||||
GUEST_ARCHS = %w(i686 x86_64)
|
||||
GUEST_ARCHS = %w[i686 x86_64]
|
||||
|
||||
begin
|
||||
|
||||
capabilities = ""
|
||||
machines = []
|
||||
models = []
|
||||
|
||||
@ -36,9 +34,9 @@ begin
|
||||
cap_xml = REXML::Document.new(capabilities)
|
||||
cap_xml = cap_xml.root
|
||||
|
||||
GUEST_ARCHS.each { |a|
|
||||
GUEST_ARCHS.each do |a|
|
||||
a_elem = cap_xml.elements["guest/arch[@name='#{a}']"]
|
||||
next if !a_elem
|
||||
next unless a_elem
|
||||
|
||||
# Evaluate the domain specific machines with higher priority
|
||||
# over the machines listed just inside the architecture.
|
||||
@ -57,7 +55,9 @@ begin
|
||||
# <domain type='kvm'>
|
||||
# <emulator>/usr/libexec/qemu-kvm</emulator>
|
||||
# <machine maxCpus='240'>pc-i440fx-rhel7.4.0</machine>
|
||||
# <machine canonical='pc-i440fx-rhel7.4.0' maxCpus='240'>pc</machine>
|
||||
# <machine canonical='pc-i440fx-rhel7.4.0' maxCpus='240'>
|
||||
# pc
|
||||
# </machine>
|
||||
# ...
|
||||
# <machine maxCpus='240'>rhel6.2.0</machine>
|
||||
# <machine maxCpus='240'>pc-i440fx-rhel7.3.0</machine>
|
||||
@ -68,36 +68,35 @@ begin
|
||||
|
||||
a_machines = []
|
||||
|
||||
['kvm', 'kqemu', 'qemu', ''].each { |type|
|
||||
['kvm', 'kqemu', 'qemu', ''].each do |type|
|
||||
if type.empty?
|
||||
d_elem = a_elem
|
||||
else
|
||||
d_elem = a_elem.elements["domain[@type='#{type}']"]
|
||||
end
|
||||
|
||||
if d_elem
|
||||
d_elem.elements.each('machine') { |m|
|
||||
a_machines << m.text
|
||||
}
|
||||
next unless d_elem
|
||||
|
||||
# take only first found domain type
|
||||
unless a_machines.empty?
|
||||
machines.concat(a_machines)
|
||||
break
|
||||
end
|
||||
d_elem.elements.each('machine') {|m| a_machines << m.text }
|
||||
|
||||
# take only first found domain type
|
||||
unless a_machines.empty?
|
||||
machines.concat(a_machines)
|
||||
break
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
cmd = "virsh -r -c qemu:///system cpu-models #{a}"
|
||||
cpu_models, e, s = Open3.capture3(cmd)
|
||||
break unless s.success?
|
||||
|
||||
cpu_models.each_line { |l|
|
||||
cpu_models.each_line do |l|
|
||||
l.chomp!
|
||||
next if l.empty? or l =~ /all CPU models are accepted/i;
|
||||
next if l.empty? || l =~ /all CPU models are accepted/i
|
||||
|
||||
models << l
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
machines.uniq!
|
||||
models.uniq!
|
||||
@ -105,6 +104,5 @@ begin
|
||||
puts "KVM_MACHINES=\"#{machines.join(' ')}\""
|
||||
puts "KVM_CPU_MODELS=\"#{models.join(' ')}\""
|
||||
puts "KVM_CPU_MODEL=\"#{cap_xml.elements['host/cpu/model'].text}\""
|
||||
|
||||
rescue
|
||||
rescue StandardError
|
||||
end
|
||||
|
@ -134,7 +134,7 @@ module NUMA
|
||||
distance_h = {}
|
||||
distance_a.each_with_index {|d, i| distance_h[d.to_i] = i }
|
||||
|
||||
distance_h = Hash[distance_h.sort]
|
||||
distance_h = distance_h.sort.to_h
|
||||
|
||||
closer = ''
|
||||
distance_h.each {|_, v| closer << v.to_s << ' ' }
|
||||
|
@ -38,14 +38,14 @@ def get_pci(filter = nil)
|
||||
command = 'lspci -mmnn'
|
||||
command << " -d #{filter}" if filter
|
||||
|
||||
text = %x(#{command})
|
||||
text = `#{command}`
|
||||
|
||||
text.split("\n").map {|l| Shellwords.split(l) }
|
||||
end
|
||||
|
||||
def get_name_and_id(text)
|
||||
m = text.match(/^(.*) \[(....)\]$/)
|
||||
return m[1], m[2]
|
||||
[m[1], m[2]]
|
||||
end
|
||||
|
||||
def parse_pci(pci)
|
||||
@ -57,8 +57,9 @@ def parse_pci(pci)
|
||||
card[:address] = "0000:#{card[:short_address].gsub(/[:.]/, ':')}"
|
||||
|
||||
begin
|
||||
numa_node = File.read("/sys/bus/pci/devices/0000:#{pci[0]}/numa_node").chomp
|
||||
rescue
|
||||
numa_node =
|
||||
File.read("/sys/bus/pci/devices/0000:#{pci[0]}/numa_node").chomp
|
||||
rescue StandardError
|
||||
numa_node = '-'
|
||||
end
|
||||
|
||||
@ -77,9 +78,9 @@ def parse_pci(pci)
|
||||
card
|
||||
end
|
||||
|
||||
def get_devices(filter=nil)
|
||||
def get_devices(filter = nil)
|
||||
if filter
|
||||
filter = [filter].flatten.map { |f| f.split(',') }.flatten
|
||||
filter = [filter].flatten.map {|f| f.split(',') }.flatten
|
||||
else
|
||||
filter = [nil]
|
||||
end
|
||||
@ -94,21 +95,22 @@ filter = CONF[:filter]
|
||||
devices = get_devices(filter)
|
||||
|
||||
def pval(name, value)
|
||||
%Q( #{name} = "#{value}")
|
||||
%( #{name} = "#{value}" )
|
||||
end
|
||||
|
||||
devices.each do |dev|
|
||||
next if !CONF[:short_address].empty? && !CONF[:short_address].include?(dev[:short_address])
|
||||
next if !CONF[:short_address].empty? &&
|
||||
!CONF[:short_address].include?(dev[:short_address])
|
||||
|
||||
if !CONF[:device_name].empty?
|
||||
matched = CONF[:device_name].each { |pattern|
|
||||
break true if !(dev[:device_name] =~ /#{pattern}/i).nil?
|
||||
}
|
||||
matched = CONF[:device_name].each do |pattern|
|
||||
break true unless (dev[:device_name] =~ /#{pattern}/i).nil?
|
||||
end
|
||||
|
||||
next if matched != true
|
||||
end
|
||||
|
||||
puts "PCI = ["
|
||||
puts 'PCI = ['
|
||||
values = [
|
||||
pval('TYPE', dev[:type]),
|
||||
pval('VENDOR', dev[:vendor]),
|
||||
@ -127,6 +129,5 @@ devices.each do |dev|
|
||||
]
|
||||
|
||||
puts values.join(",\n")
|
||||
puts "]"
|
||||
puts ']'
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user