Signed-off-by: Jonas Genannt <[email protected]>
---
lib/facter/util/xendomains.rb | 22 ++++++++++++++++++++++
lib/facter/xendomains.rb | 11 +++++++++++
spec/unit/data/xendomains | 4 ++++
spec/unit/util/xendomains.rb | 14 ++++++++++++++
4 files changed, 51 insertions(+), 0 deletions(-)
create mode 100644 lib/facter/util/xendomains.rb
create mode 100644 lib/facter/xendomains.rb
create mode 100644 spec/unit/data/xendomains
create mode 100644 spec/unit/util/xendomains.rb
diff --git a/lib/facter/util/xendomains.rb b/lib/facter/util/xendomains.rb
new file mode 100644
index 0000000..0b3b2a2
--- /dev/null
+++ b/lib/facter/util/xendomains.rb
@@ -0,0 +1,22 @@
+# A module to gather running Xen Domains
+#
+module Facter::Util::Xendomains
+ def self.get_xm_list_output
+ output = ""
+ if File.executable?('/usr/sbin/xm')
+ output = %x{/usr/sbin/xm list}
+ end
+ output
+ end
+
+ def self.get_domains
+ domains = Array.new
+ if self.get_xm_list_output
+ self.get_xm_list_output.each do |line|
+ next if line =~ /^(Name|Domain-0)/
+ domains << line.split(/\s/)[0]
+ end
+ end
+ domains.join(',')
+ end
+end
\ No newline at end of file
diff --git a/lib/facter/xendomains.rb b/lib/facter/xendomains.rb
new file mode 100644
index 0000000..cd863e1
--- /dev/null
+++ b/lib/facter/xendomains.rb
@@ -0,0 +1,11 @@
+require 'facter/util/xendomains'
+
+Facter.add("xendomains") do
+ confine :kernel => %w{Linux FreeBSD OpenBSD SunOS}
+
+ if Facter.value(:virtual) == "xen0"
+ setcode do
+ Facter::Util::Xendomains.get_domains
+ end
+ end
+end
\ No newline at end of file
diff --git a/spec/unit/data/xendomains b/spec/unit/data/xendomains
new file mode 100644
index 0000000..9b112bc
--- /dev/null
+++ b/spec/unit/data/xendomains
@@ -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
diff --git a/spec/unit/util/xendomains.rb b/spec/unit/util/xendomains.rb
new file mode 100644
index 0000000..d4b4389
--- /dev/null
+++ b/spec/unit/util/xendomains.rb
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'facter/util/xendomains'
+
+describe Facter::Util::Xendomains do
+ it "should return a list of running Xen Domains on Xen0" do
+ sample_output_file = File.dirname(__FILE__) + '/../data/xendomains'
+ xen0_domains = File.new(sample_output_file).read();
+ Facter::Util::Xendomains.stubs(:get_xm_list_output).returns(xen0_domains)
+ Facter::Util::Xendomains.get_domains().should == %{web01,mailserver}
+ end
+end
--
1.7.1
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.