ohai 7.4.1 → 7.6.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +8 -8
  3. data/Rakefile +2 -2
  4. data/lib/ohai/mixin/cloudstack_metadata.rb +88 -0
  5. data/lib/ohai/plugins/aix/kernel.rb +15 -1
  6. data/lib/ohai/plugins/aix/network.rb +5 -2
  7. data/lib/ohai/plugins/aix/virtualization.rb +39 -0
  8. data/lib/ohai/plugins/cloud.rb +32 -0
  9. data/lib/ohai/plugins/cloudstack.rb +43 -0
  10. data/lib/ohai/plugins/darwin/cpu.rb +2 -2
  11. data/lib/ohai/plugins/go.rb +30 -0
  12. data/lib/ohai/plugins/hostname.rb +1 -1
  13. data/lib/ohai/plugins/linux/filesystem.rb +19 -5
  14. data/lib/ohai/plugins/linux/platform.rb +5 -1
  15. data/lib/ohai/plugins/openstack.rb +22 -0
  16. data/lib/ohai/plugins/passwd.rb +5 -1
  17. data/lib/ohai/plugins/python.rb +3 -3
  18. data/lib/ohai/plugins/solaris2/zpools.rb +1 -1
  19. data/lib/ohai/version.rb +1 -1
  20. data/spec/unit/mixin/cloudstack_metadata_spec.rb +33 -0
  21. data/spec/unit/plugins/aix/kernel_spec.rb +6 -3
  22. data/spec/unit/plugins/aix/network_spec.rb +1 -1
  23. data/spec/unit/plugins/aix/virtualization_spec.rb +53 -0
  24. data/spec/unit/plugins/cloud_spec.rb +31 -0
  25. data/spec/unit/plugins/cloudstack_spec.rb +155 -0
  26. data/spec/unit/plugins/darwin/cpu_spec.rb +2 -2
  27. data/spec/unit/plugins/go_spec.rb +44 -0
  28. data/spec/unit/plugins/hostname_spec.rb +12 -0
  29. data/spec/unit/plugins/linux/filesystem_spec.rb +55 -40
  30. data/spec/unit/plugins/linux/platform_spec.rb +36 -0
  31. data/spec/unit/plugins/openstack_spec.rb +55 -0
  32. data/spec/unit/plugins/passwd_spec.rb +3 -2
  33. data/spec/unit/plugins/python_spec.rb +22 -20
  34. data/spec/unit/plugins/solaris2/zpools_spec.rb +153 -0
  35. metadata +75 -59
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Yjk5OTY3MGYwNTBhNGFmODNlYWYwMGIxNTcxZmY4ZDA4MzQxNTdlMg==
5
- data.tar.gz: !binary |-
6
- ZjRlYjkwYjE5ODRkYmRjMjljZWQ1ZDQ0YjVhMzk4NGUxNDRlZGRmMg==
2
+ SHA1:
3
+ metadata.gz: 9b3fe8adb1220f8ba23d9f4580d72c51b31e39cc
4
+ data.tar.gz: 8d2f029cbbc2c838b8e3f5844ffbeacc335af035
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MGNiNTJmM2Q3NDQ5NWZiZjY4MWFjMGJlOGFhOTUyYzE0MjQxNjg3MTIzODQ0
10
- ZThmOTgxMDM2MzhlYWJjOTkxYjFmYjZhMDU1MzE5MjFmOGVlNjI5ZTcyNTVl
11
- OWVkYTM1NWU5NWZmNTljNTE3YmZmM2Y3YWIxYWY3YTJjMGU2MDU=
12
- data.tar.gz: !binary |-
13
- N2Q5Y2UzMzczYWU3MzRkNTNkZjk3ZmI5NGM0ODU5Y2M5NDMwMjUxM2NlZmUz
14
- NDMwYzhjYWQ2MWMwMDgzOGYyNzUxOTQ4MjI3OWNhMTQyNTFjMWM5MGU0NzVi
15
- N2Y3NDExZWNmYmFlNGM0NTFjNmRmZDE2ZDhkY2YyYTc4YTBjYWU=
6
+ metadata.gz: ab5925dd17bdd934be8c747e764611259a416ecb02d62d54b4be2eb6b99054c59a7444d98977b71c1e47a6c1f0e9405484758f910c0cff62b2b6451d5edcab0a
7
+ data.tar.gz: b248e02c48954d9166bc2a96b07576de71f31e54bc9773c8c49ffa4672f726745594e59cb3c976c0e6933d8929c78535144adaab8b33ece599e3a6510c597a8a
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  # DESCRIPTION:
4
4
 
