ohai 6.14.0 → 6.16.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/lib/ohai/mixin/ec2_metadata.rb +61 -6
  2. data/lib/ohai/plugins/cloud.rb +69 -5
  3. data/lib/ohai/plugins/darwin/system_profiler.rb +44 -7
  4. data/lib/ohai/plugins/freebsd/virtualization.rb +16 -0
  5. data/lib/ohai/plugins/java.rb +1 -1
  6. data/lib/ohai/plugins/kernel.rb +1 -0
  7. data/lib/ohai/plugins/linode.rb +53 -0
  8. data/lib/ohai/plugins/linux/platform.rb +6 -2
  9. data/lib/ohai/plugins/network.rb +130 -44
  10. data/lib/ohai/plugins/{aix/ssh_host_key.rb → nodejs.rb} +15 -7
  11. data/lib/ohai/plugins/openstack.rb +46 -0
  12. data/lib/ohai/plugins/rackspace.rb +35 -1
  13. data/lib/ohai/plugins/solaris2/filesystem.rb +1 -1
  14. data/lib/ohai/plugins/solaris2/network.rb +2 -1
  15. data/lib/ohai/plugins/solaris2/platform.rb +2 -2
  16. data/lib/ohai/plugins/ssh_host_key.rb +63 -0
  17. data/lib/ohai/plugins/virtualization.rb +1 -1
  18. data/lib/ohai/plugins/windows/cpu.rb +20 -3
  19. data/lib/ohai/plugins/windows/kernel.rb +0 -19
  20. data/lib/ohai/plugins/windows/kernel_devices.rb +39 -0
  21. data/lib/ohai/system.rb +3 -2
  22. data/lib/ohai/version.rb +1 -1
  23. data/spec/spec_helper.rb +14 -1
  24. data/spec/support/platform_helpers.rb +31 -0
  25. data/spec/{ohai → unit}/mixin/command_spec.rb +0 -0
  26. data/spec/{ohai → unit}/mixin/from_file_spec.rb +0 -0
  27. data/spec/{ohai → unit}/plugins/c_spec.rb +0 -0
  28. data/spec/{ohai → unit}/plugins/chef_spec.rb +20 -12
  29. data/spec/unit/plugins/cloud_spec.rb +159 -0
  30. data/spec/{ohai → unit}/plugins/darwin/hostname_spec.rb +0 -0
  31. data/spec/{ohai → unit}/plugins/darwin/kernel_spec.rb +0 -0
  32. data/spec/{ohai → unit}/plugins/darwin/network_spec.rb +4 -2
  33. data/spec/{ohai → unit}/plugins/darwin/platform_spec.rb +0 -0
  34. data/spec/unit/plugins/darwin/system_profiler_output.rb +79525 -0
  35. data/spec/unit/plugins/darwin/system_profiler_spec.rb +48 -0
  36. data/spec/{ohai → unit}/plugins/dmi_spec.rb +0 -0
  37. data/spec/unit/plugins/ec2_spec.rb +199 -0
  38. data/spec/{ohai → unit}/plugins/erlang_spec.rb +0 -0
  39. data/spec/{ohai → unit}/plugins/eucalyptus_spec.rb +5 -5
  40. data/spec/{ohai → unit}/plugins/fail_spec.rb +0 -0
  41. data/spec/{ohai → unit}/plugins/freebsd/hostname_spec.rb +0 -0
  42. data/spec/{ohai → unit}/plugins/freebsd/kernel_spec.rb +0 -0
  43. data/spec/{ohai → unit}/plugins/freebsd/platform_spec.rb +0 -0
  44. data/spec/unit/plugins/freebsd/virtualization_spec.rb +99 -0
  45. data/spec/{ohai → unit}/plugins/groovy_spec.rb +0 -0
  46. data/spec/{ohai → unit}/plugins/hostname_spec.rb +0 -0
  47. data/spec/{ohai → unit}/plugins/java_spec.rb +0 -0
  48. data/spec/{ohai → unit}/plugins/kernel_spec.rb +0 -0
  49. data/spec/unit/plugins/linode_spec.rb +156 -0
  50. data/spec/{ohai → unit}/plugins/linux/cpu_spec.rb +0 -0
  51. data/spec/{ohai → unit}/plugins/linux/filesystem_spec.rb +0 -0
  52. data/spec/{ohai → unit}/plugins/linux/hostname_spec.rb +0 -0
  53. data/spec/{ohai → unit}/plugins/linux/kernel_spec.rb +0 -0
  54. data/spec/{ohai → unit}/plugins/linux/lsb_spec.rb +0 -0
  55. data/spec/{ohai → unit}/plugins/linux/network_spec.rb +3 -60
  56. data/spec/{ohai → unit}/plugins/linux/platform_spec.rb +10 -0
  57. data/spec/{ohai → unit}/plugins/linux/uptime_spec.rb +0 -0
  58. data/spec/{ohai → unit}/plugins/linux/virtualization_spec.rb +0 -0
  59. data/spec/{ohai → unit}/plugins/lua_spec.rb +0 -0
  60. data/spec/{ohai → unit}/plugins/mono_spec.rb +0 -0
  61. data/spec/{ohai → unit}/plugins/netbsd/hostname_spec.rb +0 -0
  62. data/spec/{ohai → unit}/plugins/netbsd/kernel_spec.rb +0 -0
  63. data/spec/{ohai → unit}/plugins/netbsd/platform_spec.rb +0 -0
  64. data/spec/unit/plugins/network_spec.rb +829 -0
  65. data/spec/unit/plugins/nodejs_spec.rb +51 -0
  66. data/spec/{ohai → unit}/plugins/ohai_spec.rb +0 -0
  67. data/spec/{ohai → unit}/plugins/ohai_time_spec.rb +0 -0
  68. data/spec/{ohai → unit}/plugins/openbsd/hostname_spec.rb +0 -0
  69. data/spec/{ohai → unit}/plugins/openbsd/kernel_spec.rb +0 -0
  70. data/spec/{ohai → unit}/plugins/openbsd/platform_spec.rb +0 -0
  71. data/spec/{ohai → unit}/plugins/os_spec.rb +0 -0
  72. data/spec/{ohai → unit}/plugins/passwd_spec.rb +0 -0
  73. data/spec/{ohai → unit}/plugins/perl_spec.rb +0 -0
  74. data/spec/{ohai → unit}/plugins/php_spec.rb +0 -0
  75. data/spec/{ohai → unit}/plugins/platform_spec.rb +0 -0
  76. data/spec/{ohai → unit}/plugins/python_spec.rb +0 -0
  77. data/spec/{ohai → unit}/plugins/rackspace_spec.rb +26 -0
  78. data/spec/{ohai → unit}/plugins/ruby_spec.rb +0 -0
  79. data/spec/{ohai → unit}/plugins/sigar/network_route_spec.rb +1 -0
  80. data/spec/{ohai → unit}/plugins/solaris2/hostname_spec.rb +0 -0
  81. data/spec/{ohai → unit}/plugins/solaris2/kernel_spec.rb +0 -0
  82. data/spec/{ohai → unit}/plugins/solaris2/network_spec.rb +8 -1
  83. data/spec/{ohai → unit}/plugins/solaris2/platform_spec.rb +0 -0
  84. data/spec/{ohai → unit}/plugins/solaris2/virtualization_spec.rb +0 -0
  85. data/spec/unit/plugins/ssh_host_keys_spec.rb +77 -0
  86. data/spec/{ohai → unit}/system_spec.rb +0 -0
  87. metadata +221 -184
  88. data/lib/ohai/plugins/darwin/ssh_host_key.rb +0 -25
  89. data/lib/ohai/plugins/freebsd/ssh_host_key.rb +0 -26
  90. data/lib/ohai/plugins/hpux/ssh_host_key.rb +0 -26
  91. data/lib/ohai/plugins/linux/ssh_host_key.rb +0 -26
  92. data/lib/ohai/plugins/netbsd/ssh_host_key.rb +0 -26
  93. data/lib/ohai/plugins/openbsd/ssh_host_key.rb +0 -26
  94. data/lib/ohai/plugins/solaris2/ssh_host_key.rb +0 -26
  95. data/spec/ohai/plugins/cloud_spec.rb +0 -113
  96. data/spec/ohai/plugins/ec2_spec.rb +0 -120
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Author:: Jacques Marneweck (<jacques@powertrip.co.za>)
3
+ # Copyright:: Copyright (c) 2012 Jacques Marneweck. All rights reserved.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,11 +16,19 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "keys/ssh"
19
+ provides "languages/nodejs"
20
20
 
