[Puppet-dev] [PATCH/facter 1/1] Fixed #2847 - Added mountpoint fact

7 views
Skip to first unread message

James Turnbull

unread,
Apr 30, 2010, 4:53:34 AM4/30/10
to puppe...@googlegroups.com

Signed-off-by: James Turnbull <ja...@lovedthanlost.net>
---
lib/facter/mountpoints.rb | 50 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
create mode 100644 lib/facter/mountpoints.rb

diff --git a/lib/facter/mountpoints.rb b/lib/facter/mountpoints.rb
new file mode 100644
index 0000000..c51e6e6
--- /dev/null
+++ b/lib/facter/mountpoints.rb
@@ -0,0 +1,50 @@
+begin
+
+ mountpoints = []
+ # we show devices, but we avoid outputing duplicate devices
+ devices = []
+ Facter.add("mountpoints") do
+ ignorefs = ["NFS", "nfs", "nfs4", "nfsd", "afs", "binfmt_misc", "proc", "smbfs",
+ "autofs", "iso9660", "ncpfs", "coda", "devpts", "ftpfs", "devfs",
+ "mfs", "shfs", "sysfs", "cifs", "lustre_lite", "tmpfs", "usbfs", "udf",
+ "fusectl", "fuse.snapshotfs", "rpc_pipefs"]
+ begin
+ require 'filesystem'
+ rescue Exception => e
+ confine :kernel => :linux
+ ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin"
+ fs_source = nil
+ if FileTest.exists?("/etc/mtab")
+ fs_source = "/etc/mtab"
+ elsif FileTest.exists?("/proc/mounts")
+ fs_source = "/proc/mounts"
+ end
+
+ mounts = File.read(fs_source).split("\n")
+ mounts.each do |mount|
+ mount = mount.split(" ")
+ if ((not ignorefs.include?(mount[2])) && (mount[3] !~ /bind/) && (not devices.include?(mount[0])) && (not mountpoints.include?(mount[1])))
+ mountpoints.push(mount[1])
+ end
+ devices.push(mount[0]) if not devices.include?(mount[0])
+ end
+ else
+ FileSystem.mounts.each do |m|
+ if ((not ignorefs.include?(m.fstype)) && (m.options !~ /bind/) && !devices.include?(mount[0]))
+ mountpoints.push(m.mount)
+ end
+ devices.push(m.mount) if not devices.include?(m.mount)
+ end
+ end
+ setcode do
+ mountpoints.join(",")
+ end
+ end
+ Facter.add("devices") do
+ setcode do
+ devices.join(",")
+ end
+ end
+
+rescue Exception => e
+end
--
1.6.6.1

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppe...@googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Luke Kanies

unread,
Apr 30, 2010, 1:17:23 PM4/30/10
to puppe...@googlegroups.com
I'm confused by this - why is the whole fact definition inside the
rescue block? Is this a case where we have one means of finding the
mounts if the 'filesystem' lib is available, and a different if it's
not?

In that case, I think it makes more sense to just have different fact
resolutions, one of which requires the filesystem lib.
--
Dawkins's Law of Adversarial Debate:
When two incompatible beliefs are advocated with equal intensity,
the truth does not lie half way between them.
---------------------------------------------------------------------
Luke Kanies -|- http://puppetlabs.com -|- +1(615)594-8199
Reply all
Reply to author
Forward
0 new messages