5
5
  Ohai detects data about your operating system. It can be used
6
- standalone, but it's primary purpose is to provide node data to Chef.
6
+ standalone, but its primary purpose is to provide node data to Chef.
7
7
 
8
8
  Ohai will print out a JSON data blob for all the known data about your
9
9
  system. When used with Chef, that data is reported back via node
@@ -66,20 +66,19 @@ Source:
66
66
 
67
67
  * http://github.com/opscode/ohai/tree/master
68
68
 
69
- Tickets/Issues:
69
+ Issues:
70
70
 
71
- * http://tickets.opscode.com/
72
-
73
- (Use the OHAI project)
71
+ * https://github.com/opscode/ohai/issues
74
72
 
75
73
  # LICENSE:
76
74
 
77
75
  Ohai - system information application
78
76
 
79
- Author:: Adam Jacob (<adam@getchef.com>)
80
- Copyright:: Copyright (c) 2008-2014 Chef Software, Inc.
81
- License:: Apache License, Version 2.0
77
+ * Author:: Adam Jacob (<adam@getchef.com>)
78
+ * Copyright:: Copyright (c) 2008-2014 Chef Software, Inc.
79
+ * License:: Apache License, Version 2.0
82
80
 
81
+ ```text
83
82
  Licensed under the Apache License, Version 2.0 (the "License");
84
83
  you may not use this file except in compliance with the License.
85
84
  You may obtain a copy of the License at
@@ -91,3 +90,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
91
90
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
92
91
  See the License for the specific language governing permissions and
93
92
  limitations under the License.
93
+ ```
data/Rakefile CHANGED
@@ -2,15 +2,15 @@ require 'rubygems'
2
2
  require 'rubygems/package_task'
3
3
  require 'rubygems/specification'
4
4
  require 'date'
5
+ require 'ohai/version'
5
6
 
6
7
  gemspec = eval(IO.read("ohai.gemspec"))
7
8
 
8
-
9
9
  Gem::PackageTask.new(gemspec).define
10
10
 
11
11
  desc "install the gem locally"
12
12
  task :install => [:package] do
