amazon-ec2 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
- require "test_helper"
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestEC2 < Test::Unit::TestCase
4
+
4
5
  def setup
5
6
  @conn = EC2::AWSAuthConnection.new('not a key', 'not a secret')
6
7
  end
@@ -16,4 +17,5 @@ class TestEC2 < Test::Unit::TestCase
16
17
  returns stub(:body => body, :is_a? => true)
17
18
  assert_equal true, @conn.reboot_instances('i-2ea64347', 'i-21a64348').parse
18
19
  end
20
+
19
21
  end
@@ -1,10 +1,12 @@
1
- $:.unshift File.expand_path('../lib')
2
- require "test/unit"
1
+ require 'test/unit'
2
+
3
3
  begin
4
4
  require 'rubygems'
5
5
  require 'mocha'
6
6
  require 'stubba'
7
7
  rescue LoadError
8
- abort "You need mocha installed to run tests"
8
+ abort "You need rubygems and mocha gems installed to run tests"
9
9
  end
10
- require "EC2"
10
+
11
+ require File.dirname(__FILE__) + '/../lib/EC2'
12
+
@@ -1,6 +1,7 @@
1
1
  require "test_helper"
2
2
 
3
3
  class TestResetResponse < Test::Unit::TestCase
4
+
4
5
  def setup
5
6
  body = <<-RESPONSE
6
7
  <RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-03/">
