kurchatov 0.0.5.pre5 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +1 -0
  3. data/README.md +6 -7
  4. data/Rakefile +1 -1
  5. data/Vagrantfile +5 -6
  6. data/bin/kurchatov +2 -2
  7. data/examples/check_file_contains.rb +4 -4
  8. data/examples/count_proc.rb +5 -5
  9. data/examples/cpu.rb +5 -5
  10. data/examples/disk.rb +3 -3
  11. data/examples/disk_stat.rb +6 -6
  12. data/examples/dns_check.rb +2 -2
  13. data/examples/exim.rb +1 -1
  14. data/examples/file_age.rb +5 -5
  15. data/examples/find_files.rb +1 -1
  16. data/examples/http.rb +3 -3
  17. data/examples/iptables.rb +3 -3
  18. data/examples/la.rb +12 -12
  19. data/examples/mdadm.rb +1 -1
  20. data/examples/memory.rb +8 -8
  21. data/examples/net.rb +6 -6
  22. data/examples/net_stat.rb +4 -4
  23. data/examples/nfs.rb +2 -2
  24. data/examples/nginx.rb +1 -1
  25. data/examples/nginx_500.rb +8 -8
  26. data/examples/ntp.rb +5 -5
  27. data/examples/openfiles.rb +2 -2
  28. data/examples/pgsql.rb +3 -3
  29. data/examples/ping_icmp.rb +4 -4
  30. data/examples/ping_tcp.rb +4 -4
  31. data/examples/proc_mem.rb +6 -6
  32. data/examples/rabbitmq.rb +4 -4
  33. data/examples/runit.rb +1 -1
  34. data/examples/sidekiq.rb +12 -12
  35. data/examples/sidekiq_queue_state.rb +3 -3
  36. data/examples/status_file.rb +4 -4
  37. data/examples/tw_cli.rb +4 -4
  38. data/examples/uptime.rb +4 -4
  39. data/kurchatov.gemspec +19 -18
  40. data/lib/kurchatov/application.rb +73 -74
  41. data/lib/kurchatov/mashie.rb +32 -27
  42. data/lib/kurchatov/mixin/command.rb +0 -5
  43. data/lib/kurchatov/mixin/event.rb +7 -5
  44. data/lib/kurchatov/mixin/http.rb +4 -4
  45. data/lib/kurchatov/mixin/init.rb +5 -5
  46. data/lib/kurchatov/mixin/ohai.rb +11 -3
  47. data/lib/kurchatov/mixin/queue.rb +7 -4
  48. data/lib/kurchatov/plugin/config.rb +8 -7
  49. data/lib/kurchatov/plugin/dsl.rb +3 -1
  50. data/lib/kurchatov/plugin/riemann.rb +7 -8
  51. data/lib/kurchatov/responders/http.rb +6 -6
  52. data/lib/kurchatov/responders/init.rb +3 -3
  53. data/lib/kurchatov/responders/riemann.rb +2 -4
  54. data/lib/kurchatov/responders/udp.rb +2 -3
  55. data/lib/kurchatov/riemann/client.rb +12 -12
  56. data/lib/kurchatov/riemann/event.rb +1 -1
  57. data/lib/kurchatov/riemann/message.rb +2 -2
  58. data/lib/kurchatov/version.rb +1 -1
  59. data/lib/kurchatov.rb +4 -2
  60. data/lib/ohai/plugins/darwin/cpu.rb +3 -3
  61. data/lib/ohai/plugins/darwin/hostname.rb +3 -3
  62. data/lib/ohai/plugins/darwin/platform.rb +12 -12
  63. data/lib/ohai/plugins/hostname.rb +2 -2
  64. data/lib/ohai/plugins/linux/cpu.rb +29 -29
  65. data/lib/ohai/plugins/linux/hostname.rb +4 -4
  66. data/lib/ohai/plugins/linux/platform.rb +40 -40
  67. data/lib/ohai/plugins/linux/virtualization.rb +51 -51
  68. data/lib/ohai/plugins/os.rb +26 -26
  69. data/lib/ohai/plugins/platform.rb +4 -4
  70. data/lib/ohai/plugins/virtualization.rb +17 -17
  71. data/lib/ohai/plugins/windows/cpu.rb +11 -11
  72. data/lib/ohai/plugins/windows/platform.rb +1 -1
  73. data/tests/run.sh +4 -4
  74. data/tests/server.rb +2 -2
  75. metadata +18 -3
@@ -1,13 +1,12 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "kurchatov/plugin"
4
- require "kurchatov/mashie"
3
+ require 'kurchatov/plugin'
4
+ require 'kurchatov/mashie'
5
5
 
6
6
  module Kurchatov
7
7
  module Plugins
8
8
  class Riemann < Kurchatov::Plugin
9
9
 
10
- include Kurchatov::Mixin::Queue
11
10
  include Kurchatov::Mixin::Ohai
12
11
  include Kurchatov::Mixin::Event
13
12
  include Kurchatov::Mixin::Command
@@ -17,7 +16,7 @@ module Kurchatov
17
16
 
18
17
  def initialize(name = '')
19
18
  super(name)
20
- @run_if = Proc.new {true}
19
+ @run_if = Proc.new { true }
21
20
  @plugin = Mashie.new
22
21
  @always_start = false
23
22
  @collect = nil
@@ -35,15 +34,15 @@ module Kurchatov
35
34
  end
36
35
 
37
36
  def respond_to_ohai?(opts = {})
38
- opts.each { |k,v| return false unless ohai[k] == v }
37
+ opts.each { |k, v| return false unless ohai[k] == v }
39
38
  true
40
39
  end
41
40
 
42
41
  def runnable_by_config?
43
42
  Log.info("Plugin '#{self.name}' disabled by nil collect") and return if collect.nil?
44
- Log.info("Plugin '#{self.name}' disabled in config") and return if plugin[:disable] == true
45
- Log.info("Plugin '#{self.name}' not started by run_if condition ") and
46
- return if !self.instance_eval(&run_if)
43
+ Log.info("Plugin '#{self.name}' disabled in config") and return if (plugin[:disable] == true)
44
+ Log.info("Plugin '#{self.name}' not started by run_if condition ") and
45
+ return unless self.instance_eval(&run_if)
47
46
  @plugin[:service] = name if @plugin[:service].nil?
48
47
  true
49
48
  end
@@ -15,9 +15,9 @@ module Kurchatov
15
15
  response = info
16
16
  client.gets
17
17
  headers = "HTTP/1.1 200 OK\r\n" +
18
- "Server: Kurchatov Ruby\r\n" +
19
- "Content-Length: #{response.bytesize}\r\n" +
20
- "Content-Type: application/json\r\n\r\n"
18
+ "Server: Kurchatov Ruby\r\n" +
19
+ "Content-Length: #{response.bytesize}\r\n" +
20
+ "Content-Type: application/json\r\n\r\n"
21
21
  client.print headers
22
22
  client.print response
23
23
  client.close
@@ -26,9 +26,9 @@ module Kurchatov
26
26
 
27
27
  def info
28
28
  {
29
- :version => Kurchatov::VERSION,
30
- :uptime => (Time.now - @s_time).to_i,
31
- :config => Kurchatov::Config.to_hash,
29
+ :version => Kurchatov::VERSION,
30
+ :uptime => (Time.now - @s_time).to_i,
31
+ :config => Kurchatov::Config.to_hash,
32
32
  }.to_json + "\n"
33
33
  end
34
34
 
@@ -1,3 +1,3 @@
1
- require_relative "http"
2
- require_relative "riemann"
3
- require_relative "udp"
1
+ require_relative 'http'
2
+ require_relative 'riemann'
3
+ require_relative 'udp'
@@ -1,6 +1,4 @@
1
- # encoding: utf-8
2
-
3
- require "kurchatov/riemann/client"
1
+ require 'kurchatov/riemann/client'
4
2
 
5
3
  module Kurchatov
6
4
  module Responders
@@ -34,7 +32,7 @@ module Kurchatov
34
32
  def flush
35
33
  @events_to_send ||= events.all
36
34
  unless @events_to_send.empty?
37
- @riemanns.each {|riemann| riemann << @events_to_send }
35
+ @riemanns.each { |riemann| riemann << @events_to_send }
38
36
  Log.debug("Sended events via #{@name.inspect}: #{@events_to_send}")
39
37
  end
40
38
  @events_to_send = nil
@@ -3,7 +3,6 @@ module Kurchatov
3
3
  class Udp < Kurchatov::Plugin
4
4
 
5
5
  include Kurchatov::Mixin::Event
6
- include Kurchatov::Mixin::Queue
7
6
 
8
7
  def initialize(conn)
9
8
  @host, @port = conn.split(':')
@@ -17,9 +16,9 @@ module Kurchatov
17
16
  end
18
17
  end
19
18
 
20
- def process(data,src)
19
+ def process(data, src)
21
20
  begin
22
- event << JSON.parse(data)
21
+ event(JSON.parse(data))
23
22
  src.reply "sended\n\n"
24
23
  rescue => e
25
24
  src.reply "failed to send: #{data.inspect}\n"
@@ -1,6 +1,6 @@
1
- require "timeout"
2
- require "socket"
3
- require "kurchatov/riemann/message"
1
+ require 'timeout'
2
+ require 'socket'
3
+ require 'kurchatov/riemann/message'
4
4
 
5
5
  module Kurchatov
6
6
  module Riemann
@@ -19,15 +19,15 @@ module Kurchatov
19
19
  end
20
20
 
21
21
  def <<(events)
22
- events = events.map {|e| Event.new(e) }
23
- message = Message.new(:events => events)
24
- with_connection do |socket|
25
- x = message.encode_with_length
26
- Timeout::timeout(SEND_TIMEOUT) {
27
- socket.write(x)
28
- socket.flush
29
- }
30
- end
22
+ events = events.map { |e| Event.new(e) }
23
+ message = Message.new(:events => events)
24
+ with_connection do |socket|
25
+ x = message.encode_with_length
26
+ Timeout::timeout(SEND_TIMEOUT) {
27
+ socket.write(x)
28
+ socket.flush
29
+ }
30
+ end
31
31
  end
32
32
 
33
33
  def with_connection
@@ -3,7 +3,7 @@ module Kurchatov
3
3
  class Event
4
4
  include Beefcake::Message
5
5
  optional :time, :int64, 1
6
- optional :state, :string, 2
6
+ optional :state, :string, 2
7
7
  optional :service, :string, 3
8
8
  optional :host, :string, 4
9
9
  optional :description, :string, 5
@@ -1,5 +1,5 @@
1
- require "beefcake"
2
- require "kurchatov/riemann/event"
1
+ require 'beefcake'
2
+ require 'kurchatov/riemann/event'
3
3
 
4
4
  module Kurchatov
5
5
  module Riemann
@@ -1,3 +1,3 @@
1
1
  module Kurchatov
2
- VERSION = "0.0.5.pre5"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/kurchatov.rb CHANGED
@@ -1,3 +1,5 @@
1
- require "kurchatov/version"
1
+ require 'kurchatov/version'
2
2
 
3
- module Kurchatov; end
3
+ module Kurchatov
4
+ ;
5
+ end
@@ -16,8 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "cpu"
19
+ provides 'cpu'
20
20
 
21
21
  cpu Mash.new
22
- cpu[:real] = from("sysctl -n hw.physicalcpu").to_i
23
- cpu[:total] = from("sysctl -n hw.logicalcpu").to_i
22
+ cpu[:real] = from('sysctl -n hw.physicalcpu').to_i
23
+ cpu[:total] = from('sysctl -n hw.logicalcpu').to_i
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "fqdn", "hostname"
19
+ provides 'fqdn', 'hostname'
20
20
 
21
- hostname from("hostname -s")
22
- fqdn from("hostname")
21
+ hostname from('hostname -s')
22
+ fqdn from('hostname')
@@ -16,23 +16,23 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "platform", "platform_version", "platform_build", "platform_family"
19
+ provides 'platform', 'platform_version', 'platform_build', 'platform_family'
20
20
 
21
- popen4("/usr/bin/sw_vers") do |pid, stdin, stdout, stderr|
21
+ popen4('/usr/bin/sw_vers') do |pid, stdin, stdout, stderr|
22
22
  stdin.close
23
23
  stdout.each do |line|
24
24
  case line
25
- when /^ProductName:\s+(.+)$/
26
- macname = $1
27
- macname.downcase!
28
- macname.gsub!(" ", "_")
29
- platform macname
30
- when /^ProductVersion:\s+(.+)$/
31
- platform_version $1
32
- when /^BuildVersion:\s+(.+)$/
33
- platform_build $1
25
+ when /^ProductName:\s+(.+)$/
26
+ macname = $1
27
+ macname.downcase!
28
+ macname.gsub!(' ', '_')
29
+ platform macname
30
+ when /^ProductVersion:\s+(.+)$/
31
+ platform_version $1
32
+ when /^BuildVersion:\s+(.+)$/
33
+ platform_build $1
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
- platform_family "mac_os_x"
38
+ platform_family 'mac_os_x'
@@ -16,12 +16,12 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "fqdn", "domain"
19
+ provides 'fqdn', 'domain'
20
20
 
