amazon-ec2 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ === 0.2.3 2007-07-06
2
+ * Updated gem to work with new official release of AWS API version 2007-03-01 which occurred
3
+ on July 6, 2007.
4
+ * Added support for primary new feature which supports Paid AMI's and the product codes
5
+ associated with them. Modified several methods to support this change, updated the test
6
+ cases, and added a new method EC2#confirm_product_instance.
7
+
1
8
  === 0.2.2 2007-07-03
2
9
  * Minor change to test case.
3
10
 
data/Manifest.txt CHANGED
@@ -10,6 +10,7 @@ lib/EC2/responses.rb
10
10
  lib/EC2/images.rb
11
11
  lib/EC2/instances.rb
12
12
  lib/EC2/keypairs.rb
13
+ lib/EC2/products.rb
13
14
  lib/EC2/image_attributes.rb
14
15
  lib/EC2/security_groups.rb
15
16
  License.txt
@@ -24,6 +25,7 @@ test/test_EC2_image_attributes.rb
24
25
  test/test_EC2_images.rb
25
26
  test/test_EC2_instances.rb
26
27
  test/test_EC2_keypairs.rb
28
+ test/test_EC2_products.rb
27
29
  test/test_EC2_responses.rb
28
30
  test/test_EC2_security_groups.rb
29
31
  test/test_EC2_version.rb
data/lib/EC2.rb CHANGED
@@ -22,7 +22,7 @@ module EC2
22
22
  DEFAULT_HOST = 'ec2.amazonaws.com'
23
23
 
24
24
  # This is the version of the API as defined by Amazon Web Services
25
- API_VERSION = '2007-01-19'
25
+ API_VERSION = '2007-03-01'
26
26
 
27
27
  # This release version is passed in with each request as part
28
28
  # of the HTTP 'User-Agent' header. Set this be the same value
@@ -14,35 +14,45 @@ module EC2
14
14
 
15
15
  #Amazon Developer Guide Docs:
16
16
  #
17
- # The ModifyImageAttribute operation modifies an attribute of an AMI.
18
- # Currently the only attribute supported is launchPermission. By modifying this attribute it is possible to
19
- # make an AMI public or to grant specific users launch permissions for the AMI. To make the AMI public
20
- # add the group=all attribute item. To grant launch permissions for a specific user add a
21
- # userId=<userid> attribute item.
17
+ # The ModifyImageAttribute operation modifies an attribute of an AMI. The following attributes may
18
+ # currently be modified:
19
+ #
20
+ # 'launchPermission' : Controls who has permission to launch the AMI. Launch permissions can be
21
+ # granted to specific users by adding userIds. The AMI can be made public by adding the 'all' group.
22
+ #
23
+ # 'productCodes' : Associates product codes with AMIs. This allows a developer to charge a user extra
24
+ # for using the AMIs. productCodes is a write once attribute - once it has been set it can not be
25
+ # changed or removed. Currently only one product code is supported per AMI.
22
26
  #
23
27
  #Required Arguments:
24
28
  #
25
29
  # :image_id => String (default : "")
26
- # :attribute => String (default : "launchPermission")
27
- # :operation_type => String (default : "add")
30
+ # :attribute => String ('launchPermission' or 'productCodes', default : "launchPermission")
31
+ # :operation_type => String (default : "")
28
32
  #
29
33
  #Optional Arguments:
30
34
  #
31
35
  # :user_id => Array (default : [])
32
36
  # :group => Array (default : [])
37
+ # :product_code => Array (default : [])
33
38
  #
34
39
  def modify_image_attribute( options = {} )
35
40
 
36
41
  # defaults
37
42
  options = { :image_id => "",
38
43
  :attribute => "launchPermission",
39
- :operation_type => "add",
44
+ :operation_type => "",
40
45
  :user_id => [],
41
- :group => [] }.merge(options)
46
+ :group => [],
47
+ :product_code => [] }.merge(options)
42
48
 
43
49
  raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
44
50
  raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
