diff options
author | James Gartrell <jgartrel@quaz.local> | 2009-02-06 20:53:45 -0800 |
---|---|---|
committer | James Gartrell <jgartrel@stevenbeulow2.servepath.com> | 2009-03-03 17:50:22 -0800 |
commit | 09897bf7d63d465e88f8b5f8733876adc163771c (patch) | |
tree | 959ef0906597a26e0d8e9187d8c4134d8e039356 | |
parent | f2989cb42d7774abfe9e5416061a9901fabdffc0 (diff) | |
download | ohai-09897bf7d63d465e88f8b5f8733876adc163771c.tar.gz |
Adding support for windows
-rw-r--r-- | lib/ohai/mixin/command.rb | 50 | ||||
-rw-r--r-- | lib/ohai/mixin/string.rb | 82 | ||||
-rw-r--r-- | lib/ohai/plugins/erlang.rb | 30 | ||||
-rw-r--r-- | lib/ohai/plugins/java.rb | 7 | ||||
-rw-r--r-- | lib/ohai/plugins/kernel.rb | 17 | ||||
-rw-r--r-- | lib/ohai/plugins/mswin32/hostname.rb | 50 | ||||
-rw-r--r-- | lib/ohai/plugins/mswin32/kernel.rb | 124 | ||||
-rw-r--r-- | lib/ohai/plugins/mswin32/network.rb | 230 | ||||
-rw-r--r-- | lib/ohai/plugins/mswin32/platform.rb | 42 | ||||
-rw-r--r-- | lib/ohai/plugins/python.rb | 10 | ||||
-rw-r--r-- | lib/ohai/system.rb | 1 |
11 files changed, 328 insertions, 315 deletions
diff --git a/lib/ohai/mixin/command.rb b/lib/ohai/mixin/command.rb index 77de69f7..4f909cba 100644 --- a/lib/ohai/mixin/command.rb +++ b/lib/ohai/mixin/command.rb @@ -25,6 +25,7 @@ require 'ohai/log' require 'tmpdir' require 'fcntl' require 'etc' +require 'systemu' module Ohai module Mixin @@ -40,24 +41,7 @@ module Ohai stdout_string = nil stderr_string = nil - - exec_processing_block = lambda do |pid, stdin, stdout, stderr| - stdin.close - - stdout_string = stdout.gets(nil) - if stdout_string - Ohai::Log.debug("---- Begin #{args[:command]} STDOUT ----") - Ohai::Log.debug(stdout_string.strip) - Ohai::Log.debug("---- End #{args[:command]} STDOUT ----") - end - stderr_string = stderr.gets(nil) - if stderr_string - Ohai::Log.debug("---- Begin #{args[:command]} STDERR ----") - Ohai::Log.debug(stderr_string.strip) - Ohai::Log.debug("---- End #{args[:command]} STDERR ----") - end - end - + args[:cwd] ||= Dir.tmpdir unless File.directory?(args[:cwd]) raise Ohai::Exception::Exec, "#{args[:cwd]} does not exist or is not a directory" @@ -68,26 +52,44 @@ module Ohai if args[:timeout] begin Timeout.timeout(args[:timeout]) do - status = popen4(args[:command], args, &exec_processing_block) + status, stdout_string, stderr_string = systemu(args[:command]) end rescue Exception => e Ohai::Log.error("#{args[:command_string]} exceeded timeout #{args[:timeout]}") raise(e) end else - status = popen4(args[:command], args, &exec_processing_block) + status, stdout_string, stderr_string = systemu(args[:command]) + end + + # systemu returns 42 when it hits unexpected errors + if status.exitstatus == 42 and stderr_string == "" + stderr_string = "Failed to run: #{args[:command]}, assuming command not found" + Ohai::Log.debug(stderr_string) + end + + if stdout_string + Ohai::Log.debug("---- Begin #{args[:command]} STDOUT ----") + Ohai::Log.debug(stdout_string.strip) + Ohai::Log.debug("---- End #{args[:command]} STDOUT ----") + end + if stderr_string + Ohai::Log.debug("---- Begin #{args[:command]} STDERR ----") + Ohai::Log.debug(stderr_string.strip) + Ohai::Log.debug("---- End #{args[:command]} STDERR ----") end args[:returns] ||= 0 - if status.exitstatus != args[:returns] - raise Ohai::Exception::Exec, "#{args[:command_string]} returned #{status.exitstatus}, expected #{args[:returns]}" + args[:no_status_check] ||= false + if status.exitstatus != args[:returns] and not args[:no_status_check] + raise Ohai::Exception::Exec, "#{args[:command]} returned #{status.exitstatus}, expected #{args[:returns]}" else Ohai::Log.debug("Ran #{args[:command_string]} (#{args[:command]}) returned #{status.exitstatus}") end end return status, stdout_string, stderr_string end - + module_function :run_command # This is taken directly from Ara T Howard's Open4 library, and then @@ -195,4 +197,4 @@ module Ohai module_function :popen4 end end -end
\ No newline at end of file +end diff --git a/lib/ohai/mixin/string.rb b/lib/ohai/mixin/string.rb index 63347142..70e78ee5 100644 --- a/lib/ohai/mixin/string.rb +++ b/lib/ohai/mixin/string.rb @@ -1,41 +1,41 @@ -#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-class String
- def underscore
- self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
- gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
- end
-end
-
-#module Ohai
-# module Mixin
-# module Inflections
-# # Add string function to handle WMI conversion
-# #
-# #
-# #
-# class String
-# def underscore
-# self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
-# gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
-# end
-# end
-# end
-# end
-#end
+# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +class String + def underscore + self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). + gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase + end +end + +#module Ohai +# module Mixin +# module Inflections +# # Add string function to handle WMI conversion +# # +# # +# # +# class String +# def underscore +# self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). +# gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase +# end +# end +# end +# end +#end diff --git a/lib/ohai/plugins/erlang.rb b/lib/ohai/plugins/erlang.rb index 6c58589f..0ef7ec62 100644 --- a/lib/ohai/plugins/erlang.rb +++ b/lib/ohai/plugins/erlang.rb @@ -20,18 +20,24 @@ require_plugin "languages" output = nil erlang = Mash.new -status = popen4("erl +V") do |pid, stdin, stdout, stderr| - stdin.close - output = stderr.gets.split if stderr - options = output[1] - options.gsub!(/(\(|\))/, '') - erlang[:version] = output[5] - erlang[:options] = options.split(',') - erlang[:emulator] = output[2].gsub!(/(\(|\))/, '') -end +case languages[:ruby][:host_os] +when /mswin32/ + # do nothing + true +else + status = popen4("erl +V") do |pid, stdin, stdout, stderr| + stdin.close + output = stderr.gets.split if stderr + options = output[1] + options.gsub!(/(\(|\))/, '') + erlang[:version] = output[5] + erlang[:options] = options.split(',') + erlang[:emulator] = output[2].gsub!(/(\(|\))/, '') + end -if status == 0 - if erlang[:version] and erlang[:options] and erlang[:emulator] - languages[:erlang] = erlang + if status == 0 + if erlang[:version] and erlang[:options] and erlang[:emulator] + languages[:erlang] = erlang + end end end diff --git a/lib/ohai/plugins/java.rb b/lib/ohai/plugins/java.rb index b7cfab1f..4f0579ee 100644 --- a/lib/ohai/plugins/java.rb +++ b/lib/ohai/plugins/java.rb @@ -19,9 +19,10 @@ require_plugin "languages" java = Mash.new -status = popen4("java -version") do |pid, stdin, stdout, stderr| - stdin.close - stderr.each do |line| + +status, stdout, stderr = run_command(:no_status_check => true, :command => "java -version") +if status == 0 + stderr.split("\n").each do |line| case line when /java version \"([0-9\.\_]+)\"/: java[:version] = $1 when /^(.+Runtime Environment.*) \(build (.+)\)$/: java[:runtime] = { "name" => $1, "build" => $2 } diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb index 514b4294..2f73f53e 100644 --- a/lib/ohai/plugins/kernel.rb +++ b/lib/ohai/plugins/kernel.rb @@ -16,9 +16,16 @@ # limitations under the License. # +require_plugin 'ruby' + kernel Mash.new -kernel[:name] = from("uname -s") -kernel[:release] = from("uname -r") -kernel[:version] = from("uname -v") -kernel[:machine] = from("uname -m") -kernel[:modules] = Mash.new +case languages[:ruby][:host_os] +when /mswin32/ + require_plugin "#{languages[:ruby][:host_os]}::kernel" +else + kernel[:name] = from("uname -s") + kernel[:release] = from("uname -r") + kernel[:version] = from("uname -v") + kernel[:machine] = from("uname -m") + kernel[:modules] = Mash.new +end diff --git a/lib/ohai/plugins/mswin32/hostname.rb b/lib/ohai/plugins/mswin32/hostname.rb index 91c07a15..513de4b9 100644 --- a/lib/ohai/plugins/mswin32/hostname.rb +++ b/lib/ohai/plugins/mswin32/hostname.rb @@ -1,25 +1,25 @@ -#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'ruby-wmi'
-require 'socket'
-host = WMI::Win32_ComputerSystem.find(:first)
-
-hostname "#{host.Name}"
-#hostname "#{Socket.gethostname}"
-fqdn "#{Socket.gethostbyname(Socket.gethostname).first}"
\ No newline at end of file +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'ruby-wmi' +require 'socket' +host = WMI::Win32_ComputerSystem.find(:first) + +hostname "#{host.Name}" +#hostname "#{Socket.gethostname}" +fqdn "#{Socket.gethostbyname(Socket.gethostname).first}" diff --git a/lib/ohai/plugins/mswin32/kernel.rb b/lib/ohai/plugins/mswin32/kernel.rb index e4686124..8abbd01a 100644 --- a/lib/ohai/plugins/mswin32/kernel.rb +++ b/lib/ohai/plugins/mswin32/kernel.rb @@ -1,62 +1,62 @@ -#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'ruby-wmi'
-host = WMI::Win32_OperatingSystem.find(:first)
-
-kernel[:name] = "#{host.Caption}"
-kernel[:release] = "#{host.Version}"
-kernel[:version] = "#{host.Version} Service Pack #{host.ServicePackMajorVersion} Build #{host.BuildNumber}"
-kernel[:machine] = languages[:ruby][:target_cpu]
-kernel[:os] = languages[:ruby][:host_os]
-#kernel[:os] = from("arp /a")
-
-kext = Mash.new
-pnp_drivers = Mash.new
-
-#popen4("/sbin/lsmod") do |pid, stdin, stdout, stderr|
-# stdin.close
-# stdout.each do |line|
-# if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
-# kext[$1] = { :size => $2, :refcount => $3 }
-# end
-# end
-#end
-
-drivers = WMI::Win32_PnPSignedDriver.find(:all)
-drivers.each do |driver|
- pnp_drivers[driver.DeviceID] = Mash.new
- driver.properties_.each do |p|
- pnp_drivers[driver.DeviceID][p.name.underscore.to_sym] = driver[p.name]
- end
- if driver.DeviceName
- #kext[driver.DeviceName] = { :version => driver.DriverVersion,
- # :signed => driver.IsSigned,
- # :signer => driver.Signer,
- # :id => driver.DeviceID,
- # :class => driver.DeviceClass,
- # :date => driver.DriverDate ? driver.DriverDate.to_s[0..7] : nil
- # }
- kext[driver.DeviceName] = pnp_drivers[driver.DeviceID]
- kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version]
- kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil
- end
-end
-
-kernel[:pnp_drivers] = pnp_drivers
-kernel[:modules] = kext
+# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'ruby-wmi' +host = WMI::Win32_OperatingSystem.find(:first) + +kernel[:name] = "#{host.Caption}" +kernel[:release] = "#{host.Version}" +kernel[:version] = "#{host.Version} Service Pack #{host.ServicePackMajorVersion} Build #{host.BuildNumber}" +kernel[:machine] = languages[:ruby][:target_cpu] +kernel[:os] = languages[:ruby][:host_os] +#kernel[:os] = from("arp /a") + +kext = Mash.new +pnp_drivers = Mash.new + +#popen4("/sbin/lsmod") do |pid, stdin, stdout, stderr| +# stdin.close +# stdout.each do |line| +# if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/ +# kext[$1] = { :size => $2, :refcount => $3 } +# end +# end +#end + +drivers = WMI::Win32_PnPSignedDriver.find(:all) +drivers.each do |driver| + pnp_drivers[driver.DeviceID] = Mash.new + driver.properties_.each do |p| + pnp_drivers[driver.DeviceID][p.name.underscore.to_sym] = driver[p.name] + end + if driver.DeviceName + #kext[driver.DeviceName] = { :version => driver.DriverVersion, + # :signed => driver.IsSigned, + # :signer => driver.Signer, + # :id => driver.DeviceID, + # :class => driver.DeviceClass, + # :date => driver.DriverDate ? driver.DriverDate.to_s[0..7] : nil + # } + kext[driver.DeviceName] = pnp_drivers[driver.DeviceID] + kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version] + kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil + end +end + +kernel[:pnp_drivers] = pnp_drivers +kernel[:modules] = kext diff --git a/lib/ohai/plugins/mswin32/network.rb b/lib/ohai/plugins/mswin32/network.rb index c6ec36d9..8260cf3d 100644 --- a/lib/ohai/plugins/mswin32/network.rb +++ b/lib/ohai/plugins/mswin32/network.rb @@ -1,116 +1,114 @@ -#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'ruby-wmi'
-
-def encaps_lookup(encap)
- return "Ethernet" if encap.eql?("Ethernet 802.3")
- encap
-end
-
-def derive_bcast(ipaddr, ipmask, zero_bcast = false)
- begin
- ipaddr_int = ipaddr.split(".").collect{ |x| x.to_i}.pack("C4").unpack("N").first
- ipmask_int = ipmask.split(".").collect{ |x| x.to_i}.pack("C4").unpack("N").first
- if zero_bcast
- bcast_int = ipaddr_int & ipmask_int
- else
- bcast_int = ipaddr_int | 2 ** 32 - ipmask_int - 1
- end
- bcast = [bcast_int].pack("N").unpack("C4").join(".")
- return bcast
- rescue
- return nil
- end
-end
-
-iface = Mash.new
-iface_config = Mash.new
-iface_instance = Mash.new
-
-adapters = WMI::Win32_NetworkAdapterConfiguration.find(:all)
-adapters.each do |adapter|
- i = adapter.Index
- iface_config[i] = Mash.new
- adapter.properties_.each do |p|
- iface_config[i][p.name.underscore.to_sym] = adapter[p.name]
- end
-end
-
-adapters = WMI::Win32_NetworkAdapter.find(:all)
-adapters.each do |adapter|
- i = adapter.Index
- iface_instance[i] = Mash.new
- adapter.properties_.each do |p|
- iface_instance[i][p.name.underscore.to_sym] = adapter[p.name]
- end
-end
-
-iface_instance.keys.each do |i|
- if iface_config[i][:ip_enabled] and iface_instance[i][:net_connection_id] and iface_instance[i][:interface_index]
- cint = sprintf("0x%X", iface_instance[i][:interface_index])
- iface[cint] = Mash.new
- iface[cint][:configuration] = iface_config[i]
- iface[cint][:instance] = iface_instance[i]
-
- iface[cint][:counters] = Mash.new
- iface[cint][:addresses] = []
- iface[cint][:configuration][:ip_address].each_index do |i|
- begin
- if iface[cint][:configuration][:ip_address][i] =~ /./
- iface[cint][:addresses] << {
- "family" => "inet",
- "address" => iface[cint][:configuration][:ip_address][i],
- "netmask" => iface[cint][:configuration][:ip_subnet][i],
- "broadcast" => derive_bcast( iface[cint][:configuration][:ip_address][i],
- iface[cint][:configuration][:ip_subnet][i],
- iface[cint][:configuration][:ip_use_zero_broadcast]
- )
- }
- end
- rescue
- end
- end
- iface[cint][:configuration][:mac_address].each do |mac_addr|
- iface[cint][:addresses] << {
- "family" => "lladdr",
- "address" => mac_addr
- }
- end
- iface[cint][:mtu] = iface[cint][:configuration][:mtu]
- iface[cint][:type] = iface[cint][:instance][:adapter_type]
- iface[cint][:arp] = {}
- iface[cint][:encapsulation] = encaps_lookup(iface[cint][:instance][:adapter_type])
- end
-end
-
-cint=nil
-from("arp /a").split("\n").each do |line|
- if line == ""
- cint = nil
- end
- if line =~ /^Interface:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+[-]+\s+(0x\d+)/
- cint = $2
- end
- next unless iface[cint]
- if line =~ /^\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-fA-F0-9\:-]+)/
- iface[cint][:arp][$1] = $2.gsub("-",":").downcase
- end
-end
-
-network["interfaces"] = iface
+# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'ruby-wmi' + +def encaps_lookup(encap) + return "Ethernet" if encap.eql?("Ethernet 802.3") + encap +end + +def derive_bcast(ipaddr, ipmask, zero_bcast = false) + begin + ipaddr_int = ipaddr.split(".").collect{ |x| x.to_i}.pack("C4").unpack("N").first + ipmask_int = ipmask.split(".").collect{ |x| x.to_i}.pack("C4").unpack("N").first + if zero_bcast + bcast_int = ipaddr_int & ipmask_int + else + bcast_int = ipaddr_int | 2 ** 32 - ipmask_int - 1 + end + bcast = [bcast_int].pack("N").unpack("C4").join(".") + return bcast + rescue + return nil + end +end + +iface = Mash.new +iface_config = Mash.new +iface_instance = Mash.new + +adapters = WMI::Win32_NetworkAdapterConfiguration.find(:all) +adapters.each do |adapter| + i = adapter.Index + iface_config[i] = Mash.new + adapter.properties_.each do |p| + iface_config[i][p.name.underscore.to_sym] = adapter[p.name] + end +end + +adapters = WMI::Win32_NetworkAdapter.find(:all) +adapters.each do |adapter| + i = adapter.Index + iface_instance[i] = Mash.new + adapter.properties_.each do |p| + iface_instance[i][p.name.underscore.to_sym] = adapter[p.name] + end +end + +iface_instance.keys.each do |i| + if iface_config[i][:ip_enabled] and iface_instance[i][:net_connection_id] and iface_instance[i][:interface_index] + cint = sprintf("0x%X", iface_instance[i][:interface_index]) + iface[cint] = Mash.new + iface[cint][:configuration] = iface_config[i] + iface[cint][:instance] = iface_instance[i] + + iface[cint][:counters] = Mash.new + iface[cint][:addresses] = Mash.new + iface[cint][:configuration][:ip_address].each_index do |i| + begin + if iface[cint][:configuration][:ip_address][i] =~ /./ + iface[cint][:addresses][iface[cint][:configuration][:ip_address][i]] = { + "family" => "inet", + "netmask" => iface[cint][:configuration][:ip_subnet][i], + "broadcast" => derive_bcast( iface[cint][:configuration][:ip_address][i], + iface[cint][:configuration][:ip_subnet][i], + iface[cint][:configuration][:ip_use_zero_broadcast] + ) + } + end + rescue + end + end + iface[cint][:configuration][:mac_address].each do |mac_addr| + iface[cint][:addresses][mac_addr] = { + "family" => "lladdr" + } + end + iface[cint][:mtu] = iface[cint][:configuration][:mtu] + iface[cint][:type] = iface[cint][:instance][:adapter_type] + iface[cint][:arp] = {} + iface[cint][:encapsulation] = encaps_lookup(iface[cint][:instance][:adapter_type]) + end +end + +cint=nil +from("arp /a").split("\n").each do |line| + if line == "" + cint = nil + end + if line =~ /^Interface:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+[-]+\s+(0x\d+)/ + cint = $2 + end + next unless iface[cint] + if line =~ /^\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-fA-F0-9\:-]+)/ + iface[cint][:arp][$1] = $2.gsub("-",":").downcase + end +end + +network["interfaces"] = iface diff --git a/lib/ohai/plugins/mswin32/platform.rb b/lib/ohai/plugins/mswin32/platform.rb index 07ea5216..7fb269e6 100644 --- a/lib/ohai/plugins/mswin32/platform.rb +++ b/lib/ohai/plugins/mswin32/platform.rb @@ -1,21 +1,21 @@ -#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-platform kernel['name']
-platform_version kernel['release']
-
+# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +platform kernel['name'] +platform_version kernel['release'] + diff --git a/lib/ohai/plugins/python.rb b/lib/ohai/plugins/python.rb index 1060cea6..111e2005 100644 --- a/lib/ohai/plugins/python.rb +++ b/lib/ohai/plugins/python.rb @@ -20,12 +20,10 @@ require_plugin "languages" output = nil python = Mash.new -status = popen4("python -c \"import sys; print sys.version\"") do |pid, stdin, stdout, stderr| - stdin.close - output = stdout.gets.split if stdout - python[:version] = output[0] - python[:builddate] = "%s %s %s %s" % [output[2],output[3],output[4],output[5].gsub!(/\)/,'')] -end +status, stdout, error = run_command(:no_status_check => true, :command => "python -c \"import sys; print sys.version\"") +output = stdout.split +python[:version] = output[0] +python[:builddate] = "%s %s %s %s" % [output[2],output[3],output[4],output[5].gsub!(/\)/,'')] if status == 0 languages[:python] = python if python[:version] and python[:builddate] diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index ed80c59d..90adedd7 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -21,6 +21,7 @@ require 'extlib' require 'ohai/log' require 'ohai/mixin/from_file' require 'ohai/mixin/command' +require 'ohai/mixin/string' require 'json' module Ohai |