ohai 0.3.4

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 (139) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +98 -0
  3. data/Rakefile +61 -0
  4. data/bin/ohai +24 -0
  5. data/lib/ohai.rb +27 -0
  6. data/lib/ohai/application.rb +113 -0
  7. data/lib/ohai/config.rb +29 -0
  8. data/lib/ohai/exception.rb +23 -0
  9. data/lib/ohai/log.rb +26 -0
  10. data/lib/ohai/mixin/command.rb +208 -0
  11. data/lib/ohai/mixin/from_file.rb +36 -0
  12. data/lib/ohai/mixin/string.rb +29 -0
  13. data/lib/ohai/plugins/command.rb +21 -0
  14. data/lib/ohai/plugins/darwin/filesystem.rb +57 -0
  15. data/lib/ohai/plugins/darwin/hostname.rb +22 -0
  16. data/lib/ohai/plugins/darwin/kernel.rb +37 -0
  17. data/lib/ohai/plugins/darwin/network.rb +187 -0
  18. data/lib/ohai/plugins/darwin/platform.rb +36 -0
  19. data/lib/ohai/plugins/darwin/ps.rb +23 -0
  20. data/lib/ohai/plugins/darwin/ssh_host_key.rb +25 -0
  21. data/lib/ohai/plugins/darwin/system_profiler.rb +33 -0
  22. data/lib/ohai/plugins/darwin/uptime.rb +32 -0
  23. data/lib/ohai/plugins/dmi.rb +59 -0
  24. data/lib/ohai/plugins/ec2.rb +100 -0
  25. data/lib/ohai/plugins/erlang.rb +40 -0
  26. data/lib/ohai/plugins/freebsd/cpu.rb +52 -0
  27. data/lib/ohai/plugins/freebsd/filesystem.rb +57 -0
  28. data/lib/ohai/plugins/freebsd/hostname.rb +22 -0
  29. data/lib/ohai/plugins/freebsd/kernel.rb +37 -0
  30. data/lib/ohai/plugins/freebsd/memory.rb +50 -0
  31. data/lib/ohai/plugins/freebsd/network.rb +112 -0
  32. data/lib/ohai/plugins/freebsd/platform.rb +23 -0
  33. data/lib/ohai/plugins/freebsd/ps.rb +24 -0
  34. data/lib/ohai/plugins/freebsd/ssh_host_key.rb +26 -0
  35. data/lib/ohai/plugins/freebsd/uptime.rb +32 -0
  36. data/lib/ohai/plugins/freebsd/virtualization.rb +66 -0
  37. data/lib/ohai/plugins/hostname.rb +27 -0
  38. data/lib/ohai/plugins/java.rb +36 -0
  39. data/lib/ohai/plugins/kernel.rb +33 -0
  40. data/lib/ohai/plugins/keys.rb +22 -0
  41. data/lib/ohai/plugins/languages.rb +21 -0
  42. data/lib/ohai/plugins/linux/block_device.rb +38 -0
  43. data/lib/ohai/plugins/linux/cpu.rb +60 -0
  44. data/lib/ohai/plugins/linux/filesystem.rb +57 -0
  45. data/lib/ohai/plugins/linux/hostname.rb +26 -0
  46. data/lib/ohai/plugins/linux/kernel.rb +33 -0
  47. data/lib/ohai/plugins/linux/lsb.rb +38 -0
  48. data/lib/ohai/plugins/linux/memory.rb +83 -0
  49. data/lib/ohai/plugins/linux/network.rb +112 -0
  50. data/lib/ohai/plugins/linux/platform.rb +43 -0
  51. data/lib/ohai/plugins/linux/ps.rb +23 -0
  52. data/lib/ohai/plugins/linux/ssh_host_key.rb +26 -0
  53. data/lib/ohai/plugins/linux/uptime.rb +28 -0
  54. data/lib/ohai/plugins/linux/virtualization.rb +77 -0
  55. data/lib/ohai/plugins/netbsd/cpu.rb +48 -0
  56. data/lib/ohai/plugins/netbsd/filesystem.rb +57 -0
  57. data/lib/ohai/plugins/netbsd/hostname.rb +22 -0
  58. data/lib/ohai/plugins/netbsd/kernel.rb +35 -0
  59. data/lib/ohai/plugins/netbsd/memory.rb +98 -0
  60. data/lib/ohai/plugins/netbsd/network.rb +111 -0
  61. data/lib/ohai/plugins/netbsd/platform.rb +22 -0
  62. data/lib/ohai/plugins/netbsd/ps.rb +24 -0
  63. data/lib/ohai/plugins/netbsd/ssh_host_key.rb +26 -0
  64. data/lib/ohai/plugins/netbsd/uptime.rb +31 -0
  65. data/lib/ohai/plugins/netbsd/virtualization.rb +65 -0
  66. data/lib/ohai/plugins/network.rb +52 -0
  67. data/lib/ohai/plugins/ohai_time.rb +21 -0
  68. data/lib/ohai/plugins/openbsd/cpu.rb +38 -0
  69. data/lib/ohai/plugins/openbsd/filesystem.rb +57 -0
  70. data/lib/ohai/plugins/openbsd/hostname.rb +22 -0
  71. data/lib/ohai/plugins/openbsd/kernel.rb +35 -0
  72. data/lib/ohai/plugins/openbsd/memory.rb +98 -0
  73. data/lib/ohai/plugins/openbsd/network.rb +111 -0
  74. data/lib/ohai/plugins/openbsd/platform.rb +23 -0
  75. data/lib/ohai/plugins/openbsd/ps.rb +24 -0
  76. data/lib/ohai/plugins/openbsd/ssh_host_key.rb +26 -0
  77. data/lib/ohai/plugins/openbsd/uptime.rb +32 -0
  78. data/lib/ohai/plugins/openbsd/virtualization.rb +66 -0
  79. data/lib/ohai/plugins/os.rb +48 -0
  80. data/lib/ohai/plugins/perl.rb +37 -0
  81. data/lib/ohai/plugins/platform.rb +25 -0
  82. data/lib/ohai/plugins/python.rb +37 -0
  83. data/lib/ohai/plugins/ruby.rb +39 -0
  84. data/lib/ohai/plugins/solaris2/cpu.rb +33 -0
  85. data/lib/ohai/plugins/solaris2/hostname.rb +25 -0
  86. data/lib/ohai/plugins/solaris2/kernel.rb +40 -0
  87. data/lib/ohai/plugins/solaris2/network.rb +141 -0
  88. data/lib/ohai/plugins/solaris2/platform.rb +33 -0
  89. data/lib/ohai/plugins/solaris2/ps.rb +23 -0
  90. data/lib/ohai/plugins/solaris2/ssh_host_key.rb +26 -0
  91. data/lib/ohai/plugins/uptime.rb +42 -0
  92. data/lib/ohai/plugins/virtualization.rb +86 -0
  93. data/lib/ohai/plugins/windows/filesystem.rb +44 -0
  94. data/lib/ohai/plugins/windows/hostname.rb +25 -0
  95. data/lib/ohai/plugins/windows/kernel.rb +75 -0
  96. data/lib/ohai/plugins/windows/network.rb +114 -0
  97. data/lib/ohai/plugins/windows/platform.rb +26 -0
  98. data/lib/ohai/system.rb +241 -0
  99. data/spec/ohai/mixin/command_spec.rb +37 -0
  100. data/spec/ohai/mixin/from_file_spec.rb +53 -0
  101. data/spec/ohai/plugins/darwin/hostname_spec.rb +34 -0
  102. data/spec/ohai/plugins/darwin/kernel_spec.rb +46 -0
  103. data/spec/ohai/plugins/darwin/platform_spec.rb +67 -0
  104. data/spec/ohai/plugins/dmi_spec.rb +73 -0
  105. data/spec/ohai/plugins/ec2_spec.rb +81 -0
  106. data/spec/ohai/plugins/erlang_spec.rb +63 -0
  107. data/spec/ohai/plugins/freebsd/hostname_spec.rb +34 -0
  108. data/spec/ohai/plugins/freebsd/kernel_spec.rb +37 -0
  109. data/spec/ohai/plugins/freebsd/platform_spec.rb +40 -0
  110. data/spec/ohai/plugins/hostname_spec.rb +39 -0
  111. data/spec/ohai/plugins/java_spec.rb +70 -0
  112. data/spec/ohai/plugins/kernel_spec.rb +43 -0
  113. data/spec/ohai/plugins/linux/cpu_spec.rb +128 -0
  114. data/spec/ohai/plugins/linux/hostname_spec.rb +52 -0
  115. data/spec/ohai/plugins/linux/kernel_spec.rb +31 -0
  116. data/spec/ohai/plugins/linux/lsb_spec.rb +60 -0
  117. data/spec/ohai/plugins/linux/platform_spec.rb +81 -0
  118. data/spec/ohai/plugins/linux/uptime_spec.rb +61 -0
  119. data/spec/ohai/plugins/linux/virtualization_spec.rb +131 -0
  120. data/spec/ohai/plugins/netbsd/hostname_spec.rb +34 -0
  121. data/spec/ohai/plugins/netbsd/kernel_spec.rb +36 -0
  122. data/spec/ohai/plugins/netbsd/platform_spec.rb +40 -0
  123. data/spec/ohai/plugins/ohai_time_spec.rb +46 -0
  124. data/spec/ohai/plugins/openbsd/hostname_spec.rb +34 -0
  125. data/spec/ohai/plugins/openbsd/kernel_spec.rb +37 -0
  126. data/spec/ohai/plugins/openbsd/platform_spec.rb +40 -0
  127. data/spec/ohai/plugins/os_spec.rb +69 -0
  128. data/spec/ohai/plugins/perl_spec.rb +89 -0
  129. data/spec/ohai/plugins/platform_spec.rb +56 -0
  130. data/spec/ohai/plugins/python_spec.rb +53 -0
  131. data/spec/ohai/plugins/ruby_spec.rb +51 -0
  132. data/spec/ohai/plugins/solaris2/hostname_spec.rb +43 -0
  133. data/spec/ohai/plugins/solaris2/kernel_spec.rb +164 -0
  134. data/spec/ohai/system_spec.rb +130 -0
  135. data/spec/ohai_spec.rb +27 -0
  136. data/spec/rcov.opts +2 -0
  137. data/spec/spec.opts +2 -0
  138. data/spec/spec_helper.rb +68 -0
  139. metadata +240 -0