45
- raise ArgumentError, "No ':operation_type' provided" if options[:operation_type].nil? || options[:operation_type].empty?
51
+
52
+ # OperationType is not required if modifying a product code.
53
+ unless options[:attribute] == 'productCodes'
54
+ raise ArgumentError, "No ':operation_type' provided" if options[:operation_type].nil? || options[:operation_type].empty?
55
+ end
46
56
 
47
57
  params = {
48
58
  "ImageId" => options[:image_id],
@@ -53,22 +63,23 @@ module EC2
53
63
  # test options provided and make sure they are valid
54
64
  case options[:attribute]
55
65
  when "launchPermission"
66
+
67
+ unless options[:operation_type] == "add" || options[:operation_type] == "remove"
68
+ raise ArgumentError, ":operation_type was #{options[:operation_type].to_s} but must be either 'add' or 'remove'"
69
+ end
70
+
56
71
  if (options[:user_id].nil? || options[:user_id].empty?) && (options[:group].nil? || options[:group].empty?)
57
72
  raise ArgumentError, "Option :attribute=>'launchPermission' requires ':user_id' or ':group' options to also be specified"
58
73
  end
59
-
60
74
  params.merge!(pathlist("UserId", options[:user_id])) unless options[:user_id].nil?
61
75
  params.merge!(pathlist("Group", options[:group])) unless options[:group].nil?
76
+ when "productCodes"
77
+ if (options[:product_code].nil? || options[:product_code].empty?)
78
+ raise ArgumentError, "Option :attribute=>'productCodes' requires ':product_code' to be specified"
79
+ end
80
+ params.merge!(pathlist("ProductCode", options[:product_code])) unless options[:product_code].nil?
62
81
  else
63
- raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known option."
64
- end
65
-
66
- # test options provided and make sure they are valid
67
- case options[:operation_type]
68
- when "add", "remove"
69
- # these args are ok
70
- else
71
- raise ArgumentError, ":operation_type was #{options[:operation_type].to_s} but must be 'add' or 'remove'"
82
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
72
83
  end
73
84
 
74
85
  return response_generator(:action => "ModifyImageAttribute", :params => params)
@@ -82,7 +93,7 @@ module EC2
82
93
  #Required Arguments:
83
94
  #
84
95
  # :image_id => String (default : "")
85
- # :attribute => String (default : "launchPermission")
96
+ # :attribute => String ("launchPermission" or "productCodes", default : "launchPermission")
86
97
  #
87
98
  #Optional Arguments:
88
99
  #
@@ -102,10 +113,10 @@ module EC2
102
113
 
103
114
  # test options provided and make sure they are valid
104
115
  case options[:attribute]
105
- when "launchPermission"
116
+ when "launchPermission", "productCodes"
106
117
  # these args are ok
107
118
  else
108
- raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known option."
119
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
109
120
  end
110
121
 
111
122
  return response_generator(:action => "DescribeImageAttribute", :params => params)
@@ -143,7 +154,7 @@ module EC2
143
154
  when "launchPermission"
144
155
  # these args are ok
145
156
  else
146
- raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known option."
157
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
147
158
  end
148
159
 
149
160
  return response_generator(:action => "ResetImageAttribute", :params => params)
data/lib/EC2/instances.rb CHANGED
@@ -39,6 +39,8 @@ module EC2
39
39
  # OpenSSH format). This can be done at boot time (as part of rclocal, for example) allowing for secure
40
40
  # password-less access. As the need arises, other formats will also be considered.
41
41
  #
42
+ # If the AMI has a product code attached for which the user has not subscribed, the RunInstances call will fail.
43
+ #
42
44
  #Required Arguments:
43
45
  #
44
46
  # :image_id => String (Default : "")
@@ -0,0 +1,43 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@elasticworkbench.com)
6
+ # Copyright:: Copyright (c) 2007 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
10
+
11
+ module EC2
12
+
13
+ class Base
14
+
15
+ #Amazon Developer Guide Docs:
16
+ #
17
+ # The ConfirmProductInstance operation returns true if the given product code is attached to the instance
18
+ # with the given instance id. False is returned if the product code is not attached to the instance.
19
+ #
20
+ #Required Arguments:
21
+ #
22
+ # :product_code => String (default : "")
23
+ # :instance_id => String (default : "")
24
+ #
25
+ #Optional Arguments:
26
+ #
27
+ # none
28
+ #
29
+ def confirm_product_instance( options ={} )
30
+
31
+ options = {:product_code => "", :instance_id => ""}.merge(options)
32
+
33
+ raise ArgumentError, "No product code provided" if options[:product_code].nil? || options[:product_code].empty?
34
+ raise ArgumentError, "No instance ID provided" if options[:instance_id].nil? || options[:instance_id].empty?
35
+
36
+ params = { "ProductCode" => options[:product_code], "InstanceId" => options[:instance_id] }
37
+
38
+ return response_generator(:action => "ConfirmProductInstance", :params => params)
39
+
40
+ end
41
+ end
42
+
43
+ end
data/lib/EC2/responses.rb CHANGED
@@ -32,7 +32,13 @@ module EC2
32
32
  # mechanism for the whole library while making it more accurate and much less brittle to boot!
