ohai 8.26.1 → 13.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +3 -4
  3. data/Rakefile +14 -0
  4. data/lib/ohai/application.rb +1 -0
  5. data/lib/ohai/config.rb +2 -88
  6. data/lib/ohai/dsl/plugin.rb +0 -4
  7. data/lib/ohai/exception.rb +0 -1
  8. data/lib/ohai/loader.rb +11 -2
  9. data/lib/ohai/log.rb +3 -1
  10. data/lib/ohai/mixin/command.rb +1 -318
  11. data/lib/ohai/mixin/do_metadata.rb +47 -0
  12. data/lib/ohai/mixin/ec2_metadata.rb +2 -29
  13. data/lib/ohai/mixin/gce_metadata.rb +0 -37
  14. data/lib/ohai/mixin/http_helper.rb +56 -0
  15. data/lib/ohai/mixin/network_constants.rb +0 -5
  16. data/lib/ohai/plugins/cloud.rb +144 -157
  17. data/lib/ohai/plugins/darwin/filesystem.rb +68 -22
  18. data/lib/ohai/plugins/digital_ocean.rb +24 -42
  19. data/lib/ohai/plugins/dmi.rb +81 -77
  20. data/lib/ohai/plugins/ec2.rb +33 -60
  21. data/lib/ohai/plugins/gce.rb +3 -1
  22. data/lib/ohai/plugins/hostname.rb +1 -16
  23. data/lib/ohai/plugins/linux/filesystem.rb +130 -81
  24. data/lib/ohai/plugins/linux/mdadm.rb +3 -45
  25. data/lib/ohai/plugins/linux/network.rb +1 -26
  26. data/lib/ohai/plugins/linux/platform.rb +4 -2
  27. data/lib/ohai/plugins/linux/virtualization.rb +1 -5
  28. data/lib/ohai/plugins/scala.rb +1 -13
  29. data/lib/ohai/plugins/solaris2/network.rb +1 -2
  30. data/lib/ohai/plugins/uptime.rb +0 -9
  31. data/lib/ohai/plugins/windows/cpu.rb +2 -1
  32. data/lib/ohai/plugins/windows/network.rb +1 -1
  33. data/lib/ohai/runner.rb +0 -5
  34. data/lib/ohai/system.rb +38 -8
  35. data/lib/ohai/version.rb +2 -2
  36. data/ohai.gemspec +1 -1
  37. data/spec/functional/application_spec.rb +0 -40
  38. data/spec/functional/plugins/powershell_spec.rb +1 -1
  39. data/spec/functional/plugins/root_group_spec.rb +1 -1
  40. data/spec/functional/plugins/windows/uptime_spec.rb +1 -1
  41. data/spec/ohai_spec.rb +1 -1
  42. data/spec/support/integration_helper.rb +17 -0
  43. data/spec/support/platform_helpers.rb +17 -0
  44. data/spec/unit/application_spec.rb +0 -1
  45. data/spec/unit/config_spec.rb +0 -111
  46. data/spec/unit/dsl/plugin_spec.rb +1 -1
  47. data/spec/unit/hints_spec.rb +1 -1
  48. data/spec/unit/loader_spec.rb +26 -1
  49. data/spec/unit/mixin/command_spec.rb +1 -69
  50. data/spec/unit/mixin/ec2_metadata_spec.rb +1 -1
  51. data/spec/unit/mixin/softlayer_metadata_spec.rb +1 -1
  52. data/spec/unit/plugin_config_spec.rb +0 -1
  53. data/spec/unit/plugins/abort_spec.rb +1 -1
  54. data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
  55. data/spec/unit/plugins/aix/filesystem_spec.rb +2 -1
  56. data/spec/unit/plugins/aix/hostname_spec.rb +1 -1
  57. data/spec/unit/plugins/aix/kernel_spec.rb +1 -1
  58. data/spec/unit/plugins/aix/memory_spec.rb +1 -1
  59. data/spec/unit/plugins/aix/network_spec.rb +1 -1
  60. data/spec/unit/plugins/aix/os_spec.rb +1 -1
  61. data/spec/unit/plugins/aix/platform_spec.rb +1 -1
  62. data/spec/unit/plugins/aix/uptime_spec.rb +1 -1
  63. data/spec/unit/plugins/aix/virtualization_spec.rb +1 -1
  64. data/spec/unit/plugins/azure_spec.rb +1 -1
  65. data/spec/unit/plugins/bsd/filesystem_spec.rb +1 -1
  66. data/spec/unit/plugins/bsd/virtualization_spec.rb +1 -1
  67. data/spec/unit/plugins/c_spec.rb +1 -1
  68. data/spec/unit/plugins/chef_spec.rb +1 -2
  69. data/spec/unit/plugins/cloud_spec.rb +210 -50
  70. data/spec/unit/plugins/darwin/cpu_spec.rb +1 -1
  71. data/spec/unit/plugins/darwin/filesystem_spec.rb +62 -13
  72. data/spec/unit/plugins/darwin/hardware_spec.rb +2 -2
  73. data/spec/unit/plugins/darwin/hostname_spec.rb +1 -1
  74. data/spec/unit/plugins/darwin/kernel_spec.rb +1 -1
  75. data/spec/unit/plugins/darwin/memory_spec.rb +1 -1
  76. data/spec/unit/plugins/darwin/network_spec.rb +1 -1
  77. data/spec/unit/plugins/darwin/platform_spec.rb +1 -1
  78. data/spec/unit/plugins/darwin/system_profiler_spec.rb +2 -9
  79. data/spec/unit/plugins/darwin/virtualization_spec.rb +1 -1
  80. data/spec/unit/plugins/digital_ocean_spec.rb +39 -110
  81. data/spec/unit/plugins/dmi_spec.rb +1 -1
  82. data/spec/unit/plugins/ec2_spec.rb +10 -62
  83. data/spec/unit/plugins/elixir_spec.rb +1 -1
  84. data/spec/unit/plugins/erlang_spec.rb +1 -1
  85. data/spec/unit/plugins/eucalyptus_spec.rb +1 -1
  86. data/spec/unit/plugins/fail_spec.rb +1 -1
  87. data/spec/unit/plugins/freebsd/cpu_spec.rb +1 -1
  88. data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -1
  89. data/spec/unit/plugins/freebsd/kernel_spec.rb +1 -1
  90. data/spec/unit/plugins/freebsd/os_spec.rb +1 -1
  91. data/spec/unit/plugins/freebsd/platform_spec.rb +1 -1
  92. data/spec/unit/plugins/gce_spec.rb +1 -1
  93. data/spec/unit/plugins/go_spec.rb +1 -1
  94. data/spec/unit/plugins/groovy_spec.rb +1 -1
  95. data/spec/unit/plugins/haskell_spec.rb +1 -1
  96. data/spec/unit/plugins/hostname_spec.rb +16 -41
  97. data/spec/unit/plugins/init_package_spec.rb +1 -1
  98. data/spec/unit/plugins/ip_scopes_spec.rb +18 -6
  99. data/spec/unit/plugins/java_spec.rb +1 -1
  100. data/spec/unit/plugins/joyent_spec.rb +17 -1
  101. data/spec/unit/plugins/kernel_spec.rb +1 -1
  102. data/spec/unit/plugins/linode_spec.rb +1 -1
  103. data/spec/unit/plugins/linux/block_device_spec.rb +1 -1
  104. data/spec/unit/plugins/linux/cpu_spec.rb +1 -2
  105. data/spec/unit/plugins/linux/filesystem_spec.rb +207 -201
  106. data/spec/unit/plugins/linux/fips_spec.rb +1 -1
  107. data/spec/unit/plugins/linux/hostname_spec.rb +1 -1
  108. data/spec/unit/plugins/linux/hostnamectl_spec.rb +1 -1
  109. data/spec/unit/plugins/linux/kernel_spec.rb +1 -1
  110. data/spec/unit/plugins/linux/lsb_spec.rb +1 -1
  111. data/spec/unit/plugins/linux/machineid_spec.rb +1 -1
  112. data/spec/unit/plugins/linux/mdadm_spec.rb +2 -68
  113. data/spec/unit/plugins/linux/memory_spec.rb +1 -1
  114. data/spec/unit/plugins/linux/network_spec.rb +3 -44
  115. data/spec/unit/plugins/linux/platform_spec.rb +4 -4
  116. data/spec/unit/plugins/linux/sessions_spec.rb +1 -1
  117. data/spec/unit/plugins/linux/uptime_spec.rb +1 -1
  118. data/spec/unit/plugins/linux/virtualization_spec.rb +1 -28
  119. data/spec/unit/plugins/lua_spec.rb +1 -1
  120. data/spec/unit/plugins/mono_spec.rb +1 -1
  121. data/spec/unit/plugins/netbsd/hostname_spec.rb +1 -1
  122. data/spec/unit/plugins/netbsd/kernel_spec.rb +1 -1
  123. data/spec/unit/plugins/netbsd/platform_spec.rb +1 -1
  124. data/spec/unit/plugins/network_spec.rb +1 -1
  125. data/spec/unit/plugins/nodejs_spec.rb +1 -1
  126. data/spec/unit/plugins/ohai_spec.rb +1 -1
  127. data/spec/unit/plugins/ohai_time_spec.rb +1 -1
  128. data/spec/unit/plugins/openbsd/hostname_spec.rb +1 -1
  129. data/spec/unit/plugins/openbsd/kernel_spec.rb +1 -1
  130. data/spec/unit/plugins/openbsd/platform_spec.rb +1 -1
  131. data/spec/unit/plugins/openstack_spec.rb +2 -3
  132. data/spec/unit/plugins/os_spec.rb +1 -1
  133. data/spec/unit/plugins/packages_spec.rb +1 -1
  134. data/spec/unit/plugins/passwd_spec.rb +17 -1
  135. data/spec/unit/plugins/perl_spec.rb +1 -1
  136. data/spec/unit/plugins/php_spec.rb +1 -1
  137. data/spec/unit/plugins/platform_spec.rb +1 -1
  138. data/spec/unit/plugins/powershell_spec.rb +1 -1
  139. data/spec/unit/plugins/python_spec.rb +1 -1
  140. data/spec/unit/plugins/rackspace_spec.rb +1 -2
  141. data/spec/unit/plugins/root_group_spec.rb +2 -2
  142. data/spec/unit/plugins/ruby_spec.rb +1 -1
  143. data/spec/unit/plugins/rust_spec.rb +1 -1
  144. data/spec/unit/plugins/scala_spec.rb +3 -37
  145. data/spec/unit/plugins/shard_spec.rb +1 -1
  146. data/spec/unit/plugins/shells_spec.rb +1 -1
  147. data/spec/unit/plugins/softlayer_spec.rb +1 -1
  148. data/spec/unit/plugins/solaris2/cpu_spec.rb +1 -1
  149. data/spec/unit/plugins/solaris2/dmi_spec.rb +1 -1
  150. data/spec/unit/plugins/solaris2/hostname_spec.rb +1 -1
  151. data/spec/unit/plugins/solaris2/kernel_spec.rb +1 -1
  152. data/spec/unit/plugins/solaris2/memory_spec.rb +1 -1
  153. data/spec/unit/plugins/solaris2/network_spec.rb +7 -4
  154. data/spec/unit/plugins/solaris2/platform_spec.rb +1 -1
  155. data/spec/unit/plugins/solaris2/virtualization_spec.rb +1 -1
  156. data/spec/unit/plugins/solaris2/zpools_spec.rb +1 -1
  157. data/spec/unit/plugins/ssh_host_keys_spec.rb +1 -1
  158. data/spec/unit/plugins/sysconf_spec.rb +1 -1
  159. data/spec/unit/plugins/timezone_spec.rb +1 -1
  160. data/spec/unit/plugins/virtualbox_spec.rb +1 -1
  161. data/spec/unit/plugins/vmware_spec.rb +2 -1
  162. data/spec/unit/plugins/windows/cpu_spec.rb +9 -2
  163. data/spec/unit/plugins/windows/fips_spec.rb +1 -1
  164. data/spec/unit/plugins/windows/memory_spec.rb +1 -1
  165. data/spec/unit/plugins/windows/uptime_spec.rb +1 -1
  166. data/spec/unit/plugins/windows/virtualization_spec.rb +1 -1
  167. data/spec/unit/provides_map_spec.rb +1 -1
  168. data/spec/unit/runner_spec.rb +1 -1
  169. data/spec/unit/system_spec.rb +68 -76
  170. data/spec/unit/util/file_helper_spec.rb +1 -1
  171. data/spec/unit/util/ip_helper_spec.rb +1 -1
  172. metadata +6 -20
  173. data/lib/ohai/plugins/cloud_v2.rb +0 -315
  174. data/lib/ohai/plugins/darwin/filesystem2.rb +0 -107
  175. data/lib/ohai/plugins/linux/filesystem2.rb +0 -223
  176. data/lib/ohai/plugins/linux/lspci.rb +0 -76
  177. data/lib/ohai/plugins/network_listeners.rb +0 -60
  178. data/lib/ohai/plugins/sigar/cpu.rb +0 -44
  179. data/lib/ohai/plugins/sigar/filesystem.rb +0 -50
  180. data/lib/ohai/plugins/sigar/memory.rb +0 -39
  181. data/lib/ohai/plugins/sigar/network.rb +0 -168
  182. data/lib/ohai/plugins/sigar/network_route.rb +0 -64
  183. data/lib/ohai/plugins/sigar/platform.rb +0 -30
  184. data/spec/unit/plugins/cloud_v2_spec.rb +0 -389
  185. data/spec/unit/plugins/darwin/filesystem2_spec.rb +0 -139
  186. data/spec/unit/plugins/linux/filesystem2_spec.rb +0 -437
  187. data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
  188. data/spec/unit/plugins/sigar/network_route_spec.rb +0 -148
