plugins_facter_mountpoints.rb

anarcat -, 02/11/2010 10:53 pm

Download (1.57 KB)

 
1
begin
2

    
3
  mountpoints = []
4
  # we show devices, but we avoid outputing duplicate devices
5
  devices = []
6
  Facter.add("mountpoints") do
7
    ignorefs = ["NFS", "nfs", "nfs4", "nfsd", "afs", "binfmt_misc", "proc", "smbfs", 
8
                "autofs", "iso9660", "ncpfs", "coda", "devpts", "ftpfs", "devfs", 
9
                "mfs", "shfs", "sysfs", "cifs", "lustre_lite", "tmpfs", "usbfs", "udf",
10
                "fusectl", "fuse.snapshotfs", "rpc_pipefs"]
11
    begin
12
      require 'filesystem'
13
    rescue Exception => e
14
      confine :kernel => :linux
15
      ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin"
16
      fs_source = nil
17
      if FileTest.exists?("/etc/mtab")
18
        fs_source = "/etc/mtab" 
19
      elsif FileTest.exists?("/proc/mounts")
20
        fs_source = "/proc/mounts" 
21
      end
22

    
23
      mounts = File.read(fs_source).split("\n")
24
      mounts.each do |mount|
25
        mount = mount.split(" ")
26
        if ((not ignorefs.include?(mount[2])) && (mount[3] !~ /bind/) && (not devices.include?(mount[0])) && (not mountpoints.include?(mount[1])))
27
                      mountpoints.push(mount[1])
28
        end
29
        devices.push(mount[0]) if not devices.include?(mount[0])
30
      end
31
    else
32
      FileSystem.mounts.each do |m| 
33
        if ((not ignorefs.include?(m.fstype)) && (m.options !~ /bind/) && !devices.include?(mount[0]))
34
          mountpoints.push(m.mount)
35
        end
36
        devices.push(m.mount) if not devices.include?(m.mount)
37
      end
38
    end
39
    setcode do
40
      mountpoints.join(",")
41
    end
42
  end
43
  Facter.add("devices") do
44
    setcode do
45
      devices.join(",")
46
    end
47
  end
48

    
49
rescue Exception => e
50
end