ohai 6.24.2 → 7.0.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. data/lib/ohai.rb +1 -1
  2. data/lib/ohai/application.rb +5 -12
  3. data/lib/ohai/common/dmi.rb +126 -0
  4. data/lib/ohai/config.rb +9 -9
  5. data/lib/ohai/{plugins/darwin/hostname.rb → dsl.rb} +7 -7
  6. data/lib/ohai/dsl/plugin.rb +186 -0
  7. data/lib/ohai/dsl/plugin/versionvi.rb +62 -0
  8. data/lib/ohai/dsl/plugin/versionvii.rb +106 -0
  9. data/lib/ohai/exception.rb +11 -2
  10. data/lib/ohai/hints.rb +48 -0
  11. data/lib/ohai/loader.rb +205 -0
  12. data/lib/ohai/mixin/command.rb +14 -18
  13. data/lib/ohai/mixin/constant_helper.rb +53 -0
  14. data/lib/ohai/mixin/gce_metadata.rb +0 -2
  15. data/lib/ohai/{plugins/freebsd/uptime.rb → mixin/network_constants.rb} +15 -13
  16. data/lib/ohai/mixin/os.rb +59 -0
  17. data/lib/ohai/mixin/seconds_to_human.rb +48 -0
  18. data/lib/ohai/plugins/aix/cpu.rb +26 -22
  19. data/lib/ohai/plugins/aix/filesystem.rb +47 -48
  20. data/lib/ohai/plugins/aix/kernel.rb +11 -7
  21. data/lib/ohai/plugins/aix/memory.rb +8 -4
  22. data/lib/ohai/plugins/aix/network.rb +73 -82
  23. data/lib/ohai/plugins/aix/platform.rb +9 -6
  24. data/lib/ohai/plugins/aix/uptime.rb +14 -12
  25. data/lib/ohai/plugins/azure.rb +33 -11
  26. data/lib/ohai/plugins/c.rb +103 -78
  27. data/lib/ohai/plugins/chef.rb +20 -8
  28. data/lib/ohai/plugins/cloud.rb +234 -230
  29. data/lib/ohai/plugins/command.rb +6 -2
  30. data/lib/ohai/plugins/darwin/cpu.rb +10 -4
  31. data/lib/ohai/plugins/darwin/filesystem.rb +32 -32
  32. data/lib/ohai/plugins/darwin/network.rb +157 -154
  33. data/lib/ohai/plugins/darwin/platform.rb +18 -16
  34. data/lib/ohai/plugins/darwin/system_profiler.rb +49 -46
  35. data/lib/ohai/plugins/dmi.rb +102 -102
  36. data/lib/ohai/plugins/ec2.rb +30 -28
  37. data/lib/ohai/plugins/erlang.rb +19 -16
  38. data/lib/ohai/plugins/eucalyptus.rb +37 -36
  39. data/lib/ohai/plugins/freebsd/cpu.rb +34 -29
  40. data/lib/ohai/plugins/freebsd/filesystem.rb +32 -32
  41. data/lib/ohai/plugins/freebsd/memory.rb +35 -25
  42. data/lib/ohai/plugins/freebsd/network.rb +94 -89
  43. data/lib/ohai/plugins/freebsd/platform.rb +10 -4
  44. data/lib/ohai/plugins/freebsd/virtualization.rb +62 -61
  45. data/lib/ohai/plugins/gce.rb +30 -36
  46. data/lib/ohai/plugins/groovy.rb +14 -11
  47. data/lib/ohai/plugins/hostname.rb +132 -10
  48. data/lib/ohai/plugins/ip_scopes.rb +31 -16
  49. data/lib/ohai/plugins/java.rb +45 -21
  50. data/lib/ohai/plugins/kernel.rb +186 -19
  51. data/lib/ohai/plugins/keys.rb +6 -2
  52. data/lib/ohai/plugins/languages.rb +6 -2
  53. data/lib/ohai/plugins/linode.rb +38 -30
  54. data/lib/ohai/plugins/linux/block_device.rb +19 -15
  55. data/lib/ohai/plugins/linux/cpu.rb +42 -38
  56. data/lib/ohai/plugins/linux/filesystem.rb +70 -130
  57. data/lib/ohai/plugins/linux/lsb.rb +35 -35
  58. data/lib/ohai/plugins/linux/memory.rb +65 -61
  59. data/lib/ohai/plugins/linux/network.rb +343 -362
  60. data/lib/ohai/plugins/linux/platform.rb +90 -88
  61. data/lib/ohai/plugins/linux/virtualization.rb +95 -90
  62. data/lib/ohai/plugins/lua.rb +14 -10
  63. data/lib/ohai/plugins/mono.rb +17 -13
  64. data/lib/ohai/plugins/netbsd/cpu.rb +25 -23
  65. data/lib/ohai/plugins/netbsd/filesystem.rb +32 -32
  66. data/lib/ohai/plugins/netbsd/memory.rb +59 -59
  67. data/lib/ohai/plugins/netbsd/network.rb +92 -88
  68. data/lib/ohai/plugins/netbsd/platform.rb +10 -3
  69. data/lib/ohai/plugins/netbsd/virtualization.rb +41 -38
  70. data/lib/ohai/plugins/network.rb +131 -130
  71. data/lib/ohai/plugins/network_listeners.rb +26 -22
  72. data/lib/ohai/plugins/nodejs.rb +14 -10
  73. data/lib/ohai/plugins/ohai.rb +11 -6
  74. data/lib/ohai/plugins/ohai_time.rb +6 -2
  75. data/lib/ohai/plugins/openbsd/cpu.rb +20 -15
  76. data/lib/ohai/plugins/openbsd/filesystem.rb +32 -32
  77. data/lib/ohai/plugins/openbsd/memory.rb +59 -59
  78. data/lib/ohai/plugins/openbsd/network.rb +92 -88
  79. data/lib/ohai/plugins/openbsd/platform.rb +10 -4
  80. data/lib/ohai/plugins/openbsd/virtualization.rb +41 -39
  81. data/lib/ohai/plugins/openstack.rb +23 -21
  82. data/lib/ohai/plugins/os.rb +8 -32
  83. data/lib/ohai/plugins/passwd.rb +27 -22
  84. data/lib/ohai/plugins/perl.rb +21 -16
  85. data/lib/ohai/plugins/php.rb +15 -12
  86. data/lib/ohai/plugins/platform.rb +9 -9
  87. data/lib/ohai/plugins/{linux/kernel.rb → ps.rb} +13 -12
  88. data/lib/ohai/plugins/python.rb +16 -12
  89. data/lib/ohai/plugins/rackspace.rb +82 -77
  90. data/lib/ohai/plugins/root_group.rb +13 -9
  91. data/lib/ohai/plugins/ruby.rb +50 -48
  92. data/lib/ohai/plugins/sigar/cpu.rb +21 -17
  93. data/lib/ohai/plugins/sigar/filesystem.rb +26 -23
  94. data/lib/ohai/plugins/sigar/memory.rb +17 -14
  95. data/lib/ohai/plugins/sigar/network.rb +133 -67
  96. data/lib/ohai/plugins/sigar/network_route.rb +33 -28
  97. data/lib/ohai/plugins/sigar/platform.rb +10 -6
  98. data/lib/ohai/plugins/solaris2/cpu.rb +41 -33
  99. data/lib/ohai/plugins/solaris2/dmi.rb +146 -146
  100. data/lib/ohai/plugins/solaris2/filesystem.rb +74 -77
  101. data/lib/ohai/plugins/{aix/hostname.rb → solaris2/memory.rb} +7 -4
  102. data/lib/ohai/plugins/solaris2/network.rb +91 -86
  103. data/lib/ohai/plugins/solaris2/platform.rb +40 -36
  104. data/lib/ohai/plugins/solaris2/virtualization.rb +54 -59
  105. data/lib/ohai/plugins/solaris2/zpools.rb +38 -38
  106. data/lib/ohai/plugins/ssh_host_key.rb +49 -45
  107. data/lib/ohai/plugins/uptime.rb +87 -25
  108. data/lib/ohai/plugins/virtualization.rb +59 -55
  109. data/lib/ohai/plugins/windows/cpu.rb +44 -40
  110. data/lib/ohai/plugins/windows/filesystem.rb +28 -22
  111. data/lib/ohai/plugins/windows/network.rb +88 -79
  112. data/lib/ohai/plugins/windows/platform.rb +10 -3
  113. data/lib/ohai/provides_map.rb +184 -0
  114. data/lib/ohai/runner.rb +109 -0
  115. data/lib/ohai/system.rb +103 -184
  116. data/lib/ohai/version.rb +4 -3
  117. data/spec/data/plugins/___lib64___libc.so.6.output +135 -0
  118. data/spec/data/plugins/___lib___libc.so.6.output +135 -0
  119. data/spec/data/plugins/cc.output +135 -0
  120. data/spec/data/plugins/cl.output +135 -0
  121. data/spec/data/plugins/devenv.com.output +135 -0
  122. data/spec/data/plugins/env.output +71 -0
  123. data/spec/data/plugins/erl.output +144 -0
  124. data/spec/data/plugins/gcc.output +135 -0
  125. data/spec/data/plugins/groovy.output +159 -0
  126. data/spec/data/plugins/java.output +143 -0
  127. data/spec/data/plugins/lua.output +143 -0
  128. data/spec/data/plugins/messages.rb +8 -0
  129. data/spec/data/plugins/node.output +143 -0
  130. data/spec/data/plugins/perl.output +143 -0
  131. data/spec/data/plugins/php.output +143 -0
  132. data/spec/data/plugins/python.output +143 -0
  133. data/spec/data/plugins/uname.output +71 -0
  134. data/spec/data/plugins/v6message.rb +2 -0
  135. data/spec/data/plugins/v7message.rb +7 -0
  136. data/spec/data/plugins/what.output +135 -0
  137. data/spec/data/plugins/xlc.output +135 -0
  138. data/spec/spec_helper.rb +52 -18
  139. data/spec/support/integration_helper.rb +44 -0
  140. data/spec/unit/dsl/plugin_spec.rb +298 -0
  141. data/spec/unit/hints_spec.rb +65 -0
  142. data/spec/unit/loader_spec.rb +226 -0
  143. data/spec/unit/mixin/ec2_metadata_spec.rb +9 -9
  144. data/spec/unit/plugins/aix/cpu_spec.rb +17 -18
  145. data/spec/unit/plugins/aix/filesystem_spec.rb +20 -18
  146. data/spec/unit/plugins/aix/hostname_spec.rb +8 -4
  147. data/spec/unit/plugins/aix/kernel_spec.rb +13 -12
  148. data/spec/unit/plugins/aix/network_spec.rb +66 -45
  149. data/spec/unit/plugins/aix/platform_spec.rb +11 -10
  150. data/spec/unit/plugins/aix/uptime_spec.rb +7 -8
  151. data/spec/unit/plugins/azure_spec.rb +20 -21
  152. data/spec/unit/plugins/c_spec.rb +88 -87
  153. data/spec/unit/plugins/chef_spec.rb +5 -6
  154. data/spec/unit/plugins/cloud_spec.rb +81 -82
  155. data/spec/unit/plugins/darwin/cpu_spec.rb +8 -9
  156. data/spec/unit/plugins/darwin/hostname_spec.rb +23 -11
  157. data/spec/unit/plugins/darwin/kernel_spec.rb +39 -16
  158. data/spec/unit/plugins/darwin/network_spec.rb +375 -378
  159. data/spec/unit/plugins/darwin/platform_spec.rb +23 -50
  160. data/spec/unit/plugins/darwin/system_profiler_spec.rb +7 -8
  161. data/spec/unit/plugins/dmi_spec.rb +7 -12
  162. data/spec/unit/plugins/ec2_spec.rb +70 -59
  163. data/spec/unit/plugins/erlang_spec.rb +18 -20
  164. data/spec/unit/plugins/eucalyptus_spec.rb +37 -33
  165. data/spec/unit/plugins/fail_spec.rb +276 -23
  166. data/spec/unit/plugins/freebsd/hostname_spec.rb +11 -9
  167. data/spec/unit/plugins/freebsd/kernel_spec.rb +8 -8
  168. data/spec/unit/plugins/freebsd/platform_spec.rb +9 -10
  169. data/spec/unit/plugins/freebsd/virtualization_spec.rb +32 -32
  170. data/spec/unit/plugins/gce_spec.rb +19 -25
  171. data/spec/unit/plugins/groovy_spec.rb +10 -16
  172. data/spec/unit/plugins/hostname_spec.rb +45 -20
  173. data/spec/unit/plugins/ip_scopes_spec.rb +97 -0
  174. data/spec/unit/plugins/java_spec.rb +145 -99
  175. data/spec/unit/plugins/kernel_spec.rb +51 -15
  176. data/spec/unit/plugins/linode_spec.rb +31 -29
  177. data/spec/unit/plugins/linux/cpu_spec.rb +42 -43
  178. data/spec/unit/plugins/linux/filesystem_spec.rb +143 -324
  179. data/spec/unit/plugins/linux/hostname_spec.rb +16 -23
  180. data/spec/unit/plugins/linux/kernel_spec.rb +22 -8
  181. data/spec/unit/plugins/linux/lsb_spec.rb +54 -56
  182. data/spec/unit/plugins/linux/network_spec.rb +196 -238
  183. data/spec/unit/plugins/linux/platform_spec.rb +186 -205
  184. data/spec/unit/plugins/linux/uptime_spec.rb +13 -25
  185. data/spec/unit/plugins/linux/virtualization_spec.rb +149 -129
  186. data/spec/unit/plugins/lua_spec.rb +12 -15
  187. data/spec/unit/plugins/mono_spec.rb +10 -15
  188. data/spec/unit/plugins/netbsd/hostname_spec.rb +17 -7
  189. data/spec/unit/plugins/netbsd/kernel_spec.rb +8 -8
  190. data/spec/unit/plugins/netbsd/platform_spec.rb +8 -10
  191. data/spec/unit/plugins/network_spec.rb +358 -235
  192. data/spec/unit/plugins/nodejs_spec.rb +13 -15
  193. data/spec/unit/plugins/ohai_spec.rb +3 -4
  194. data/spec/unit/plugins/ohai_time_spec.rb +8 -9
  195. data/spec/unit/plugins/openbsd/hostname_spec.rb +21 -11
  196. data/spec/unit/plugins/openbsd/kernel_spec.rb +8 -8
  197. data/spec/unit/plugins/openbsd/platform_spec.rb +6 -12
  198. data/spec/unit/plugins/openstack_spec.rb +214 -0
  199. data/spec/unit/plugins/os_spec.rb +13 -16
  200. data/spec/unit/plugins/passwd_spec.rb +12 -13
  201. data/spec/unit/plugins/perl_spec.rb +20 -44
  202. data/spec/unit/plugins/php_spec.rb +20 -15
  203. data/spec/unit/plugins/platform_spec.rb +24 -29
  204. data/spec/unit/plugins/python_spec.rb +13 -17
  205. data/spec/unit/plugins/rackspace_spec.rb +90 -57
  206. data/spec/unit/plugins/root_group_spec.rb +17 -19
  207. data/spec/unit/plugins/ruby_spec.rb +15 -16
  208. data/spec/unit/plugins/sigar/network_route_spec.rb +12 -13
  209. data/spec/unit/plugins/solaris2/cpu_spec.rb +82 -0
  210. data/spec/unit/plugins/solaris2/hostname_spec.rb +12 -13
  211. data/spec/unit/plugins/solaris2/kernel_spec.rb +11 -15
  212. data/{lib/ohai/plugins/openbsd/uptime.rb → spec/unit/plugins/solaris2/memory_spec.rb} +10 -12
  213. data/spec/unit/plugins/solaris2/network_spec.rb +44 -20
  214. data/spec/unit/plugins/solaris2/platform_spec.rb +13 -22
  215. data/spec/unit/plugins/solaris2/virtualization_spec.rb +37 -45
  216. data/spec/unit/plugins/ssh_host_keys_spec.rb +11 -15
  217. data/spec/unit/provides_map_spec.rb +208 -0
  218. data/spec/unit/runner_spec.rb +488 -0
  219. data/spec/unit/system_spec.rb +639 -104
  220. metadata +151 -87
  221. checksums.yaml +0 -7
  222. data/lib/ohai/mixin/from_file.rb +0 -36
  223. data/lib/ohai/plugins/aix/ps.rb +0 -23
  224. data/lib/ohai/plugins/darwin/kernel.rb +0 -37
  225. data/lib/ohai/plugins/darwin/ps.rb +0 -23
  226. data/lib/ohai/plugins/darwin/uptime.rb +0 -32
  227. data/lib/ohai/plugins/dmi_common.rb +0 -121
  228. data/lib/ohai/plugins/freebsd/hostname.rb +0 -22
  229. data/lib/ohai/plugins/freebsd/kernel.rb +0 -37
  230. data/lib/ohai/plugins/freebsd/ps.rb +0 -24
  231. data/lib/ohai/plugins/hpux/cpu.rb +0 -19
  232. data/lib/ohai/plugins/hpux/filesystem.rb +0 -19
  233. data/lib/ohai/plugins/hpux/hostname.rb +0 -19
  234. data/lib/ohai/plugins/hpux/memory.rb +0 -19
  235. data/lib/ohai/plugins/hpux/network.rb +0 -19
  236. data/lib/ohai/plugins/hpux/platform.rb +0 -19
  237. data/lib/ohai/plugins/hpux/ps.rb +0 -23
  238. data/lib/ohai/plugins/hpux/uptime.rb +0 -19
  239. data/lib/ohai/plugins/linux/hostname.rb +0 -40
  240. data/lib/ohai/plugins/linux/ps.rb +0 -23
  241. data/lib/ohai/plugins/linux/uptime.rb +0 -28
  242. data/lib/ohai/plugins/netbsd/hostname.rb +0 -22
  243. data/lib/ohai/plugins/netbsd/kernel.rb +0 -35
  244. data/lib/ohai/plugins/netbsd/ps.rb +0 -24
  245. data/lib/ohai/plugins/netbsd/uptime.rb +0 -31
  246. data/lib/ohai/plugins/openbsd/hostname.rb +0 -22
  247. data/lib/ohai/plugins/openbsd/kernel.rb +0 -35
  248. data/lib/ohai/plugins/openbsd/ps.rb +0 -24
  249. data/lib/ohai/plugins/sigar/hostname.rb +0 -28
  250. data/lib/ohai/plugins/sigar/uptime.rb +0 -27
  251. data/lib/ohai/plugins/solaris2/hostname.rb +0 -34
  252. data/lib/ohai/plugins/solaris2/kernel.rb +0 -40
  253. data/lib/ohai/plugins/solaris2/ps.rb +0 -23
  254. data/lib/ohai/plugins/solaris2/uptime.rb +0 -36
  255. data/lib/ohai/plugins/windows/hostname.rb +0 -33
  256. data/lib/ohai/plugins/windows/kernel.rb +0 -58
  257. data/lib/ohai/plugins/windows/kernel_devices.rb +0 -39
  258. data/lib/ohai/plugins/windows/uptime.rb +0 -23
  259. data/spec/unit/mixin/from_file_spec.rb +0 -53
