From 02c2912fb94edd37d6d7001e28714c11d5939f6d Mon Sep 17 00:00:00 2001 From: Paul Nasrat Date: Sat, 24 Jan 2009 12:52:07 +0000 Subject: Refactor - rename ipmess to interfaces --- lib/facter/interfaces.rb | 33 +++++++++++++++++++++++++++++++++ lib/facter/ipmess.rb | 33 --------------------------------- spec/unit/interfaces.rb | 19 +++++++++++++++++++ spec/unit/ipmess.rb | 19 ------------------- 4 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 lib/facter/interfaces.rb delete mode 100644 lib/facter/ipmess.rb create mode 100644 spec/unit/interfaces.rb delete mode 100644 spec/unit/ipmess.rb diff --git a/lib/facter/interfaces.rb b/lib/facter/interfaces.rb new file mode 100644 index 0000000..bf0cc6e --- /dev/null +++ b/lib/facter/interfaces.rb @@ -0,0 +1,33 @@ +# interfaces.rb +# Try to get additional Facts about the machine's network interfaces +# +# Original concept Copyright (C) 2007 psychedelys +# Update and *BSD support (C) 2007 James Turnbull +# + +require 'facter/util/ip' + +# Note that most of this only works on a fixed list of platforms; notably, Darwin +# is missing. + +Facter.add(:interfaces) do + confine :kernel => Facter::Util::IP.supported_platforms + setcode do + Facter::Util::IP.get_interfaces.collect { |iface| Facter::Util::IP.alphafy(iface) }.join(",") + end +end + +Facter::Util::IP.get_interfaces.each do |interface| + mi = Facter::Util::IP.alphafy(interface) + + # Make a fact for each detail of each interface. Yay. + # There's no point in confining these facts, since we wouldn't be able to create + # them if we weren't running on a supported platform. + %w{ipaddress macaddress netmask}.each do |label| + Facter.add(label + "_" + mi) do + setcode do + Facter::Util::IP.get_interface_value(interface, label) + end + end + end +end diff --git a/lib/facter/ipmess.rb b/lib/facter/ipmess.rb deleted file mode 100644 index 2887b64..0000000 --- a/lib/facter/ipmess.rb +++ /dev/null @@ -1,33 +0,0 @@ -# ipmess.rb -# Try to get additional Facts about the machine's network interfaces -# -# Original concept Copyright (C) 2007 psychedelys -# Update and *BSD support (C) 2007 James Turnbull -# - -require 'facter/util/ip' - -# Note that most of this only works on a fixed list of platforms; notably, Darwin -# is missing. - -Facter.add(:interfaces) do - confine :kernel => Facter::Util::IP.supported_platforms - setcode do - Facter::Util::IP.get_interfaces.collect { |iface| Facter::Util::IP.alphafy(iface) }.join(",") - end -end - -Facter::Util::IP.get_interfaces.each do |interface| - mi = Facter::Util::IP.alphafy(interface) - - # Make a fact for each detail of each interface. Yay. - # There's no point in confining these facts, since we wouldn't be able to create - # them if we weren't running on a supported platform. - %w{ipaddress macaddress netmask}.each do |label| - Facter.add(label + "_" + mi) do - setcode do - Facter::Util::IP.get_interface_value(interface, label) - end - end - end -end diff --git a/spec/unit/interfaces.rb b/spec/unit/interfaces.rb new file mode 100644 index 0000000..49d5d1f --- /dev/null +++ b/spec/unit/interfaces.rb @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../spec_helper' + +require 'facter' + +describe "Per Interface IP facts" do + before do + Facter.loadfacts + end + + it "should replace the ':' in an interface list with '_'" do + # So we look supported + Facter.fact(:kernel).stubs(:value).returns("SunOS") + + Facter::Util::IP.expects(:get_interfaces).returns %w{eth0:1 eth1:2} + Facter.fact(:interfaces).value.should == %{eth0_1,eth1_2} + end +end diff --git a/spec/unit/ipmess.rb b/spec/unit/ipmess.rb deleted file mode 100644 index a67216c..0000000 --- a/spec/unit/ipmess.rb +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../spec_helper' - -require 'facter' - -describe "Messy IP facts" do - before do - Facter.loadfacts - end - - it "should replace the ':' in an interface list with '_'" do - # So we look supported - Facter.fact(:kernel).stubs(:value).returns("SunOS") - - Facter::Util::IP.expects(:get_interfaces).returns %w{eth0:1 eth1:2} - Facter.fact(:interfaces).value.should == %{eth0_1,eth1_2} - end -end -- cgit