Created
August 18, 2011 08:50
-
-
Save dcarley/1153679 to your computer and use it in GitHub Desktop.
Facter OpenVZ HN/VE detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb | |
index a583995..a38b0a7 100644 | |
--- a/lib/facter/virtual.rb | |
+++ b/lib/facter/virtual.rb | |
@@ -158,10 +158,10 @@ Facter.add("is_virtual") do | |
confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD} | |
setcode do | |
- if Facter.value(:virtual) != "physical" && Facter.value(:virtual) != "xen0" | |
- "true" | |
- else | |
+ if ["physical", "xen0", "openvzhn"].include?(Facter.value(:virtual)) | |
"false" | |
+ else | |
+ "true" | |
end | |
end | |
end | |
diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb | |
index 68317af..d653434 100644 | |
--- a/spec/unit/virtual_spec.rb | |
+++ b/spec/unit/virtual_spec.rb | |
@@ -182,12 +182,18 @@ describe "is_virtual fact" do | |
Facter.fact(:is_virtual).value.should == "true" | |
end | |
- it "should be true when running on openvz" do | |
+ it "should be true when running on openvzve" do | |
Facter.fact(:kernel).stubs(:value).returns("Linux") | |
Facter.fact(:virtual).stubs(:value).returns("openvzve") | |
Facter.fact(:is_virtual).value.should == "true" | |
end | |
+ it "should be true when running on openvzhn" do | |
+ Facter.fact(:kernel).stubs(:value).returns("Linux") | |
+ Facter.fact(:virtual).stubs(:value).returns("openvzhn") | |
+ Facter.fact(:is_virtual).value.should == "false" | |
+ end | |
+ | |
it "should be true when running on kvm" do | |
Facter.fact(:kernel).stubs(:value).returns("Linux") | |
Facter.fact(:virtual).stubs(:value).returns("kvm") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment