Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new OpenVZ proc files #39

Closed
wants to merge 12 commits into from
7 changes: 4 additions & 3 deletions lib/ohai/plugins/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
def has_ec2_mac?
network[:interfaces].values.each do |iface|
unless iface[:arp].nil?
has_mac = iface[:arp].value?("fe:ff:ff:ff:ff:ff")
Ohai::Log.debug("has_ec2_mac? == true")
return true if has_mac
if iface[:arp].value?("fe:ff:ff:ff:ff:ff")
Ohai::Log.debug("has_ec2_mac? == true")
return true
end
end
end
Ohai::Log.debug("has_ec2_mac? == false")
Expand Down
17 changes: 8 additions & 9 deletions lib/ohai/plugins/linux/virtualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,14 @@
end
end

# http://wiki.openvz.org/Proc/user_beancounters
if File.exists?("/proc/user_beancounters")
if File.read("/proc/user_beancounters") =~ /\n\s+0:\s+/
virtualization[:emulator] = "openvz"
virtualization[:role] = "host"
else
virtualization[:emulator] = "openvz"
virtualization[:role] = "guest"
end
# Detect OpenVZ / Virtuozzo.
# http://wiki.openvz.org/BC_proc_entries
if File.exists?("/proc/bc/0")
virtualization[:system] = "openvz"
virtualization[:role] = "host"
elsif File.exists?("/proc/vz")
virtualization[:system] = "openvz"
virtualization[:role] = "guest"
end

# http://www.dmo.ca/blog/detecting-virtualization-on-linux
Expand Down
7 changes: 5 additions & 2 deletions lib/ohai/plugins/sigar/network_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@ def flags(flags)
f
end

# From sigar: include/sigar.h sigar_net_route_t
SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname]

sigar=Sigar.new
sigar.net_route_list.each do |route|
next unless network[:interfaces][route.ifname] # this should never happen
network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
route_data={}
(route.methods-Object.methods).each do |m|
SIGAR_ROUTE_METHODS.each do |m|
if(m == :flags)
route_data[m]=flags(route.send(m))
else
route_data[m]=route.send(m)
end
end
network[:interfaces][route.ifname][:route][route.destination] = route_data
end
end
2 changes: 1 addition & 1 deletion lib/ohai/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

module Ohai
OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
VERSION = '0.6.11'
VERSION = '0.6.12.rc.1'
end

18 changes: 9 additions & 9 deletions spec/ohai/plugins/linux/virtualization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,24 @@
end
end
describe "when we are checking for openvz" do
it "should set openvz host if /proc/user_beancounters contains 0:" do
File.should_receive(:exists?).with("/proc/user_beancounters").and_return(true)
File.stub!(:read).with("/proc/user_beancounters").and_return("\n 0: ")
it "should set openvz host if /proc/bc/0 exists" do
File.should_receive(:exists?).with("/proc/bc/0").and_return(true)
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization][:emulator].should == "openvz"
@ohai[:virtualization][:system].should == "openvz"
@ohai[:virtualization][:role].should == "host"
end

it "should set openvz guest if /proc/user_beancounters doesn't contain 0:" do
File.should_receive(:exists?).with("/proc/user_beancounters").and_return(true)
File.stub!(:read).with("/proc/user_beancounters").and_return("101:")
it "should set openvz guest if /proc/bc/0 doesn't exist and /proc/vz exists" do
File.should_receive(:exists?).with("/proc/bc/0").and_return(false)
File.should_receive(:exists?).with("/proc/vz").and_return(true)
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization][:emulator].should == "openvz"
@ohai[:virtualization][:system].should == "openvz"
@ohai[:virtualization][:role].should == "guest"
end

it "should not set virtualization if openvz isn't there" do
File.should_receive(:exists?).at_least(:once).and_return(false)
File.should_receive(:exists?).with("/proc/bc/0").and_return(false)
File.should_receive(:exists?).with("/proc/vz").and_return(false)
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization].should == {}
end
Expand Down
5 changes: 3 additions & 2 deletions spec/ohai/plugins/sigar/network_route_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@
@net_route_conf={
:destination => "192.168.1.0",
:gateway => "0.0.0.0",
:mask => "255.255.255.0",
:flags => 1,
:refcnt => 0,
:use => 0,
:ifname => "eth0",
:metric => 0,
:mtu => 0,
:window => 0,
:irtt => 0
:irtt => 0,
:ifname => "eth0"
}
net_route=double("Sigar::NetRoute")
@net_route_conf.each_pair do |k,v|
Expand Down