33
33
  #
34
34
 
35
- require 'xmlsimple'
35
+ require 'rubygems'
36
+ begin
37
+ require 'xmlsimple'
38
+ rescue Exception => e
39
+ require 'xml-simple'
40
+ end
41
+
36
42
 
37
43
  class Response < OpenStruct
38
44
 
data/lib/EC2/version.rb CHANGED
@@ -12,7 +12,7 @@ module EC2 #:nodoc:
12
12
  module VERSION #:nodoc:
13
13
  MAJOR = 0
14
14
  MINOR = 2
15
- TINY = 2
15
+ TINY = 3
16
16
  STRING = [MAJOR, MINOR, TINY].join('.')
17
17
  end
18
18
  end
@@ -16,7 +16,7 @@ context "The EC2 console " do
16
16
  @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
17
 
18
18
  @get_console_output_response_body = <<-RESPONSE
19
- <GetConsoleOutputResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
19
+ <GetConsoleOutputResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
20
20
  <instanceId>i-28a64341</instanceId>
21
21
  <timestamp>2007-01-03 15:00:00</timestamp>
22
22
  <output>
@@ -16,19 +16,19 @@ context "EC2 image_attributes " do
16
16
  @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
17
 
18
18
  @modify_image_attribute_response_body = <<-RESPONSE
19
- <ModifyImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-01-19">
19
+ <ModifyImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
20
20
  <return>true</return>
21
21
  </ModifyImageAttributeResponse>
22
22
  RESPONSE
23
23
 
24
24
  @reset_image_attribute_response_body = <<-RESPONSE
25
- <ResetImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
25
+ <ResetImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
26
26
  <return>true</return>
27
27
  </ResetImageAttributeResponse>
28
28
  RESPONSE
29
29
 
30
- @describe_image_attribute_response_body = <<-RESPONSE
31
- <DescribeImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-01-19">
30
+ @describe_image_attribute_response_body_launch_permissions = <<-RESPONSE
31
+ <DescribeImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
32
32
  <imageId>ami-61a54008</imageId>
33
33
  <launchPermission>
34
34
  <item>
@@ -41,6 +41,17 @@ context "EC2 image_attributes " do
41
41
  </DescribeImageAttributeResponse>
42
42
  RESPONSE
43
43
 
44
+ @describe_image_attribute_response_body_product_codes = <<-RESPONSE
45
+ <DescribeImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-03">
46
+ <imageId>ami-61a54008</imageId>
47
+ <productCodes>
48
+ <item>
49
+ <productCode>774F4FF8</productCode>
50
+ </item>
51
+ </productCodes>
52
+ </DescribeImageAttributeResponse>
53
+ RESPONSE
54
+
44
55
  end
45
56
 
46
57
 
@@ -88,6 +99,18 @@ context "EC2 image_attributes " do
88
99
  end
89
100
 
90
101
 