21
21
  require_plugin "#{os}::hostname"
22
22
 
23
23
  # Domain is everything after the first dot
24
24
  if fqdn
25
25
  fqdn =~ /.+?\.(.*)/
26
- domain $1
26
+ domain $1
27
27
  end
@@ -16,42 +16,42 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "cpu"
19
+ provides 'cpu'
20
20
 
21
21
  cpuinfo = Mash.new
22
22
  real_cpu = Mash.new
23
23
  cpu_number = 0
24
24
  current_cpu = nil
25
25
 
26
- File.open("/proc/cpuinfo").each do |line|
26
+ File.open('/proc/cpuinfo').each do |line|
27
27
  case line
28
- when /processor\s+:\s(.+)/
29
- cpuinfo[$1] = Mash.new
30
- current_cpu = $1
31
- cpu_number += 1
32
- when /vendor_id\s+:\s(.+)/
33
- cpuinfo[current_cpu]["vendor_id"] = $1
34
- when /cpu family\s+:\s(.+)/
35
- cpuinfo[current_cpu]["family"] = $1
36
- when /model\s+:\s(.+)/
37
- cpuinfo[current_cpu]["model"] = $1
38
- when /stepping\s+:\s(.+)/
39
- cpuinfo[current_cpu]["stepping"] = $1
40
- when /physical id\s+:\s(.+)/
41
- cpuinfo[current_cpu]["physical_id"] = $1
42
- real_cpu[$1] = true
43
- when /core id\s+:\s(.+)/
44
- cpuinfo[current_cpu]["core_id"] = $1
45
- when /cpu cores\s+:\s(.+)/
46
- cpuinfo[current_cpu]["cores"] = $1
47
- when /model name\s+:\s(.+)/
48
- cpuinfo[current_cpu]["model_name"] = $1
49
- when /cpu MHz\s+:\s(.+)/
50
- cpuinfo[current_cpu]["mhz"] = $1
51
- when /cache size\s+:\s(.+)/
52
- cpuinfo[current_cpu]["cache_size"] = $1
53
- when /flags\s+:\s(.+)/
54
- cpuinfo[current_cpu]["flags"] = $1.split(' ')
28
+ when /processor\s+:\s(.+)/
29
+ cpuinfo[$1] = Mash.new
30
+ current_cpu = $1
31
+ cpu_number += 1
32
+ when /vendor_id\s+:\s(.+)/
33
+ cpuinfo[current_cpu]['vendor_id'] = $1
34
+ when /cpu family\s+:\s(.+)/
35
+ cpuinfo[current_cpu]['family'] = $1
36
+ when /model\s+:\s(.+)/
37
+ cpuinfo[current_cpu]['model'] = $1
38
+ when /stepping\s+:\s(.+)/
39
+ cpuinfo[current_cpu]['stepping'] = $1
40
+ when /physical id\s+:\s(.+)/
41
+ cpuinfo[current_cpu]['physical_id'] = $1
42
+ real_cpu[$1] = true
43
+ when /core id\s+:\s(.+)/
44
+ cpuinfo[current_cpu]['core_id'] = $1
45
+ when /cpu cores\s+:\s(.+)/
46
+ cpuinfo[current_cpu]['cores'] = $1
47
+ when /model name\s+:\s(.+)/
48
+ cpuinfo[current_cpu]['model_name'] = $1
49
+ when /cpu MHz\s+:\s(.+)/
50
+ cpuinfo[current_cpu]['mhz'] = $1
51
+ when /cache size\s+:\s(.+)/
52
+ cpuinfo[current_cpu]['cache_size'] = $1
53
+ when /flags\s+:\s(.+)/
54
+ cpuinfo[current_cpu]['flags'] = $1.split(' ')
55
55
  end
56
56
  end
57
57
 
@@ -16,11 +16,11 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "hostname", "fqdn"
19
+ provides 'hostname', 'fqdn'
20
20
 
21
- hostname from("hostname -s")
21
+ hostname from('hostname -s')
22
22
  begin
23
- fqdn from("hostname --fqdn")
23
+ fqdn from('hostname --fqdn')
24
24
  rescue
25
- Ohai::Log.debug("hostname -f returned an error, probably no domain is set")
25
+ Ohai::Log.debug('hostname -f returned an error, probably no domain is set')
26
26
  end
@@ -17,77 +17,77 @@
17
17
  #
18
18
 
19
19
  def get_redhatish_platform(contents)
20
- contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
20
+ contents[/^Red Hat/i] ? 'redhat' : contents[/(\w+)/i, 1].downcase
21
21
  end
22
22
 
23
23
  def get_redhatish_version(contents)
24
24
  contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1]
25
25
  end
26
26
 
27
- provides "platform", "platform_version", "platform_family"
27
+ provides 'platform', 'platform_version', 'platform_family'
28
28
 
29
29
  require_plugin 'linux::lsb'
30
30
 
31
31
  # platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching
32
- if File.exists?("/etc/oracle-release")
33
- contents = File.read("/etc/oracle-release").chomp
34
- platform "oracle"
32
+ if File.exists?('/etc/oracle-release')
33
+ contents = File.read('/etc/oracle-release').chomp
34
+ platform 'oracle'
35
35
  platform_version get_redhatish_version(contents)
36
- elsif File.exists?("/etc/enterprise-release")
37
- contents = File.read("/etc/enterprise-release").chomp
38
- platform "oracle"
36
+ elsif File.exists?('/etc/enterprise-release')
37
+ contents = File.read('/etc/enterprise-release').chomp
38
+ platform 'oracle'
39
39
  platform_version get_redhatish_version(contents)
40
- elsif File.exists?("/etc/debian_version")
40
+ elsif File.exists?('/etc/debian_version')
41
41
  # Ubuntu and Debian both have /etc/debian_version
42
42
  # Ubuntu should always have a working lsb, debian does not by default
43
43
  if lsb[:id] =~ /Ubuntu/i
44
- platform "ubuntu"
44
+ platform 'ubuntu'
45
45
  platform_version lsb[:release]
46
46
  elsif lsb[:id] =~ /LinuxMint/i
47
- platform "linuxmint"
47
+ platform 'linuxmint'
48
48
  platform_version lsb[:release]
49
- else
50
- if File.exists?("/usr/bin/raspi-config")
51
- platform "raspbian"
49
+ else
50
+ if File.exists?('/usr/bin/raspi-config')
51
+ platform 'raspbian'
52
52
  else
53
- platform "debian"
53
+ platform 'debian'
54
54
  end
55
- platform_version File.read("/etc/debian_version").chomp
55
+ platform_version File.read('/etc/debian_version').chomp
56
56
  end
57
- elsif File.exists?("/etc/redhat-release")
58
- contents = File.read("/etc/redhat-release").chomp
57
+ elsif File.exists?('/etc/redhat-release')
58
+ contents = File.read('/etc/redhat-release').chomp
59
59
  platform get_redhatish_platform(contents)
60
60
  platform_version get_redhatish_version(contents)
61
- elsif File.exists?("/etc/system-release")
62
- contents = File.read("/etc/system-release").chomp
61
+ elsif File.exists?('/etc/system-release')
62
+ contents = File.read('/etc/system-release').chomp
63
63
  platform get_redhatish_platform(contents)
64
64
  platform_version get_redhatish_version(contents)
65
65
  elsif File.exists?('/etc/gentoo-release')
66
- platform "gentoo"
66
+ platform 'gentoo'
67
67
  platform_version File.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join
68
68
  elsif File.exists?('/etc/SuSE-release')
69
- platform "suse"
70
- suse_release = File.read("/etc/SuSE-release")
71
- platform_version suse_release.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
72
- platform_version suse_release.scan(/VERSION = ([\d\.]{2,})/).flatten.join(".") if platform_version == ""
69
+ platform 'suse'
70
+ suse_release = File.read('/etc/SuSE-release')
71
+ platform_version suse_release.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join('.')
72
+ platform_version suse_release.scan(/VERSION = ([\d\.]{2,})/).flatten.join('.') if platform_version == ''
73
73
  elsif File.exists?('/etc/slackware-version')
74
- platform "slackware"
75
- platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join
74
+ platform 'slackware'
75
+ platform_version File.read('/etc/slackware-version').scan(/(\d+|\.+)/).join
76
76
  elsif File.exists?('/etc/arch-release')
77
- platform "arch"
77
+ platform 'arch'
78
78
  # no way to determine platform_version in a rolling release distribution
79
79
  # kernel release will be used - ex. 2.6.32-ARCH
80
80
  elsif lsb[:id] =~ /RedHat/i
81
- platform "redhat"
81
+ platform 'redhat'
82
82
  platform_version lsb[:release]
83
83
  elsif lsb[:id] =~ /Amazon/i
84
- platform "amazon"
84
+ platform 'amazon'
85
85
  platform_version lsb[:release]
86
86
  elsif lsb[:id] =~ /ScientificSL/i
87
- platform "scientific"
87
+ platform 'scientific'
88
88
  platform_version lsb[:release]
89
89
  elsif lsb[:id] =~ /XenServer/i
90
- platform "xenserver"
90
+ platform 'xenserver'
91
91
  platform_version lsb[:release]
92
92
  elsif lsb[:id] # LSB can provide odd data that changes between releases, so we currently fall back on it rather than dealing with its subtleties
93
93
  platform lsb[:id].downcase
@@ -97,17 +97,17 @@ end
97
97
 
98
98
  case platform
99
99
  when /debian/, /ubuntu/, /linuxmint/, /raspbian/
100
- platform_family "debian"
100
+ platform_family 'debian'
101
101
  when /fedora/
102
- platform_family "fedora"
102
+ platform_family 'fedora'
103
103
  when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/, /xenserver/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
104
- platform_family "rhel"
104
+ platform_family 'rhel'
105
105
  when /suse/
106
- platform_family "suse"
106
+ platform_family 'suse'
107
107
  when /gentoo/
108
- platform_family "gentoo"
108
+ platform_family 'gentoo'
109
109
  when /slackware/
110
- platform_family "slackware"
111
- when /arch/
112
- platform_family "arch"
110
+ platform_family 'slackware'
111
+ when /arch/
112
+ platform_family 'arch'
113
113
  end
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "virtualization"
19
+ provides 'virtualization'
20
20
 
21
21
  virtualization Mash.new
22
22
 
@@ -25,15 +25,15 @@ virtualization Mash.new
25
25
 
26
26
  ## Xen
27
27
  # /proc/xen is an empty dir for EL6 + Linode Guests
28
- if File.exists?("/proc/xen")
29
- virtualization[:system] = "xen"
28
+ if File.exists?('/proc/xen')
29
+ virtualization[:system] = 'xen'
30
30
  # Assume guest
31
- virtualization[:role] = "guest"
31
+ virtualization[:role] = 'guest'
32
32
 
33
33
  # This file should exist on most Xen systems, normally empty for guests
34
- if File.exists?("/proc/xen/capabilities")
35
- if File.read("/proc/xen/capabilities") =~ /control_d/i
36
- virtualization[:role] = "host"
34
+ if File.exists?('/proc/xen/capabilities')
35
+ if File.read('/proc/xen/capabilities') =~ /control_d/i
36
+ virtualization[:role] = 'host'
37
37
  end
38
38
  end
39
39
  end
@@ -46,17 +46,17 @@ end
46
46
  # but rather be additive - btm
47
47
 
48
48
  # Detect from kernel module
49
- if File.exists?("/proc/modules")
50
- modules = File.read("/proc/modules")
49
+ if File.exists?('/proc/modules')
50
+ modules = File.read('/proc/modules')
51
51
  if modules =~ /^kvm/
52
- virtualization[:system] = "kvm"
53
- virtualization[:role] = "host"
52
+ virtualization[:system] = 'kvm'
53
+ virtualization[:role] = 'host'
54
54
  elsif modules =~ /^vboxdrv/
55
- virtualization[:system] = "vbox"
56
- virtualization[:role] = "host"
55
+ virtualization[:system] = 'vbox'
56
+ virtualization[:role] = 'host'
57
57
  elsif modules =~ /^vboxguest/
58
- virtualization[:system] = "vbox"
59
- virtualization[:role] = "guest"
58
+ virtualization[:system] = 'vbox'
59
+ virtualization[:role] = 'guest'
60
60
  end
61
61
  end
62
62
 
