[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, upstream, updated. 51bcebe38cab6088c901f1006339bbe40a36d161

James Turnbull james at lovedthanlost.net
Wed Aug 18 05:55:51 UTC 2010


The following commit has been merged in the upstream branch:
commit ffcae46df5d5336995348544139540c0e564ae2e
Author: Jonas Genannt <jonas at brachium-system.net>
Date:   Mon Apr 12 20:23:31 2010 +0200

    Fixed #3403 - Added fact to query vlans; added spec test

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
diff --git a/spec/unit/data/linux_vlan_config b/spec/unit/data/linux_vlan_config
new file mode 100644
index 0000000..3aa7dbd
--- /dev/null
+++ b/spec/unit/data/linux_vlan_config
@@ -0,0 +1,6 @@
+VLAN Dev name	 | VLAN ID
+Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
+eth0.400       | 400  | eth0
+eth0.300       | 300  | eth0
+eth0.200       | 200  | eth0
+eth0.100       | 100  | eth0
diff --git a/spec/unit/util/vlans.rb b/spec/unit/util/vlans.rb
new file mode 100644
index 0000000..e06a2af
--- /dev/null
+++ b/spec/unit/util/vlans.rb
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'facter/util/vlans'
+
+describe Facter::Util::Vlans do
+    it "should return a list of vlans on Linux" do
+        sample_output_file = File.dirname(__FILE__) + '/../data/linux_vlan_config'
+        linux_vlanconfig = File.new(sample_output_file).read();
+        Facter::Util::Vlans.stubs(:get_vlan_config).returns(linux_vlanconfig)
+        Facter::Util::Vlans.get_vlans().should == %{400,300,200,100}
+    end
+end

-- 
Packaging of Facter for debian



More information about the Pkg-puppet-devel mailing list