amazon-ec2 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -1,5 +1,18 @@
1
1
  =CHANGELOG.txt : Amazon Elastic Compute Cloud (EC2) Ruby Gem
2
2
 
3
+
4
+ ===0.0.7 (03/15/2007)
5
+ * Applied patch from Kevin Clark which does the following:
6
+ * New method to the instances.rb to allow for issuing a reboot command to an EC2 instance.
7
+ * New Mocha based tests (Mocha test suite must be installed to run tests. 'sudo gem install mocha')
8
+ * Cleanup of the test directory.
9
+ * Applied patch from Randy Bias related to CGI escaping error. From his notes:
10
+
11
+ I finally figured out what was going on. It was a compound problem. The first being that you can't CGI::encode the UserData early. You have to just Base64 encode it. Unfortunately, when you Base64 encode it, it means that some encodings will be padded with extra chars, specifically the '=', but &, ? and = get stripped by EC2.canonial_string. So if a Base64 encoding has trailing ='s for padding, these get stripped and then you sign the UserData Base64 payload sans the padding. But it looks like Amazon's side is doing the right thing and is signing the padding. So, the signatures mis-match.
12
+
13
+ I've got the complete patch here and it's about as elegant/clean as I could make it in a short period of time. It's a little tough to strip those equal signs when there are so many in the URI. I think this works pretty well, though. I'm splitting the URI on '&', then for each field ripping out all '&' and '?' and only the first '='. Then stitching it back together.
14
+
15
+
3
16
  ===0.0.6 (03/02/2007)
4
17
  * Patched instances.rb with a bugfix and patch provided by Randy Bias (Thanks Randy!).
5
18
  Only minimally tested so please let me know if this causes any problems for anyone.
data/Manifest.txt CHANGED
@@ -13,7 +13,8 @@ lib/EC2/keypairs.rb
13
13
  lib/EC2/image_attributes.rb
14
14
  lib/EC2/security_groups.rb
15
15
 
16
+ test/test_ec2.rb
16
17
  test/test_helper.rb
17
- test/EC2_test.rb
18
+ test/test_responses.rb
18
19
 
19
20
  examples/ec2-example.rb
data/lib/EC2.rb CHANGED
@@ -39,7 +39,7 @@ module EC2
39
39
  PORTS_BY_SECURITY = { true => 443, false => 80 }
40
40
 
41
41
  # This is the version of the API as defined by Amazon Web Services
42
- API_VERSION = '2006-10-01'
42
+ API_VERSION = '2007-01-03'
43
43
 
44
44
  # This release version is passed in with each request as part
45
45
  # of the HTTP 'User-Agent' header. Set this be the same value
@@ -53,7 +53,11 @@ module EC2
53
53
  # Note: The parameters in the path passed in must already be sorted in
54
54
  # case-insensitive alphabetical order and must not be url encoded.
55
55
  def EC2.canonical_string(path)
56
- buf = path.gsub(/\&|\?|=/,"")
56
+ buf = ""
57
+ path.split('&').each { |field|
58
+ buf << field.gsub(/\&|\?/,"").sub(/=/,"")
59
+ }
60
+ return buf
57
61
  end
58
62
 
59
63
  # Encodes the given string with the aws_secret_access_key, by taking the
data/lib/EC2/instances.rb CHANGED
@@ -59,7 +59,7 @@ module EC2
59
59
  if in_params[:base64Encoded]
60
60
  userData = in_params[:userData]
61
61
  else
62
- userData = CGI::escape(Base64.encode64(in_params[:userData]).gsub(/\n/,"").strip())
62
+ userData = Base64.encode64(in_params[:userData]).gsub(/\n/,"").strip()
63
63
  end
64
64
  else
65
65
  userData = nil
@@ -107,6 +107,15 @@ module EC2
107
107
  TerminateInstancesResponse.new(make_request("TerminateInstances", params))
108
108
  end
109
109
 
110
+ # The RebootInstances operation requests a reboot of one or more instances.
111
+ # This operation is asynchronous; it only queues a request to reboot the specified
112
+ # instance(s). The operation will succeed provided the instances are valid and
113
+ # belong to the user. Terminated instances will be ignored.
114
+ def reboot_instances(*instance_ids)
115
+ raise "No instance ids given" if instance_ids.empty?
116
+ params = pathlist("InstanceId", instance_ids)
117
+ ResetInstancesResponse.new(make_request("RebootInstances", params))
118
+ end
110
119
  end
111
120
 
112
121
  end
data/lib/EC2/responses.rb CHANGED
@@ -223,6 +223,14 @@ module EC2
223
223
  end
224
224
  end