@@ -65,61 +65,61 @@ end
65
65
  # 2.6.27-9-server (intrepid) has this / 2.6.18-6-amd64 (etch) does not
66
66
  # It would be great if we could read pv_info in the kernel
67
67
  # Wait for reply to: http://article.gmane.org/gmane.comp.emulators.kvm.devel/27885
68
- if File.exists?("/proc/cpuinfo")
69
- if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU/
70
- virtualization[:system] = "kvm"
71
- virtualization[:role] = "guest"
68
+ if File.exists?('/proc/cpuinfo')
69
+ if File.read('/proc/cpuinfo') =~ /QEMU Virtual CPU/
70
+ virtualization[:system] = 'kvm'
71
+ virtualization[:role] = 'guest'
72
72
  end
73
73
  end
74
74
 
75
75
  # Detect OpenVZ / Virtuozzo.
76
76
  # http://wiki.openvz.org/BC_proc_entries
77
- if File.exists?("/proc/bc/0")
78
- virtualization[:system] = "openvz"
79
- virtualization[:role] = "host"
80
- elsif File.exists?("/proc/vz")
81
- virtualization[:system] = "openvz"
82
- virtualization[:role] = "guest"
77
+ if File.exists?('/proc/bc/0')
78
+ virtualization[:system] = 'openvz'
79
+ virtualization[:role] = 'host'
80
+ elsif File.exists?('/proc/vz')
81
+ virtualization[:system] = 'openvz'
82
+ virtualization[:role] = 'guest'
83
83
  end
84
84
 
85
85
  # http://www.dmo.ca/blog/detecting-virtualization-on-linux
86
- if File.exists?("/usr/sbin/dmidecode")
87
- popen4("dmidecode") do |pid, stdin, stdout, stderr|
86
+ if File.exists?('/usr/sbin/dmidecode')
87
+ popen4('dmidecode') do |pid, stdin, stdout, stderr|
88
88
  stdin.close
89
89
  dmi_info = stdout.read
90
90
  case dmi_info
91
- when /Manufacturer: Microsoft/
92
- if dmi_info =~ /Product Name: Virtual Machine/
93
- virtualization[:system] = "virtualpc"
94
- virtualization[:role] = "guest"
95
- end
96
- when /Manufacturer: VMware/
97
- if dmi_info =~ /Product Name: VMware Virtual Platform/
98
- virtualization[:system] = "vmware"
99
- virtualization[:role] = "guest"
100
- end
101
- when /Manufacturer: Xen/
102
- if dmi_info =~ /Product Name: HVM domU/
103
- virtualization[:system] = "xen"
104
- virtualization[:role] = "guest"
105
- end
106
- else
107
- nil
91
+ when /Manufacturer: Microsoft/
92
+ if dmi_info =~ /Product Name: Virtual Machine/
93
+ virtualization[:system] = 'virtualpc'
94
+ virtualization[:role] = 'guest'
95
+ end
96
+ when /Manufacturer: VMware/
97
+ if dmi_info =~ /Product Name: VMware Virtual Platform/
98
+ virtualization[:system] = 'vmware'
99
+ virtualization[:role] = 'guest'
100
+ end
101
+ when /Manufacturer: Xen/
102
+ if dmi_info =~ /Product Name: HVM domU/
103
+ virtualization[:system] = 'xen'
104
+ virtualization[:role] = 'guest'
105
+ end
106
+ else
107
+ nil
108
108
  end
109
109
 
110
110
  end
111
111
  end
112
112
 
113
113
  # Detect Linux-VServer
114
- if File.exists?("/proc/self/status")
115
- proc_self_status = File.read("/proc/self/status")
114
+ if File.exists?('/proc/self/status')
115
+ proc_self_status = File.read('/proc/self/status')
116
116
  vxid = proc_self_status.match(/^(s_context|VxID): (\d+)$/)
117
117
  if vxid and vxid[2]
118
- virtualization[:system] = "linux-vserver"
119
- if vxid[2] == "0"
120
- virtualization[:role] = "host"
118
+ virtualization[:system] = 'linux-vserver'
119
+ if vxid[2] == '0'
120
+ virtualization[:role] = 'host'
121
121
  else
122
- virtualization[:role] = "guest"
123
- end
122
+ virtualization[:role] = 'guest'
123
+ end
124
124
  end
125
125
  end