@@ -16,10 +16,13 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require_plugin "#{os}::kernel"
19
+ Ohai.plugin(:Platform) do
20
+ provides "platform", "platform_version", "platform_family"
21
+ depends "kernel"
20
22
 
21
- provides "platform", "platform_version", "platform_family"
22
-
23
- platform kernel[:name]
24
- platform_version [kernel[:version], kernel[:release]].join(".")
25
- platform_family platform
23
+ collect_data(:aix) do
24
+ platform kernel[:name]
25
+ platform_version [kernel[:version], kernel[:release]].join(".")
26
+ platform_family platform
27
+ end
28
+ end
@@ -15,20 +15,22 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  #
18
- require 'date'
19
18
 
20
- provides "uptime", "uptime_seconds"
19
+ Ohai.plugin(:Uptime) do
20
+ provides "uptime", "uptime_seconds"
21
21
 
22
- # Example output:
23
- # $ who -b
24
- # . system boot Jul 9 17:51
25
- popen4('who -b') do |pid, stdin, stdout, stderr|
26
- stdin.close
27
- stdout.each do |line|
28
- if line =~ /.* boot (.+)/
29
- uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i
30
- uptime self._seconds_to_human(uptime_seconds)
31
- break
22
+ collect_data(:aix) do
23
+ require 'date'
24
+ # Example output:
25
+ # $ who -b
26
+ # . system boot Jul 9 17:51
27
+ so = shell_out('who -b')
28
+ so.stdout.lines.each do |line|
29
+ if line =~ /.* boot (.+)/
30
+ uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i
31
+ uptime seconds_to_human(uptime_seconds)
32
+ break
33
+ end
32
34
  end
