More stronger way to detect physical data storage devices (with fixs for KVM)
Change-Id: Ia5f400a6ce137ae21e0ce99095856959039b6d41
This commit is contained in:
parent
7389f1df43
commit
fe278ad627
29
bin/agent
29
bin/agent
|
@ -224,7 +224,7 @@ class NodeAgent
|
||||||
|
|
||||||
begin
|
begin
|
||||||
(@os[:block_device] or {} rescue {}).each do |bname, binfo|
|
(@os[:block_device] or {} rescue {}).each do |bname, binfo|
|
||||||
if /^(sd|vd|hd|cciss|xvd).+$/ =~ bname and binfo
|
if physical_data_storage_devices.include?(bname) && binfo
|
||||||
dname = bname.gsub(/!/, '/')
|
dname = bname.gsub(/!/, '/')
|
||||||
# 512 bytes is the size of one sector by default
|
# 512 bytes is the size of one sector by default
|
||||||
block_size = 512
|
block_size = 512
|
||||||
|
@ -252,6 +252,33 @@ class NodeAgent
|
||||||
basepath.split("/")[2..-1].join("/") if basepath
|
basepath.split("/")[2..-1].join("/") if basepath
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def physical_data_storage_devices
|
||||||
|
@blocks ||= []
|
||||||
|
return @blocks unless @blocks.empty?
|
||||||
|
|
||||||
|
raise "Path /sys/block does not exist" unless File.exists?("/sys/block")
|
||||||
|
|
||||||
|
Dir["/sys/block/*"].each do |block_device_dir|
|
||||||
|
basename_dir = File.basename(block_device_dir)
|
||||||
|
|
||||||
|
properties = `udevadm info --query=property --export --name=#{basename_dir}`.inject({}) do |result, raw_propety|
|
||||||
|
key, value = raw_propety.split(/\=/)
|
||||||
|
result.update(key.strip => value.strip.chomp("'").reverse.chomp("'").reverse)
|
||||||
|
end
|
||||||
|
|
||||||
|
if File.exists?("/sys/block/#{basename_dir}/removable")
|
||||||
|
removable = File.open("/sys/block/#{basename_dir}/removable"){ |f| f.read_nonblock(1024).strip }
|
||||||
|
end
|
||||||
|
# look at https://github.com/torvalds/linux/blob/master/Documentation/devices.txt
|
||||||
|
# KVM virtio volumes has code 252 in CentOS, but 253 in Ubuntu
|
||||||
|
if [3, 8, 202, 252, 253].include?(properties['MAJOR'].to_i) && removable =~ /^0$/
|
||||||
|
# Exclude LVM volumes (in CentOS - 253, in Ubuntu - 252) using additional check
|
||||||
|
@blocks << basename_dir unless properties['DEVPATH'].include?('virtual')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@blocks
|
||||||
|
end
|
||||||
|
|
||||||
def _is_virtualbox
|
def _is_virtualbox
|
||||||
@os[:dmi][:system][:product_name] == "VirtualBox" rescue false
|
@os[:dmi][:system][:product_name] == "VirtualBox" rescue false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue