ohai 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'date'
5
5
  require 'spec/rake/spectask'
6
6
 
7
7
  GEM = "ohai"
8
- GEM_VERSION = "0.3.6"
8
+ GEM_VERSION = "0.4.0"
9
9
  AUTHOR = "Adam Jacob"
10
10
  EMAIL = "adam@opscode.com"
11
11
  HOMEPAGE = "http://wiki.opscode.com/display/ohai"
@@ -21,7 +21,8 @@ spec = Gem::Specification.new do |s|
21
21
  s.author = AUTHOR
22
22
  s.email = EMAIL
23
23
  s.homepage = HOMEPAGE
24
-
24
+
25
+ s.add_dependency "json"
25
26
  s.add_dependency "extlib"
26
27
  s.add_dependency "systemu"
27
28
  s.add_dependency "mixlib-cli"
@@ -50,7 +51,7 @@ end
50
51
 
51
52
  desc "install the gem locally"
52
53
  task :install => [:package] do
53
- sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
54
+ sh %{gem install pkg/#{GEM}-#{GEM_VERSION}}
54
55
  end
55
56
 
56
57
  desc "create a gemspec file"
data/bin/ohai CHANGED
@@ -19,6 +19,22 @@
19
19
  # limitations under the License.
20
20
  #
21
21
 
22
+ require 'rubygems'
23
+
22
24
  $: << File.join(File.dirname(__FILE__), "..", "lib")
23
- require 'ohai/application'
25
+ begin
26
+ require 'rubygems'
27
+ rescue LoadError
28
+ # must be debian! ;)
29
+ missing_rubygems = true
30
+ end
31
+ begin
32
+ require 'ohai/application'
33
+ rescue LoadError
34
+ if missing_rubygems
35
+ STDERR.puts "rubygems previously failed to load - is it installed?"
36
+ end
37
+
38
+ raise
39
+ end
24
40
  Ohai::Application.new.run
@@ -23,5 +23,5 @@ require 'ohai/config'
23
23
  require 'ohai/system'
24
24
 
25
25
  module Ohai
26
- VERSION = '0.3.6'
26
+ VERSION = '0.4.0'
27
27
  end
@@ -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.
@@ -21,7 +21,7 @@ require 'mixlib/cli'
21
21
 
22
22
  class Ohai::Application
23
23
  include Mixlib::CLI
24
-
24
+
25
25
  option :directory,
26
26
  :short => "-d DIRECTORY",
27
27
  :long => "--directory DIRECTORY",
@@ -31,8 +31,8 @@ class Ohai::Application
31
31
  :short => "-f FILE",
32
32
  :long => "--file FILE",
33
33
  :description => "A file to run Ohai against"
34
-
35
- option :log_level,
34
+
35
+ option :log_level,
36
36
  :short => "-l LEVEL",
37
37
  :long => "--log_level LEVEL",
38
38
  :description => "Set the log level (debug, info, warn, error, fatal)",
@@ -43,7 +43,7 @@ class Ohai::Application
43
43
  :long => "--logfile LOGLOCATION",
44
44
  :description => "Set the log file location, defaults to STDOUT - recommended for daemonizing",
45
45
  :proc => nil
46
-
46
+
47
47
  option :help,
48
48
  :short => "-h",
49
49
  :long => "--help",
@@ -75,10 +75,10 @@ class Ohai::Application
75
75
  Ohai::Config[:plugin_path] << Ohai::Config[:directory]
76
76
  end
77
77
  end
78
-
78
+
79
79
  def configure_logging
80
80
  Ohai::Log.init(Ohai::Config[:log_location])
81
- Ohai::Log.level(Ohai::Config[:log_level])
81
+ Ohai::Log.level = Ohai::Config[:log_level]
82
82
  end
83
83
 
84
84
  def run_application
@@ -89,8 +89,8 @@ class Ohai::Application
89
89
  ohai.all_plugins
90
90
  end
91
91
  if @attributes.length > 0
92
- @attributes.each do |a|
93
- puts ohai.attributes_print(a)
92
+ @attributes.each do |a|
93
+ puts ohai.attributes_print(a)
94
94
  end
95
95
  else
96
96
  puts ohai.json_pretty_print
@@ -22,5 +22,9 @@ require 'mixlib/log'
22
22
  module Ohai
23
23
  class Log
24
24
  extend Mixlib::Log
25
+
26
+ init(Ohai::Config[:log_location])
27
+ level = Ohai::Config[:log_level]
28
+
25
29
  end
26
30
  end
@@ -1,22 +1,19 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
3
  # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
- # License:: GNU GPL, Version 3
4
+ # License:: Apache License, Version 2.0
5
5
  #
6
- # Copyright (C) 2008, Opscode Inc.
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
7
9
  #
8
- # This program is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
10
+ # http://www.apache.org/licenses/LICENSE-2.0
12
11
  #
13
- # This program is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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.
20
17
  #
21
18
 
22
19
  require 'ohai/exception'
@@ -0,0 +1,80 @@
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
+ provides "cloud"
18
+
19
+ require_plugin "ec2"
20
+ require_plugin "rackspace"
21
+
22
+ # Make top-level cloud hashes
23
+ #
24
+ def create_objects
25
+ cloud Mash.new
26
+ cloud[:public_ips] = Array.new
27
+ cloud[:private_ips] = Array.new
28
+ end
29
+
30
+ # ----------------------------------------
31
+ # ec2
32
+ # ----------------------------------------
33
+
34
+ # Is current cloud ec2?
35
+ #
36
+ # === Return
37
+ # true:: If ec2 Hash is defined
38
+ # false:: Otherwise
39
+ def on_ec2?
40
+ ec2 != nil
41
+ end
42
+
43
+ # Fill cloud hash with ec2 values
44
+ def get_ec2_values
45
+ cloud[:public_ips] << ec2['public_ipv4']
46
+ cloud[:private_ips] << ec2['local_ipv4']
47
+ cloud[:provider] = "ec2"
48
+ end
49
+
50
+ # setup ec2 cloud
51
+ if on_ec2?
52
+ create_objects
53
+ get_ec2_values
54
+ end
55
+
56
+ # ----------------------------------------
57
+ # rackspace
58
+ # ----------------------------------------
59
+
60
+ # Is current cloud rackspace?
61
+ #
62
+ # === Return
63
+ # true:: If rackspace Hash is defined
64
+ # false:: Otherwise
65
+ def on_rackspace?
66
+ rackspace != nil
67
+ end
68
+
69
+ # Fill cloud hash with rackspace values
70
+ def get_rackspace_values
71
+ cloud[:public_ips] << rackspace['public_ip']
72
+ cloud[:private_ips] << rackspace['private_ip']
73
+ cloud[:provider] = "rackspace"
74
+ end
75
+
76
+ # setup rackspace cloud
77
+ if on_rackspace?
78
+ create_objects
79
+ get_rackspace_values
80
+ end
@@ -15,6 +15,13 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  #
18
+ def get_redhatish_platform(contents)
19
+ contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
20
+ end
21
+
22
+ def get_redhatish_version(contents)
23
+ contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1]
24
+ end
18
25
 
19
26
  provides "platform", "platform_version"
20
27
 
@@ -27,17 +34,17 @@ elsif File.exists?("/etc/debian_version")
27
34
  platform "debian"
28
35
  platform_version File.read("/etc/debian_version").chomp
29
36
  elsif File.exists?("/etc/redhat-release")
30
- platform "redhat"
31
- File.open("/etc/redhat-release").each do |line|
32
- platform "centos" if line =~ /centos/i
33
- case line
34
- when /\(Rawhide\)/
35
- platform_version "rawhide"
36
- when /release ([\d\.]+)/
37
- platform_version $1
38
- end
39
- end
37
+ contents = File.read("/etc/redhat-release").chomp
38
+ platform get_redhatish_platform(contents)
39
+ platform_version get_redhatish_version(contents)
40
40
  elsif File.exists?('/etc/gentoo-release')
41
41
  platform "gentoo"
42
42
  platform_version IO.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join
43
+ elsif File.exists?('/etc/SuSE-release')
44
+ platform "suse"
45
+ platform_version IO.read('/etc/SuSE-release').scan(/\d+\.\d+/)[0]
46
+ elsif File.exists?('/etc/arch-release')
47
+ platform "arch"
48
+ # no way to determine platform_version in a rolling release distribution
49
+ # kernel release will be used - ex. 2.6.32-ARCH
43
50
  end
@@ -54,24 +54,21 @@ end
54
54
  if File.exists?("/usr/sbin/dmidecode")
55
55
  popen4("dmidecode") do |pid, stdin, stdout, stderr|
56
56
  stdin.close
57
- found_virt_manufacturer = nil
58
- stdout.each do |line|
59
- case line
60
- when /Manufacturer: Microsoft/
61
- found_virt_manufacturer = "virtualpc"
62
- when / Product Name: Virtual Machine/
63
- if found_virt_manufacturer == "virtualpc"
64
- virtualization[:emulator] = "virtualpc"
65
- virtualization[:role] = "guest"
66
- end
67
- when /Manufacturer: VMware/
68
- found_virt_manufacturer = "vmware"
69
- when /Product Name: VMware Virtual Platform/
70
- if found_virt_manufacturer == "vmware"
71
- virtualization[:emulator] = "vmware"
72
- virtualization[:role] = "guest"
73
- end
57
+ dmi_info = stdout.string
58
+ case dmi_info
59
+ when /Manufacturer: Microsoft/
60
+ if dmi_info =~ /Product Name: Virtual Machine/
61
+ virtualization[:emulator] = "virtualpc"
62
+ virtualization[:role] = "guest"
63
+ end
64
+ when /Manufacturer: VMware/
65
+ if dmi_info =~ /Product Name: VMware Virtual Platform/
66
+ virtualization[:emulator] = "vmware"
67
+ virtualization[:role] = "guest"
74
68
  end
69
+ else
70
+ nil
75
71
  end
72
+
76
73
  end
77
74
  end
@@ -0,0 +1,22 @@
1
+ provides 'etc', 'current_user'
2
+
3
+ require 'etc'
4
+
5
+ unless etc
6
+ etc Mash.new
7
+
8
+ etc[:passwd] = Mash.new
9
+ etc[:group] = Mash.new
10
+
11
+ Etc.passwd do |entry|
12
+ etc[:passwd][entry.name] = Mash.new(:dir => entry.dir, :gid => entry.gid, :uid => entry.uid, :shell => entry.shell, :gecos => entry.gecos)
13
+ end
14
+
15
+ Etc.group do |entry|
16
+ etc[:group][entry.name] = Mash.new(:gid => entry.gid, :members => entry.mem)
17
+ end
18
+ end
19
+
20
+ unless current_user
21
+ current_user Etc.getlogin
22
+ end
@@ -0,0 +1,60 @@
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
+ provides "rackspace"
18
+
19
+ require_plugin "network"
20
+
21
+ # Checks for matching rackspace arp mac
22
+ #
23
+ # === Return
24
+ # true:: If mac address matches
25
+ # false:: Otherwise
26
+ def has_rackspace_mac?
27
+ network[:interfaces].values.each do |iface|
28
+ unless iface[:arp].nil?
29
+ return true if iface[:arp].value?("00:00:0c:07:ac:01")
30
+ end
31
+ end
32
+ false
33
+ end
34
+
35
+ # Identifies the rackspace cloud
36
+ #
37
+ # === Return
38
+ # true:: If the rackspace cloud can be identified
39
+ # false:: Otherwise
40
+ def looks_like_rackspace?
41
+ has_rackspace_mac?
42
+ end
43
+
44
+ # Names rackspace ip address
45
+ #
46
+ # === Parameters
47
+ # name<Symbol>:: Use :public_ip or :private_ip
48
+ # eth<Symbol>:: Interface name of public or private ip
49
+ def get_ip_address(name, eth)
50
+ network[:interfaces][eth][:addresses].each do |key, info|
51
+ rackspace[name] = key if info['family'] == 'inet'
52
+ end
53
+ end
54
+
55
+ # Adds rackspace Mash
56
+ if looks_like_rackspace?
57
+ rackspace Mash.new
58
+ get_ip_address(:public_ip, :eth0)
59
+ get_ip_address(:private_ip, :eth1)
60
+ end
@@ -20,20 +20,49 @@ provides "languages/ruby"
20
20
 
21
21
  require_plugin "languages"
22
22
 
23
+
24
+ def run_ruby(command)
25
+ cmd = "ruby -e \"require 'rbconfig'; #{command}\""
26
+ status, stdout, stderr = run_command(:no_status_check => true, :command => cmd)
27
+ stdout.strip
28
+ end
29
+
30
+
23
31
  languages[:ruby] = Mash.new
24
32
 
25
- languages[:ruby][:platform] = RUBY_PLATFORM
26
- languages[:ruby][:version] = RUBY_VERSION
27
- languages[:ruby][:release_date] = RUBY_RELEASE_DATE
28
- languages[:ruby][:target] = ::Config::CONFIG['target']
29
- languages[:ruby][:target_cpu] = ::Config::CONFIG['target_cpu']
30
- languages[:ruby][:target_vendor] = ::Config::CONFIG['target_vendor']
31
- languages[:ruby][:target_os] = ::Config::CONFIG['target_os']
32
- languages[:ruby][:host] = ::Config::CONFIG['host']
33
- languages[:ruby][:host_cpu] = ::Config::CONFIG['host_cpu']
34
- languages[:ruby][:host_os] = ::Config::CONFIG['host_os']
35
- languages[:ruby][:host_vendor] = ::Config::CONFIG['host_vendor']
36
- if File.exists?("#{::Config::CONFIG['bindir']}/gem")
37
- languages[:ruby][:gems_dir] = %x{#{::Config::CONFIG['bindir']}/gem env gemdir}.chomp!
33
+ values = {
34
+ :platform => "RUBY_PLATFORM",
35
+ :version => "RUBY_VERSION",
36
+ :release_date => "RUBY_RELEASE_DATE",
37
+ :target => "::Config::CONFIG['target']",
38
+ :target_cpu => "::Config::CONFIG['target_cpu']",
39
+ :target_vendor => "::Config::CONFIG['target_vendor']",
40
+ :target_os => "::Config::CONFIG['target_os']",
41
+ :host => "::Config::CONFIG['host']",
42
+ :host_cpu => "::Config::CONFIG['host_cpu']",
43
+ :host_os => "::Config::CONFIG['host_os']",
44
+ :host_vendor => "::Config::CONFIG['host_vendor']",
45
+ :bin_dir => "::Config::CONFIG['bindir']",
46
+ :ruby_bin => "::File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name'])"
47
+ }
48
+
49
+ # Create a query string from above hash
50
+ env_string = ""
51
+ values.keys.each do |v|
52
+ env_string << "#{v}:\#{#{values[v]}},"
53
+ end
54
+
55
+ # Query the system ruby
56
+ result = run_ruby "puts \\\"#{env_string}\\\""
57
+
58
+ # Parse results to plugin hash
59
+ result.split(',').each do |entry|
60
+ key, value = entry.split(':')
61
+ languages[:ruby][key.to_sym] = value
62
+ end
63
+
64
+ # Perform one more (conditional) query
65
+ bin_dir = languages[:ruby][:bin_dir]
66
+ if File.exist?("#{bin_dir}\/gem")
67
+ languages[:ruby][:gems_dir] = run_ruby "puts %x{#{bin_dir}\/gem env gemdir}.chomp!"
38
68
  end
39
- languages[:ruby][:ruby_bin] = File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name'])