21
- require_plugin "keys"
21
+ require_plugin "languages"
22
22
 
23
- keys[:ssh] = Mash.new
23
+ output = nil
24
24
 
25
- keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1]
26
- keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1]
25
+ nodejs = Mash.new
26
+
27
+ status, stdout, stderr = run_command(:no_status_check => true, :command => "node -v")
28
+ if status == 0
29
+ output = stdout.split
30
+ if output.length >= 1
31
+ nodejs[:version] = output[0][1..output[0].length]
32
+ end
33
+ languages[:nodejs] = nodejs if nodejs[:version]
34
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Author:: Matt Ray (<matt@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ provides "openstack"
19
+
20
+ require 'ohai/mixin/ec2_metadata'
21
+
22
+ extend Ohai::Mixin::Ec2Metadata
23
+
24
+ # does it matter that it's not hitting latest?
25
+ #Ec2Metadata::EC2_METADATA_URL = "/latest/meta-data"
26
+
27
+ # Adds openstack Mash
28
+ if hint?('openstack') || hint?('hp')
29
+ Ohai::Log.debug("ohai openstack")
30
+ openstack Mash.new
31
+ #for now, use the metadata service
32
+ if can_metadata_connect?(EC2_METADATA_ADDR,80)
33
+ Ohai::Log.debug("connecting to the OpenStack metadata service")
34
+ self.fetch_metadata.each {|k, v| openstack[k] = v }
35
+ case
36
+ when hint?('hp')
37
+ openstack['provider'] = 'hp'
38
+ else
39
+ openstack['provider'] = 'openstack'
40
+ end
41
+ else
42
+ Ohai::Log.debug("unable to connect to the OpenStack metadata service")
43
+ end
44
+ else
45
+ Ohai::Log.debug("NOT ohai openstack")
46
+ end
@@ -58,8 +58,39 @@ end
58
58
  # eth<Symbol>:: Interface name of public or private ip
59
59
  def get_ip_address(name, eth)
60
60
  network[:interfaces][eth][:addresses].each do |key, info|
61
- rackspace[name] = key if info['family'] == 'inet'
61
+ if info['family'] == 'inet'
62
+ rackspace[name] = key
63
+ break # break when we found an address
64
+ end
65
+ end
66
+ end
67
+
68
+ # Names rackspace ipv6 address for interface
69
+ #
70
+ # === Parameters
71
+ # name<Symbol>:: Use :public_ip or :private_ip
72
+ # eth<Symbol>:: Interface name of public or private ip
73
+ def get_global_ipv6_address(name, eth)
74
+ network[:interfaces][eth][:addresses].each do |key, info|
75
+ # check if we got an ipv6 address and if its in global scope
76
+ if info['family'] == 'inet6' && info['scope'] == 'Global'
77
+ rackspace[name] = key
78
+ break # break when we found an address
79
+ end
80
+ end
81
+ end
82
+
83
+ # Get the rackspace region
84
+ #
85
+ def get_region()
86
+ status, stdout, stderr = run_command(:no_status_check => true, :command => "xenstore-ls vm-data/provider_data")
87
+ if status == 0
88
+ stdout.split("\n").each do |line|
89
+ rackspace[:region] = line.split[2].delete('\"') if line =~ /^region/
90
+ end
62
91
  end
92
+ rescue Ohai::Exceptions::Exec
93
+ Ohai::Log.debug("Unable to find xenstore-ls, cannot capture region information for Rackspace cloud")
63
94
  end
64
95
 
65
96
  # Adds rackspace Mash
@@ -67,9 +98,12 @@ if looks_like_rackspace?
67
98
  rackspace Mash.new
68
99
  get_ip_address(:public_ip, :eth0)
69
100
  get_ip_address(:private_ip, :eth1)
101
+ get_region()
70
102
  # public_ip + private_ip are deprecated in favor of public_ipv4 and local_ipv4 to standardize.
71
103
  rackspace[:public_ipv4] = rackspace[:public_ip]
104
+ get_global_ipv6_address(:public_ipv6, :eth0)
72
105
  rackspace[:public_hostname] = "#{rackspace[:public_ip].gsub('.','-')}.static.cloud-ips.com"
73
106
  rackspace[:local_ipv4] = rackspace[:private_ip]
107
+ get_global_ipv6_address(:local_ipv6, :eth1)
74
108
  rackspace[:local_hostname] = hostname
75
109
  end
@@ -21,7 +21,7 @@ provides "filesystem"
21
21
  fs = Mash.new
22
22
 
23
23
  # Grab filesystem data from df
24
- popen4("df -ka") do |pid, stdin, stdout, stderr|
24
+ popen4("df -Pka") do |pid, stdin, stdout, stderr|
25
25
  stdin.close
26
26
  stdout.each do |line|
27
27
  case line
@@ -60,6 +60,7 @@ require 'scanf'
60
60
  def encaps_lookup(ifname)
61
61
  return "Ethernet" if ifname.eql?("e1000g")
62
62
  return "Ethernet" if ifname.eql?("eri")
63
+ return "Ethernet" if ifname.eql?("net")
63
64
  return "Loopback" if ifname.eql?("lo")
64
65
  "Unknown"
65
66
  end
@@ -82,7 +83,7 @@ popen4("ifconfig -a") do |pid, stdin, stdout, stderr|
82
83
  iface[cint] = Mash.new unless iface[cint]
83
84
  iface[cint][:mtu] = $2
84
85
  iface[cint][:index] = $3
85
- if line =~ / flags\=\d+\<((ADDRCONF|ANYCAST|BROADCAST|CoS|DEPRECATED|DHCP|DUPLICATE|FAILED|FIXEDMTU|INACTIVE|LOOPBACK|MIP|MULTI_BCAST|MULTICAST|NOARP|NOFAILOVER|NOLOCAL|NONUD|NORTEXCH|NOXMIT|OFFLINE|POINTOPOINT|PREFERRED|PRIVATE|ROUTER|RUNNING|STANDBY|TEMPORARY|UNNUMBERED|UP|VIRTUAL|XRESOLV|IPv4|IPv6|,)+)\>\s/
86
+ if line =~ / flags\=\d+\<((ADDRCONF|ANYCAST|BROADCAST|CoS|DEPRECATED|DHCP|DUPLICATE|FAILED|FIXEDMTU|INACTIVE|L3PROTECT|LOOPBACK|MIP|MULTI_BCAST|MULTICAST|NOARP|NOFAILOVER|NOLOCAL|NONUD|NORTEXCH|NOXMIT|OFFLINE|POINTOPOINT|PREFERRED|PRIVATE|ROUTER|RUNNING|STANDBY|TEMPORARY|UNNUMBERED|UP|VIRTUAL|XRESOLV|IPv4|IPv6|,)+)\>\s/
86
87
  flags = $1.split(',')
87
88
  else
88
89
  flags = Array.new
@@ -39,6 +39,8 @@ end
39
39
  File.open("/etc/release") do |file|
40
40
  while line = file.gets
41
41
  case line
42
+ when /^.*(SmartOS).*$/
43
+ platform "smartos"
42
44
  when /^\s*(OmniOS).*r(\d+).*$/
43
45
  platform "omnios"
44
46
  platform_version $2
@@ -54,8 +56,6 @@ File.open("/etc/release") do |file|
54
56
  platform "solaris2"
55
57
  when /^\s*(NexentaCore)\s.*$/
56
58
  platform "nexentacore"
57
- when /^\s*(SmartOS)\s.*$/
58
- platform "smartos"
59
59
  end
60
60
  end
61
61
  end
@@ -0,0 +1,63 @@
1
+ #
2
+ # Author:: Bryan McLellan <btm@opscode.com>
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ provides "keys/ssh"
20
+ require_plugin "keys"
21
+
22
+ keys[:ssh] = Mash.new
23
+
24
+ def is_dsa_or_rsa?(file)
25
+ case IO.read(file).split[0]
26
+ when "ssh-dss"
27
+ "dsa"
28
+ when "ssh-rsa"
29
+ "rsa"
30
+ else
31
+ nil
32
+ end
33
+ end
34
+
35
+ sshd_config = if File.exists?("/etc/ssh/sshd_config")
36
+ "/etc/ssh/sshd_config"
37
+ elsif File.exists?("/etc/sshd_config")
38
+ # Darwin
39
+ "/etc/sshd_config"
40
+ else
41
+ Ohai::Log.debug("Failed to find sshd configuration file")
42
+ nil
43
+ end
44
+
45
+ if sshd_config
46
+ File.open(sshd_config) do |conf|
47
+ conf.each_line do |line|
48
+ if line.match(/^hostkey\s/i)
49
+ pub_file = "#{line.split[1]}.pub"
50
+ key_type = is_dsa_or_rsa?(pub_file)
51
+ keys[:ssh]["host_#{key_type}_public"] = IO.read(pub_file).split[1] unless key_type.nil?
52
+ end
53
+ end
54
+ end
55
+ else
56
+ if keys[:ssh][:host_dsa_public].nil? && File.exists?("/etc/ssh/ssh_host_dsa_key.pub")
57
+ keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1]
58
+ end
59
+
60
+ if keys[:ssh][:host_rsa_public].nil? && File.exists?("/etc/ssh/ssh_host_rsa_key.pub")
61
+ keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1]
62
+ end
63
+ end
@@ -73,7 +73,7 @@ unless virtualization.nil? || !(virtualization[:role].eql?("host"))
73
73
  virtualization[:storage][pool][:volumes] = Mash.new