33
35
  end
34
36
  end
@@ -1,13 +1,35 @@
1
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
 
2
- provides "azure"
17
+ Ohai.plugin(:Azure) do
18
+ provides "azure"
3
19
 
4
-
5
- azure_metadata_from_hints = hint?('azure')
6
- if azure_metadata_from_hints
7
- Ohai::Log.debug("azure_metadata_from_hints is present.")
8
- azure Mash.new
9
- azure_metadata_from_hints.each {|k, v| azure[k] = v }
10
- else
11
- Ohai::Log.debug("No hints present for azure.")
12
- false
13
- end
20
+ collect_data do
21
+ # The azure hints are populated by the knife plugin for Azure.
22
+ # The project is located at https://github.com/opscode/knife-azure
23
+ # Please see the lib/chef/knife/azure_server_create.rb file in that
24
+ # project for details
25
+ azure_metadata_from_hints = hint?('azure')
26
+ if azure_metadata_from_hints
27
+ Ohai::Log.debug("azure_metadata_from_hints is present.")
28
+ azure Mash.new
29
+ azure_metadata_from_hints.each {|k, v| azure[k] = v }
30
+ else
31
+ Ohai::Log.debug("No hints present for azure.")
32
+ false
33
+ end
34
+ end
35
+ end
@@ -18,93 +18,118 @@
18
18
 
