rightscale-ohai 0.3.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +98 -0
  3. data/Rakefile +59 -0
  4. data/bin/ohai +78 -0
  5. data/lib/ohai/config.rb +118 -0
  6. data/lib/ohai/exception.rb +23 -0
  7. data/lib/ohai/log/formatter.rb +57 -0
  8. data/lib/ohai/log.rb +89 -0
  9. data/lib/ohai/mixin/command.rb +203 -0
  10. data/lib/ohai/mixin/from_file.rb +36 -0
  11. data/lib/ohai/mixin/string.rb +29 -0
  12. data/lib/ohai/plugins/cloud.rb +35 -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/network.rb +52 -0
  56. data/lib/ohai/plugins/ohai_time.rb +21 -0
  57. data/lib/ohai/plugins/os.rb +43 -0
  58. data/lib/ohai/plugins/perl.rb +37 -0
  59. data/lib/ohai/plugins/platform.rb +25 -0
  60. data/lib/ohai/plugins/python.rb +37 -0
  61. data/lib/ohai/plugins/rightscale.rb +53 -0
  62. data/lib/ohai/plugins/ruby.rb +37 -0
  63. data/lib/ohai/plugins/solaris2/cpu.rb +33 -0
  64. data/lib/ohai/plugins/solaris2/hostname.rb +22 -0
  65. data/lib/ohai/plugins/solaris2/kernel.rb +21 -0
  66. data/lib/ohai/plugins/solaris2/network.rb +141 -0
  67. data/lib/ohai/plugins/solaris2/platform.rb +33 -0
  68. data/lib/ohai/plugins/solaris2/ps.rb +23 -0
  69. data/lib/ohai/plugins/solaris2/ssh_host_key.rb +26 -0
  70. data/lib/ohai/plugins/uptime.rb +42 -0
  71. data/lib/ohai/plugins/virtualization.rb +86 -0
  72. data/lib/ohai/plugins/windows/filesystem.rb +44 -0
  73. data/lib/ohai/plugins/windows/hostname.rb +25 -0
  74. data/lib/ohai/plugins/windows/kernel.rb +75 -0
  75. data/lib/ohai/plugins/windows/network.rb +114 -0
  76. data/lib/ohai/plugins/windows/platform.rb +26 -0
  77. data/lib/ohai/system.rb +226 -0
  78. data/lib/ohai.rb +27 -0
  79. data/spec/ohai/log/log_formatter_spec.rb +50 -0
  80. data/spec/ohai/log_spec.rb +63 -0
  81. data/spec/ohai/mixin/from_file_spec.rb +53 -0
  82. data/spec/ohai/plugins/cloud_spec.rb +64 -0
  83. data/spec/ohai/plugins/darwin/hostname_spec.rb +34 -0
  84. data/spec/ohai/plugins/darwin/kernel_spec.rb +46 -0
  85. data/spec/ohai/plugins/darwin/platform_spec.rb +67 -0
  86. data/spec/ohai/plugins/dmi_spec.rb +73 -0
  87. data/spec/ohai/plugins/ec2_spec.rb +77 -0
  88. data/spec/ohai/plugins/erlang_spec.rb +63 -0
  89. data/spec/ohai/plugins/freebsd/hostname_spec.rb +34 -0
  90. data/spec/ohai/plugins/freebsd/kernel_spec.rb +37 -0
  91. data/spec/ohai/plugins/freebsd/platform_spec.rb +40 -0
  92. data/spec/ohai/plugins/hostname_spec.rb +39 -0
  93. data/spec/ohai/plugins/java_spec.rb +70 -0
  94. data/spec/ohai/plugins/kernel_spec.rb +43 -0
  95. data/spec/ohai/plugins/linux/cpu_spec.rb +128 -0
  96. data/spec/ohai/plugins/linux/hostname_spec.rb +52 -0
  97. data/spec/ohai/plugins/linux/kernel_spec.rb +31 -0
  98. data/spec/ohai/plugins/linux/lsb_spec.rb +60 -0
  99. data/spec/ohai/plugins/linux/platform_spec.rb +81 -0
  100. data/spec/ohai/plugins/linux/uptime_spec.rb +61 -0
  101. data/spec/ohai/plugins/linux/virtualization_spec.rb +131 -0
  102. data/spec/ohai/plugins/ohai_time_spec.rb +46 -0
  103. data/spec/ohai/plugins/os_spec.rb +58 -0
  104. data/spec/ohai/plugins/perl_spec.rb +89 -0
  105. data/spec/ohai/plugins/platform_spec.rb +56 -0
  106. data/spec/ohai/plugins/python_spec.rb +53 -0
  107. data/spec/ohai/plugins/rightscale_spec.rb +71 -0
  108. data/spec/ohai/plugins/ruby_spec.rb +51 -0
  109. data/spec/ohai/system_spec.rb +130 -0
  110. data/spec/ohai_spec.rb +27 -0
  111. data/spec/rcov.opts +2 -0
  112. data/spec/spec.opts +2 -0
  113. data/spec/spec_helper.rb +66 -0
  114. metadata +209 -0