74
74
  sp.list_volumes.each do |v|
75
75
  virtualization[:storage][pool][:volumes][v] = Mash.new
76
- sv = sp.lookup_volume_by_name pool
76
+ sv = sp.lookup_volume_by_name v
77
77
  ['key','name','path'].each {|a| virtualization[:storage][pool][:volumes][v][a] = sv.send(a)}
78
78
  ['allocation','capacity','type'].each {|a| virtualization[:storage][pool][:volumes][v][a] = sv.info.send(a)}
79
79
  end
@@ -25,7 +25,24 @@ cpu_number = 0
25
25
  index = 0
26
26
 
27
27
  WMI::Win32_Processor.find(:all).each do |processor|
28
- cpu_number += processor.numberofcores
28
+ #
29
+ # On Windows Server 2003 R2 (i.e. 5.2.*), numberofcores property
30
+ # doesn't exist on the Win32_Processor class unless the user has
31
+ # patched their system with:
32
+ # http://support.microsoft.com/kb/932370
33
+ #
34
+ # We're returning nil for cpu["cores"] and cpu["count"]
35
+ # when we don't see numberofcores property
36
+ #
37
+
38
+ number_of_cores = nil
39
+ begin
40
+ number_of_cores = processor.numberofcores
41
+ cpu_number += number_of_cores
42
+ rescue NoMethodError => e
43
+ Ohai::Log.info("Can not find numberofcores property on Win32_Processor. Consider applying this patch: http://support.microsoft.com/kb/932370")
44
+ end
45
+
29
46
  current_cpu = index.to_s