102
+ specify "should be able to be changed with modify_image_attribute ( with :attribute=>'productCodes')" do
103
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
104
+ "Attribute"=>"productCodes",
105
+ "OperationType"=>"",
106
+ "ProductCode.1"=>"774F4FF8"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
107
+
108
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008",
109
+ :attribute=>"productCodes",
110
+ :product_code=>["774F4FF8"]).should.be.an.instance_of EC2::Response
111
+ end
112
+
113
+
91
114
  specify "should be able to be changed with modify_image_attribute ( with :attribute and multiple :user_id and :group elements)" do
92
115
  @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
93
116
  "Attribute"=>"launchPermission",
@@ -114,13 +137,21 @@ context "EC2 image_attributes " do
114
137
  lambda { @ec2.modify_image_attribute(:image_id=>nil, :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
115
138
  lambda { @ec2.modify_image_attribute(:image_id=>"", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
116
139
 
117
- # :attribute currently has one option which is 'launchPermission', it should fail with any other value, nil, or empty
140
+ # :attribute currently has two options which are 'launchPermission' and 'productCodes, it should fail with any other value, nil, or empty
118
141
  lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil, :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
119
142
  lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
120
143
  lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
121
144
 
122
- # :attribute option should fail if neither :group nor :user_id are also provided
145
+ # :attribute => 'launchPermission' option should fail if neither :group nor :user_id are also provided
123
146
  lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add") }.should.raise(EC2::ArgumentError)
147
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => nil) }.should.raise(EC2::ArgumentError)
148
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => "") }.should.raise(EC2::ArgumentError)
149
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => nil) }.should.raise(EC2::ArgumentError)
150
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => "") }.should.raise(EC2::ArgumentError)
151
+
152
+ # :attribute => 'productCodes' option should fail if :product_code isn't also provided
153
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes", :product_code=>nil) }.should.raise(EC2::ArgumentError)
154
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes", :product_code=>"") }.should.raise(EC2::ArgumentError)
124
155
 
125
156
  # :operation_type currently has two options which are 'add' and 'remove', and it should fail with any other, nil or empty
126
157
  lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>nil, :group=>["all"]) }.should.raise(EC2::ArgumentError)
@@ -129,10 +160,10 @@ context "EC2 image_attributes " do
129
160
  end
130
161
 
131
162
 
132
- specify "method describe_image_attribute should return the proper attributes" do
163
+ specify "method describe_image_attribute should return the proper attributes when called with launchPermission" do
133
164
  @ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
134
165
  "Attribute"=>"launchPermission" }).
135
- returns stub(:body => @describe_image_attribute_response_body, :is_a? => true)
166
+ returns stub(:body => @describe_image_attribute_response_body_launch_permissions, :is_a? => true)
136
167
 
137
168
  @ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "launchPermission").
138
169
  should.be.an.instance_of EC2::Response
@@ -144,16 +175,35 @@ context "EC2 image_attributes " do
144
175
  end
145
176
 
146
177
 
178
+ specify "method describe_image_attribute should return the proper attributes when called with productCodes" do
179
+ @ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
180
+ "Attribute"=>"productCodes" }).
181
+ returns stub(:body => @describe_image_attribute_response_body_product_codes, :is_a? => true)
182
+
183
+ @ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "productCodes").
184
+ should.be.an.instance_of EC2::Response
185
+
186
+ response = @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes")
187
+ response.imageId.should.equal "ami-61a54008"
188
+ response.productCodes.item[0].productCode.should.equal "774F4FF8"
189
+ end
190
+
191
+
147
192
  specify "should raise an exception when describe_image_attribute is called with incorrect arguments" do
148
193
  # method args can't be nil or empty
149
194
  lambda { @ec2.describe_image_attribute() }.should.raise(EC2::ArgumentError)
150
195
  lambda { @ec2.describe_image_attribute(:image_id=>"") }.should.raise(EC2::ArgumentError)
151
196
 