@@ -0,0 +1,260 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ Amazon Web Services EC2 Ruby Gem
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>Amazon Web Services EC2 Ruby Gem</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/amazon-ec2"; return false'>
35
+ Get Version
36
+ <a href="http://rubyforge.org/projects/amazon-ec2" class="numbers">0.0.8</a>
37
+ </div>
38
+ <h1>&#x2192; &#8216;amazon-ec2&#8217;</h1>
39
+
40
+
41
+ <h2>About</h2>
42
+
43
+
44
+ <p>Amazon Web Services offers a compute power on demand capability known as the Elastic Compute Cloud (EC2). Using the current <span class="caps">API</span>’s the compute resources in the cloud can be provisioned on demand by making <span class="caps">SOAP</span> or <span class="caps">HTTP</span> Query <span class="caps">API</span> calls to <span class="caps">EC2</span>.</p>
45
+
46
+
47
+ <p>This ‘Amazon-EC2’ Ruby Gem is an interface library that can be used to interact with the Amazon <span class="caps">EC2</span> system using the Query <span class="caps">API</span>.</p>
48
+
49
+
50
+ <h2>Important Note</h2>
51
+
52
+
53
+ <p>In December of 2006 Amazon Web Services released a sample Ruby code library for interacting with <span class="caps">EC2</span>. I have packaged this sample code as this Ruby Gem as a service to the Ruby community and do not plan to be actively maintaining this code on a full-time basis.</p>
54
+
55
+
56
+ <p>All I ask in return is if you have some Ruby skills and can contribute documentation, automated unit tests, bug fixes, or enhancements as Subversion patch files that you please do so. I will be happy to incorporate those changes directly into the library as appropriate.</p>
57
+
58
+
59
+ <p>Alternatively, if you are interested in becoming a more seriously involved contributing developer with full check-in privileges on the source code please feel free to contact me and we can discuss the best way to do so.</p>
60
+
61
+
62
+ <h2>Project Info</h2>
63
+
64
+
65
+ <p>This project is managed as a RubyForge project which you can find at <a href="http://amazon-ec2.rubyforge.org/">http://amazon-ec2.rubyforge.org/</a> and this is always the best place to find the latest news, report any bugs, submit feature requests, or provide patches.</p>
66
+
67
+
68
+ <h2>Installing</h2>
69
+
70
+
71
+ <p>This gem follows the standard conventions for installation on any system with Ruby and RubyGems installed. If you have worked with gems before this will look very familiar.</p>
72
+
73
+
74
+ <h3>Installation pre-requisites</h3>
75
+
76
+
77
+ <p>Before you can make use of this gem you will need an <a href="https://aws-portal.amazon.com/gp/aws/developer/registration/index.html">Amazon Web Services developer account</a>. This account must also be specifically enabled for Amazon <span class="caps">EC2</span> usage. <span class="caps">AWS</span> will provide you with an ‘AWS Access Key ID’ and a ‘Secret Access Key’ which will allow you to authenticate any <span class="caps">API</span> calls you make and ensure correct billing to you for usage of the service. Take note of these (and keep them secret!).</p>
78
+
79
+
80
+ <h3>Installing the gem</h3>
81
+
82
+
83
+ <p>Linux / <span class="caps">OS X</span> : <pre syntax="ruby">sudo gem install amazon-ec2</pre></p>
84
+
85
+
86
+ <p>Microsoft Windows : <pre syntax="ruby">gem install amazon-ec2</pre></p>
87
+
88
+
89
+ <h2>Sample Usage</h2>
90
+
91
+
92
+ <p>The library exposes one main interface class <pre syntax="ruby">AWSAuthConnection</pre></p>
93
+
94
+
95
+ <p>It is through an instance of this class that you will perform all the operations for using using the <span class="caps">EC2</span> service including query string header signing.</p>
96
+
97
+
98
+ <p>The public methods on &#8216;AWSAuthConnection&#8217; closely mirror the <span class="caps">EC2</span> Query <span class="caps">API</span>, and as such the Query <span class="caps">API</span> Reference in the <a href="http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=84"><span class="caps">EC2</span> Developer Guide</a> should be consulted.</p>
99
+
100
+
101
+ <h3>Standalone Ruby Script Usage Sample</h3>
102
+
103
+
104
+ <pre syntax="ruby">
105
+ #!/usr/bin/env ruby
106
+
107
+ require 'rubygems'
108
+ require 'ec2'
109
+
110
+ AWS_ACCESS_KEY_ID = '--YOUR AWS ACCESS KEY ID--'
111
+ AWS_SECRET_ACCESS_KEY = '--YOUR AWS SECRET ACCESS KEY--'
112
+
113
+ conn = EC2::AWSAuthConnection.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
114
+
115
+ puts "----- listing images -----"
116
+ puts conn.describe_images()
117
+ </pre>
118
+
119
+ <p>An example Ruby script which exercises the library is provided for use as a starting point in the gem installation. Consult the file which is installed at :</p>
120
+
121
+
122
+ <pre syntax="ruby">[your amazon-ec2 gem dir]/examples/ec2-example.rb</pre>
123
+
124
+ <h3>Ruby on Rails Usage Sample</h3>
125
+
126
+
127
+ <p>in config/environment.rb:</p>
128
+
129
+
130
+ <pre syntax="ruby">
131
+ # Include Amazon Web Services EC2 library gem
132
+ require_gem 'amazon-ec2'
133
+ </pre>
134
+
135
+ in app/controllers/your_controller.rb:
136
+ <pre syntax="ruby">
137
+ ...
138
+ conn = EC2::AWSAuthConnection.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
139
+
140
+ # The .parse method gives you back an array of
141
+ # values from the API response that you can
142
+ # use in your view
143
+ @ec2_images = conn.describe_images().parse
144
+
145
+ # Or with some parameters
146
+ # (in this case specific owner ID's)
147
+ @ec2_images_mine = ec2.describe_images([],["522821470517"],[]).parse
148
+ ...
149
+ </pre>
150
+
151
+ <p>in app/views/your_view.rhtml:</p>
152
+
153
+
154
+ <p>Test it out with something like this&#8230;</p>
155
+
156
+
157
+ <pre syntax="ruby">
158
+ ...
159
+ &lt;%= debug(@ec2_images) %&gt;
160
+ &lt;%= debug(@ec2_images_mine) %&gt;
161
+ ...
162
+ </pre>
163
+
164
+ <p>Or this&#8230;</p>
165
+
166
+
167
+ <pre syntax="ruby">
168
+ ...
169
+ &lt;% @ec2_images.each do |image| %&gt;
170
+ &lt;% image.each_with_index do |value, index| %&gt;
171
+ &lt;%= "#{index} =&gt; #{value}" %&gt;&lt;br /&gt;
172
+ &lt;% end %&gt;
173
+ &lt;% end %&gt;
174
+ ...
175
+ </pre>
176
+
177
+ <p>Or even this&#8230;</p>
178
+
179
+
180
+ <pre syntax="ruby">
181
+ ...
182
+ &lt;table&gt;
183
+ &lt;tr&gt;
184
+ &lt;th&gt;Id&lt;/th&gt;
185
+ &lt;th&gt;Location&lt;/th&gt;
186
+ &lt;th&gt;Owner&lt;/th&gt;
187
+ &lt;th&gt;State&lt;/th&gt;
188
+ &lt;th&gt;Public?&lt;/th&gt;
189
+ &lt;/tr&gt;
190
+
191
+ &lt;% for ec2_image in @ec2_images %&gt;
192
+ &lt;tr&gt;
193
+ &lt;td&gt;&lt;%=h ec2_image[1] %&gt;&lt;/td&gt;
194
+ &lt;td&gt;&lt;%=h ec2_image[2] %&gt;&lt;/td&gt;
195
+ &lt;td&gt;&lt;%=h ec2_image[3] %&gt;&lt;/td&gt;
196
+ &lt;td&gt;&lt;%=h ec2_image[4] %&gt;&lt;/td&gt;
197
+ &lt;td&gt;&lt;%=h ec2_image[5] %&gt;&lt;/td&gt;
198
+ &lt;/tr&gt;
199
+ &lt;% end %&gt;
200
+ &lt;/table&gt;
201
+ ...
202
+ </pre>
203
+
204
+ <h2>Resources</h2>
205
+
206
+
207
+ <h3>Project Related</h3>
208
+
209
+
210
+ <p><a href="http://aws.amazon.com/">http://aws.amazon.com/</a>
211
+ <a href="http://amazon-ec2.rubyforge.org/">http://amazon-ec2.rubyforge.org/</a></p>
212
+
213
+
214
+ <h3>Project Tools</h3>
215
+
216
+
217
+ <p><a href="http://rubyforge.org/projects/amazon-ec2/">Project Home</a>
218
+ <a href="http://rubyforge.org/frs/?group_id=2753">Downloads</a>
219
+ <a href="http://rubyforge.org/scm/?group_id=2753">Browse Code</a>
220
+ <a href="http://rubyforge.org/tracker/?group_id=2753">Report Bugs</a>
221
+ <a href="http://rubyforge.org/tracker/?group_id=2753">Request Features</a>
222
+ <a href="http://rubyforge.org/tracker/?group_id=2753">Submit Patches</a></p>
223
+
224
+
225
+ <h3>Related Projects</h3>
226
+
227
+
228
+ <p><a href="http://capazon.rubyforge.org/">Capazon</a></p>
229
+
230
+
231
+ <h2>Credits</h2>
232
+
233
+
234
+ <p>The original sample code for this library was provided by Amazon Web Services, <span class="caps">LLC</span>. Thanks to them for providing all of us with samples that got this started.</p>
235
+
236
+
237
+ <p>Thanks to Dr. Nic Williams and his great &#8216;NewGem&#8217; Ruby Gem Generator. This gem of a Gem helped me package up this code for distribution in a flash! You can find Dr. Nic&#8217;s NewGem generator at <a href="http://newgem.rubyforge.org/">http://newgem.rubyforge.org/</a></p>
238
+
239
+
240
+ <h2>Contact</h2>
241
+
242
+
243
+ <p>Comments, patches, and bug reports are welcome. Send an email to the address below or use the RubyForge forum for this project.</p>
244
+ <p class="coda">
245
+ <a href="mailto:grempe-at-rubyforge-dot-org">Glenn Rempe</a>, 30th May 2007<br>
246
+ </p>
247
+ </div>
248
+
249
+ <!-- insert site tracking codes here, like Google Urchin -->
250
+
251
+ <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
252
+
253
+ </script>
254
+ <script type="text/javascript">
255
+ _uacct = "UA-312156-11";
256
+ urchinTracker();
257
+ </script>
258
+
259
+ </body>
260
+ </html>
@@ -0,0 +1,173 @@
1
+ h1. Amazon Web Services EC2 Ruby Gem
2
+
3
+ h1. &#x2192; 'amazon-ec2'
4
+
5
+ h2. About
6
+
7
+ Amazon Web Services offers a compute power on demand capability known as the Elastic Compute Cloud (EC2). Using the current API’s the compute resources in the cloud can be provisioned on demand by making SOAP or HTTP Query API calls to EC2.
8
+
9
+ This ‘Amazon-EC2’ Ruby Gem is an interface library that can be used to interact with the Amazon EC2 system using the Query API.
10
+
11
+ h2. Important Note
12
+
13
+ In December of 2006 Amazon Web Services released a sample Ruby code library for interacting with EC2. I have packaged this sample code as this Ruby Gem as a service to the Ruby community and do not plan to be actively maintaining this code on a full-time basis.
14
+
15
+ All I ask in return is if you have some Ruby skills and can contribute documentation, automated unit tests, bug fixes, or enhancements as Subversion patch files that you please do so. I will be happy to incorporate those changes directly into the library as appropriate.
16
+
17
+ Alternatively, if you are interested in becoming a more seriously involved contributing developer with full check-in privileges on the source code please feel free to contact me and we can discuss the best way to do so.
18
+
19
+ h2. Project Info
20
+
21
+ This project is managed as a RubyForge project which you can find at "http://amazon-ec2.rubyforge.org/":http://amazon-ec2.rubyforge.org/ and this is always the best place to find the latest news, report any bugs, submit feature requests, or provide patches.
22
+
23
+ h2. Installing
24
+
25
+ This gem follows the standard conventions for installation on any system with Ruby and RubyGems installed. If you have worked with gems before this will look very familiar.
26
+
27
+ h3. Installation pre-requisites
28
+
29
+ Before you can make use of this gem you will need an "Amazon Web Services developer account":https://aws-portal.amazon.com/gp/aws/developer/registration/index.html. This account must also be specifically enabled for Amazon EC2 usage. AWS will provide you with an ‘AWS Access Key ID’ and a ‘Secret Access Key’ which will allow you to authenticate any API calls you make and ensure correct billing to you for usage of the service. Take note of these (and keep them secret!).
30
+
31
+ h3. Installing the gem
32
+
33
+ Linux / OS X : <pre syntax="ruby">sudo gem install amazon-ec2</pre>
34
+
35
+ Microsoft Windows : <pre syntax="ruby">gem install amazon-ec2</pre>
36
+
37
+
38
+ h2. Sample Usage
39
+
40
+ The library exposes one main interface class <pre syntax="ruby">AWSAuthConnection</pre>
41
+
42
+ It is through an instance of this class that you will perform all the operations for using using the EC2 service including query string header signing.
43
+
44
+ The public methods on 'AWSAuthConnection' closely mirror the EC2 Query API, and as such the Query API Reference in the "EC2 Developer Guide":http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=84 should be consulted.
45
+
46
+ h3. Standalone Ruby Script Usage Sample
47
+
48
+ <pre syntax="ruby">
49
+ #!/usr/bin/env ruby
50
+
51
+ require 'rubygems'
52
+ require 'ec2'
53
+
54
+ AWS_ACCESS_KEY_ID = '--YOUR AWS ACCESS KEY ID--'
55
+ AWS_SECRET_ACCESS_KEY = '--YOUR AWS SECRET ACCESS KEY--'
56
+
57
+ conn = EC2::AWSAuthConnection.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
58
+
59
+ puts "----- listing images -----"
60
+ puts conn.describe_images()
61
+ </pre>
62
+
63
+ An example Ruby script which exercises the library is provided for use as a starting point in the gem installation. Consult the file which is installed at :
64
+
65
+ <pre syntax="ruby">[your amazon-ec2 gem dir]/examples/ec2-example.rb</pre>
66
+
67
+ h3. Ruby on Rails Usage Sample
68
+
69
+ in config/environment.rb:
70
+
71
+ <pre syntax="ruby">
72
+ # Include Amazon Web Services EC2 library gem
73
+ require_gem 'amazon-ec2'
74
+ </pre>
75
+
76
+ in app/controllers/your_controller.rb:
77
+ <pre syntax="ruby">
78
+ ...
79
+ conn = EC2::AWSAuthConnection.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
80
+
81
+ # The .parse method gives you back an array of
82
+ # values from the API response that you can
83
+ # use in your view
84
+ @ec2_images = conn.describe_images().parse
85
+
86
+ # Or with some parameters
87
+ # (in this case specific owner ID's)
88
+ @ec2_images_mine = ec2.describe_images([],["522821470517"],[]).parse
89
+ ...
90
+ </pre>
91
+
92
+ in app/views/your_view.rhtml:
93
+
94
+ Test it out with something like this...
95
+
96
+ <pre syntax="ruby">
97
+ ...
98
+ <%= debug(@ec2_images) %>
99
+ <%= debug(@ec2_images_mine) %>
100
+ ...
101
+ </pre>
102
+
103
+ Or this...
104
+
105
+ <pre syntax="ruby">
106
+ ...
107
+ <% @ec2_images.each do |image| %>
108
+ <% image.each_with_index do |value, index| %>
109
+ <%= "#{index} => #{value}" %><br />
110
+ <% end %>
111
+ <% end %>
112
+ ...
113
+ </pre>
114
+
115
+ Or even this...
116
+
117
+ <pre syntax="ruby">
118
+ ...
119
+ <table>
120
+ <tr>
121
+ <th>Id</th>
122
+ <th>Location</th>
123
+ <th>Owner</th>
124
+ <th>State</th>
125
+ <th>Public?</th>
126
+ </tr>
127
+
128
+ <% for ec2_image in @ec2_images %>
129
+ <tr>
130
+ <td><%=h ec2_image[1] %></td>
131
+ <td><%=h ec2_image[2] %></td>
132
+ <td><%=h ec2_image[3] %></td>
133
+ <td><%=h ec2_image[4] %></td>
134
+ <td><%=h ec2_image[5] %></td>
135
+ </tr>
136
+ <% end %>
137
+ </table>
138
+ ...
139
+ </pre>
140
+
141
+
142
+ h2. Resources
143
+
144
+ h3. Project Related
145
+
146
+ "http://aws.amazon.com/":http://aws.amazon.com/
147
+ "http://amazon-ec2.rubyforge.org/":http://amazon-ec2.rubyforge.org/
148
+
149
+ h3. Project Tools
150
+
151
+ "Project Home":http://rubyforge.org/projects/amazon-ec2/
152
+ "Downloads":http://rubyforge.org/frs/?group_id=2753
153
+ "Browse Code":http://rubyforge.org/scm/?group_id=2753
154
+ "Report Bugs":http://rubyforge.org/tracker/?group_id=2753
155
+ "Request Features":http://rubyforge.org/tracker/?group_id=2753
156
+ "Submit Patches":http://rubyforge.org/tracker/?group_id=2753
157
+
158
+
159
+ h3. Related Projects
160
+
161
+ "Capazon":http://capazon.rubyforge.org/
162
+
163
+
164
+ h2. Credits
165
+
166
+ The original sample code for this library was provided by Amazon Web Services, LLC. Thanks to them for providing all of us with samples that got this started.
167
+
168
+ Thanks to Dr. Nic Williams and his great 'NewGem' Ruby Gem Generator. This gem of a Gem helped me package up this code for distribution in a flash! You can find Dr. Nic's NewGem generator at "http://newgem.rubyforge.org/":http://newgem.rubyforge.org/
169
+
170
+
171
+ h2. Contact
172
+
173
+ Comments, patches, and bug reports are welcome. Send an email to the address below or use the RubyForge forum for this project.