30
47
  index += 1
31
48
  cpuinfo[current_cpu] = Mash.new
@@ -35,7 +52,7 @@ WMI::Win32_Processor.find(:all).each do |processor|
35
52
  cpuinfo[current_cpu]["stepping"] = processor.stepping
36
53
  cpuinfo[current_cpu]["physical_id"] = processor.deviceid
37
54
  #cpuinfo[current_cpu]["core_id"] = XXX
38
- cpuinfo[current_cpu]["cores"] = processor.numberofcores
55
+ cpuinfo[current_cpu]["cores"] = number_of_cores
39
56
  cpuinfo[current_cpu]["model_name"] = processor.description
40
57
  cpuinfo[current_cpu]["mhz"] = processor.maxclockspeed.to_s
41
58
  cpuinfo[current_cpu]["cache_size"] = "#{processor.l2cachesize} KB"
@@ -43,5 +60,5 @@ WMI::Win32_Processor.find(:all).each do |processor|
43
60
  end
44
61
 
45
62
  cpu cpuinfo
46
- cpu[:total] = cpu_number
63
+ cpu[:total] = (cpu_number == 0) ? nil : cpu_number
47
64
  cpu[:real] = index
@@ -56,22 +56,3 @@ host.properties_.each do |p|
56
56
  end
57
57
 
58
58
  kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")
59
-
60
- kext = Mash.new
61
- pnp_drivers = Mash.new
62
-
63
- drivers = WMI::Win32_PnPSignedDriver.find(:all)
64
- drivers.each do |driver|
65
- pnp_drivers[driver.DeviceID] = Mash.new
66
- driver.properties_.each do |p|
67
- pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver.send(p.name)
68
- end
69
- if driver.DeviceName
70
- kext[driver.DeviceName] = pnp_drivers[driver.DeviceID]
71
- kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version]
72
- kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil
73
- end
74
- end
75
-
76
- kernel[:pnp_drivers] = pnp_drivers
77
- kernel[:modules] = kext
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author:: James Gartrell (<jgartrel@gmail.com>)
3
+ # Copyright:: Copyright (c) 2009 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ require 'ruby-wmi'
19
+
20
+ WIN32OLE.codepage = WIN32OLE::CP_UTF8
21
+
22
+ kext = Mash.new
23
+ pnp_drivers = Mash.new
24
+
25
+ drivers = WMI::Win32_PnPSignedDriver.find(:all)
26
+ drivers.each do |driver|
27
+ pnp_drivers[driver.DeviceID] = Mash.new
28
+ driver.properties_.each do |p|
29
+ pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver.send(p.name)
30
+ end
31
+ if driver.DeviceName
32
+ kext[driver.DeviceName] = pnp_drivers[driver.DeviceID]
33
+ kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version]
34
+ kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil
35
+ end
36
+ end
37
+
38
+ kernel[:pnp_drivers] = pnp_drivers
39
+ kernel[:modules] = kext
@@ -21,6 +21,7 @@ require 'ohai/log'
21
21
  require 'ohai/mixin/from_file'
