Created
September 28, 2010 20:56
-
-
Save RamaRoberts/601760 to your computer and use it in GitHub Desktop.
This file contains 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
module Facter::Xvm | |
# | |
# Report if this a an Xvm Dom0 or a DomU. If its a Dom0, also report | |
# a list of any DomU's on the machine (that aren't shut off) | |
# | |
# ASSUMPTIONS: | |
# 1. 'uname -i' reports something unique to identify a Dom0 or a DomU | |
# 2. if the 'virsh' command *also* exists, its a Dom0 | |
# | |
def self.is_xvm_architecture | |
arch = "" | |
if File.exists?("/usr/bin/uname") | |
arch = %x{echo | /usr/bin/uname -i} | |
end | |
return arch.chomp.eql?("i86xpv") | |
end | |
def self.get_domains | |
vlist = "" | |
domains = [] | |
if File.exists?("/usr/bin/virsh") | |
vlist = %x{echo | /usr/bin/virsh list}.split("\n") | |
end | |
vlist.each do |l| | |
if l =~ /\s+\d+\s+(\S+).*?/ | |
domains << $1 unless $1.eql?("Domain-0") | |
end | |
end | |
domains | |
end | |
facter_prefix = "" | |
facter_value = "" | |
if (Facter::Xvm::is_xvm_architecture) | |
facter_prefix="xvm" | |
facter_value = "DomU" | |
end | |
domains = Facter::Xvm::get_domains | |
if (domains.length > 0) | |
#facter_prefix="xvm-domains" | |
facter_prefix="xvm" | |
facter_value = domains.join(",") | |
end | |
if (facter_value.length > 1) | |
Facter.add(facter_prefix) do | |
setcode do | |
facter_value | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment