Signed-off-by: James Turnbull <[email protected]>
---
 lib/facter/util/ip.rb                         |   17 +++++++-
 spec/unit/data/hpux_ifconfig_single_interface |    2 +
 spec/unit/data/hpux_netstat_all_interfaces    |    6 +++
 spec/unit/util/ip.rb                          |   51 ++++++++++++++++++++++++-
 4 files changed, 72 insertions(+), 4 deletions(-)
 create mode 100644 spec/unit/data/hpux_ifconfig_single_interface
 create mode 100644 spec/unit/data/hpux_netstat_all_interfaces

diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb
index 25acf3a..d889d99 100644
--- a/lib/facter/util/ip.rb
+++ b/lib/facter/util/ip.rb
@@ -16,9 +16,14 @@ module Facter::Util::IP
             :netmask    => /netmask\s+0x(\w{8})/
         },
         :sunos => {
-            :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
+            :ipaddress  => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
             :macaddress => 
/(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/,
             :netmask    => /netmask\s+(\w{8})/
+        },
+        :"hp-ux" => {
+            :ipaddress  => /\s+inet (\S+)\s.*/,
+            :macaddress => /(?:[0-9a-f]{2}[:-]){5}[0-9a-f]{2}/,
+            :netmask    => /.*\s+netmask (\S+)\s.*/
         }
     }
 
@@ -28,7 +33,7 @@ module Facter::Util::IP
     end
 
     def self.convert_from_hex?(kernel)
-        kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin]
+        kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, 
:"hp-ux"]
         kernels_to_convert.include?(kernel)
     end
 
@@ -60,6 +65,8 @@ module Facter::Util::IP
             output = %x{/sbin/ifconfig -a}
         when 'SunOS'
             output = %x{/usr/sbin/ifconfig -a}
+        when 'HP-UX'
+            output = %x{/bin/netstat -i}
         end
         output
     end
@@ -71,6 +78,12 @@ module Facter::Util::IP
             output = %x{/sbin/ifconfig #{interface}}
         when 'SunOS'
             output = %x{/usr/sbin/ifconfig #{interface}}
+        when 'HP-UX'
+           mac = ""
+           ifc = %x{/usr/sbin/ifconfig #{interface}}
+           %x{/usr/sbin/lanscan}.scan(/(\dx\S+).*UP\s+(\w+\d+)/).each {|i| mac 
= i[0] if i.include?(interface) }
+           mac.sub(/0x(\S+)/,'\1').scan(/../).join(":")
+           output = ifc + " " + mac
         end
         output
     end
diff --git a/spec/unit/data/hpux_ifconfig_single_interface 
b/spec/unit/data/hpux_ifconfig_single_interface
new file mode 100644
index 0000000..3a2c7f0
--- /dev/null
+++ b/spec/unit/data/hpux_ifconfig_single_interface
@@ -0,0 +1,2 @@
+lan0: flags=1843<UP,BROADCAST,RUNNING,MULTICAST,CKO>
+       inet 168.24.80.71 netmask ffffff00 broadcast 168.24.80.255
diff --git a/spec/unit/data/hpux_netstat_all_interfaces 
b/spec/unit/data/hpux_netstat_all_interfaces
new file mode 100644
index 0000000..fac7c45
--- /dev/null
+++ b/spec/unit/data/hpux_netstat_all_interfaces
@@ -0,0 +1,6 @@
+Name      Mtu  Network         Address         Ipkts   Ierrs Opkts   Oerrs Coll
+lan1      1500 10.11.0.0       latte.bkins.bor.usg.edu 
+                                               572527659 0     1129421249 0    
 0   
+lan0      1500 168.24.80.0     latte.gabest.usg.edu 
+                                               519222647 0     329127145 0     
0   
+lo0       4136 loopback        localhost       14281117 0     14281125 0     0 
diff --git a/spec/unit/util/ip.rb b/spec/unit/util/ip.rb
index 222ce9a..b40f4a5 100644
--- a/spec/unit/util/ip.rb
+++ b/spec/unit/util/ip.rb
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 require 'facter/util/ip'
 
 describe Facter::Util::IP do
-    [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin].each do |platform|
+    [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux"].each do 
|platform|
         it "should be supported on #{platform}" do
             Facter::Util::IP.supported_platforms.should be_include(platform)
         end
@@ -41,6 +41,13 @@ describe Facter::Util::IP do
         Facter::Util::IP.get_interfaces().should == ["lo0", "e1000g0"]
     end
 
+    it "should return a list three interfaces on HP-UX with three interfaces 
multiply reporting" do
+        sample_output_file = File.dirname(__FILE__) + 
'/../data/hpux_netstat_all_interfaces'
+        hpux_netstat = File.new(sample_output_file).read()
+        Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat)
+        Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"]
+    end 
+
     it "should return a value for a specific interface" do
         Facter::Util::IP.should respond_to(:get_interface_value)
     end
@@ -80,6 +87,36 @@ describe Facter::Util::IP do
         Facter::Util::IP.get_network_value("e1000g0").should == "172.16.15.0"
     end
 
+    it "should return ipaddress information for HP-UX" do
+        sample_output_file = File.dirname(__FILE__) + 
"/../data/hpux_ifconfig_single_interface"
+        hpux_ifconfig_interface = File.new(sample_output_file).read()
+
+        
Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
+        Facter.stubs(:value).with(:kernel).returns("HP-UX")
+
+        Facter::Util::IP.get_interface_value("lan0", "ipaddress").should == 
"168.24.80.71"
+    end 
+
+    it "should return netmask information for HP-UX" do
+        sample_output_file = File.dirname(__FILE__) + 
"/../data/hpux_ifconfig_single_interface"
+        hpux_ifconfig_interface = File.new(sample_output_file).read()
+
+        
Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
+        Facter.stubs(:value).with(:kernel).returns("HP-UX")
+
+        Facter::Util::IP.get_interface_value("lan0", "netmask").should == 
"255.255.255.0"
+    end 
+
+    it "should return calculated network information for HP-UX" do
+        sample_output_file = File.dirname(__FILE__) + 
"/../data/hpux_ifconfig_single_interface"
+        hpux_ifconfig_interface = File.new(sample_output_file).read()
+
+        
Facter::Util::IP.stubs(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
+        Facter.stubs(:value).with(:kernel).returns("HP-UX")
+
+        Facter::Util::IP.get_network_value("lan0").should == "168.24.80.0"
+    end 
+
     it "should return interface information for FreeBSD supported via an 
alias" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/6.0-STABLE_FreeBSD_ifconfig"
         ifconfig_interface = File.new(sample_output_file).read()
@@ -120,6 +157,16 @@ describe Facter::Util::IP do
         Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == 
"255.255.255.0"
     end
 
+    it "should return a human readable netmask on HP-UX" do
+        sample_output_file = File.dirname(__FILE__) + 
"/../data/hpux_ifconfig_single_interface"
+        hpux_ifconfig_interface = File.new(sample_output_file).read()
+
+        
Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
+        Facter.stubs(:value).with(:kernel).returns("HP-UX")
+
+        Facter::Util::IP.get_interface_value("lan0", "netmask").should == 
"255.255.255.0"
+    end 
+
     it "should return a human readable netmask on Darwin" do
         sample_output_file = File.dirname(__FILE__) + 
"/../data/darwin_ifconfig_single_interface"
 
@@ -137,7 +184,7 @@ describe Facter::Util::IP do
         Facter::Util::IP.get_bonding_master("eth0:1").should be_nil
     end
 
-    [:freebsd, :netbsd, :openbsd, :sunos, :darwin].each do |platform|
+    [:freebsd, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux"].each do |platform|
         it "should require conversion from hex on #{platform}" do
             Facter::Util::IP.convert_from_hex?(platform).should == true
         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 [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.

Reply via email to