19
19
  require 'rbconfig'
20
20
 
21
- provides "languages/c"
21
+ Ohai.plugin(:C) do
22
+ provides "languages/c"
22
23
 
23
- require_plugin "languages"
24
+ depends "languages"
24
25
 
25
- c = Mash.new
26
+ collect_data do
27
+ c = Mash.new
26
28
 
27
- #gcc
28
- status, stdout, stderr = run_command(:no_status_check => true, :command => "gcc -v")
29
- if status == 0
30
- description = stderr.split($/).last
31
- output = description.split
32
- if output.length >= 3
33
- c[:gcc] = Mash.new
34
- c[:gcc][:version] = output[2]
35
- c[:gcc][:description] = description
36
- end
37
- end
29
+ #gcc
30
+ begin
31
+ so = shell_out("gcc -v")
32
+ if so.exitstatus == 0
33
+ description = so.stderr.split($/).last
34
+ output = description.split
35
+ if output.length >= 3
36
+ c[:gcc] = Mash.new
37
+ c[:gcc][:version] = output[2]
38
+ c[:gcc][:description] = description
39
+ end
40
+ end
41
+ rescue Errno::ENOENT
42
+ end
38
43
 
39
- #glibc
40
- ["/lib/libc.so.6", "/lib64/libc.so.6"].each do |glibc|
41
- status, stdout, stderr = run_command(:no_status_check => true, :command => glibc)
42
- if status == 0
43
- description = stdout.split($/).first
44
- if description =~ /(\d+\.\d+\.?\d*)/
45
- c[:glibc] = Mash.new
46
- c[:glibc][:version] = $1
47
- c[:glibc][:description] = description
44
+ #glibc
45
+ ["/lib/libc.so.6", "/lib64/libc.so.6"].each do |glibc|
46
+ begin
47
+ so = shell_out( Ohai.abs_path( glibc ))
48
+ if so.exitstatus == 0
49
+ description = so.stdout.split($/).first
50
+ if description =~ /(\d+\.\d+\.?\d*)/
51
+ c[:glibc] = Mash.new
52
+ c[:glibc][:version] = $1
53
+ c[:glibc][:description] = description
54
+ end
55
+ break
56
+ end
57
+ rescue Errno::ENOENT
58
+ end
48
59
  end
