Skip to content

Instantly share code, notes, and snippets.

@dcarley dcarley/gist:1153679
Created Aug 18, 2011

Embed
What would you like to do?
Facter OpenVZ HN/VE detection
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
You can’t perform that action at this time.