@@ -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,57 @@
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 'logger'
20
+ require 'time'
21
+
22
+ module Ohai
23
+ class Log
24
+ class Formatter < Logger::Formatter
25
+ @@show_time = true
26
+
27
+ def self.show_time=(show=false)
28
+ @@show_time = show
29
+ end
30
+
31
+ # Prints a log message as '[time] severity: message' if Ohai::Log::Formatter.show_time == true.
32
+ # Otherwise, doesn't print the time.
33
+ def call(severity, time, progname, msg)
34
+ if @@show_time
35
+ sprintf("[%s] %s: %s\n", time.rfc2822(), severity, msg2str(msg))
36
+ else
37
+ sprintf("%s: %s\n", severity, msg2str(msg))
38
+ end
39
+ end
40
+
41
+ # Converts some argument to a Logger.severity() call to a string. Regular strings pass through like
42
+ # normal, Exceptions get formatted as "message (class)\nbacktrace", and other random stuff gets
43
+ # put through "object.inspect"
44
+ def msg2str(msg)
45
+ case msg
46
+ when ::String
47
+ msg
48
+ when ::Exception
49
+ "#{ msg.message } (#{ msg.class })\n" <<
50
+ (msg.backtrace || []).join("\n")
51
+ else
52
+ msg.inspect
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
data/lib/ohai/log.rb ADDED
@@ -0,0 +1,89 @@
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 'ohai/log/formatter'
21
+ require 'logger'
22
+
23
+ module Ohai
24
+ class Log
25
+
26
+ @logger = nil
27
+
28
+ class << self
29
+ attr_accessor :logger #:nodoc
30
+
31
+ # Use Ohai::Logger.init when you want to set up the logger manually. Arguments to this method
32
+ # get passed directly to Logger.new, so check out the documentation for the standard Logger class
33
+ # to understand what to do here.
34
+ #
35
+ # If this method is called with no arguments, it will log to STDOUT at the :info level.
36
+ #
37
+ # It also configures the Logger instance it creates to use the custom Ohai::Log::Formatter class.
38
+ def init(*opts)
39
+ if opts.length == 0
40
+ @logger = Logger.new(STDOUT)
41
+ else
42
+ @logger = Logger.new(*opts)
43
+ end
44
+ @logger.formatter = Ohai::Log::Formatter.new()
45
+ level(Ohai::Config.log_level)
46
+ end
47
+
48
+ # Sets the level for the Logger object by symbol. Valid arguments are:
49
+ #
50
+ # :debug
51
+ # :info
52
+ # :warn
53
+ # :error
54
+ # :fatal
55
+ #
56
+ # Throws an ArgumentError if you feed it a bogus log level.
57
+ def level(loglevel)
58
+ init() unless @logger
59
+ case loglevel
60
+ when :debug
61
+ @logger.level = Logger::DEBUG
62
+ when :info
63
+ @logger.level = Logger::INFO
64
+ when :warn
65
+ @logger.level = Logger::WARN
66
+ when :error
67
+ @logger.level = Logger::ERROR
68
+ when :fatal
69
+ @logger.level = Logger::FATAL
70
+ else
71
+ raise ArgumentError, "Log level must be one of :debug, :info, :warn, :error, or :fatal"
72
+ end
73
+ end
74
+
75
+ # Passes any other method calls on directly to the underlying Logger object created with init. If
76
+ # this method gets hit before a call to Ohai::Logger.init has been made, it will call
77
+ # Ohai::Logger.init() with no arguments.
78
+ def method_missing(method_symbol, *args)
79
+ init() unless @logger
80
+ if args.length > 0
81
+ @logger.send(method_symbol, *args)
82
+ else
83
+ @logger.send(method_symbol)
84
+ end
85
+ end
86
+
87
+ end # class << self
88
+ end
89
+ end
@@ -0,0 +1,203 @@
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] ||= nil
113
+
114
+ pw, pr, pe, ps = IO.pipe, IO.pipe, IO.pipe, IO.pipe
115
+
116
+ verbose = $VERBOSE
117
+ begin
118
+ $VERBOSE = nil
119
+ ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
120
+
121
+ cid = fork {
122
+ pw.last.close
123
+ STDIN.reopen pw.first
124
+ pw.first.close
125
+
126
+ pr.first.close
127
+ STDOUT.reopen pr.last
128
+ pr.last.close
129
+
130
+ pe.first.close
131
+ STDERR.reopen pe.last
132
+ pe.last.close
133
+
134
+ STDOUT.sync = STDERR.sync = true
135
+
136
+ if args[:user]
137
+ Process.euid = args[:user]
138
+ Process.uid = args[:user]
139
+ end
140
+
141
+ if args[:group]
142
+ Process.egid = args[:group]
143
+ Process.gid = args[:group]
144
+ end
145
+
146
+ if args[:environment]
147
+ args[:environment].each do |key,value|
148
+ ENV[key] = value
149
+ end
150
+ end
151
+
152
+ begin
153
+ if cmd.kind_of?(Array)
154
+ exec(*cmd)
155
+ else
156
+ exec(cmd)
157
+ end
158
+ raise 'forty-two'
159
+ rescue Exception => e
160
+ Marshal.dump(e, ps.last)
161
+ ps.last.flush
162
+ end
163
+ ps.last.close unless (ps.last.closed?)
164
+ exit!
165
+ }
166
+ ensure
167
+ $VERBOSE = verbose
168
+ end
169
+
170
+ [pw.first, pr.last, pe.last, ps.last].each{|fd| fd.close}
171
+
172
+ begin
173
+ e = Marshal.load ps.first
174
+ # If we get here, exec failed. Collect status of child to prevent
175
+ # zombies.
176
+ Process.waitpid(cid)
177
+ raise(Exception === e ? e : "unknown failure!")
178
+ rescue EOFError # If we get an EOF error, then the exec was successful
179
+ 42
180
+ ensure
181
+ ps.first.close
182
+ end
183
+
184
+ pw.last.sync = true
185
+
186
+ pi = [pw.last, pr.first, pe.first]
187
+
188
+ if b
189
+ begin
190
+ b[cid, *pi]
191
+ Process.waitpid2(cid).last
192
+ ensure
193
+ pi.each{|fd| fd.close unless fd.closed?}
194
+ end
195
+ else
196
+ [cid, pw.last, pr.first, pe.first]
197
+ end
198
+ end
199
+
200
+ module_function :popen4
201
+ end
202
+ end
203
+ 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,35 @@
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
+
21
+ def on_ec2?
22
+ ec2 != nil
23
+ end
24
+
25
+ def get_ec2_values
26
+ cloud[:instance_id] = ec2['instance_id']
27
+ cloud[:public_ip] = ec2['public_ipv4']
28
+ cloud[:private_ip] = ec2['local_ipv4']
29
+ cloud[:provider] = "ec2"
30
+ end
31
+
32
+ if on_ec2?
33
+ cloud Mash.new
34
+ get_ec2_values
35
+ end