49
- break
50
- end
51
- end
52
60
 
53
- #ms cl
54
- status, stdout, stderr = run_command(:no_status_check => true, :command => "cl /?")
55
- if status == 0
56
- description = stderr.split($/).first
57
- if description =~ /Compiler Version ([\d\.]+)/
58
- c[:cl] = Mash.new
59
- c[:cl][:version] = $1
60
- c[:cl][:description] = description
61
- end
62
- end
61
+ #ms cl
62
+ begin
63
+ so = shell_out("cl /?")
64
+ if so.exitstatus == 0
65
+ description = so.stderr.lines.first.chomp
66
+ if description =~ /Compiler Version ([\d\.]+)/
67
+ c[:cl] = Mash.new
68
+ c[:cl][:version] = $1
69
+ c[:cl][:description] = description
70
+ end
71
+ end
72
+ rescue Errno::ENOENT
73
+ end
63
74
 
64
- #ms vs
65
- status, stdout, stderr = run_command(:no_status_check => true, :command => "devenv.com /?")
66
- if status == 0
67
- lines = stdout.split($/)
68
- description = lines[0].length == 0 ? lines[1] : lines[0]
69
- if description =~ /Visual Studio Version ([\d\.]+)/
70
- c[:vs] = Mash.new
71
- c[:vs][:version] = $1.chop
72
- c[:vs][:description] = description
73
- end
74
- end
75
+ #ms vs
76
+ begin
77
+ so = shell_out("devenv.com /?")
78
+ if so.exitstatus == 0
79
+ lines = so.stdout.split($/)
80
+ description = lines[0].length == 0 ? lines[1] : lines[0]
81
+ if description =~ /Visual Studio Version ([\d\.]+)/
82
+ c[:vs] = Mash.new
83
+ c[:vs][:version] = $1.chop
84
+ c[:vs][:description] = description
85
+ end
86
+ end
87
+ rescue Errno::ENOENT
88
+ end
75
89
 
76
- #ibm xlc
77
- status, stdout, stderr = run_command(:no_status_check => true, :command => "xlc -qversion")
78
- if status == 0 or (status >> 8) == 249
79
- description = stdout.split($/).first
80
- if description =~ /V(\d+\.\d+)/
81
- c[:xlc] = Mash.new
82
- c[:xlc][:version] = $1
83
- c[:xlc][:description] = description.strip
84
- end
85
- end
90
+ #ibm xlc
91
+ begin
92
+ so = shell_out("xlc -qversion")
93
+ if so.exitstatus == 0 or (so.exitstatus >> 8) == 249
94
+ description = so.stdout.split($/).first
95
+ if description =~ /V(\d+\.\d+)/
96
+ c[:xlc] = Mash.new
97
+ c[:xlc][:version] = $1
98
+ c[:xlc][:description] = description.strip
99
+ end
100
+ end
101
+ rescue Errno::ENOENT
102
+ end
86
103
 
87
- #sun pro
88
- status, stdout, stderr = run_command(:no_status_check => true, :command => "cc -V -flags")
89
- if status == 0
90
- output = stderr.split
91
- if stderr =~ /^cc: Sun C/ && output.size >= 4
92
- c[:sunpro] = Mash.new
93
- c[:sunpro][:version] = output[3]
94
- c[:sunpro][:description] = stderr.chomp
95
- end
96
- end
104
+ #sun pro
105
+ begin
106
+ so = shell_out("cc -V -flags")
107
+ if so.exitstatus == 0
108
+ output = so.stderr.split
109
+ if so.stderr =~ /^cc: Sun C/ && output.size >= 4
110
+ c[:sunpro] = Mash.new
111
+ c[:sunpro][:version] = output[3]
112
+ c[:sunpro][:description] = so.stderr.chomp
113
+ end
114
+ end
115
+ rescue Errno::ENOENT
116
+ end
97
117
 
98
- #hpux cc
99
- status, stdout, stderr = run_command(:no_status_check => true, :command => "what /opt/ansic/bin/cc")
100
- if status == 0
101
- description = stdout.split($/).select { |line| line =~ /HP C Compiler/ }.first
102
- if description
103
- output = description.split
104
- c[:hpcc] = Mash.new
105
- c[:hpcc][:version] = output[1] if output.size >= 1
106
- c[:hpcc][:description] = description.strip
118
+ #hpux cc
119
+ begin
120
+ so = shell_out("what /opt/ansic/bin/cc")
121
+ if so.exitstatus == 0
122
+ description = so.stdout.split($/).select { |line| line =~ /HP C Compiler/ }.first
123
+ if description
124
+ output = description.split
125
+ c[:hpcc] = Mash.new
126
+ c[:hpcc][:version] = output[1] if output.size >= 1
127
+ c[:hpcc][:description] = description.strip
128
+ end
129
+ end
130
+ rescue Errno::ENOENT
131
+ end
132
+
133
+ languages[:c] = c if c.keys.length > 0
107
134
  end
