ohai 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
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,29 @@
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
+ require 'mixlib/config'
20
+
21
+ module Ohai
22
+ class Config
23
+ extend Mixlib::Config
24
+
25
+ log_level :info
26
+ log_location STDOUT
27
+ plugin_path [ File.expand_path(File.join(File.dirname(__FILE__), 'plugins'))]
28
+ end
29
+ 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
+ module Ohai
20
+ module Exceptions
21
+ class Exec < RuntimeError; end
22
+ end
23
+ end
@@ -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
+ require 'ohai/config'
20
+ require 'mixlib/log'
21
+
22
+ module Ohai
23
+ class Log
24
+ extend Mixlib::Log
25
+ end
26
+ end
@@ -0,0 +1,208 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # License:: GNU GPL, Version 3
5
+ #
6
+ # Copyright (C) 2008, Opscode Inc.
7
+ #
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.
12
+ #
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/>.
20
+ #
21
+
22
+ require 'ohai/exception'
23
+ require 'ohai/config'
24
+ require 'ohai/log'
25
+ require 'tmpdir'
26
+ require 'fcntl'
27
+ require 'etc'
28
+ require 'systemu'
29
+
30
+ module Ohai
31
+ module Mixin
32
+ module Command
33
+
34
+ def run_command(args={})
35
+ if args.has_key?(:creates)
36
+ if File.exists?(args[:creates])
37
+ Ohai::Log.debug("Skipping #{args[:command]} - creates #{args[:creates]} exists.")
38
+ return false
39
+ end
40
+ end
41
+
42
+ stdout_string = nil
43
+ stderr_string = nil
44
+
45
+ args[:cwd] ||= Dir.tmpdir
46
+ unless File.directory?(args[:cwd])
47
+ raise Ohai::Exceptions::Exec, "#{args[:cwd]} does not exist or is not a directory"
48
+ end
49
+
50
+ status = nil
51
+ Dir.chdir(args[:cwd]) do
52
+ if args[:timeout]
53
+ begin
54
+ Timeout.timeout(args[:timeout]) do
55
+ status, stdout_string, stderr_string = systemu(args[:command])
56
+ end
57
+ rescue Exception => e
58
+ Ohai::Log.error("#{args[:command_string]} exceeded timeout #{args[:timeout]}")
59
+ raise(e)
60
+ end
61
+ else
62
+ status, stdout_string, stderr_string = systemu(args[:command])
63
+ end
64
+
65
+ # systemu returns 42 when it hits unexpected errors
66
+ if status.exitstatus == 42 and stderr_string == ""
67
+ stderr_string = "Failed to run: #{args[:command]}, assuming command not found"
68
+ Ohai::Log.debug(stderr_string)
69
+ end
70
+
71
+ if stdout_string
72
+ Ohai::Log.debug("---- Begin #{args[:command]} STDOUT ----")
73
+ Ohai::Log.debug(stdout_string.strip)
74
+ Ohai::Log.debug("---- End #{args[:command]} STDOUT ----")
75
+ end
76
+ if stderr_string
77
+ Ohai::Log.debug("---- Begin #{args[:command]} STDERR ----")
78
+ Ohai::Log.debug(stderr_string.strip)
79
+ Ohai::Log.debug("---- End #{args[:command]} STDERR ----")
80
+ end
81
+
82
+ args[:returns] ||= 0
83
+ args[:no_status_check] ||= false
84
+ if status.exitstatus != args[:returns] and not args[:no_status_check]
85
+ raise Ohai::Exceptions::Exec, "#{args[:command_string]} returned #{status.exitstatus}, expected #{args[:returns]}"
86
+ else
87
+ Ohai::Log.debug("Ran #{args[:command_string]} (#{args[:command]}) returned #{status.exitstatus}")
88
+ end
89
+ end
90
+ return status, stdout_string, stderr_string
91
+ end
92
+
93
+ module_function :run_command
94
+
95
+ # This is taken directly from Ara T Howard's Open4 library, and then
96
+ # modified to suit the needs of Ohai. Any bugs here are most likely
97
+ # my own, and not Ara's.
98
+ #
99
+ # The original appears in external/open4.rb in its unmodified form.
100
+ #
101
+ # Thanks Ara!
102
+ def popen4(cmd, args={}, &b)
103
+
104
+ args[:user] ||= nil
105
+ unless args[:user].kind_of?(Integer)
106
+ args[:user] = Etc.getpwnam(args[:user]).uid if args[:user]
107
+ end
108
+ args[:group] ||= nil
109
+ unless args[:group].kind_of?(Integer)
110
+ args[:group] = Etc.getgrnam(args[:group]).gid if args[:group]
111
+ end
112
+ args[:environment] ||= {}
113
+
114
+ # Default on C locale so parsing commands output can be done
115
+ # independently of the node's default locale.
116
+ # "LC_ALL" could be set to nil, in which case we also must ignore it.
117
+ unless args[:environment].has_key?("LC_ALL")
118
+ args[:environment]["LC_ALL"] = "C"
119
+ end
120
+
121
+ pw, pr, pe, ps = IO.pipe, IO.pipe, IO.pipe, IO.pipe
122
+
123
+ verbose = $VERBOSE
124
+ begin
125
+ $VERBOSE = nil
126
+ ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
127
+
128
+ cid = fork {
129
+ pw.last.close
130
+ STDIN.reopen pw.first
131
+ pw.first.close
132
+
133
+ pr.first.close
134
+ STDOUT.reopen pr.last
135
+ pr.last.close
136
+
137
+ pe.first.close
138
+ STDERR.reopen pe.last
139
+ pe.last.close
140
+
141
+ STDOUT.sync = STDERR.sync = true
142
+
143
+ if args[:user]
144
+ Process.euid = args[:user]
145
+ Process.uid = args[:user]
146
+ end
147
+
148
+ if args[:group]
149
+ Process.egid = args[:group]
150
+ Process.gid = args[:group]
151
+ end
152
+
153
+ args[:environment].each do |key,value|
154
+ ENV[key] = value
155
+ end
156
+
157
+ begin
158
+ if cmd.kind_of?(Array)
159
+ exec(*cmd)
160
+ else
161
+ exec(cmd)
162
+ end
163
+ raise 'forty-two'
164
+ rescue Exception => e
165
+ Marshal.dump(e, ps.last)
166
+ ps.last.flush
167
+ end
168
+ ps.last.close unless (ps.last.closed?)
169
+ exit!
170
+ }
171
+ ensure
172
+ $VERBOSE = verbose
173
+ end
174
+
175
+ [pw.first, pr.last, pe.last, ps.last].each{|fd| fd.close}
176
+
177
+ begin
178
+ e = Marshal.load ps.first
179
+ # If we get here, exec failed. Collect status of child to prevent
180
+ # zombies.
181
+ Process.waitpid(cid)
182
+ raise(Exception === e ? e : "unknown failure!")
183
+ rescue EOFError # If we get an EOF error, then the exec was successful
184
+ 42
185
+ ensure
186
+ ps.first.close
187
+ end
188
+
189
+ pw.last.sync = true
190
+
191
+ pi = [pw.last, pr.first, pe.first]
192
+
193
+ if b
194
+ begin
195
+ b[cid, *pi]
196
+ Process.waitpid2(cid).last
197
+ ensure
198
+ pi.each{|fd| fd.close unless fd.closed?}
199
+ end
200
+ else
201
+ [cid, pw.last, pr.first, pe.first]
202
+ end
203
+ end
204
+
205
+ module_function :popen4
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,36 @@
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
+ module Ohai
20
+ module Mixin
21
+ module FromFile
22
+
23
+ # Loads a given ruby file, and runs instance_eval against it in the context of the current
24
+ # object.
25
+ #
26
+ # Raises an IOError if the file cannot be found, or is not readable.
27
+ def from_file(filename)
28
+ if File.exists?(filename) && File.readable?(filename)
29
+ self.instance_eval(IO.read(filename), filename, 1)
30
+ else
31
+ raise IOError, "Cannot open or read #{filename}!"
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
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
+ class String
20
+ # Add string function to handle WMI property conversion to json hash keys
21
+ # Makes an underscored, lowercase form from the expression in the string.
22
+ # underscore will also change ’::’ to ’/’ to convert namespaces to paths.
23
+ # This should implement the same functionality as underscore method in
24
+ # ActiveSupport::CoreExtensions::String::Inflections
25
+ def wmi_underscore
26
+ self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
27
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
28
+ end
29
+ end
@@ -0,0 +1,21 @@
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"
20
+
21
+ command Mash.new
@@ -0,0 +1,57 @@
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 "filesystem"
20
+
21
+ fs = Mash.new
22
+
23
+ block_size = 0
24
+ popen4("df") do |pid, stdin, stdout, stderr|
25
+ stdin.close
26
+ stdout.each do |line|
27
+ case line
28
+ when /^Filesystem\s+(\d+)-/
29
+ block_size = $1.to_i
30
+ next
31
+ when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
32
+ filesystem = $1
33
+ fs[filesystem] = Mash.new
34
+ fs[filesystem][:block_size] = block_size
35
+ fs[filesystem][:kb_size] = $2.to_i / (1024 / block_size)
36
+ fs[filesystem][:kb_used] = $3.to_i / (1024 / block_size)
37
+ fs[filesystem][:kb_available] = $4.to_i / (1024 / block_size)
38
+ fs[filesystem][:percent_used] = $5
39
+ fs[filesystem][:mount] = $6
40
+ end
41
+ end
42
+ end
43
+
44
+ popen4("mount") do |pid, stdin, stdout, stderr|
45
+ stdin.close
46
+ stdout.each do |line|
47
+ if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
48
+ filesystem = $1
49
+ fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
50
+ fs[filesystem][:mount] = $2
51
+ fs[filesystem][:fs_type] = $3
52
+ fs[filesystem][:mount_options] = $4.split(/,\s*/)
53
+ end
54
+ end
55
+ end
56
+
57
+ filesystem fs
@@ -0,0 +1,22 @@
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 "fqdn", "hostname"
20
+
21
+ hostname from("hostname -s")
22
+ fqdn from("hostname")