152
- # :image_id option must be not be empty or nil
197
+ # :image_id option must be not be empty or nil w/ launchPermission
153
198
  lambda { @ec2.describe_image_attribute(:image_id=>nil, :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
154
199
  lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
155
200
 
156
- # :attribute currently has one option which is 'launchPermission', it should fail with any other value, nil, or empty
201
+ # :image_id option must be not be empty or nil w/ productCodes
202
+ lambda { @ec2.describe_image_attribute(:image_id=>nil, :attribute=>"productCodes") }.should.raise(EC2::ArgumentError)
203
+ lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"productCodes") }.should.raise(EC2::ArgumentError)
204
+
205
+ # :attribute currently has two options which are 'launchPermission' and 'productCodes', it should fail with any other values,
206
+ # nil, or empty
157
207
  lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil) }.should.raise(EC2::ArgumentError)
158
208
  lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"") }.should.raise(EC2::ArgumentError)
159
209
  lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo") }.should.raise(EC2::ArgumentError)
@@ -16,13 +16,13 @@ context "An EC2 image " do
16
16
  @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
17
 
18
18
  @register_image_response_body = <<-RESPONSE
19
- <RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
19
+ <RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
20
20
  <imageId>ami-61a54008</imageId>
21
21
  </RegisterImageResponse>
22
22
  RESPONSE
23
23
 
24
24
  @describe_image_response_body = <<-RESPONSE
25
- <DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
25
+ <DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
26
26
  <imagesSet>
27
27
  <item>
28
28
  <imageId>ami-61a54008</imageId>
@@ -30,6 +30,11 @@ context "An EC2 image " do
30
30
  <imageState>available</imageState>
31
31
  <imageOwnerId>AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA</imageOwnerId>
32
32
  <isPublic>true</isPublic>
33
+ <productCodes>
34
+ <item>
35
+ <productCode>774F4FF8</productCode>
36
+ </item>
37
+ </productCodes>
33
38
  </item>
34
39
  <item>
35
40
  <imageId>ami-61a54009</imageId>
@@ -43,7 +48,7 @@ context "An EC2 image " do
43
48
  RESPONSE
44
49
 
45
50
  @deregister_image_response_body = <<-RESPONSE
46
- <DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
51
+ <DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
47
52
  <return>true</return>
48
53
  </DeregisterImageResponse>
49
54
  RESPONSE
@@ -93,6 +98,7 @@ context "An EC2 image " do
93
98
  response.imagesSet.item[0].imageState.should.equal "available"
94
99
  response.imagesSet.item[0].imageOwnerId.should.equal "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA"
95
100
  response.imagesSet.item[0].isPublic.should.equal "true"
101
+ response.imagesSet.item[0].productCodes.item[0].productCode.should.equal "774F4FF8"
96
102
 
97
103
  # test second 'Item' object returned
98
104
  response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
@@ -16,7 +16,7 @@ context "EC2 instances " do
16
16
  @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
17
 
18
18
  @run_instances_response_body = <<-RESPONSE
19
- <RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
19
+ <RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
20
20
  <reservationId>r-47a5402e</reservationId>
21
21
  <ownerId>495219933132</ownerId>
22
22
  <groupSet>
@@ -63,7 +63,7 @@ context "EC2 instances " do
63
63
  RESPONSE
64
64
 
65
65
  @describe_instances_response_body = <<-RESPONSE
66
- <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
66
+ <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
67
67
  <reservationSet>
68
68
  <item>
69
69
  <reservationId>r-44a5402d</reservationId>
@@ -84,6 +84,11 @@ context "EC2 instances " do
84
84
  <privateDnsName>domU-12-31-35-00-1E-01.z-2.compute-1.internal</privateDnsName>
85
85
  <dnsName>ec2-72-44-33-4.z-2.compute-1.amazonaws.com</dnsName>
86
86
  <keyName>example-key-name</keyName>
87
+ <productCodesSet>
88
+ <item>
89
+ <productCode>774F4FF8</productCode>
90
+ </item>
91
+ </productCodesSet>
87
92
  </item>
88
93
  </instancesSet>
89
94
  </item>