108
135
  end
109
-
110
- languages[:c] = c if c.keys.length > 0
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,10 +16,22 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/version'
20
- provides "chef"
19
+ Ohai.plugin(:Chef) do
20
+ provides "chef_packages/chef"
21
+
22
+ collect_data do
23
+ begin
24
+ require 'chef/version'
25
+ rescue Gem::LoadError
26
+ # this catches when you've done a major version bump of ohai, but
27
+ # your chef gem is incompatible, so we can't load it in the same VM
28
+ # (affects mostly internal testing)
29
+ next
30
+ end
21
31
 
22
- self[:chef_packages] = Mash.new unless self[:chef_packages]
23
- self[:chef_packages][:chef] = Mash.new
24
- self[:chef_packages][:chef][:version] = Chef::VERSION
25
- self[:chef_packages][:chef][:chef_root] = Chef::CHEF_ROOT
32
+ chef_packages Mash.new unless chef_packages
33
+ chef_packages[:chef] = Mash.new
34
+ chef_packages[:chef][:version] = Chef::VERSION
35
+ chef_packages[:chef][:chef_root] = Chef::CHEF_ROOT
36
+ end
37
+ end
@@ -14,241 +14,245 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- provides "cloud"
18
-
19
- require_plugin "ec2"
20
- require_plugin "gce"
21
- require_plugin "rackspace"
22
- require_plugin "eucalyptus"
23
- require_plugin "linode"
24
- require_plugin "openstack"
25
- require_plugin "azure"
26
-
27
- # Make top-level cloud hashes
28
- #
29
- def create_objects
30
- cloud Mash.new
31
- cloud[:public_ips] = Array.new
32
- cloud[:private_ips] = Array.new
33
- end
34
- #---------------------------------------
35
- # Google Compute Engine (gce)
36
- #--------------------------------------
37
-
38
- # Is current cloud gce?
39
- #
40
- # === Return
41
- # true:: If gce Hash is defined
42
- # false:: Otherwise
43
- def on_gce?
44
- gce != nil
45
- end
46
-
47
- # Fill cloud hash with gce values
48
- def get_gce_values
49
- cloud[:public_ipv4] = []
50
- cloud[:local_ipv4] = []
51
-
52
- public_ips = gce['instance']["networkInterfaces"].collect do |interface|
53
- if interface.has_key?('accessConfigs')
54
- interface['accessConfigs'].collect{|ac| ac['externalIp']}
17
+ Ohai.plugin(:Cloud) do
18
+ provides "cloud"
19
+
20
+ depends "ec2"
21
+ depends "gce"
22
+ depends "rackspace"
23
+ depends "eucalyptus"
24
+ depends "linode"
25
+ depends "openstack"
26
+ depends "azure"
27
+
28
+ # Make top-level cloud hashes
29
+ #
30
+ def create_objects
31
+ cloud Mash.new
32
+ cloud[:public_ips] = Array.new
33
+ cloud[:private_ips] = Array.new
34
+ end
35
+ #---------------------------------------
36
+ # Google Compute Engine (gce)
37
+ #--------------------------------------
38
+
39
+ # Is current cloud gce?
40
+ #
41
+ # === Return
42
+ # true:: If gce Hash is defined
43
+ # false:: Otherwise
44
+ def on_gce?
45
+ gce != nil
46
+ end
47
+
48
+ # Fill cloud hash with gce values
49
+ def get_gce_values
50
+ cloud[:public_ipv4] = []
51
+ cloud[:local_ipv4] = []
52
+
53
+ public_ips = gce['instance']["networkInterfaces"].collect do |interface|
54
+ if interface.has_key?('accessConfigs')
55
+ interface['accessConfigs'].collect{|ac| ac['externalIp']}
56
+ end
57
+ end.flatten.compact
58
+
59
+ private_ips = gce['instance']["networkInterfaces"].collect do |interface|
60
+ interface['ip']
61
+ end.compact
62
+
63
+ cloud[:public_ips] += public_ips
64
+ cloud[:private_ips] += private_ips
65
+ cloud[:public_ipv4] += public_ips
66
+ cloud[:public_hostname] = nil
67
+ cloud[:local_ipv4] += private_ips
68
+ cloud[:local_hostname] = gce['instance']['hostname']
69
+ cloud[:provider] = "gce"
70
+ end
71
+
72
+ # ----------------------------------------
73
+ # ec2
74
+ # ----------------------------------------
75
+
76
+ # Is current cloud ec2?
77
+ #
78
+ # === Return
79
+ # true:: If ec2 Hash is defined
80
+ # false:: Otherwise
81
+ def on_ec2?
82
+ ec2 != nil
83
+ end
84
+
85
+ # Fill cloud hash with ec2 values
86
+ def get_ec2_values
87
+ cloud[:public_ips] << ec2['public_ipv4']
88
+ cloud[:private_ips] << ec2['local_ipv4']
89
+ cloud[:public_ipv4] = ec2['public_ipv4']
90
+ cloud[:public_hostname] = ec2['public_hostname']
91
+ cloud[:local_ipv4] = ec2['local_ipv4']
92
+ cloud[:local_hostname] = ec2['local_hostname']
93
+ cloud[:provider] = "ec2"
94
+ end
95
+
96
+ # ----------------------------------------
97
+ # rackspace
98
+ # ----------------------------------------
99
+
100
+ # Is current cloud rackspace?
101
+ #
102
+ # === Return
103
+ # true:: If rackspace Hash is defined
104
+ # false:: Otherwise
105
+ def on_rackspace?
106
+ rackspace != nil
107
+ end
108
+
109
+ # Fill cloud hash with rackspace values
110
+ def get_rackspace_values
111
+ cloud[:public_ips] << rackspace['public_ipv4'] if rackspace['public_ipv4']
112
+ cloud[:private_ips] << rackspace['local_ipv4'] if rackspace['local_ipv4']
113
+ cloud[:public_ipv4] = rackspace['public_ipv4']
114
+ cloud[:public_ipv6] = rackspace['public_ipv6']
115
+ cloud[:public_hostname] = rackspace['public_hostname']
116
+ cloud[:local_ipv4] = rackspace['local_ipv4']
117
+ cloud[:local_ipv6] = rackspace['local_ipv6']
118
+ cloud[:local_hostname] = rackspace['local_hostname']
119
+ cloud[:provider] = "rackspace"
120
+ end
121
+
122
+ # ----------------------------------------
123
+ # linode
124
+ # ----------------------------------------
125
+
126
+ # Is current cloud linode?
127
+ #
128
+ # === Return
129
+ # true:: If linode Hash is defined
130
+ # false:: Otherwise
131
+ def on_linode?
132
+ linode != nil
133
+ end
134
+
135
+ # Fill cloud hash with linode values
136
+ def get_linode_values
137
+ cloud[:public_ips] << linode['public_ip']
138
+ cloud[:private_ips] << linode['private_ip']
139
+ cloud[:public_ipv4] = linode['public_ipv4']
140
+ cloud[:public_hostname] = linode['public_hostname']
141
+ cloud[:local_ipv4] = linode['local_ipv4']
142
+ cloud[:local_hostname] = linode['local_hostname']
143
+ cloud[:provider] = "linode"
144
+ end
145
+
146
+ # ----------------------------------------
147
+ # eucalyptus
148
+ # ----------------------------------------
149
+
150
+ # Is current cloud eucalyptus?
151
+ #
152
+ # === Return
153
+ # true:: If eucalyptus Hash is defined
154
+ # false:: Otherwise
155
+ def on_eucalyptus?
156
+ eucalyptus != nil
157
+ end
158
+
159
+ def get_eucalyptus_values
160
+ cloud[:public_ips] << eucalyptus['public_ipv4']
161
+ cloud[:private_ips] << eucalyptus['local_ipv4']
162
+ cloud[:public_ipv4] = eucalyptus['public_ipv4']
163
+ cloud[:public_hostname] = eucalyptus['public_hostname']
164
+ cloud[:local_ipv4] = eucalyptus['local_ipv4']
165
+ cloud[:local_hostname] = eucalyptus['local_hostname']
166
+ cloud[:provider] = "eucalyptus"
167
+ end
168
+
169
+ # ----------------------------------------
170
+ # openstack
171
+ # ----------------------------------------
172
+
173
+ # Is current cloud openstack-based?
174
+ #
175
+ # === Return
176
+ # true:: If openstack Hash is defined
177
+ # false:: Otherwise
178
+ def on_openstack?
179
+ openstack != nil
180
+ end
181
+
182
+ # Fill cloud hash with openstack values
183
+ def get_openstack_values
184
+ cloud[:public_ips] << openstack['public_ipv4']
185
+ cloud[:private_ips] << openstack['local_ipv4']
186
+ cloud[:public_ipv4] = openstack['public_ipv4']
187
+ cloud[:public_hostname] = openstack['public_hostname']
188
+ cloud[:local_ipv4] = openstack['local_ipv4']
189
+ cloud[:local_hostname] = openstack['local_hostname']
190
+ cloud[:provider] = openstack['provider']
191
+ end
192
+
193
+ # ----------------------------------------
194
+ # azure
195
+ # ----------------------------------------
196
+
197
+ # Is current cloud azure?
198
+ #
199
+ # === Return
200
+ # true:: If azure Hash is defined
201
+ # false:: Otherwise
202
+ def on_azure?
203
+ azure != nil
204
+ end
205
+
206
+ # Fill cloud hash with azure values
207
+ def get_azure_values
208
+ cloud[:vm_name] = azure["vm_name"]
209
+ cloud[:public_ips] << azure['public_ip']
210
+ cloud[:public_fqdn] = azure['public_fqdn']
211
+ cloud[:public_ssh_port] = azure['public_ssh_port'] if azure['public_ssh_port']
212
+ cloud[:public_winrm_port] = azure['public_winrm_port'] if azure['public_winrm_port']
213
+ cloud[:provider] = "azure"
214
+ end
215
+
216
+ collect_data do
217
+ # setup gce cloud
218
+ if on_gce?
219
+ create_objects
220
+ get_gce_values
55
221
  end