@@ -0,0 +1,141 @@
1
+ #
2
+ # Author:: Benjamin Black (<nostromo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
19
+ # EXAMPLE SOLARIS IFCONFIG OUTPUT; CURRENTLY, ONLY SIMPLE STUFF IS SUPPORTED (E.G., NO TUNNELS)
20
+ # DEAR SUN: YOU GET AN F FOR YOUR IFCONFIG
21
+ #lo0:3: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
22
+ # inet 127.0.0.1 netmask ff000000
23
+ #e1000g0:3: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 3
24
+ # inet 72.2.115.28 netmask ffffff80 broadcast 72.2.115.127
25
+ #e1000g2:1: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 4
26
+ # inet 10.2.115.28 netmask ffffff80 broadcast 10.2.115.127
27
+ # inet6 2001:0db8:3c4d:55:a00:20ff:fe8e:f3ad/64
28
+ #ip.tun0: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
29
+ # inet tunnel src 109.146.85.57 tunnel dst 109.146.85.212
30
+ # tunnel security settings --> use 'ipsecconf -ln -i ip.tun1'
31
+ # tunnel hop limit 60
32
+ # inet6 fe80::6d92:5539/10 --> fe80::6d92:55d4
33
+ #ip.tun0:1: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
34
+ # inet6 2::45/128 --> 2::46
35
+ #lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
36
+ # inet 127.0.0.1 netmask ff000000
37
+ #eri0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 \
38
+ #index 2
39
+ # inet 172.17.128.208 netmask ffffff00 broadcast 172.17.128.255
40
+ #ip6.tun0: flags=10008d1<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST,IPv4> \
41
+ #mtu 1460
42
+ # index 3
43
+ # inet6 tunnel src fe80::1 tunnel dst fe80::2
44
+ # tunnel security settings --> use 'ipsecconf -ln -i ip.tun1'
45
+ # tunnel hop limit 60 tunnel encapsulation limit 4
46
+ # inet 10.0.0.208 --> 10.0.0.210 netmask ff000000
47
+ #qfe1: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 3
48
+ # usesrc vni0
49
+ # inet6 fe80::203:baff:fe17:4be0/10
50
+ # ether 0:3:ba:17:4b:e0
51
+ #vni0: flags=2002210041<UP,RUNNING,NOXMIT,NONUD,IPv6,VIRTUAL> mtu 0
52
+ # index 5
53
+ # srcof qfe1
54
+ # inet6 fe80::203:baff:fe17:4444/128
55
+
56
+ provides "network"
57
+
58
+ require 'scanf'
59
+
60
+ def encaps_lookup(ifname)
61
+ return "Ethernet" if ifname.eql?("e1000g")
62
+ return "Ethernet" if ifname.eql?("eri")
63
+ return "Loopback" if ifname.eql?("lo")
64
+ "Unknown"
65
+ end
66
+
67
+ def arpname_to_ifname(iface, arpname)
68
+ iface.keys.each do |ifn|
69
+ return ifn if ifn.split(':')[0].eql?(arpname)
70
+ end
71
+
72
+ nil
73
+ end
74
+
75
+ iface = Mash.new
76
+ popen4("ifconfig -a") do |pid, stdin, stdout, stderr|
77
+ stdin.close
78
+ cint = nil
79
+ stdout.each do |line|
80
+ if line =~ /^([0-9a-zA-Z\.\:\-]+): \S+ mtu (\d+) index (\d+)/
81
+ cint = $1
82
+ iface[cint] = Mash.new
83
+ iface[cint][:mtu] = $2
84
+ iface[cint][:index] = $3
85
+ if line =~ / flags\=\d+\<((ADDRCONF|ANYCAST|BROADCAST|CoS|DEPRECATED|DHCP|DUPLICATE|FAILED|FIXEDMTU|INACTIVE|LOOPBACK|MIP|MULTI_BCAST|MULTICAST|NOARP|NOFAILOVER|NOLOCAL|NONUD|NORTEXCH|NOXMIT|OFFLINE|POINTOPOINT|PREFERRED|PRIVATE|ROUTER|RUNNING|STANDBY|TEMPORARY|UNNUMBERED|UP|VIRTUAL|XRESOLV|IPv4|IPv6|,)+)\>\s/
86
+ flags = $1.split(',')
87
+ else
88
+ flags = Array.new
89
+ end
90
+ iface[cint][:flags] = flags.flatten
91
+ if cint =~ /^(\w+)(\d+.*)/
92
+ iface[cint][:type] = $1
93
+ iface[cint][:number] = $2
94
+ iface[cint][:encapsulation] = encaps_lookup($1)
95
+ end
96
+ end
97
+ if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask (([0-9a-f]){1,8})\s*$/
98
+ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
99
+ iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf('%2x'*4)*"."}
100
+ end
101
+ if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask (([0-9a-f]){1,8}) broadcast (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
102
+ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
103
+ iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf('%2x'*4)*".", "broadcast" => $4 }
104
+ end
105
+ if line =~ /\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*)\/(\d+)\s*$/
106
+ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
107
+ iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $4 }
108
+ end
109
+ end
110
+ end
111
+
112
+ popen4("arp -an") do |pid, stdin, stdout, stderr|
113
+ stdin.close
114
+ stdout.each do |line|
115
+ if line =~ /([0-9a-zA-Z]+)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\w+)\s+([a-zA-Z0-9\.\:\-]+)/
116
+ next unless iface[arpname_to_ifname(iface, $1)] # this should never happen, except on solaris because sun hates you.
117
+ iface[arpname_to_ifname(iface, $1)][:arp] = Mash.new unless iface[arpname_to_ifname(iface, $1)][:arp]
118
+ iface[arpname_to_ifname(iface, $1)][:arp][$2] = $5
119
+ end
120
+ end
121
+ end
122
+
123
+ iface.keys.each do |ifn|
124
+ iaddr = nil
125
+ if iface[ifn][:encapsulation].eql?("Ethernet")
126
+ iface[ifn][:addresses].keys.each do |addr|
127
+ if [ifn][:addresses][addr]["family"].eql?("inet")
128
+ iaddr = addr
129
+ break
130
+ end
131
+ end
132
+ iface[ifn][:arp].keys.each do |addr|
133
+ if addr.eql?(iaddr)
134
+ iface[ifn][:addresses][iface[ifn][:arp][iaddr]] = { "family" => "lladdr" }
135
+ break
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ network[:interfaces] = iface
@@ -0,0 +1,33 @@
1
+ #
2
+ # Author:: Benjamin Black (<nostromo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
19
+ provides "platform", "platform_version", "platform_build"
20
+
21
+ popen4("uname -X") do |pid, stdin, stdout, stderr|
22
+ stdin.close
23
+ stdout.each do |line|
24
+ case line
25
+ when /^System =\s+(.+)$/
26
+ platform = ($1.eql?("SunOS") ? "solaris2" : $1.downcase)
27
+ when /^Release =\s+(.+)$/
28
+ platform_version $1
29
+ when /^KernelID =\s+(.+)$/
30
+ platform_build $1
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
19
+ provides "command/ps"
20
+
21
+ require_plugin 'command'
22
+
23
+ command[:ps] = 'ps -ef'
@@ -0,0 +1,26 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
19
+ provides "keys/ssh"
20
+
21
+ require_plugin "keys"
22
+
23
+ keys[:ssh] = Mash.new
24
+
25
+ keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1]
26
+ keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1]
@@ -0,0 +1,42 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
19
+ def _seconds_to_human(seconds)
20
+ days = seconds.to_i / 86400
21
+ seconds -= 86400 * days
22
+
23
+ hours = seconds.to_i / 3600
24
+ seconds -= 3600 * hours
25
+
26
+ minutes = seconds.to_i / 60
27
+ seconds -= 60 * minutes
28
+
29
+ if days > 1
30
+ return sprintf("%d days %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds)
31
+ elsif days == 1
32
+ return sprintf("%d day %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds)
33
+ elsif hours > 0
34
+ return sprintf("%d hours %02d minutes %02d seconds", hours, minutes, seconds)
35
+ elsif minutes > 0
36
+ return sprintf("%d minutes %02d seconds", minutes, seconds)
37
+ else
38
+ return sprintf("%02d seconds", seconds)
39
+ end
40
+ end
41
+
42
+
@@ -0,0 +1,86 @@
1
+ #
2
+ # Author:: Benjamin Black (<bb@opscode.com>)
3
+ # Copyright:: Copyright (c) 2009 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
+
19
+ provides "virtualization"
20
+
21
+ require_plugin "#{os}::virtualization"
22
+
23
+ unless virtualization.nil? || !(virtualization[:role].eql?("host"))
24
+ begin
25
+ require 'libvirt'
26
+ require 'hpricot'
27
+
28
+ emu = (virtualization[:emulator].eql?('kvm') ? 'qemu' : virtualization[:emulator])
29
+ virtualization[:libvirt_version] = Libvirt::version(emu)[0].to_s
30
+
31
+ virtconn = Libvirt::open_read_only("#{emu}:///system")
32
+
33
+ virtualization[:uri] = virtconn.uri
34
+ virtualization[:capabilities] = Mash.new
35
+ virtualization[:capabilities][:xml_desc] = (virtconn.capabilities.split("\n").collect {|line| line.strip}).join
36
+ #xdoc = Hpricot virtualization[:capabilities][:xml_desc]
37
+
38
+ virtualization[:nodeinfo] = Mash.new
39
+ ni = virtconn.node_get_info
40
+ ['cores','cpus','memory','mhz','model','nodes','sockets','threads'].each {|a| virtualization[:nodeinfo][a] = ni.send(a)}
41
+
42
+ virtualization[:domains] = Mash.new
43
+ virtconn.list_domains.each do |d|
44
+ dv = virtconn.lookup_domain_by_id d
45
+ virtualization[:domains][dv.name] = Mash.new
46
+ virtualization[:domains][dv.name][:id] = d
47
+ virtualization[:domains][dv.name][:xml_desc] = (dv.xml_desc.split("\n").collect {|line| line.strip}).join
48
+ ['os_type','uuid'].each {|a| virtualization[:domains][dv.name][a] = dv.send(a)}
49
+ ['cpu_time','max_mem','memory','nr_virt_cpu','state'].each {|a| virtualization[:domains][dv.name][a] = dv.info.send(a)}
50
+ #xdoc = Hpricot virtualization[:domains][dv.name][:xml_desc]
51
+
52
+ end
53
+
54
+ virtualization[:networks] = Mash.new
55
+ virtconn.list_networks.each do |n|
56
+ nv = virtconn.lookup_network_by_name n
57
+ virtualization[:networks][n] = Mash.new
58
+ virtualization[:networks][n][:xml_desc] = (nv.xml_desc.split("\n").collect {|line| line.strip}).join
59
+ ['bridge_name','uuid'].each {|a| virtualization[:networks][n][a] = nv.send(a)}
60
+ #xdoc = Hpricot virtualization[:networks][n][:xml_desc]
61
+
62
+ end
63
+
64
+ virtualization[:storage] = Mash.new
65
+ virtconn.list_storage_pools.each do |pool|
66
+ sp = virtconn.lookup_storage_pool_by_name pool
67
+ virtualization[:storage][pool] = Mash.new
68
+ virtualization[:storage][pool][:xml_desc] = (sp.xml_desc.split("\n").collect {|line| line.strip}).join
69
+ ['autostart','uuid'].each {|a| virtualization[:storage][pool][a] = sp.send(a)}
70
+ ['allocation','available','capacity','state'].each {|a| virtualization[:storage][pool][a] = sp.info.send(a)}
71
+ #xdoc = Hpricot virtualization[:storage][pool][:xml_desc]
72
+
73
+ virtualization[:storage][pool][:volumes] = Mash.new
74
+ sp.list_volumes.each do |v|
75
+ virtualization[:storage][pool][:volumes][v] = Mash.new
76
+ sv = sp.lookup_volume_by_name pool
77
+ ['key','name','path'].each {|a| virtualization[:storage][pool][:volumes][v][a] = sv.send(a)}
78
+ ['allocation','capacity','type'].each {|a| virtualization[:storage][pool][:volumes][v][a] = sv.info.send(a)}
79
+ end
80
+ end
81
+
82
+ virtconn.close
83
+ rescue LoadError => e
84
+ Ohai::Log.debug("Can't load gem: #{e}. virtualization plugin is disabled.")
85
+ end
86
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # Author:: James Gartrell (<jgartrel@gmail.com>)
3
+ # Copyright:: Copyright (c) 2009 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
+
19
+ require 'ruby-wmi'
20
+
21
+ fs = Mash.new
22
+ ld_info = Mash.new
23
+
24
+ # Grab filesystem data from WMI
25
+ # Note: we should really be parsing Win32_Volume and Win32_Mapped drive
26
+ disks = WMI::Win32_LogicalDisk.find(:all)
27
+ disks.each do |disk|
28
+ filesystem = disk.DeviceID
29
+ fs[filesystem] = Mash.new
30
+ ld_info[filesystem] = Mash.new
31
+ disk.properties_.each do |p|
32
+ ld_info[filesystem][p.name.wmi_underscore.to_sym] = disk[p.name]
33
+ end
34
+ fs[filesystem][:kb_size] = ld_info[filesystem][:size].to_i / 1000
35
+ fs[filesystem][:kb_available] = ld_info[filesystem][:free_space].to_i / 1000
36
+ fs[filesystem][:kb_used] = fs[filesystem][:kb_size].to_i - fs[filesystem][:kb_available].to_i
37
+ fs[filesystem][:percent_used] = (fs[filesystem][:kb_size].to_i != 0 ? fs[filesystem][:kb_used].to_i * 100 / fs[filesystem][:kb_size].to_i : 0)
38
+ fs[filesystem][:mount] = ld_info[filesystem][:name]
39
+ fs[filesystem][:fs_type] = ld_info[filesystem][:file_system].downcase unless ld_info[filesystem][:file_system] == nil
40
+ fs[filesystem][:volume_name] = ld_info[filesystem][:volume_name]
41
+ end
42
+
43
+ # Set the filesystem data
44
+ filesystem fs
@@ -0,0 +1,25 @@
1
+ #
2
+ # Author:: James Gartrell (<jgartrel@gmail.com>)
3
+ # Copyright:: Copyright (c) 2009 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
+
19
+ require 'ruby-wmi'
20
+ require 'socket'
21
+
22
+ host = WMI::Win32_ComputerSystem.find(:first)
23
+ hostname "#{host.Name}"
24
+ #hostname "#{Socket.gethostname}"
25
+ fqdn "#{Socket.gethostbyname(Socket.gethostname).first}"
@@ -0,0 +1,75 @@
1
+ #
2
+ # Author:: James Gartrell (<jgartrel@gmail.com>)
3
+ # Copyright:: Copyright (c) 2009 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
+
19
+ require 'ruby-wmi'
20
+
21
+ def machine_lookup(sys_type)
22
+ return "i386" if sys_type.eql?("X86-based PC")
23
+ return "x86_64" if sys_type.eql?("x64-based PC")
24
+ sys_type
25
+ end
26
+
27
+ def os_lookup(sys_type)
28
+ return "Unknown" if sys_type.to_s.eql?("0")
29
+ return "Other" if sys_type.to_s.eql?("1")
30
+ return "MSDOS" if sys_type.to_s.eql?("14")
31
+ return "WIN3x" if sys_type.to_s.eql?("15")
32
+ return "WIN95" if sys_type.to_s.eql?("16")
33
+ return "WIN98" if sys_type.to_s.eql?("17")
34
+ return "WINNT" if sys_type.to_s.eql?("18")
35
+ return "WINCE" if sys_type.to_s.eql?("19")
36
+ return nil
37
+ end
38
+
39
+ host = WMI::Win32_OperatingSystem.find(:first)
40
+ kernel[:os_info] = Mash.new
41
+ host.properties_.each do |p|
42
+ kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name]
43
+ end
44
+
45
+ kernel[:name] = "#{kernel[:os_info][:caption]}"
46
+ kernel[:release] = "#{kernel[:os_info][:version]}"
47
+ kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
48
+ kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
49
+
50
+ host = WMI::Win32_ComputerSystem.find(:first)
51
+ kernel[:cs_info] = Mash.new
52
+ host.properties_.each do |p|
53
+ kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name]
54
+ end
55
+
56
+ kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")
57
+
58
+ kext = Mash.new
59
+ pnp_drivers = Mash.new
60
+
61
+ drivers = WMI::Win32_PnPSignedDriver.find(:all)
62
+ drivers.each do |driver|
63
+ pnp_drivers[driver.DeviceID] = Mash.new
64
+ driver.properties_.each do |p|
65
+ pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver[p.name]
66
+ end
67
+ if driver.DeviceName
68
+ kext[driver.DeviceName] = pnp_drivers[driver.DeviceID]
69
+ kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version]
70
+ kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil
71
+ end
72
+ end
73
+
74
+ kernel[:pnp_drivers] = pnp_drivers
75
+ kernel[:modules] = kext