22
22
  require 'ohai/mixin/command'
23
23
  require 'ohai/mixin/string'
24
+ require 'mixlib/shellout'
24
25
 
25
26
  require 'yajl'
26
27
 
@@ -244,8 +245,8 @@ module Ohai
244
245
  data = data[part]
245
246
  end
246
247
  raise ArgumentError, "I cannot find an attribute named #{a}!" if data.nil?
247
- case a
248
- when Hash,Mash,Array
248
+ case data
249
+ when Hash,Mash,Array,Fixnum
249
250
  json_pretty_print(data)
250
251
  when String
251
252
  if data.respond_to?(:lines)
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = '6.14.0'
21
+ VERSION = '6.16.0.beta.1'
22
22
  end
23
23
 
@@ -1,7 +1,9 @@
1
1
  require 'rspec'
2
- require 'mixlib/config'
3
2
 
3
+ $:.unshift(File.expand_path("../..", __FILE__))
4
4
  $:.unshift(File.dirname(__FILE__) + '/../lib')
5
+
6
+ require 'spec/support/platform_helpers'
5
7
  require 'ohai'
6
8
  Ohai::Config[:log_level] = :error
7
9
 
@@ -54,3 +56,14 @@ module SimpleFromFile
54
56
  self.instance_eval(IO.read(filename), filename, 1)
55
57
  end
56
58
  end
59
+
60
+ RSpec.configure do |config|
61
+ config.treat_symbols_as_metadata_keys_with_true_values = true
62
+
63
+ config.filter_run_excluding :windows_only => true unless windows?
64
+ config.filter_run_excluding :unix_only => true unless unix?
65
+ config.filter_run_excluding :ruby_18_only => true unless ruby_18?
66
+ config.filter_run_excluding :ruby_19_only => true unless ruby_19?
67
+ config.filter_run_excluding :requires_root => true unless ENV['USER'] == 'root'
68
+ config.filter_run_excluding :requires_unprivileged_user => true if ENV['USER'] == 'root'
69
+ end
@@ -0,0 +1,31 @@
1
+ def ruby_19?
2
+ !!(RUBY_VERSION =~ /^1.9/)
3
+ end
4
+
5
+ def ruby_18?
6
+ !!(RUBY_VERSION =~ /^1.8/)
7
+ end
8
+
9
+ def windows?
10
+ !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
11
+ end
12
+
13
+ # def jruby?
14
+
15
+ def unix?
16
+ !windows?
17
+ end
18
+
19
+ def os_x?
20
+ !!(RUBY_PLATFORM =~ /darwin/)
21
+ end
22
+
23
+ def solaris?
24
+ !!(RUBY_PLATFORM =~ /solaris/)
25
+ end
26
+
27
+ def freebsd?
28
+ !!(RUBY_PLATFORM =~ /freebsd/)
29
+ end
30
+
31
+ DEV_NULL = windows? ? 'NUL' : '/dev/null'