56
- end.flatten.compact
57
-
58
- private_ips = gce['instance']["networkInterfaces"].collect do |interface|
59
- interface['ip']
60
- end.compact
61
-
62
- cloud[:public_ips] += public_ips
63
- cloud[:private_ips] += private_ips
64
- cloud[:public_ipv4] += public_ips
65
- cloud[:public_hostname] = nil
66
- cloud[:local_ipv4] += private_ips
67
- cloud[:local_hostname] = gce['instance']['hostname']
68
- cloud[:provider] = "gce"
69
- end
70
-
71
- # setup gce cloud
72
- if on_gce?
73
- create_objects
74
- get_gce_values
75
- end
76
-
77
- # ----------------------------------------
78
- # ec2
79
- # ----------------------------------------
80
-
81
- # Is current cloud ec2?
82
- #
83
- # === Return
84
- # true:: If ec2 Hash is defined
85
- # false:: Otherwise
86
- def on_ec2?
87
- ec2 != nil
88
- end
89
-
90
- # Fill cloud hash with ec2 values
91
- def get_ec2_values
92
- cloud[:public_ips] << ec2['public_ipv4']
93
- cloud[:private_ips] << ec2['local_ipv4']
94
- cloud[:public_ipv4] = ec2['public_ipv4']
95
- cloud[:public_hostname] = ec2['public_hostname']
96
- cloud[:local_ipv4] = ec2['local_ipv4']
97
- cloud[:local_hostname] = ec2['local_hostname']
98
- cloud[:provider] = "ec2"
99
- end
100
-
101
- # setup ec2 cloud
102
- if on_ec2?
103
- create_objects
104
- get_ec2_values
105
- end
106
-
107
- # ----------------------------------------
108
- # rackspace
109
- # ----------------------------------------
110
222
 