@@ -92,13 +97,13 @@ context "EC2 instances " do
92
97
  RESPONSE
93
98
 
94
99
  @reboot_instances_response_body = <<-RESPONSE
95
- <RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
100
+ <RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
96
101
  <return>true</return>
97
102
  </RebootInstancesResponse>
98
103
  RESPONSE
99
104
 
100
105
  @terminate_instances_response_body = <<-RESPONSE
101
- <TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
106
+ <TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
102
107
  <instancesSet>
103
108
  <item>
104
109
  <instanceId>i-28a64341</instanceId>
@@ -238,6 +243,7 @@ context "EC2 instances " do
238
243
  response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
239
244
  response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
240
245
  response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
246
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
241
247
  end
242
248
 
243
249
 
@@ -256,6 +262,7 @@ context "EC2 instances " do
256
262
  response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
257
263
  response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
258
264
  response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
265
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
259
266
  end
260
267
 
261
268
 
@@ -16,7 +16,7 @@ context "EC2 keypairs " do
16
16
  @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
17
 
18
18
  @create_keypair_response_body = <<-RESPONSE
19
- <CreateKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
19
+ <CreateKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
20
20
  <keyName>example-key-name</keyName>
21
21
  <keyFingerprint>1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f</keyFingerprint>
22
22
  <keyMaterial>-----BEGIN RSA PRIVATE KEY-----
@@ -46,7 +46,7 @@ context "EC2 keypairs " do
46
46
  RESPONSE
47
47
 
48
48
  @describe_keypairs_response_body = <<-RESPONSE
49
- <DescribeKeyPairsResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
49
+ <DescribeKeyPairsResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
50
50
  <keySet>
51
51
  <item>
52
52
  <keyName>example-key-name</keyName>
@@ -57,7 +57,7 @@ context "EC2 keypairs " do
57
57
  RESPONSE
58
58
 
59
59
  @delete_keypair_body = <<-RESPONSE
60
- <DeleteKeyPair xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
60
+ <DeleteKeyPair xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
61
61
  <return>true</return>
62
62
  </DeleteKeyPair>
63
63
  RESPONSE
@@ -0,0 +1,48 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@elasticworkbench.com)
6
+ # Copyright:: Copyright (c) 2007 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "An EC2 instance " do
14
+
15
+ setup do
16
+ @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
+
18
+ @confirm_product_instance_response_body = <<-RESPONSE
19
+ <ConfirmProductInstanceResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
20
+ <result>true</result>
21
+ <ownerId>254933287430</ownerId>
22
+ </ConfirmProductInstanceResponse>
23
+ RESPONSE
24
+
25
+ end
26
+
27
+
28
+ specify "should indicate whether a product code is attached to an instance" do
29
+ @ec2.stubs(:make_request).with('ConfirmProductInstance', {"ProductCode"=>"774F4FF8", "InstanceId"=>"i-10a64379"}).
30
+ returns stub(:body => @confirm_product_instance_response_body, :is_a? => true)
31
+
32
+ @ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" ).should.be.an.instance_of EC2::Response
33
+ response = @ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" )
34
+ response.ownerId.should.equal "254933287430"
35
+ response.result.should.equal "true"
36
+ end
37
+
38
+
39
+ specify "method get_console_output should raise an exception when called without nil/empty string arguments" do
40
+ lambda { @ec2.confirm_product_instance() }.should.raise(EC2::ArgumentError)
41
+ lambda { @ec2.confirm_product_instance(:product_code => "774F4FF8", :instance_id => nil) }.should.raise(EC2::ArgumentError)
42
+ lambda { @ec2.confirm_product_instance(:product_code => "774F4FF8", :instance_id => "") }.should.raise(EC2::ArgumentError)
43
+ lambda { @ec2.confirm_product_instance(:product_code => nil, :instance_id => "i-10a64379") }.should.raise(EC2::ArgumentError)
44
+ lambda { @ec2.confirm_product_instance(:product_code => "", :instance_id => "i-10a64379") }.should.raise(EC2::ArgumentError)
45
+ end
46
+
47
+
48
+ end
@@ -15,7 +15,7 @@ context "The Response classes " do
15
15
 