13
- sh %{gem install pkg/#{ohai}-#{OHAI_VERSION}}
13
+ sh %{gem install pkg/ohai-#{Ohai::VERSION}.gem}
14
14
  end
15
15
 
16
16
  begin
@@ -0,0 +1,88 @@
1
+ #
2
+ # Author:: Olle Lundberg (<geek@nerd.sh>)
3
+ # Copyright:: Copyright (c) 2014 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 'ohai/mixin/ec2_metadata'
19
+ require 'ohai/hints'
20
+ require 'net/dhcp'
21
+ require 'socket'
22
+
23
+
24
+ module Ohai
25
+ module Mixin
26
+ module CloudstackMetadata
27
+ include Ohai::Mixin::Ec2Metadata
28
+
29
+ def self.discover_dhcp_server
30
+ response = ''
31
+ if Ohai::Hints.hint?('cloudstack')
32
+ begin
33
+ request = DHCP::Discover.new
34
+
35
+ listensock = UDPSocket.new
36
+ sendsock = UDPSocket.new
37
+
38
+ listensock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
39
+ sendsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
40
+
41
+ sendsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
42
+ sendaddr = "<broadcast>"
43
+ listenport = 68
44
+
45
+ listensock.bind('', listenport)
46
+ sendsock.connect(sendaddr, 67)
47
+
48
+ sendsock.send(request.pack, 0)
49
+
50
+ data = listensock.recvfrom_nonblock(1500)
51
+ rescue Exception => e
52
+ if (defined?(IO::WaitReadable) && e.instance_of?(IO::WaitReadable)) ||
53
+ (e.instance_of?(Errno::EAGAIN) || e.instance_of?(Errno::EWOULDBLOCK)) # This OR branch can be removed when ruby > 1.8.7
54
+ unless IO.select([listensock], nil, nil, 10)
55
+ # timeout reached
56
+ Ohai::Log.debug("Timeout reached awaiting response from DHCP server")
57
+ else
58
+ # try to read from the socket again
59
+ data = listensock.recvfrom_nonblock(1500)
60
+ end
61
+ else
62
+ Ohai::Log.debug("Exceptions encountered when trying to connect to dhcp server. #{e.message}")
63
+ end
64
+ ensure
65
+ sendsock.close
66
+ listensock.close
67
+ if data
68
+ response = [DHCP::Message.from_udp_payload(data[0]).siaddr].pack('N').unpack('C4').join('.')
69
+ end
70
+ end
71
+ end
72
+ response
73
+ end
74
+
75
+ CLOUDSTACK_METADATA_ADDR = self.discover_dhcp_server unless defined?(CLOUDSTACK_METADATA_ADDR)
76
+
77
+ def http_client
78
+ Net::HTTP.start(CLOUDSTACK_METADATA_ADDR).tap { |h| h.read_timeout = 600 }
79
+ end
80
+
81
+ def best_api_version
82
+ 'latest'
83
+ end
84
+
85
+ end
86
+ end
87
+ end
88
+
@@ -26,6 +26,20 @@ Ohai.plugin(:Kernel) do
26
26
  kernel[:release] = shell_out("uname -r").stdout.split($/)[0]
27
27
  kernel[:version] = shell_out("uname -v").stdout.split($/)[0]
28
28
  kernel[:machine] = shell_out("uname -p").stdout.split($/)[0]
29
- kernel[:modules] = Mash.new
29
+
30
+ modules = Mash.new
31
+ so = shell_out("genkex -d")
32
+ # Text address Size Data address Size File
33
+ #
34
+ # f1000000c0338000 77000 f1000000c0390000 1ec8c /usr/lib/drivers/cluster
35
+ # 6390000 20000 63a0000 ba8 /usr/lib/drivers/if_en
36
+ # f1000000c0318000 20000 f1000000c0320000 17138 /usr/lib/drivers/random
37
+ so.stdout.lines do |line|
38
+ if line =~ /\s*([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([a-zA-Z0-9\/\._]+)/
39
+ modules[$5] = { :text => { :address => $1, :size => $2 }, :data => { :address => $3, :size => $4 } }
40
+ end
41
+ end
42
+
43
+ kernel[:modules] = modules
30
44
  end
31
45
  end
@@ -42,6 +42,9 @@ Ohai.plugin(:Network) do
42
42
 
43
43
  iface = Mash.new
44
44
 
45
+ network Mash.new unless network
46
+ network[:interfaces] = Mash.new unless network[:interfaces]
47
+
45
48
  # :default_interface, :default_gateway - route -n get 0
46
49
  so = shell_out("route -n get 0")
47
50
  so.stdout.lines.each do |line|
@@ -90,10 +93,10 @@ Ohai.plugin(:Network) do
90
93
  if line =~ /broadcast\s(\S+)\s/
91
94
  iface[interface][:addresses][tmp_addr][:broadcast] = $1
92
95
  end
93
- elsif line =~ /inet6 ([a-f0-9\:%]+)\/(\d+)/
96
+ elsif line =~ /inet6 ([a-f0-9\:]+)%?([\d]*)\/?(\d*)/
94
97
  # TODO do we have more properties on inet6 in aix? broadcast
95
98
  iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
96
- iface[interface][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2 }
99
+ iface[interface][:addresses][$1] = { "family" => "inet6", "zone_index" => $2, "prefixlen" => $3 }
97
100
  else
98
101
  # load all key-values, example "tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1"
99
102
  properties = line.split
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author:: Julian C. Dunn (<jdunn@getchef.com>)
3
+ # Copyright:: Copyright (c) 2014 Chef Software, 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
+ Ohai.plugin(:Virtualization) do
20
+ provides "virtualization"
21
+
22
+ collect_data(:aix) do
23
+ virtualization Mash.new
24
+
25
+ so = shell_out("uname -L")
26
+ lpar_no = so.stdout.split($/)[0].split(/\s/)[0]
27
+ lpar_name = so.stdout.split($/)[0].split(/\s/)[1]
28
+
29
+ unless lpar_no.to_i == -1 || (lpar_no.to_i == 1 && lpar_name == "NULL")
30
+ virtualization[:lpar_no] = lpar_no
31
+ virtualization[:lpar_name] = lpar_name
32
+ end
33
+
34
+ so = shell_out("uname -W")
35
+ wpar_no = so.stdout.split($/)[0]
36
+ virtualization[:wpar_no] = wpar_no unless wpar_no.to_i == 0
37
+
38
+ end
39
+ end
@@ -24,6 +24,7 @@ Ohai.plugin(:Cloud) do
24
24
  depends "linode"
25
25
  depends "openstack"
26
26
  depends "azure"
27
+ depends "cloudstack"
27
28
 
28
29
  # Make top-level cloud hashes
29
30
  #
@@ -215,6 +216,31 @@ Ohai.plugin(:Cloud) do
215
216
  cloud[:provider] = "azure"
216
217
  end
217
218
 
219
+ # ----------------------------------------
220
+ # cloudstack
221
+ # ----------------------------------------
222
+
223
+ # Is current cloud cloudstack-based?
224
+ #
225
+ # === Return
226
+ # true:: If cloudstack Hash is defined
227
+ # false:: Otherwise
228
+ def on_cloudstack?
229
+ cloudstack != nil
230
+ end
231
+
232
+ # Fill cloud hash with cloudstack values
233
+ def get_cloudstack_values
234
+ cloud[:public_ips] << cloudstack['public_ipv4']
235
+ cloud[:private_ips] << cloudstack['local_ipv4']
236
+ cloud[:public_ipv4] = cloudstack['public_ipv4']
237
+ cloud[:public_hostname] = cloudstack['public_hostname']
238
+ cloud[:local_ipv4] = cloudstack['local_ipv4']
239
+ cloud[:local_hostname] = cloudstack['local_hostname']
240
+ cloud[:vm_id] = cloudstack['vm_id']
241
+ cloud[:provider] = "cloudstack"
242
+ end
243
+
218
244
  collect_data do
219
245
  # setup gce cloud
220
246
  if on_gce?
@@ -256,5 +282,11 @@ Ohai.plugin(:Cloud) do
256
282
  create_objects
257
283
  get_azure_values
258
284
  end
285
+
286
+ # setup cloudstack cloud
287
+ if on_cloudstack?
288
+ create_objects
289
+ get_cloudstack_values
290
+ end
259
291
  end
260
292
  end
@@ -0,0 +1,43 @@
1
+ #
2
+ # Author:: Olle Lundberg (<geek@nerd.sh>)
3
+ # Copyright:: Copyright (c) 2014 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 'ohai/mixin/cloudstack_metadata'
19
+
20
+ Ohai.plugin(:Cloudstack) do
21
+ provides "cloudstack"
22
+
23
+ include Ohai::Mixin::CloudstackMetadata
24
+
25
+ collect_data do
26
+ # Adds cloudstack Mash
27
+ if hint?('cloudstack')
28
+ Ohai::Log.debug("found 'cloudstack' hint. Will try to connect to the metadata server")
29
+
30
+ if can_metadata_connect?(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR, 80)
31
+ cloudstack Mash.new
32
+ Ohai::Log.debug("connecting to the 'cloudstack' metadata service")
33
+ fetch_metadata.each { |k, v| cloudstack[k] = v }
34
+ else
35
+ Ohai::Log.debug("unable to connect to the 'cloudstack' metadata service")
36
+ end
37
+ else
38
+ Ohai::Log.debug("unable to find 'cloudstack' hint. Won't connect to the metadata server.")
39
+ end
40
+ end
41
+ end
42
+
43
+
@@ -29,9 +29,9 @@ Ohai.plugin(:CPU) do
29
29
  so = shell_out("sysctl -n hw.cpufrequency")
30
30
  cpu[:mhz] = so.stdout.to_i / 1000000
31
31
  so = shell_out("sysctl -n machdep.cpu.vendor")
32
- cpu[:vendor_id] = so.stdout
32
+ cpu[:vendor_id] = so.stdout.chomp
33
33
  so = shell_out("sysctl -n machdep.cpu.brand_string")
34
- cpu[:model_name] = so.stdout
34
+ cpu[:model_name] = so.stdout.chomp
35
35
  so = shell_out("sysctl -n machdep.cpu.model")
36
36
  cpu[:model] = so.stdout.to_i
37
37
  so = shell_out("sysctl -n machdep.cpu.family")
@@ -0,0 +1,30 @@
1
+ # Author:: Christian Vozar (<christian@rogueethic.com>)
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
+
16
+ Ohai.plugin(:Go) do
17
+ provides "languages/go"
18
+ depends "languages"
19
+
20
+ collect_data do
21
+ output = nil
22
+ go = Mash.new
23
+ so = shell_out("go version")
24
+ if so.exitstatus == 0
25
+ output = so.stdout.split
26
+ go[:version] = output[2].slice!(2..16)
27
+ languages[:go] = go if go[:version]
28
+ end
29
+ end
30
+ end
@@ -67,7 +67,7 @@ Ohai.plugin(:Hostname) do
67
67
  def collect_hostname
68
68
  # Hostname is everything before the first dot
69
69
  if machinename
70
- machinename =~ /(.+?)\./
70
+ machinename =~ /(\w+)\.?/
71
71
  hostname $1
72
72
  elsif fqdn
73
73
  fqdn =~ /(.+?)\./
@@ -32,6 +32,14 @@ Ohai.plugin(:Filesystem) do
32
32
  have_lsblk ? /^(\S+) (\S+)/ : /^(\S+): #{attr}="(\S+)"/
33
33
  end
34
34
 
35
+ def find_device(name)
36
+ %w{/dev /dev/mapper}.each do |dir|
37
+ path = File.join(dir, name)
38
+ return path if File.exist?(path)
39
+ end
40
+ name
41
+ end
42
+
35
43
  collect_data(:linux) do
36
44
  fs = Mash.new
37
45
  have_lsblk = File.executable?('/bin/lsblk')
@@ -82,7 +90,7 @@ Ohai.plugin(:Filesystem) do
82
90
  end
83
91
  end
84
92
 
85
- have_lsblk = File.exists?('/bin/lsblk')
93
+ have_lsblk = File.exist?('/bin/lsblk')
86
94
 
87
95
  # Gather more filesystem types via libuuid, even devices that's aren't mounted
88
96
  cmd = get_blk_cmd('TYPE', have_lsblk)
@@ -91,8 +99,10 @@ Ohai.plugin(:Filesystem) do
91
99
  so.stdout.lines do |line|
92
100
  if line =~ regex
93
101
  filesystem = $1
102
+ type = $2
103
+ filesystem = find_device(filesystem) unless filesystem.start_with?('/')
94
104
  fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
95
- fs[filesystem][:fs_type] = $2
105
+ fs[filesystem][:fs_type] = type
96
106
  end
97
107
  end
98
108
 
@@ -103,8 +113,10 @@ Ohai.plugin(:Filesystem) do
103
113
  so.stdout.lines do |line|
104
114
  if line =~ regex
105
115
  filesystem = $1
116
+ uuid = $2
117
+ filesystem = find_device(filesystem) unless filesystem.start_with?('/')
106
118
  fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
107
- fs[filesystem][:uuid] = $2
119
+ fs[filesystem][:uuid] = uuid
108
120
  end
109
121
  end
110
122
 
@@ -115,13 +127,15 @@ Ohai.plugin(:Filesystem) do
115
127
  so.stdout.lines do |line|
116
128
  if line =~ regex
117
129
  filesystem = $1
130
+ label = $2
131
+ filesystem = find_device(filesystem) unless filesystem.start_with?('/')
118
132
  fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
119
- fs[filesystem][:label] = $2
133
+ fs[filesystem][:label] = label
120
134
  end
121
135
  end
122
136
 
123
137
  # Grab any missing mount information from /proc/mounts
124
- if File.exists?('/proc/mounts')
138
+ if File.exist?('/proc/mounts')
125
139
  mounts = ''
126
140
  # Due to https://tickets.opscode.com/browse/OHAI-196
127
141
  # we have to non-block read dev files. Ew.