111
- # Is current cloud rackspace?
112
- #
113
- # === Return
114
- # true:: If rackspace Hash is defined
115
- # false:: Otherwise
116
- def on_rackspace?
117
- rackspace != nil
118
- end
119
-
120
- # Fill cloud hash with rackspace values
121
- def get_rackspace_values
122
- cloud[:public_ips] << rackspace['public_ipv4'] if rackspace['public_ipv4']
123
- cloud[:private_ips] << rackspace['local_ipv4'] if rackspace['local_ipv4']
124
- cloud[:public_ipv4] = rackspace['public_ipv4']
125
- cloud[:public_ipv6] = rackspace['public_ipv6']
126
- cloud[:public_hostname] = rackspace['public_hostname']
127
- cloud[:local_ipv4] = rackspace['local_ipv4']
128
- cloud[:local_ipv6] = rackspace['local_ipv6']
129
- cloud[:local_hostname] = rackspace['local_hostname']
130
- cloud[:provider] = "rackspace"
131
- end
132
-
133
- # setup rackspace cloud
134
- if on_rackspace?
135
- create_objects
136
- get_rackspace_values
137
- end
138
-
139
- # ----------------------------------------
140
- # linode
141
- # ----------------------------------------
142
-
143
- # Is current cloud linode?
144
- #
145
- # === Return
146
- # true:: If linode Hash is defined
147
- # false:: Otherwise
148
- def on_linode?
149
- linode != nil
150
- end
151
-
152
- # Fill cloud hash with linode values
153
- def get_linode_values
154
- cloud[:public_ips] << linode['public_ip']
155
- cloud[:private_ips] << linode['private_ip']
156
- cloud[:public_ipv4] = linode['public_ipv4']
157
- cloud[:public_hostname] = linode['public_hostname']
158
- cloud[:local_ipv4] = linode['local_ipv4']
159
- cloud[:local_hostname] = linode['local_hostname']
160
- cloud[:provider] = "linode"
161
- end
162
-
163
- # setup linode cloud data
164
- if on_linode?
165
- create_objects
166
- get_linode_values
167
- end
168
-
169
- # ----------------------------------------
170
- # eucalyptus
171
- # ----------------------------------------
172
-
173
- # Is current cloud eucalyptus?
174
- #
175
- # === Return
176
- # true:: If eucalyptus Hash is defined
177
- # false:: Otherwise
178
- def on_eucalyptus?
179
- eucalyptus != nil
180
- end
181
-
182
- def get_eucalyptus_values
183
- cloud[:public_ips] << eucalyptus['public_ipv4']
184
- cloud[:private_ips] << eucalyptus['local_ipv4']
185
- cloud[:public_ipv4] = eucalyptus['public_ipv4']
186
- cloud[:public_hostname] = eucalyptus['public_hostname']
187
- cloud[:local_ipv4] = eucalyptus['local_ipv4']
188
- cloud[:local_hostname] = eucalyptus['local_hostname']
189
- cloud[:provider] = "eucalyptus"
190
- end
191
-
192
- if on_eucalyptus?
193
- create_objects
194
- get_eucalyptus_values
195
- end
196
-
197
- # ----------------------------------------
198
- # openstack
199
- # ----------------------------------------
200
-
201
- # Is current cloud openstack-based?
202
- #
203
- # === Return
204
- # true:: If openstack Hash is defined
205
- # false:: Otherwise
206
- def on_openstack?
207
- openstack != nil
208
- end
209
-
210
- # Fill cloud hash with openstack values
211
- def get_openstack_values
212
- cloud[:public_ips] << openstack['public_ipv4']
213
- cloud[:private_ips] << openstack['local_ipv4']
214
- cloud[:public_ipv4] = openstack['public_ipv4']
215
- cloud[:public_hostname] = openstack['public_hostname']
216
- cloud[:local_ipv4] = openstack['local_ipv4']
217
- cloud[:local_hostname] = openstack['local_hostname']
218
- cloud[:provider] = openstack['provider']
219
- end
223
+ # setup ec2 cloud
224
+ if on_ec2?
225
+ create_objects
226
+ get_ec2_values
227
+ end
220
228
 
221
- # setup openstack cloud
222
- if on_openstack?
223
- create_objects
224
- get_openstack_values
225
- end
229
+ # setup rackspace cloud
230
+ if on_rackspace?
231
+ create_objects
232
+ get_rackspace_values
233
+ end
226
234
 
227
- # ----------------------------------------
228
- # azure
229
- # ----------------------------------------
235
+ # setup linode cloud data
236
+ if on_linode?
237
+ create_objects
238
+ get_linode_values
239
+ end
230
240
 
231
- # Is current cloud azure?
232
- #
233
- # === Return
234
- # true:: If azure Hash is defined
235
- # false:: Otherwise
236
- def on_azure?
237
- azure != nil
238
- end
241
+ if on_eucalyptus?
242
+ create_objects
243
+ get_eucalyptus_values
244
+ end
239
245
 
240
- # Fill cloud hash with azure values
241
- def get_azure_values
242
- cloud[:vm_name] = azure["vm_name"]
243
- cloud[:public_ips] << azure['public_ip']
244
- cloud[:public_fqdn] = azure['public_fqdn']
245
- cloud[:public_ssh_port] = azure['public_ssh_port'] if azure['public_ssh_port']
246
- cloud[:public_winrm_port] = azure['public_winrm_port'] if azure['public_winrm_port']
247
- cloud[:provider] = "azure"
248
- end
246
+ # setup openstack cloud
247
+ if on_openstack?
248
+ create_objects
249
+ get_openstack_values
250
+ end
249
251
 
250
- # setup azure cloud data
251
- if on_azure?
252
- create_objects
253
- get_azure_values
252
+ # setup azure cloud data
253
+ if on_azure?
254
+ create_objects
255
+ get_azure_values
256
+ end
257
+ end
254
258
  end