16
16
  setup do
17
17
  @http_xml = <<-RESPONSE
18
- <RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
18
+ <RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
19
19
  <return>true</return>
20
20
  </RebootInstancesResponse>
21
21
  RESPONSE
@@ -16,19 +16,19 @@ context "EC2 security groups " do
16
16
  @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
17
 
18
18
  @create_security_group_response_body = <<-RESPONSE
19
- <CreateSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
19
+ <CreateSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
20
20
  <return>true</return>
21
21
  </CreateSecurityGroupResponse>
22
22
  RESPONSE
23
23
 
24
24
  @delete_security_group_response_body = <<-RESPONSE
25
- <DeleteSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19">
25
+ <DeleteSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
26
26
  <return>true</return>
27
27
  </DeleteSecurityGroupResponse>
28
28
  RESPONSE
29
29
 
30
30
  @describe_security_groups_response_body = <<-RESPONSE
31
- <DescribeSecurityGroupsResponse xm-lns="http://ec2.amazonaws.com/doc/2007-01-19">
31
+ <DescribeSecurityGroupsResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
32
32
  <securityGroupInfo>
33
33
  <item>
34
34
  <ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
@@ -67,13 +67,13 @@ context "EC2 security groups " do
67
67
  RESPONSE
68
68
 
69
69
  @authorize_security_group_ingress_response_body = <<-RESPONSE
70
- <AuthorizeSecurityGroupIngressResponse xm-lns="http://ec2.amazonaws.com/doc/2007-01-19">
70
+ <AuthorizeSecurityGroupIngressResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
71
71
  <return>true</return>
72
72
  </AuthorizeSecurityGroupIngressResponse>
73
73
  RESPONSE
74
74
 
75
75
  @revoke_security_group_ingress_response_body = <<-RESPONSE
76
- <RevokeSecurityGroupIngressResponse xm-lns="http://ec2.amazonaws.com/doc/2007-01-19">
76
+ <RevokeSecurityGroupIngressResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
77
77
  <return>true</return>
78
78
  </RevokeSecurityGroupIngressResponse>
79
79
  RESPONSE
@@ -16,7 +16,7 @@ context "The EC2 Gem " do
16
16
  setup do
17
17
  @major = 0
18
18
  @minor = 2
19
- @tiny = 2
19
+ @tiny = 3
20
20
  @string = [@major, @minor, @tiny].join('.')
21
21
  end
22
22
 
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>Amazon Web Services EC2 Ruby Gem</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/amazon-ec2"; return false'>
35
35
  Get Version
36
- <a href="http://rubyforge.org/projects/amazon-ec2" class="numbers">0.2.2</a>
36
+ <a href="http://rubyforge.org/projects/amazon-ec2" class="numbers">0.2.3</a>
37
37
  </div>
38
38
  <h2>&#x2192; &#8216;amazon-ec2&#8217;</h2>
39
39
 
@@ -65,6 +65,13 @@
65
65
  <p>This release (&gt;= 0.2.0) represents a major re-write of this gem and contains contributions from several people who make use of this gem for their own applications. Trust us, its worth the pain of upgrading if you have been using an older version. Some of the major enhancements you will find are:</p>
66
66
 
67
67
 
68
+ <ul>
69
+ <li>Updated <span class="caps">API</span> version in the query <span class="caps">API</span> request to 2007-03-01, and added all known method calls
70
+ in this version of the <span class="caps">API</span> to the gem (including paid <span class="caps">AMI</span> support with product codes, reboot, viewing console output, <span class="caps">NAT</span> addressing
71
+ and more!)</li>
72
+ </ul>
73
+
74
+
68
75
  <ul>
69
76
  <li><span class="caps">MAJOR</span> library changes : <span class="caps">THESE CHANGES ARE NOT BACKWARD COMPATIBLE</span>!! You will need to update
70
77
  the way in which you make calls, handle responses, and rescue exceptions from this library.