225
225
 
226
+ class ResetInstancesResponse < Response
227
+ def parse
228
+ doc = REXML::Document.new(@http_xml)
229
+ # Let's use the tag they're actually returning since it doesn't match the docs -- Kevin Clark 2/26/07
230
+ REXML::XPath.match( doc, "//return").first.text == "true" ? true : false
231
+ end
232
+ end
233
+
226
234
 
227
235
  class CreateSecurityGroupResponse < Response
228
236
  def parse
data/lib/EC2/version.rb CHANGED
@@ -2,7 +2,7 @@ module EC2 #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 6
5
+ TINY = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/test_ec2.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "test_helper"
2
+
3
+ class TestEC2 < Test::Unit::TestCase
4
+ def setup
5
+ @conn = EC2::AWSAuthConnection.new('not a key', 'not a secret')
6
+ end
7
+
8
+ def test_reboot_instances
9
+ body = <<-RESPONSE
10
+ <RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-03/">
11
+ <return>true</return>
12
+ </RebootInstancesResponse>
13
+ RESPONSE
14
+
15
+ @conn.expects(:make_request).with('RebootInstances', {"InstanceId.1"=>"i-2ea64347", "InstanceId.2"=>"i-21a64348"}).
16
+ returns stub(:body => body, :is_a? => true)
17
+ assert_equal true, @conn.reboot_instances('i-2ea64347', 'i-21a64348').parse
18
+ end
19
+ end
data/test/test_helper.rb CHANGED
@@ -1,15 +1,10 @@
1
- require 'test/unit'
2
-
3
- # include the test cases that are part of this suite.
4
- # these are broken out into the same functional groups
5
- # as the module components in the lib/EC2 dir.
6
- require 'tc_ec2_base'
7
- require 'tc_images'
8
- require 'tc_image_attributes'
9
- require 'tc_keypairs'
10
- require 'tc_instances'
11
- require 'tc_responses'
12
- require 'tc_security_groups'
13
- require 'tc_version'
14
-
15
- require File.dirname(__FILE__) + '/../lib/EC2'
1
+ $:.unshift File.expand_path('../lib')
2
+ require "test/unit"
3
+ begin
4
+ require 'rubygems'
5
+ require 'mocha'
6
+ require 'stubba'
7
+ rescue LoadError
8
+ abort "You need mocha installed to run tests"
9
+ end
10
+ require "EC2"
@@ -0,0 +1,16 @@
1
+ require "test_helper"
2
+
3
+ class TestResetResponse < Test::Unit::TestCase
4
+ def setup
5
+ body = <<-RESPONSE
6
+ <RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-03/">
7
+ <return>true</return>
8
+ </RebootInstancesResponse>
9
+ RESPONSE
10
+ @response = EC2::ResetInstancesResponse.new(stub(:body => body, :is_a? => true))
11
+ end
12
+
13
+ def test_parse
14
+ assert_equal true, @response.parse
15
+ end
16
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: amazon-ec2
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.6
7
- date: 2007-03-02 00:00:00 -08:00
6
+ version: 0.0.7
7
+ date: 2007-03-15 00:00:00 -07:00
8
8
  summary: An interface library that allows Ruby or Ruby on Rails applications to easily connect to the HTTP 'Query API' for the Amazon Web Services Elastic Compute Cloud (EC2) and manipulate server instances.
9
9
  require_paths:
10
10
  - lib
@@ -44,11 +44,12 @@ files:
44
44
  - lib/EC2/keypairs.rb
45
45
  - lib/EC2/image_attributes.rb
46
46
  - lib/EC2/security_groups.rb
47
+ - test/test_ec2.rb
47
48
  - test/test_helper.rb
48
- - test/EC2_test.rb
49
+ - test/test_responses.rb
49
50
  - examples/ec2-example.rb
50
- test_files:
51
- - test/EC2_test.rb
51
+ test_files: []
52
+
52
53
  rdoc_options:
53
54
  - --quiet
54
55
  - --title
@@ -77,5 +78,5 @@ dependencies:
77
78
  requirements:
78
79
  - - ">="
79
80
  - !ruby/object:Gem::Version
80
- version: 1.1.7
81
+ version: 1.2.0
81
82
  version:
data/test/EC2_test.rb DELETED
@@ -1,13 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- # This is the top of the test suite. This file is what is
4
- # automatically run when 'rake test' is run. Individual test
5
- # cases are found in the tc_* files. Do any setup for
6
- # all of the test cases in the setup method of this file.
7
-
8
- class EC2Test < Test::Unit::TestCase
9
-
10
- def setup
11
- end
12
-
13
- end