kerryb-amazon-ec2 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +265 -0
- data/LICENSE +66 -0
- data/README.rdoc +322 -0
- data/Rakefile +35 -0
- data/bin/ec2-gem-example.rb +67 -0
- data/bin/ec2sh +62 -0
- data/bin/setup.rb +25 -0
- data/lib/EC2/availability_zones.rb +41 -0
- data/lib/EC2/console.rb +44 -0
- data/lib/EC2/elastic_ips.rb +153 -0
- data/lib/EC2/exceptions.rb +147 -0
- data/lib/EC2/image_attributes.rb +166 -0
- data/lib/EC2/images.rb +134 -0
- data/lib/EC2/instances.rb +213 -0
- data/lib/EC2/keypairs.rb +94 -0
- data/lib/EC2/products.rb +43 -0
- data/lib/EC2/responses.rb +64 -0
- data/lib/EC2/security_groups.rb +232 -0
- data/lib/EC2/snapshots.rb +94 -0
- data/lib/EC2/volumes.rb +170 -0
- data/lib/EC2.rb +270 -0
- data/test/test_EC2.rb +68 -0
- data/test/test_EC2_availability_zones.rb +49 -0
- data/test/test_EC2_console.rb +54 -0
- data/test/test_EC2_elastic_ips.rb +144 -0
- data/test/test_EC2_image_attributes.rb +238 -0
- data/test/test_EC2_images.rb +197 -0
- data/test/test_EC2_instances.rb +336 -0
- data/test/test_EC2_keypairs.rb +123 -0
- data/test/test_EC2_products.rb +48 -0
- data/test/test_EC2_responses.rb +52 -0
- data/test/test_EC2_s3_xmlsimple.rb +80 -0
- data/test/test_EC2_security_groups.rb +205 -0
- data/test/test_EC2_snapshots.rb +83 -0
- data/test/test_EC2_volumes.rb +142 -0
- data/test/test_helper.rb +19 -0
- metadata +120 -0
@@ -0,0 +1,336 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Glenn Rempe (mailto:glenn@rempe.us)
|
6
|
+
# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://github.com/grempe/amazon-ec2/tree/master
|
9
|
+
#++
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
|
+
|
13
|
+
context "EC2 instances " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
+
|
18
|
+
@run_instances_response_body = <<-RESPONSE
|
19
|
+
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-08-29">
|
20
|
+
<reservationId>r-47a5402e</reservationId>
|
21
|
+
<ownerId>495219933132</ownerId>
|
22
|
+
<groupSet>
|
23
|
+
<item>
|
24
|
+
<groupId>default</groupId>
|
25
|
+
</item>
|
26
|
+
</groupSet>
|
27
|
+
<instancesSet>
|
28
|
+
<item>
|
29
|
+
<instanceId>i-2ba64342</instanceId>
|
30
|
+
<imageId>ami-60a54009</imageId>
|
31
|
+
<instanceState>
|
32
|
+
<code>0</code>
|
33
|
+
<name>pending</name>
|
34
|
+
</instanceState>
|
35
|
+
<privateDnsName></privateDnsName>
|
36
|
+
<dnsName></dnsName>
|
37
|
+
<keyName>example-key-name</keyName>
|
38
|
+
<amiLaunchIndex>0</amiLaunchIndex>
|
39
|
+
<instanceType>m1.small</instanceType>
|
40
|
+
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
|
41
|
+
</item>
|
42
|
+
<item>
|
43
|
+
<instanceId>i-2bc64242</instanceId>
|
44
|
+
<imageId>ami-60a54009</imageId>
|
45
|
+
<instanceState>
|
46
|
+
<code>0</code>
|
47
|
+
<name>pending</name>
|
48
|
+
</instanceState>
|
49
|
+
<privateDnsName></privateDnsName>
|
50
|
+
<dnsName></dnsName>
|
51
|
+
<keyName>example-key-name</keyName>
|
52
|
+
<amiLaunchIndex>1</amiLaunchIndex>
|
53
|
+
<instanceType>m1.small</instanceType>
|
54
|
+
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
|
55
|
+
</item>
|
56
|
+
<item>
|
57
|
+
<instanceId>i-2be64332</instanceId>
|
58
|
+
<imageId>ami-60a54009</imageId>
|
59
|
+
<instanceState>
|
60
|
+
<code>0</code>
|
61
|
+
<name>pending</name>
|
62
|
+
</instanceState>
|
63
|
+
<privateDnsName></privateDnsName>
|
64
|
+
<dnsName></dnsName>
|
65
|
+
<keyName>example-key-name</keyName>
|
66
|
+
<amiLaunchIndex>2</amiLaunchIndex>
|
67
|
+
<instanceType>m1.small</instanceType>
|
68
|
+
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
|
69
|
+
</item>
|
70
|
+
</instancesSet>
|
71
|
+
</RunInstancesResponse>
|
72
|
+
RESPONSE
|
73
|
+
|
74
|
+
@describe_instances_response_body = <<-RESPONSE
|
75
|
+
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-08-29">
|
76
|
+
<reservationSet>
|
77
|
+
<item>
|
78
|
+
<reservationId>r-44a5402d</reservationId>
|
79
|
+
<ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
|
80
|
+
<groupSet>
|
81
|
+
<item>
|
82
|
+
<groupId>default</groupId>
|
83
|
+
</item>
|
84
|
+
</groupSet>
|
85
|
+
<instancesSet>
|
86
|
+
<item>
|
87
|
+
<instanceId>i-28a64341</instanceId>
|
88
|
+
<imageId>ami-6ea54007</imageId>
|
89
|
+
<instanceState>
|
90
|
+
<code>0</code>
|
91
|
+
<name>running</name>
|
92
|
+
</instanceState>
|
93
|
+
<privateDnsName>domU-12-31-35-00-1E-01.z-2.compute-1.internal</privateDnsName>
|
94
|
+
<dnsName>ec2-72-44-33-4.z-2.compute-1.amazonaws.com</dnsName>
|
95
|
+
<keyName>example-key-name</keyName>
|
96
|
+
<productCodesSet>
|
97
|
+
<item><productCode>774F4FF8</productCode></item>
|
98
|
+
</productCodesSet>
|
99
|
+
<instanceType>m1.small</instanceType>
|
100
|
+
<launchTime>2007-08-07T11:54:42.000Z</launchTime>
|
101
|
+
</item>
|
102
|
+
</instancesSet>
|
103
|
+
</item>
|
104
|
+
</reservationSet>
|
105
|
+
</DescribeInstancesResponse>
|
106
|
+
RESPONSE
|
107
|
+
|
108
|
+
@reboot_instances_response_body = <<-RESPONSE
|
109
|
+
<RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
110
|
+
<return>true</return>
|
111
|
+
</RebootInstancesResponse>
|
112
|
+
RESPONSE
|
113
|
+
|
114
|
+
@terminate_instances_response_body = <<-RESPONSE
|
115
|
+
<TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
116
|
+
<instancesSet>
|
117
|
+
<item>
|
118
|
+
<instanceId>i-28a64341</instanceId>
|
119
|
+
<shutdownState>
|
120
|
+
<code>32</code>
|
121
|
+
<name>shutting-down</name>
|
122
|
+
</shutdownState>
|
123
|
+
<previousState>
|
124
|
+
<code>0</code>
|
125
|
+
<name>pending</name>
|
126
|
+
</previousState>
|
127
|
+
</item>
|
128
|
+
<item>
|
129
|
+
<instanceId>i-21a64348</instanceId>
|
130
|
+
<shutdownState>
|
131
|
+
<code>32</code>
|
132
|
+
<name>shutting-down</name>
|
133
|
+
</shutdownState>
|
134
|
+
<previousState>
|
135
|
+
<code>0</code>
|
136
|
+
<name>pending</name>
|
137
|
+
</previousState>
|
138
|
+
</item>
|
139
|
+
</instancesSet>
|
140
|
+
</TerminateInstancesResponse>
|
141
|
+
RESPONSE
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
specify "should be able to be run" do
|
146
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
147
|
+
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
148
|
+
|
149
|
+
@ec2.run_instances( :image_id => "ami-60a54009" ).should.be.an.instance_of Hash
|
150
|
+
|
151
|
+
response = @ec2.run_instances( :image_id => "ami-60a54009" )
|
152
|
+
|
153
|
+
response.reservationId.should.equal "r-47a5402e"
|
154
|
+
response.ownerId.should.equal "495219933132"
|
155
|
+
|
156
|
+
response.groupSet.item[0].groupId.should.equal "default"
|
157
|
+
|
158
|
+
response.instancesSet.item.length.should.equal 3
|
159
|
+
|
160
|
+
response.instancesSet.item[0].instanceId.should.equal "i-2ba64342"
|
161
|
+
response.instancesSet.item[0].imageId.should.equal "ami-60a54009"
|
162
|
+
response.instancesSet.item[0].instanceState.code.should.equal "0"
|
163
|
+
response.instancesSet.item[0].instanceState.name.should.equal "pending"
|
164
|
+
response.instancesSet.item[0].privateDnsName
|
165
|
+
response.instancesSet.item[0].dnsName.should.be.nil
|
166
|
+
response.instancesSet.item[0].keyName.should.equal "example-key-name"
|
167
|
+
response.instancesSet.item[0].instanceType.should.equal "m1.small"
|
168
|
+
response.instancesSet.item[0].launchTime.should.equal "2007-08-07T11:51:50.000Z"
|
169
|
+
|
170
|
+
response.instancesSet.item[1].instanceId.should.equal "i-2bc64242"
|
171
|
+
response.instancesSet.item[1].imageId.should.equal "ami-60a54009"
|
172
|
+
response.instancesSet.item[1].instanceState.code.should.equal "0"
|
173
|
+
response.instancesSet.item[1].instanceState.name.should.equal "pending"
|
174
|
+
response.instancesSet.item[1].privateDnsName
|
175
|
+
response.instancesSet.item[1].dnsName.should.be.nil
|
176
|
+
response.instancesSet.item[1].keyName.should.equal "example-key-name"
|
177
|
+
response.instancesSet.item[1].instanceType.should.equal "m1.small"
|
178
|
+
response.instancesSet.item[1].launchTime.should.equal "2007-08-07T11:51:50.000Z"
|
179
|
+
|
180
|
+
response.instancesSet.item[2].instanceId.should.equal "i-2be64332"
|
181
|
+
response.instancesSet.item[2].imageId.should.equal "ami-60a54009"
|
182
|
+
response.instancesSet.item[2].instanceState.code.should.equal "0"
|
183
|
+
response.instancesSet.item[2].instanceState.name.should.equal "pending"
|
184
|
+
response.instancesSet.item[2].privateDnsName
|
185
|
+
response.instancesSet.item[2].dnsName.should.be.nil
|
186
|
+
response.instancesSet.item[2].keyName.should.equal "example-key-name"
|
187
|
+
response.instancesSet.item[2].instanceType.should.equal "m1.small"
|
188
|
+
response.instancesSet.item[2].launchTime.should.equal "2007-08-07T11:51:50.000Z"
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
specify "method 'run_instances' should reject invalid arguments" do
|
193
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
194
|
+
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
195
|
+
|
196
|
+
lambda { @ec2.run_instances() }.should.raise(EC2::ArgumentError)
|
197
|
+
lambda { @ec2.run_instances( :image_id => "" ) }.should.raise(EC2::ArgumentError)
|
198
|
+
|
199
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1 ) }.should.not.raise(EC2::ArgumentError)
|
200
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 0 ) }.should.raise(EC2::ArgumentError)
|
201
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => nil ) }.should.raise(EC2::ArgumentError)
|
202
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => "" ) }.should.raise(EC2::ArgumentError)
|
203
|
+
|
204
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 1 ) }.should.not.raise(EC2::ArgumentError)
|
205
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 0 ) }.should.raise(EC2::ArgumentError)
|
206
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => nil ) }.should.raise(EC2::ArgumentError)
|
207
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => "" ) }.should.raise(EC2::ArgumentError)
|
208
|
+
|
209
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "public" ) }.should.not.raise(EC2::ArgumentError)
|
210
|
+
#lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "direct" ) }.should.not.raise(EC2::ArgumentError)
|
211
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => nil ) }.should.raise(EC2::ArgumentError)
|
212
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "" ) }.should.raise(EC2::ArgumentError)
|
213
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "foo" ) }.should.raise(EC2::ArgumentError)
|
214
|
+
|
215
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => true ) }.should.not.raise(EC2::ArgumentError)
|
216
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => false ) }.should.not.raise(EC2::ArgumentError)
|
217
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => nil ) }.should.raise(EC2::ArgumentError)
|
218
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "" ) }.should.raise(EC2::ArgumentError)
|
219
|
+
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "foo" ) }.should.raise(EC2::ArgumentError)
|
220
|
+
end
|
221
|
+
|
222
|
+
|
223
|
+
specify "should be able specify an availability_zone" do
|
224
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123", "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
225
|
+
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
226
|
+
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :availability_zone => "zone123", :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of Hash
|
227
|
+
end
|
228
|
+
|
229
|
+
specify "should be able to call run_instances with :user_data and :base64_encoded => true (default is false)" do
|
230
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
231
|
+
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
232
|
+
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of Hash
|
233
|
+
end
|
234
|
+
|
235
|
+
specify "should be able specify an kernel_id" do
|
236
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123", "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small', 'KernelId' => 'kernfoo').
|
237
|
+
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
238
|
+
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :availability_zone => "zone123", :group_id => [], :user_data => "foo", :base64_encoded => true, :kernel_id => 'kernfoo' ).should.be.an.instance_of Hash
|
239
|
+
end
|
240
|
+
|
241
|
+
specify "should be able to call run_instances with :user_data and :base64_encoded => false" do
|
242
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
243
|
+
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
244
|
+
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => false ).should.be.an.instance_of Hash
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
specify "should be able to be described and return the correct Ruby response class" do
|
249
|
+
@ec2.stubs(:make_request).with('DescribeInstances', {}).
|
250
|
+
returns stub(:body => @describe_instances_response_body, :is_a? => true)
|
251
|
+
@ec2.describe_instances.should.be.an.instance_of Hash
|
252
|
+
response = @ec2.describe_instances
|
253
|
+
response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
specify "should be able to be described with no params and return an array of Items" do
|
258
|
+
@ec2.stubs(:make_request).with('DescribeInstances', {}).
|
259
|
+
returns stub(:body => @describe_instances_response_body, :is_a? => true)
|
260
|
+
@ec2.describe_instances.reservationSet.item.length.should.equal 1
|
261
|
+
response = @ec2.describe_instances
|
262
|
+
response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
|
263
|
+
response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
|
264
|
+
response.reservationSet.item[0].groupSet.item[0].groupId.should.equal "default"
|
265
|
+
response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
|
266
|
+
response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
|
267
|
+
response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
|
268
|
+
response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
|
269
|
+
response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
|
270
|
+
response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
|
271
|
+
response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
|
272
|
+
response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
specify "should be able to be described with params of Array of :instance_id's and return an array of Items" do
|
277
|
+
@ec2.stubs(:make_request).with('DescribeInstances', {"InstanceId.1" => "i-28a64341"}).
|
278
|
+
returns stub(:body => @describe_instances_response_body, :is_a? => true)
|
279
|
+
@ec2.describe_instances( :instance_id => "i-28a64341" ).reservationSet.item.length.should.equal 1
|
280
|
+
response = @ec2.describe_instances( :instance_id => "i-28a64341" )
|
281
|
+
response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
|
282
|
+
response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
|
283
|
+
response.reservationSet.item[0].groupSet.item[0].groupId.should.equal "default"
|
284
|
+
response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
|
285
|
+
response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
|
286
|
+
response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
|
287
|
+
response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
|
288
|
+
response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
|
289
|
+
response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
|
290
|
+
response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
|
291
|
+
response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
|
292
|
+
end
|
293
|
+
|
294
|
+
|
295
|
+
specify "method reboot_instances should raise an exception when called without nil/empty string arguments" do
|
296
|
+
lambda { @ec2.reboot_instances() }.should.raise(EC2::ArgumentError)
|
297
|
+
lambda { @ec2.reboot_instances( :instance_id => nil ) }.should.raise(EC2::ArgumentError)
|
298
|
+
lambda { @ec2.reboot_instances( :instance_id => "" ) }.should.raise(EC2::ArgumentError)
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
specify "should be able to be rebooted when provided with an :instance_id" do
|
303
|
+
@ec2.expects(:make_request).with('RebootInstances', {"InstanceId.1"=>"i-2ea64347", "InstanceId.2"=>"i-21a64348"}).
|
304
|
+
returns stub(:body => @reboot_instances_response_body, :is_a? => true)
|
305
|
+
@ec2.reboot_instances( :instance_id => ["i-2ea64347", "i-21a64348"] ).class.should.equal Hash
|
306
|
+
end
|
307
|
+
|
308
|
+
|
309
|
+
specify "method terminate_instances should raise an exception when called without nil/empty string arguments" do
|
310
|
+
lambda { @ec2.terminate_instances() }.should.raise(EC2::ArgumentError)
|
311
|
+
lambda { @ec2.terminate_instances( :instance_id => nil ) }.should.raise(EC2::ArgumentError)
|
312
|
+
lambda { @ec2.terminate_instances( :instance_id => "" ) }.should.raise(EC2::ArgumentError)
|
313
|
+
end
|
314
|
+
|
315
|
+
|
316
|
+
specify "should be able to be terminated when provided with an :instance_id" do
|
317
|
+
@ec2.stubs(:make_request).with('TerminateInstances', {"InstanceId.1"=>"i-28a64341", "InstanceId.2"=>"i-21a64348"}).
|
318
|
+
returns stub(:body => @terminate_instances_response_body, :is_a? => true)
|
319
|
+
@ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal Hash
|
320
|
+
|
321
|
+
@response = @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] )
|
322
|
+
|
323
|
+
@response.instancesSet.item[0].instanceId.should.equal "i-28a64341"
|
324
|
+
@response.instancesSet.item[0].shutdownState.code.should.equal "32"
|
325
|
+
@response.instancesSet.item[0].shutdownState.name.should.equal "shutting-down"
|
326
|
+
@response.instancesSet.item[0].previousState.code.should.equal "0"
|
327
|
+
@response.instancesSet.item[0].previousState.name.should.equal "pending"
|
328
|
+
|
329
|
+
@response.instancesSet.item[1].instanceId.should.equal "i-21a64348"
|
330
|
+
@response.instancesSet.item[1].shutdownState.code.should.equal "32"
|
331
|
+
@response.instancesSet.item[1].shutdownState.name.should.equal "shutting-down"
|
332
|
+
@response.instancesSet.item[1].previousState.code.should.equal "0"
|
333
|
+
@response.instancesSet.item[1].previousState.name.should.equal "pending"
|
334
|
+
end
|
335
|
+
|
336
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Glenn Rempe (mailto:glenn@rempe.us)
|
6
|
+
# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://github.com/grempe/amazon-ec2/tree/master
|
9
|
+
#++
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
|
+
|
13
|
+
context "EC2 keypairs " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
+
|
18
|
+
@create_keypair_response_body = <<-RESPONSE
|
19
|
+
<CreateKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
|
+
<keyName>example-key-name</keyName>
|
21
|
+
<keyFingerprint>1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f</keyFingerprint>
|
22
|
+
<keyMaterial>-----BEGIN RSA PRIVATE KEY-----
|
23
|
+
MIIEoQIBAAKCAQBuLFg5ujHrtm1jnutSuoO8Xe56LlT+HM8v/xkaa39EstM3/aFxTHgElQiJLChp
|
24
|
+
HungXQ29VTc8rc1bW0lkdi23OH5eqkMHGhvEwqa0HWASUMll4o3o/IX+0f2UcPoKCOVUR+jx71Sg
|
25
|
+
5AU52EQfanIn3ZQ8lFW7Edp5a3q4DhjGlUKToHVbicL5E+g45zfB95wIyywWZfeW/UUF3LpGZyq/
|
26
|
+
ebIUlq1qTbHkLbCC2r7RTn8vpQWp47BGVYGtGSBMpTRP5hnbzzuqj3itkiLHjU39S2sJCJ0TrJx5
|
27
|
+
i8BygR4s3mHKBj8l+ePQxG1kGbF6R4yg6sECmXn17MRQVXODNHZbAgMBAAECggEAY1tsiUsIwDl5
|
28
|
+
91CXirkYGuVfLyLflXenxfI50mDFms/mumTqloHO7tr0oriHDR5K7wMcY/YY5YkcXNo7mvUVD1pM
|
29
|
+
ZNUJs7rw9gZRTrf7LylaJ58kOcyajw8TsC4e4LPbFaHwS1d6K8rXh64o6WgW4SrsB6ICmr1kGQI7
|
30
|
+
3wcfgt5ecIu4TZf0OE9IHjn+2eRlsrjBdeORi7KiUNC/pAG23I6MdDOFEQRcCSigCj+4/mciFUSA
|
31
|
+
SWS4dMbrpb9FNSIcf9dcLxVM7/6KxgJNfZc9XWzUw77Jg8x92Zd0fVhHOux5IZC+UvSKWB4dyfcI
|
32
|
+
tE8C3p9bbU9VGyY5vLCAiIb4qQKBgQDLiO24GXrIkswF32YtBBMuVgLGCwU9h9HlO9mKAc2m8Cm1
|
33
|
+
jUE5IpzRjTedc9I2qiIMUTwtgnw42auSCzbUeYMURPtDqyQ7p6AjMujp9EPemcSVOK9vXYL0Ptco
|
34
|
+
xW9MC0dtV6iPkCN7gOqiZXPRKaFbWADp16p8UAIvS/a5XXk5jwKBgQCKkpHi2EISh1uRkhxljyWC
|
35
|
+
iDCiK6JBRsMvpLbc0v5dKwP5alo1fmdR5PJaV2qvZSj5CYNpMAy1/EDNTY5OSIJU+0KFmQbyhsbm
|
36
|
+
rdLNLDL4+TcnT7c62/aH01ohYaf/VCbRhtLlBfqGoQc7+sAc8vmKkesnF7CqCEKDyF/dhrxYdQKB
|
37
|
+
gC0iZzzNAapayz1+JcVTwwEid6j9JqNXbBc+Z2YwMi+T0Fv/P/hwkX/ypeOXnIUcw0Ih/YtGBVAC
|
38
|
+
DQbsz7LcY1HqXiHKYNWNvXgwwO+oiChjxvEkSdsTTIfnK4VSCvU9BxDbQHjdiNDJbL6oar92UN7V
|
39
|
+
rBYvChJZF7LvUH4YmVpHAoGAbZ2X7XvoeEO+uZ58/BGKOIGHByHBDiXtzMhdJr15HTYjxK7OgTZm
|
40
|
+
gK+8zp4L9IbvLGDMJO8vft32XPEWuvI8twCzFH+CsWLQADZMZKSsBasOZ/h1FwhdMgCMcY+Qlzd4
|
41
|
+
JZKjTSu3i7vhvx6RzdSedXEMNTZWN4qlIx3kR5aHcukCgYA9T+Zrvm1F0seQPbLknn7EqhXIjBaT
|
42
|
+
P8TTvW/6bdPi23ExzxZn7KOdrfclYRph1LHMpAONv/x2xALIf91UB+v5ohy1oDoasL0gij1houRe
|
43
|
+
2ERKKdwz0ZL9SWq6VTdhr/5G994CK72fy5WhyERbDjUIdHaK3M849JJuf8cSrvSb4g==
|
44
|
+
-----END RSA PRIVATE KEY-----</keyMaterial>
|
45
|
+
</CreateKeyPairResponse>
|
46
|
+
RESPONSE
|
47
|
+
|
48
|
+
@describe_keypairs_response_body = <<-RESPONSE
|
49
|
+
<DescribeKeyPairsResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
50
|
+
<keySet>
|
51
|
+
<item>
|
52
|
+
<keyName>example-key-name</keyName>
|
53
|
+
<keyFingerprint>1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f</keyFingerprint>
|
54
|
+
</item>
|
55
|
+
</keySet>
|
56
|
+
</DescribeKeyPairsResponse>
|
57
|
+
RESPONSE
|
58
|
+
|
59
|
+
@delete_keypair_body = <<-RESPONSE
|
60
|
+
<DeleteKeyPair xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
61
|
+
<return>true</return>
|
62
|
+
</DeleteKeyPair>
|
63
|
+
RESPONSE
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
specify "should be able to be created" do
|
69
|
+
@ec2.stubs(:make_request).with('CreateKeyPair', {"KeyName"=>"example-key-name"}).
|
70
|
+
returns stub(:body => @create_keypair_response_body, :is_a? => true)
|
71
|
+
|
72
|
+
@ec2.create_keypair( :key_name => "example-key-name" ).should.be.an.instance_of Hash
|
73
|
+
|
74
|
+
response = @ec2.create_keypair( :key_name => "example-key-name" )
|
75
|
+
response.keyName.should.equal "example-key-name"
|
76
|
+
response.keyFingerprint.should.equal "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f"
|
77
|
+
response.keyMaterial.should.not.equal ""
|
78
|
+
response.keyMaterial.should.not.be.nil
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
specify "method create_keypair should reject bad arguments" do
|
83
|
+
@ec2.stubs(:make_request).with('CreateKeyPair', {"KeyName"=>"example-key-name"}).
|
84
|
+
returns stub(:body => @create_keypair_response_body, :is_a? => true)
|
85
|
+
|
86
|
+
lambda { @ec2.create_keypair( :key_name => "example-key-name" ) }.should.not.raise(EC2::ArgumentError)
|
87
|
+
lambda { @ec2.create_keypair() }.should.raise(EC2::ArgumentError)
|
88
|
+
lambda { @ec2.create_keypair( :key_name => nil ) }.should.raise(EC2::ArgumentError)
|
89
|
+
lambda { @ec2.create_keypair( :key_name => "" ) }.should.raise(EC2::ArgumentError)
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
specify "should be able to be described with describe_keypairs" do
|
94
|
+
@ec2.stubs(:make_request).with('DescribeKeyPairs', {"KeyName.1"=>"example-key-name"}).
|
95
|
+
returns stub(:body => @describe_keypairs_response_body, :is_a? => true)
|
96
|
+
@ec2.describe_keypairs( :key_name => "example-key-name" ).should.be.an.instance_of Hash
|
97
|
+
response = @ec2.describe_keypairs( :key_name => "example-key-name" )
|
98
|
+
response.keySet.item[0].keyName.should.equal "example-key-name"
|
99
|
+
response.keySet.item[0].keyFingerprint.should.equal "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f"
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
specify "should be able to be deleted with delete_keypairs" do
|
104
|
+
@ec2.stubs(:make_request).with('DeleteKeyPair', {"KeyName"=>"example-key-name"}).
|
105
|
+
returns stub(:body => @delete_keypair_body, :is_a? => true)
|
106
|
+
@ec2.delete_keypair( :key_name => "example-key-name" ).should.be.an.instance_of Hash
|
107
|
+
response = @ec2.delete_keypair( :key_name => "example-key-name" )
|
108
|
+
response.return.should.equal "true"
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
specify "method delete_keypair should reject bad argument" do
|
113
|
+
@ec2.stubs(:make_request).with('DeleteKeyPair', {"KeyName"=>"example-key-name"}).
|
114
|
+
returns stub(:body => @delete_keypair_body, :is_a? => true)
|
115
|
+
|
116
|
+
lambda { @ec2.delete_keypair( :key_name => "example-key-name" ) }.should.not.raise(EC2::ArgumentError)
|
117
|
+
lambda { @ec2.delete_keypair() }.should.raise(EC2::ArgumentError)
|
118
|
+
lambda { @ec2.delete_keypair( :key_name => nil ) }.should.raise(EC2::ArgumentError)
|
119
|
+
lambda { @ec2.delete_keypair( :key_name => "" ) }.should.raise(EC2::ArgumentError)
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
@@ -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@rempe.us)
|
6
|
+
# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://github.com/grempe/amazon-ec2/tree/master
|
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 Hash
|
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
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Glenn Rempe (mailto:glenn@rempe.us)
|
6
|
+
# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://github.com/grempe/amazon-ec2/tree/master
|
9
|
+
#++
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
|
+
|
13
|
+
context "The Response classes " do
|
14
|
+
|
15
|
+
|
16
|
+
setup do
|
17
|
+
@http_xml = <<-RESPONSE
|
18
|
+
<RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
19
|
+
<return>true</return>
|
20
|
+
</RebootInstancesResponse>
|
21
|
+
RESPONSE
|
22
|
+
|
23
|
+
@response = EC2::Response.parse(:xml => @http_xml)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
specify "should show the response as a formatted string when calling #inspect" do
|
28
|
+
@response.inspect.should.equal %{{"return"=>"true", "xmlns"=>"http://ec2.amazonaws.com/doc/2007-03-01"}}
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
specify "should be a Hash" do
|
33
|
+
@response.kind_of?(Hash).should.equal true
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
specify "should return its members" do
|
38
|
+
@response.keys.length.should.equal 2
|
39
|
+
test_array = ["return", "xmlns"].sort
|
40
|
+
@response.keys.sort.should.equal test_array
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Note: since we are now returning a hash of the xml, there should be no need for anyone to re-parse the xml.
|
45
|
+
# Therefore storing the xml on the object is a waste of memory, and is not done.
|
46
|
+
#
|
47
|
+
# specify "should return the original amazon XML response in the 'xml' attribute of the response object." do
|
48
|
+
# @response.xml.should.equal @http_xml
|
49
|
+
# end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Glenn Rempe (mailto:glenn@rempe.us)
|
6
|
+
# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://github.com/grempe/amazon-ec2/tree/master
|
9
|
+
#++
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
|
+
|
13
|
+
# NOTE : These tests exercise amazon-ec2 when used with the aws/s3 gem
|
14
|
+
# which was demonstrating some breaking behavior. The fix was to
|
15
|
+
# add the XmlSimple option "'keeproot' => false" in responses.rb
|
16
|
+
|
17
|
+
context "EC2 aws-s3 compat test" do
|
18
|
+
|
19
|
+
setup do
|
20
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
21
|
+
|
22
|
+
@describe_instances_response_body = <<-RESPONSE
|
23
|
+
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-08-29">
|
24
|
+
<reservationSet>
|
25
|
+
<item>
|
26
|
+
<reservationId>r-44a5402d</reservationId>
|
27
|
+
<ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
|
28
|
+
<groupSet>
|
29
|
+
<item>
|
30
|
+
<groupId>default</groupId>
|
31
|
+
</item>
|
32
|
+
</groupSet>
|
33
|
+
<instancesSet>
|
34
|
+
<item>
|
35
|
+
<instanceId>i-28a64341</instanceId>
|
36
|
+
<imageId>ami-6ea54007</imageId>
|
37
|
+
<instanceState>
|
38
|
+
<code>0</code>
|
39
|
+
<name>running</name>
|
40
|
+
</instanceState>
|
41
|
+
<privateDnsName>domU-12-31-35-00-1E-01.z-2.compute-1.internal</privateDnsName>
|
42
|
+
<dnsName>ec2-72-44-33-4.z-2.compute-1.amazonaws.com</dnsName>
|
43
|
+
<keyName>example-key-name</keyName>
|
44
|
+
<productCodesSet>
|
45
|
+
<item><productCode>774F4FF8</productCode></item>
|
46
|
+
</productCodesSet>
|
47
|
+
<instanceType>m1.small</instanceType>
|
48
|
+
<launchTime>2007-08-07T11:54:42.000Z</launchTime>
|
49
|
+
</item>
|
50
|
+
</instancesSet>
|
51
|
+
</item>
|
52
|
+
</reservationSet>
|
53
|
+
</DescribeInstancesResponse>
|
54
|
+
RESPONSE
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
specify "should be able to be described and return the correct Ruby response class" do
|
59
|
+
@ec2.stubs(:make_request).with('DescribeInstances', {}).
|
60
|
+
returns stub(:body => @describe_instances_response_body, :is_a? => true)
|
61
|
+
@ec2.describe_instances.should.be.an.instance_of Hash
|
62
|
+
response = @ec2.describe_instances
|
63
|
+
response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
|
64
|
+
end
|
65
|
+
|
66
|
+
specify "should be able to be described and return the correct Ruby response class when the aws/s3 lib is required" do
|
67
|
+
begin
|
68
|
+
require 'aws/s3s'
|
69
|
+
@ec2.stubs(:make_request).with('DescribeInstances', {}).
|
70
|
+
returns stub(:body => @describe_instances_response_body, :is_a? => true)
|
71
|
+
@ec2.describe_instances.should.be.an.instance_of Hash
|
72
|
+
response = @ec2.describe_instances
|
73
|
+
response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
|
74
|
+
rescue LoadError
|
75
|
+
# do nothing. no aws/s3 gem installed to test against
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|