@@ -120,13 +127,6 @@ Marcel Molina&#8217;s fine <span class="caps">AWS</span>::S3 library.</li>
120
127
  </ul>
121
128
 
122
129
 
123
- <ul>
124
- <li>Updated <span class="caps">API</span> version in the query <span class="caps">API</span> request to 2007-01-19, and added all known method calls
125
- in this version of the <span class="caps">API</span> to the gem (including reboot, viewing console output, <span class="caps">NAT</span> addressing
126
- and more!)</li>
127
- </ul>
128
-
129
-
130
130
  <ul>
131
131
  <li>Removed .parse method as it is no longer needed or wanted.</li>
132
132
  </ul>
@@ -543,7 +543,7 @@ ami-23b6534a
543
543
 
544
544
  <p>Comments, patches, and bug reports are welcome. Send an email to the address below or use the RubyForge forum for this project.</p>
545
545
  <p class="coda">
546
- <a href="mailto:grempe-at-rubyforge-dot-org">Glenn Rempe</a>, 3rd July 2007<br>
546
+ <a href="mailto:grempe-at-rubyforge-dot-org">Glenn Rempe</a>, 6th July 2007<br>
547
547
  </p>
548
548
  </div>
549
549
 
data/website/index.txt CHANGED
@@ -22,6 +22,10 @@ h2. What's new?
22
22
 
23
23
  This release (>= 0.2.0) represents a major re-write of this gem and contains contributions from several people who make use of this gem for their own applications. Trust us, its worth the pain of upgrading if you have been using an older version. Some of the major enhancements you will find are:
24
24
 
25
+ * Updated API version in the query API request to 2007-03-01, and added all known method calls
26
+ in this version of the API to the gem (including paid AMI support with product codes, reboot, viewing console output, NAT addressing
27
+ and more!)
28
+
25
29
  * MAJOR library changes : THESE CHANGES ARE NOT BACKWARD COMPATIBLE!! You will need to update
26
30
  the way in which you make calls, handle responses, and rescue exceptions from this library.
27
31
  If you prefer not to make these changes you can feel free to continue to use the older version
@@ -59,10 +63,6 @@ which contain your ACCESS_KEY_ID and SECRET_ACCESS_KEY for this to work. Otherw
59
63
  will be thrown when you try to start it. This is way cool and shamelessly borrowed from
60
64
  Marcel Molina's fine AWS::S3 library.
61
65
 
62
- * Updated API version in the query API request to 2007-01-19, and added all known method calls
63
- in this version of the API to the gem (including reboot, viewing console output, NAT addressing
64
- and more!)
65
-
66
66
  * Removed .parse method as it is no longer needed or wanted.
67
67
 
68
68
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: amazon-ec2
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.2
7
- date: 2007-07-03 00:00:00 -07:00
6
+ version: 0.2.3
7
+ date: 2007-07-06 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
@@ -41,6 +41,7 @@ files:
41
41
  - lib/EC2/images.rb
42
42
  - lib/EC2/instances.rb
43
43
  - lib/EC2/keypairs.rb
44
+ - lib/EC2/products.rb
44
45
  - lib/EC2/image_attributes.rb
45
46
  - lib/EC2/security_groups.rb
46
47
  - License.txt
@@ -55,6 +56,7 @@ files:
55
56
  - test/test_EC2_images.rb
56
57
  - test/test_EC2_instances.rb
57
58
  - test/test_EC2_keypairs.rb
59
+ - test/test_EC2_products.rb
58
60
  - test/test_EC2_responses.rb
59
61
  - test/test_EC2_security_groups.rb
60
62
  - test/test_EC2_version.rb
@@ -71,6 +73,7 @@ test_files:
71
73
  - test/test_EC2_images.rb
72
74
  - test/test_EC2_instances.rb
73
75
  - test/test_EC2_keypairs.rb
76
+ - test/test_EC2_products.rb
74
77
  - test/test_EC2_responses.rb
75
78
  - test/test_EC2_security_groups.rb
76
79
  - test/test_EC2_version.rb