diff options
author | Jonas Genannt <jonas@brachium-system.net> | 2010-04-12 20:23:31 +0200 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2010-06-13 00:52:00 +1000 |
commit | ffcae46df5d5336995348544139540c0e564ae2e (patch) | |
tree | 279571bc75e50e6a8da65250667e08c7b74c22e8 /lib | |
parent | d4b8401dc4b2323a0c162e59e3f98b355d2c3c40 (diff) | |
download | facter-ffcae46df5d5336995348544139540c0e564ae2e.tar.gz facter-ffcae46df5d5336995348544139540c0e564ae2e.tar.xz facter-ffcae46df5d5336995348544139540c0e564ae2e.zip |
Fixed #3403 - Added fact to query vlans; added spec test
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facter/util/vlans.rb | 24 | ||||
-rw-r--r-- | lib/facter/vlans.rb | 8 |
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/facter/util/vlans.rb b/lib/facter/util/vlans.rb new file mode 100644 index 0000000..6d226ff --- /dev/null +++ b/lib/facter/util/vlans.rb @@ -0,0 +1,24 @@ +# A module to gather vlan facts +# +module Facter::Util::Vlans + def self.get_vlan_config + output = "" + if File.exists?('/proc/net/vlan/config') and File.readable?('/proc/net/vlan/config') + output = File.open('/proc/net/vlan/config').read + end + output + end + + def self.get_vlans + vlans = Array.new + if self.get_vlan_config + self.get_vlan_config.each do |line| + if line =~ /^([0-9A-Za-z]+)\.([0-9]+) / + vlans.insert(-1, $~[2]) if $~[2] + end + end + end + + vlans.join(',') + end +end diff --git a/lib/facter/vlans.rb b/lib/facter/vlans.rb new file mode 100644 index 0000000..d65bdd8 --- /dev/null +++ b/lib/facter/vlans.rb @@ -0,0 +1,8 @@ +require 'facter/util/vlans' + + Facter.add("vlans") do + confine :kernel => :linux + setcode do + Facter::Util::Vlans.get_vlans + end + end |