forked from puppetlabs/facter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parses `/usr/sbin/xm list` and returns a comma-separated list of domains. Based on a patch submitted by Jonas Genannt.
- Loading branch information
Rein Henrichs
authored and
Paul Berry
committed
Nov 10, 2010
1 parent
d4df963
commit f007a9d
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# A module to gather running Xen Domains | ||
# | ||
module Facter::Util::Xendomains | ||
def self.get_domains | ||
if xm_list = Facter::Util::Resolution.exec('/usr/sbin/xm list') | ||
domains = xm_list.split("\n").reject { |line| line =~ /^(Name|Domain-0)/ } | ||
domains.map { |line| line.split(/\s/)[0] }.join(',') | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'facter/util/xendomains' | ||
|
||
Facter.add("xendomains") do | ||
confine :kernel => %w{Linux FreeBSD OpenBSD SunOS} | ||
confine :virtual => 'xen0' | ||
|
||
setcode do | ||
Facter::Util::Xendomains.get_domains | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Name ID Mem VCPUs State Time(s) | ||
Domain-0 0 656 4 r----- 48140.9 | ||
web01 48 512 2 -b---- 97651.5 | ||
mailserver 53 512 4 -b---- 7536.1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.dirname(__FILE__) + '/../../spec_helper' | ||
|
||
require 'facter/util/xendomains' | ||
|
||
describe Facter::Util::Xendomains do | ||
describe ".get_domains" do | ||
it "should return a list of running Xen Domains on Xen0" do | ||
sample_output_file = File.dirname(__FILE__) + '/../data/xendomains' | ||
xen0_domains = File.read(sample_output_file) | ||
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/xm list').returns(xen0_domains) | ||
Facter::Util::Xendomains.get_domains.should == %{web01,mailserver} | ||
end | ||
|
||
context "when xm list isn't executable" do | ||
it "should be nil" do | ||
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/xm list').returns(nil) | ||
Facter::Util::Xendomains.get_domains.should == nil | ||
end | ||
end | ||
end | ||
end |