lib/facter/util/ip.rb in facter-1.7.2 vs lib/facter/util/ip.rb in facter-1.7.3.rc1

- old
+ new

@@ -29,15 +29,11 @@ :"hp-ux" => { :ipaddress => /\s+inet (\S+)\s.*/, :macaddress => /(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/, :netmask => /.*\s+netmask (\S+)\s.*/ }, - :windows => { - :ipaddress => /\s+IP Address:\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, - :ipaddress6 => /Address ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, - :netmask => /\s+Subnet Prefix:\s+\S+\s+\(mask ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\)/ - } + :windows => {} } # Convert an interface name into purely alphanumeric characters. def self.alphafy(interface) interface.gsub(/[^a-z0-9_]/i, '_') @@ -59,16 +55,17 @@ result end end def self.get_interfaces + if Facter.value(:kernel) == 'windows' + require 'facter/util/ip/windows' + return Facter::Util::IP::Windows.interfaces + end + return [] unless output = Facter::Util::IP.get_all_interface_output() - # windows interface names contain spaces and are quoted and can appear multiple - # times as ipv4 and ipv6 - return output.scan(/\s* connected\s*(\S.*)/).flatten.uniq if Facter.value(:kernel) == 'windows' - # Our regex appears to be stupid, in that it leaves colons sitting # at the end of interfaces. So, we have to trim those trailing # characters. I tried making the regex better but supporting all # platforms with a single regex is probably a bit too much. output.scan(/^\S+/).collect { |i| i.sub(/:$/, '') }.uniq @@ -87,13 +84,10 @@ output.gsub!(/\*/, "") # delete asterisks. output.gsub!(/^[^\n]*none[^\n]*\n/, "") # delete lines with 'none' instead of IPs. output.sub!(/^[^\n]*\n/, "") # delete the header line. output end - when 'windows' - output = %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ip show interface| - output += %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show interface| end output end @@ -170,16 +164,13 @@ end def self.get_output_for_interface_and_label(interface, label) return get_single_interface_output(interface) unless Facter.value(:kernel) == 'windows' - if label == 'ipaddress6' - output = %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show address \"#{interface}\"| - else - output = %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ip show address \"#{interface}\"| - end - output + require 'facter/util/ip/windows' + output = Facter::Util::IP::Windows.value_for_interface_and_label(interface, label) + output ? output : "" end def self.get_bonding_master(interface) if Facter.value(:kernel) != 'Linux' return nil @@ -218,9 +209,14 @@ # @api private # # @return [String] representing the requested value. An empty array is # returned if the kernel is not supported by the REGEX_MAP constant. def self.get_interface_value(interface, label) + if Facter.value(:kernel) == 'windows' + require 'facter/util/ip/windows' + return Facter::Util::IP::Windows.value_for_interface_and_label(interface, label) + end + tmp1 = [] kernel = Facter.value(:kernel).downcase.to_sym # If it's not directly in the map or aliased in the map, then we don't know how to deal with it.