@@ -1,315 +0,0 @@
1
- #
2
- # Author:: Cary Penniman (<cary@rightscale.com>)
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- Ohai.plugin(:CloudV2) do
18
- provides "cloud_v2"
19
-
20
- depends "ec2"
21
- depends "gce"
22
- depends "rackspace"
23
- depends "eucalyptus"
24
- depends "linode"
25
- depends "openstack"
26
- depends "azure"
27
- depends "digital_ocean"
28
-
29
- # Class to help enforce the interface exposed to node[:cloud] (OHAI-542)
30
- #
31
- # cloud[:provider] - (String) the cloud provider the VM is running on.
32
- #
33
- # cloud[:public_hostname] - (String) a fully qualified hostname
34
- # cloud[:local_hostname] - (String) a hostname resolvable on the internal (private) network
35
- #
36
- # cloud[:public_ipv4_addrs] - (Array) a list of all publicly accessible IPv4 addresses
37
- # cloud[:local_ipv4_addrs] - (Array) a list of all private IPv4 addresses
38
- # cloud[:public_ipv4] - (String) the first public IPv4 address detected
39
- # cloud[:local_ipv4] - (String) the first private IPv4 address detected
40
- #
41
- # cloud[:public_ipv6_addrs] - (Array) a list of all publicly accessible IPv6 addresses
42
- # cloud[:local_ipv6_addrs] - (Array) a list of all private IPv6 addresses
43
- # cloud[:public_ipv6] - (String) the first public IPv6 address detected
44
- # cloud[:local_ipv6] - (String) the first private IPv6 address detected
45
- #
46
- class CloudAttrs
47
- attr_writer :provider, :public_hostname, :local_hostname
48
-
49
- def initialize
50
- @cloud = Mash.new
51
- end
52
-
53
- def add_ipv4_addr(ip, accessibility)
54
- return if ip.nil? # just skip if ip is nil
55
- ipaddr = validate_ip_addr(ip, :ipv4)
56
-
57
- case accessibility
58
- when :public
59
- @cloud[:public_ipv4_addrs] ||= Array.new
60
- @cloud[:public_ipv4_addrs] << ipaddr.to_s
61
- when :private
62
- @cloud[:local_ipv4_addrs] ||= Array.new
63
- @cloud[:local_ipv4_addrs] << ipaddr.to_s
64
- else
65
- raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private."
66
- end
67
- end
68
-
69
- def add_ipv6_addr(ip, accessibility)
70
- return if ip.nil? # just skip if ip is nil
71
- ipaddr = validate_ip_addr(ip, :ipv6)
72
-
73
- raise "ERROR: invalid ipv6 address of '#{ip}' detected. " unless ipaddr.ipv6?
74
- case accessibility
75
- when :public
76
- @cloud[:public_ipv6_addrs] ||= Array.new
77
- @cloud[:public_ipv6_addrs] << ipaddr.to_s
78
- when :private
79
- @cloud[:local_ipv6_addrs] ||= Array.new
80
- @cloud[:local_ipv6_addrs] << ipaddr.to_s
81
- else
82
- raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private."
83
- end
84
- end
85
-
86
- def cloud_mash
87
- @cloud[:provider] = @provider if @provider
88
-
89
- @cloud[:public_hostname] = @public_hostname if @public_hostname
90
- @cloud[:local_hostname] = @local_hostname if @local_hostname
91
-
92
- @cloud[:public_ipv4] = @cloud[:public_ipv4_addrs][0] if @cloud[:public_ipv4_addrs]
93
- @cloud[:local_ipv4] = @cloud[:local_ipv4_addrs][0] if @cloud[:local_ipv4_addrs]
94
-
95
- @cloud[:public_ipv6] = @cloud[:public_ipv6_addrs][0] if @cloud[:public_ipv6_addrs]
96
- @cloud[:local_ipv6] = @cloud[:local_ipv6_addrs][0] if @cloud[:local_ipv6_addrs]
97
-
98
- # if empty, return nil
99
- (@cloud.empty?) ? nil : @cloud
100
- end
101
-
102
- private
103
-
104
- def validate_ip_addr(ip, address_family = :ipv4)
105
- ipaddr = ""
106
- begin
107
- ipaddr = IPAddr.new(ip)
108
- raise ArgumentError, "not valid #{address_family} address" unless (address_family == :ipv4) ? ipaddr.ipv4? : ipaddr.ipv6?
109
- rescue ArgumentError => e
110
- raise "ERROR: the ohai 'cloud' plugin failed with an IP address of '#{ip}' : #{e.message}"
111
- end
112
- ipaddr
113
- end
114
- end
115
-
116
- #---------------------------------------
117
- # Google Compute Engine (gce)
118
- #--------------------------------------
119
-
120
- def on_gce?
121
- gce != nil
122
- end
123
-
124
- def get_gce_values
125
- public_ips = gce["instance"]["networkInterfaces"].collect do |interface|
126
- if interface.has_key?("accessConfigs")
127
- interface["accessConfigs"].collect { |ac| ac["externalIp"] unless ac["externalIp"] == "" }
128
- end
129
- end.flatten.compact
130
-
131
- private_ips = gce["instance"]["networkInterfaces"].collect do |interface|
132
- interface["ip"]
133
- end.compact
134
-
135
- public_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :public) }
136
- private_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :private) }
137
- @cloud_attr_obj.local_hostname = gce["instance"]["hostname"]
138
- @cloud_attr_obj.provider = "gce"
139
- end
140
-
141
- # ----------------------------------------
142
- # ec2
143
- # ----------------------------------------
144
-
145
- # Is current cloud ec2?
146
- #
147
- # === Return
148
- # true:: If ec2 Hash is defined
149
- # false:: Otherwise
150
- def on_ec2?
151
- ec2 != nil
152
- end
153
-
154
- # Fill cloud hash with ec2 values
155
- def get_ec2_values
156
- @cloud_attr_obj.add_ipv4_addr(ec2["public_ipv4"], :public)
157
- @cloud_attr_obj.add_ipv4_addr(ec2["local_ipv4"], :private)
158
- @cloud_attr_obj.public_hostname = ec2["public_hostname"]
159
- @cloud_attr_obj.local_hostname = ec2["local_hostname"]
160
- @cloud_attr_obj.provider = "ec2"
161
- end
162
-
163
- # ----------------------------------------
164
- # rackspace
165
- # ----------------------------------------
166
-
167
- # Is current cloud rackspace?
168
- #
169
- # === Return
170
- # true:: If rackspace Hash is defined
171
- # false:: Otherwise
172
- def on_rackspace?
173
- rackspace != nil
174
- end
175
-
176
- # Fill cloud hash with rackspace values
177
- def get_rackspace_values
178
- @cloud_attr_obj.add_ipv4_addr(rackspace["public_ipv4"], :public)
179
- @cloud_attr_obj.add_ipv4_addr(rackspace["local_ipv4"], :private)
180
- @cloud_attr_obj.add_ipv6_addr(rackspace["public_ipv6"], :public)
181
- @cloud_attr_obj.add_ipv6_addr(rackspace["local_ipv6"], :private)
182
- @cloud_attr_obj.public_hostname = rackspace["public_hostname"]
183
- @cloud_attr_obj.local_hostname = rackspace["local_hostname"]
184
- @cloud_attr_obj.provider = "rackspace"
185
- end
186
-
187
- # ----------------------------------------
188
- # linode
189
- # ----------------------------------------
190
-
191
- # Is current cloud linode?
192
- #
193
- # === Return
194
- # true:: If linode Hash is defined
195
- # false:: Otherwise
196
- def on_linode?
197
- linode != nil
198
- end
199
-
200
- # Fill cloud hash with linode values
201
- def get_linode_values
202
- @cloud_attr_obj.add_ipv4_addr(linode["public_ip"], :public)
203
- @cloud_attr_obj.add_ipv4_addr(linode["private_ip"], :private)
204
- @cloud_attr_obj.public_hostname = linode["public_hostname"]
205
- @cloud_attr_obj.local_hostname = linode["local_hostname"]
206
- @cloud_attr_obj.provider = "linode"
207
- end
208
-
209
- # ----------------------------------------
210
- # eucalyptus
211
- # ----------------------------------------
212
-
213
- # Is current cloud eucalyptus?
214
- #
215
- # === Return
216
- # true:: If eucalyptus Hash is defined
217
- # false:: Otherwise
218
- def on_eucalyptus?
219
- eucalyptus != nil
220
- end
221
-
222
- def get_eucalyptus_values
223
- @cloud_attr_obj.add_ipv4_addr(eucalyptus["public_ipv4"], :public)
224
- @cloud_attr_obj.add_ipv4_addr(eucalyptus["local_ipv4"], :private)
225
- @cloud_attr_obj.public_hostname = eucalyptus["public_hostname"]
226
- @cloud_attr_obj.local_hostname = eucalyptus["local_hostname"]
227
- @cloud_attr_obj.provider = "eucalyptus"
228
- end
229
-
230
- # ----------------------------------------
231
- # openstack
232
- # ----------------------------------------
233
-
234
- # Is current cloud openstack-based?
235
- #
236
- # === Return
237
- # true:: If openstack Hash is defined
238
- # false:: Otherwise
239
- def on_openstack?
240
- openstack != nil
241
- end
242
-
243
- # Fill cloud hash with openstack values
244
- def get_openstack_values
245
- @cloud_attr_obj.add_ipv4_addr(openstack["public_ipv4"], :public)
246
- @cloud_attr_obj.add_ipv4_addr(openstack["local_ipv4"], :private)
247
- @cloud_attr_obj.public_hostname = openstack["public_hostname"]
248
- @cloud_attr_obj.local_hostname = openstack["local_hostname"]
249
- @cloud_attr_obj.provider = openstack["provider"]
250
- end
251
-
252
- # ----------------------------------------
253
- # azure
254
- # ----------------------------------------
255
-
256
- # Is current cloud azure?
257
- #
258
- # === Return
259
- # true:: If azure Hash is defined
260
- # false:: Otherwise
261
- def on_azure?
262
- azure != nil
263
- end
264
-
265
- # Fill cloud hash with azure values
266
- def get_azure_values
267
- @cloud_attr_obj.add_ipv4_addr(azure["public_ip"], :public)
268
- @cloud_attr_obj.add_ipv4_addr(azure["private_ip"], :private)
269
- @cloud_attr_obj.public_hostname = azure["public_fqdn"]
270
- @cloud_attr_obj.provider = "azure"
271
- end
272
-
273
- # ----------------------------------------
274
- # digital_ocean
275
- # ----------------------------------------
276
-
277
- # Is current cloud digital_ocean?
278
- #
279
- # === Return
280
- # true:: If digital_ocean Mash is defined
281
- # false:: Otherwise
282
- def on_digital_ocean?
283
- digital_ocean != nil
284
- end
285
-
286
- # Fill cloud hash with digital_ocean values
287
- def get_digital_ocean_values
288
- digital_ocean["networks"].each do |network, addresses|
289
- type = network == "v4" ? "ipv4" : "ipv6"
290
- addresses.each do |address|
291
- @cloud_attr_obj.send("add_#{type}_addr", address["ip_address"], address["type"].to_sym)
292
- end
293
- end
294
- @cloud_attr_obj.public_hostname = digital_ocean["name"]
295
- @cloud_attr_obj.provider = "digital_ocean"
296
- end
297
-
298
- collect_data do
299
- require "ipaddr"
300
-
301
- @cloud_attr_obj = CloudAttrs.new()
302
-
303
- get_gce_values if on_gce?
304
- get_ec2_values if on_ec2?
305
- get_rackspace_values if on_rackspace?
306
- get_linode_values if on_linode?
307
- get_eucalyptus_values if on_eucalyptus?
308
- get_openstack_values if on_openstack?
309
- get_azure_values if on_azure?
310
- get_digital_ocean_values if on_digital_ocean?
311
-
312
- # set node[:cloud] hash here
313
- cloud_v2 @cloud_attr_obj.cloud_mash
314
- end
315
- end
@@ -1,107 +0,0 @@
1
- #
2
- # Author:: Phil Dibowitz (<phil@ipom.com>)
3
- # Author:: Benjamin Black (<bb@chef.io>)
4
- # Copyright:: Copyright (c) 2009-2016 Chef Software, Inc.
5
- # Copyright:: Copyright (c) 2015 Facebook, Inc.
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
-
21
- Ohai.plugin(:Filesystem2) do
22
- provides "filesystem2"
23
-
24
- def generate_device_view(fs)
25
- view = {}
26
- fs.each_value do |entry|
27
- view[entry[:device]] = Mash.new unless view[entry[:device]]
28
- entry.each do |key, val|
29
- next if %w{device mount}.include?(key)
30
- view[entry[:device]][key] = val
31
- end
32
- if entry[:mount]
33
- view[entry[:device]][:mounts] = [] unless view[entry[:device]][:mounts]
34
- view[entry[:device]][:mounts] << entry[:mount]
35
- end
36
- end
37
- view
38
- end
39
-
40
- def generate_mountpoint_view(fs)
41
- view = {}
42
- fs.each_value do |entry|
43
- next unless entry[:mount]
44
- view[entry[:mount]] = Mash.new unless view[entry[:mount]]
45
- entry.each do |key, val|
46
- next if %w{mount device}.include?(key)
47
- view[entry[:mount]][key] = val
48
- end
49
- if entry[:device]
50
- view[entry[:mount]][:devices] = [] unless view[entry[:mount]][:devices]
51
- view[entry[:mount]][:devices] << entry[:device]
52
- end
53
- end
54
- view
55
- end
56
-
57
- collect_data(:darwin) do
58
- fs = Mash.new
59
- block_size = 0
60
- # on new versions of OSX, -i is default, on old versions it's not, so
61
- # specifying it gets consistent output
62
- so = shell_out("df -i")
63
- so.stdout.each_line do |line|
64
- case line
65
- when /^Filesystem\s+(\d+)-/
66
- block_size = $1.to_i
67
- next
68
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(\d+)\s+(\d+)\s+(\d+%)\s+(.+)$/
69
- key = "#{$1},#{$9}"
70
- fs[key] = Mash.new
71
- fs[key][:block_size] = block_size
72
- fs[key][:device] = $1
73
- fs[key][:kb_size] = ($2.to_i / (1024 / block_size)).to_s
74
- fs[key][:kb_used] = ($3.to_i / (1024 / block_size)).to_s
75
- fs[key][:kb_available] = ($4.to_i / (1024 / block_size)).to_s
76
- fs[key][:percent_used] = $5
77
- fs[key][:inodes_used] = $6
78
- fs[key][:inodes_available] = $7
79
- fs[key][:total_inodes] = ($6.to_i + $7.to_i).to_s
80
- fs[key][:inodes_percent_used] = $8
81
- fs[key][:mount] = $9
82
- end
83
- end
84
-
85
- so = shell_out("mount")
86
- so.stdout.lines do |line|
87
- if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
88
- key = "#{$1},#{$2}"
89
- fs[key] = Mash.new unless fs.has_key?(key)
90
- fs[key][:mount] = $2
91
- fs[key][:fs_type] = $3
92
- fs[key][:mount_options] = $4.split(/,\s*/)
93
- end
94
- end
95
-
96
- by_pair = fs
97
- by_device = generate_device_view(fs)
98
- by_mountpoint = generate_mountpoint_view(fs)
99
-
100
- fs2 = Mash.new
101
- fs2["by_device"] = by_device
102
- fs2["by_mountpoint"] = by_mountpoint
103
- fs2["by_pair"] = by_pair
104
-
105
- filesystem2 fs2
106
- end
107
- end
@@ -1,223 +0,0 @@
1
- #
2
- # Author:: Phil Dibowitz <phil@ipom.com>
3
- # Author:: Adam Jacob <adam@chef.io>
4
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
5
- # Copyright:: Copyright (c) 2015 Facebook, Inc.
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
-
21
- Ohai.plugin(:Filesystem2) do
22
- provides "filesystem2"
23
-
24
- def find_device(name)
25
- %w{/dev /dev/mapper}.each do |dir|
26
- path = File.join(dir, name)
27
- return path if File.exist?(path)
28
- end
29
- name
30
- end
31
-
32
- def parse_line(line, have_lsblk)
33
- if have_lsblk
34
- regex = /NAME="(\S+).*?" UUID="(\S*)" LABEL="(\S*)" FSTYPE="(\S*)"/
35
- if line =~ regex
36
- dev = $1
37
- dev = find_device(dev) unless dev.start_with?("/")
38
- uuid = $2
39
- label = $3
40
- fs_type = $4
41
- return { :dev => dev, :uuid => uuid, :label => label, :fs_type => fs_type }
42
- end
43
- else
44
- bits = line.split
45
- dev = bits.shift.split(":")[0]
46
- f = { :dev => dev }
47
- bits.each do |keyval|
48
- if keyval =~ /(\S+)="(\S+)"/
49
- key = $1.downcase.to_sym
50
- key = :fs_type if key == :type
51
- f[key] = $2
52
- end
53
- end
54
- return f
55
- end
56
- return nil
57
- end
58
-
59
- def generate_device_view(fs)
60
- view = {}
61
- fs.each_value do |entry|
62
- view[entry[:device]] = Mash.new unless view[entry[:device]]
63
- entry.each do |key, val|
64
- next if %w{device mount}.include?(key)
65
- view[entry[:device]][key] = val
66
- end
67
- view[entry[:device]][:mounts] ||= []
68
- if entry[:mount]
69
- view[entry[:device]][:mounts] << entry[:mount]
70
- end
71
- end
72
- view
73
- end
74
-
75
- def generate_mountpoint_view(fs)
76
- view = {}
77
- fs.each_value do |entry|
78
- next unless entry[:mount]
79
- view[entry[:mount]] = Mash.new unless view[entry[:mount]]
80
- entry.each do |key, val|
81
- next if %w{mount device}.include?(key)
82
- view[entry[:mount]][key] = val
83
- end
84
- view[entry[:mount]][:devices] ||= []
85
- if entry[:device]
86
- view[entry[:mount]][:devices] << entry[:device]
87
- end
88
- end
89
- view
90
- end
91
-
92
- collect_data(:linux) do
93
- fs = Mash.new
94
-
95
- # Grab filesystem data from df
96
- so = shell_out("df -P")
97
- so.stdout.each_line do |line|
98
- case line
99
- when /^Filesystem\s+1024-blocks/
100
- next
101
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
102
- key = "#{$1},#{$6}"
103
- fs[key] = Mash.new
104
- fs[key][:device] = $1
105
- fs[key][:kb_size] = $2
106
- fs[key][:kb_used] = $3
107
- fs[key][:kb_available] = $4
108
- fs[key][:percent_used] = $5
109
- fs[key][:mount] = $6
110
- end
111
- end
112
-
113
- # Grab filesystem inode data from df
114
- so = shell_out("df -iP")
115
- so.stdout.each_line do |line|
116
- case line
117
- when /^Filesystem\s+Inodes/
118
- next
119
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
120
- key = "#{$1},#{$6}"
121
- fs[key] ||= Mash.new
122
- fs[key][:device] = $1
123
- fs[key][:total_inodes] = $2
124
- fs[key][:inodes_used] = $3
125
- fs[key][:inodes_available] = $4
126
- fs[key][:inodes_percent_used] = $5
127
- fs[key][:mount] = $6
128
- end
129
- end
130
-
131
- # Grab mount information from /bin/mount
132
- so = shell_out("mount")
133
- so.stdout.each_line do |line|
134
- if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/
135
- key = "#{$1},#{$2}"
136
- fs[key] = Mash.new unless fs.has_key?(key)
137
- fs[key][:device] = $1
138
- fs[key][:mount] = $2
139
- fs[key][:fs_type] = $3
140
- fs[key][:mount_options] = $4.split(",")
141
- end
142
- end
143
-
144
- have_lsblk = File.exist?("/bin/lsblk")
145
- if have_lsblk
146
- cmd = "lsblk -n -P -o NAME,UUID,LABEL,FSTYPE"
147
- else
148
- # CentOS5 and other platforms don't have lsblk
149
- cmd = "blkid"
150
- end
151
-
152
- so = shell_out(cmd)
153
- so.stdout.each_line do |line|
154
- parsed = parse_line(line, have_lsblk)
155
- next if parsed.nil?
156
- # lsblk lists each device once, so we need to update all entries
157
- # in the hash that are related to this device
158
- keys_to_update = []
159
- fs.each_key do |key|
160
- keys_to_update << key if key.start_with?("#{parsed[:dev]},")
161
- end
162
-
163
- if keys_to_update.empty?
164
- key = "#{parsed[:dev]},"
165
- fs[key] = Mash.new
166
- fs[key][:device] = parsed[:dev]
167
- keys_to_update << key
168
- end
169
-
170
- keys_to_update.each do |key|
171
- [:fs_type, :uuid, :label].each do |subkey|
172
- if parsed[subkey] && !parsed[subkey].empty?
173
- fs[key][subkey] = parsed[subkey]
174
- end
175
- end
176
- end
177
- end
178
-
179
- # Grab any missing mount information from /proc/mounts
180
- if File.exist?("/proc/mounts")
181
- mounts = ""
182
- # Due to https://tickets.opscode.com/browse/OHAI-196
183
- # we have to non-block read dev files. Ew.
184
- f = File.open("/proc/mounts")
185
- loop do
186
- begin
187
- data = f.read_nonblock(4096)
188
- mounts << data
189
- # We should just catch EOFError, but the kernel had a period of
190
- # bugginess with reading virtual files, so we're being extra
191
- # cautious here, catching all exceptions, and then we'll read
192
- # whatever data we might have
193
- rescue Exception
194
- break
195
- end
196
- end
197
- f.close
198
- mounts.each_line do |line|
199
- if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/
200
- key = "#{$1},#{$2}"
201
- next if fs.has_key?(key)
202
- fs[key] = Mash.new
203
- fs[key][:device] = $1
204
- fs[key][:mount] = $2
205
- fs[key][:fs_type] = $3
206
- fs[key][:mount_options] = $4.split(",")
207
- end
208
- end
209
- end
210
-
211
- by_pair = fs
212
- by_device = generate_device_view(fs)
213
- by_mountpoint = generate_mountpoint_view(fs)
214
-
215
- fs2 = Mash.new
216
- fs2["by_device"] = by_device
217
- fs2["by_mountpoint"] = by_mountpoint
218
- fs2["by_pair"] = by_pair
219
-
220
- # Set the filesystem data
221
- filesystem2 fs2
222
- end
223
- end