newrelic-amazon-ec2 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/.gitignore +8 -0
  2. data/.yardopts +1 -0
  3. data/ChangeLog +293 -0
  4. data/LICENSE +66 -0
  5. data/README.rdoc +354 -0
  6. data/README_dev.rdoc +12 -0
  7. data/Rakefile +101 -0
  8. data/VERSION +1 -0
  9. data/amazon-ec2.gemspec +134 -0
  10. data/bin/ec2-gem-example.rb +137 -0
  11. data/bin/ec2-gem-profile.rb +10 -0
  12. data/bin/ec2sh +62 -0
  13. data/bin/setup.rb +28 -0
  14. data/deps.rip +1 -0
  15. data/lib/AWS.rb +292 -0
  16. data/lib/AWS/Autoscaling.rb +70 -0
  17. data/lib/AWS/Autoscaling/autoscaling.rb +273 -0
  18. data/lib/AWS/Cloudwatch.rb +32 -0
  19. data/lib/AWS/Cloudwatch/monitoring.rb +89 -0
  20. data/lib/AWS/EC2.rb +33 -0
  21. data/lib/AWS/EC2/availability_zones.rb +21 -0
  22. data/lib/AWS/EC2/console.rb +23 -0
  23. data/lib/AWS/EC2/elastic_ips.rb +81 -0
  24. data/lib/AWS/EC2/image_attributes.rb +133 -0
  25. data/lib/AWS/EC2/images.rb +101 -0
  26. data/lib/AWS/EC2/instances.rb +212 -0
  27. data/lib/AWS/EC2/keypairs.rb +61 -0
  28. data/lib/AWS/EC2/products.rb +21 -0
  29. data/lib/AWS/EC2/security_groups.rb +183 -0
  30. data/lib/AWS/EC2/snapshots.rb +59 -0
  31. data/lib/AWS/EC2/volumes.rb +115 -0
  32. data/lib/AWS/ELB.rb +71 -0
  33. data/lib/AWS/ELB/load_balancers.rb +178 -0
  34. data/lib/AWS/exceptions.rb +122 -0
  35. data/lib/AWS/responses.rb +21 -0
  36. data/newrelic-amazon-ec2.gemspec +136 -0
  37. data/perftools/ec2prof +0 -0
  38. data/perftools/ec2prof-results.dot +132 -0
  39. data/perftools/ec2prof-results.txt +100 -0
  40. data/perftools/ec2prof.symbols +102 -0
  41. data/test/test_Autoscaling_groups.rb +336 -0
  42. data/test/test_EC2.rb +68 -0
  43. data/test/test_EC2_availability_zones.rb +49 -0
  44. data/test/test_EC2_console.rb +54 -0
  45. data/test/test_EC2_elastic_ips.rb +144 -0
  46. data/test/test_EC2_image_attributes.rb +238 -0
  47. data/test/test_EC2_images.rb +197 -0
  48. data/test/test_EC2_instances.rb +429 -0
  49. data/test/test_EC2_keypairs.rb +123 -0
  50. data/test/test_EC2_products.rb +48 -0
  51. data/test/test_EC2_responses.rb +53 -0
  52. data/test/test_EC2_s3_xmlsimple.rb +80 -0
  53. data/test/test_EC2_security_groups.rb +205 -0
  54. data/test/test_EC2_snapshots.rb +83 -0
  55. data/test/test_EC2_volumes.rb +142 -0
  56. data/test/test_ELB_load_balancers.rb +239 -0
  57. data/test/test_helper.rb +23 -0
  58. data/wsdl/2007-08-29.ec2.wsdl +1269 -0
  59. data/wsdl/2008-02-01.ec2.wsdl +1614 -0
  60. data/wsdl/2008-05-05.ec2.wsdl +2052 -0
  61. data/wsdl/2008-12-01.ec2.wsdl +2354 -0
  62. metadata +218 -0
@@ -0,0 +1,429 @@
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
+ before do
16
+ @ec2 = AWS::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
+
143
+ @monitor_instances_response_body = <<-RESPONSE
144
+ <MonitorInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/">
145
+ <requestId>fe62a64c-49fb-4a3c-8d9b-61aba146d390</requestId>
146
+ <instancesSet>
147
+ <item>
148
+ <instanceId>i-138fc47a</instanceId>
149
+ <monitoring>
150
+ <state>pending</state>
151
+ </monitoring>
152
+ </item>
153
+ <item>
154
+ <instanceId>i-33457a5a</instanceId>
155
+ <monitoring>
156
+ <state>pending</state>
157
+ </monitoring>
158
+ </item>
159
+ </instancesSet>
160
+ </MonitorInstancesResponse>
161
+ RESPONSE
162
+
163
+ @unmonitor_instances_response_body = <<-RESPONSE
164
+ <UnmonitorInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/">
165
+ <requestId>7dbc5095-f3ae-46d8-a5b1-19df118ceb05</requestId>
166
+ <instancesSet>
167
+ <item>
168
+ <instanceId>i-138fc47a</instanceId>
169
+ <monitoring>
170
+ <state>disabling</state>
171
+ </monitoring>
172
+ </item>
173
+ <item>
174
+ <instanceId>i-33457a5a</instanceId>
175
+ <monitoring>
176
+ <state>disabling</state>
177
+ </monitoring>
178
+ </item>
179
+ </instancesSet>
180
+ </UnmonitorInstancesResponse>
181
+
182
+ RESPONSE
183
+ end
184
+
185
+
186
+ specify "should be able to be run" do
187
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public', 'InstanceType' => 'm1.small').
188
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
189
+
190
+ @ec2.run_instances( :image_id => "ami-60a54009" ).should.be.an.instance_of Hash
191
+
192
+ response = @ec2.run_instances( :image_id => "ami-60a54009" )
193
+
194
+ response.reservationId.should.equal "r-47a5402e"
195
+ response.ownerId.should.equal "495219933132"
196
+
197
+ response.groupSet.item[0].groupId.should.equal "default"
198
+
199
+ response.instancesSet.item.length.should.equal 3
200
+
201
+ response.instancesSet.item[0].instanceId.should.equal "i-2ba64342"
202
+ response.instancesSet.item[0].imageId.should.equal "ami-60a54009"
203
+ response.instancesSet.item[0].instanceState.code.should.equal "0"
204
+ response.instancesSet.item[0].instanceState.name.should.equal "pending"
205
+ response.instancesSet.item[0].privateDnsName
206
+ response.instancesSet.item[0].dnsName.should.be.nil
207
+ response.instancesSet.item[0].keyName.should.equal "example-key-name"
208
+ response.instancesSet.item[0].instanceType.should.equal "m1.small"
209
+ response.instancesSet.item[0].launchTime.should.equal "2007-08-07T11:51:50.000Z"
210
+
211
+ response.instancesSet.item[1].instanceId.should.equal "i-2bc64242"
212
+ response.instancesSet.item[1].imageId.should.equal "ami-60a54009"
213
+ response.instancesSet.item[1].instanceState.code.should.equal "0"
214
+ response.instancesSet.item[1].instanceState.name.should.equal "pending"
215
+ response.instancesSet.item[1].privateDnsName
216
+ response.instancesSet.item[1].dnsName.should.be.nil
217
+ response.instancesSet.item[1].keyName.should.equal "example-key-name"
218
+ response.instancesSet.item[1].instanceType.should.equal "m1.small"
219
+ response.instancesSet.item[1].launchTime.should.equal "2007-08-07T11:51:50.000Z"
220
+
221
+ response.instancesSet.item[2].instanceId.should.equal "i-2be64332"
222
+ response.instancesSet.item[2].imageId.should.equal "ami-60a54009"
223
+ response.instancesSet.item[2].instanceState.code.should.equal "0"
224
+ response.instancesSet.item[2].instanceState.name.should.equal "pending"
225
+ response.instancesSet.item[2].privateDnsName
226
+ response.instancesSet.item[2].dnsName.should.be.nil
227
+ response.instancesSet.item[2].keyName.should.equal "example-key-name"
228
+ response.instancesSet.item[2].instanceType.should.equal "m1.small"
229
+ response.instancesSet.item[2].launchTime.should.equal "2007-08-07T11:51:50.000Z"
230
+ end
231
+
232
+
233
+ specify "method 'run_instances' should reject invalid arguments" do
234
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public', 'InstanceType' => 'm1.small').
235
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
236
+
237
+ lambda { @ec2.run_instances() }.should.raise(AWS::ArgumentError)
238
+ lambda { @ec2.run_instances( :image_id => "" ) }.should.raise(AWS::ArgumentError)
239
+
240
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1 ) }.should.not.raise(AWS::ArgumentError)
241
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 0 ) }.should.raise(AWS::ArgumentError)
242
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => nil ) }.should.raise(AWS::ArgumentError)
243
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => "" ) }.should.raise(AWS::ArgumentError)
244
+
245
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 1 ) }.should.not.raise(AWS::ArgumentError)
246
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 0 ) }.should.raise(AWS::ArgumentError)
247
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => nil ) }.should.raise(AWS::ArgumentError)
248
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => "" ) }.should.raise(AWS::ArgumentError)
249
+
250
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "public" ) }.should.not.raise(AWS::ArgumentError)
251
+ #lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "direct" ) }.should.not.raise(AWS::ArgumentError)
252
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => nil ) }.should.raise(AWS::ArgumentError)
253
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "" ) }.should.raise(AWS::ArgumentError)
254
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "foo" ) }.should.raise(AWS::ArgumentError)
255
+
256
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => true ) }.should.not.raise(AWS::ArgumentError)
257
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => false ) }.should.not.raise(AWS::ArgumentError)
258
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => nil ) }.should.raise(AWS::ArgumentError)
259
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "" ) }.should.raise(AWS::ArgumentError)
260
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "foo" ) }.should.raise(AWS::ArgumentError)
261
+ end
262
+
263
+
264
+ specify "should be able specify an availability_zone" do
265
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123", "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
266
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
267
+ @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
268
+ end
269
+
270
+ specify "should be able to call run_instances with :user_data and :base64_encoded => true (default is false)" do
271
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
272
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
273
+ @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
274
+ end
275
+
276
+ specify "should be able specify an kernel_id" do
277
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123", "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small', 'KernelId' => 'kernfoo').
278
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
279
+ @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
280
+ end
281
+
282
+ specify "should be able to call run_instances with :user_data and :base64_encoded => false" do
283
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
284
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
285
+ @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
286
+ end
287
+
288
+ specify "should get no user data for when options has no user_data key" do
289
+ @ec2.extract_user_data({}).should == nil
290
+ end
291
+
292
+ specify "should get plain string user data when options has user_data and no base64 key" do
293
+ @ec2.extract_user_data({:user_data => "foo\nbar"}).should == "foo\nbar"
294
+ end
295
+
296
+ specify "should strip new lines and base64 encode when options has both user_data and base64" do
297
+ @ec2.extract_user_data({:user_data => "binary\ndata\nhere\n", :base64_encoded => true}).should == "YmluYXJ5CmRhdGEKaGVyZQo="
298
+ end
299
+
300
+
301
+ specify "should be able to be described and return the correct Ruby response class" do
302
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
303
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
304
+ @ec2.describe_instances.should.be.an.instance_of Hash
305
+ response = @ec2.describe_instances
306
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
307
+ end
308
+
309
+
310
+ specify "should be able to be described with no params and return an array of Items" do
311
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
312
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
313
+ @ec2.describe_instances.reservationSet.item.length.should.equal 1
314
+ response = @ec2.describe_instances
315
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
316
+ response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
317
+ response.reservationSet.item[0].groupSet.item[0].groupId.should.equal "default"
318
+ response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
319
+ response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
320
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
321
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
322
+ response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
323
+ response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
324
+ response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
325
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
326
+ end
327
+
328
+
329
+ specify "should be able to be described with params of Array of :instance_id's and return an array of Items" do
330
+ @ec2.stubs(:make_request).with('DescribeInstances', {"InstanceId.1" => "i-28a64341"}).
331
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
332
+ @ec2.describe_instances( :instance_id => "i-28a64341" ).reservationSet.item.length.should.equal 1
333
+ response = @ec2.describe_instances( :instance_id => "i-28a64341" )
334
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
335
+ response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
336
+ response.reservationSet.item[0].groupSet.item[0].groupId.should.equal "default"
337
+ response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
338
+ response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
339
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
340
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
341
+ response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
342
+ response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
343
+ response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
344
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
345
+ end
346
+
347
+
348
+ specify "method reboot_instances should raise an exception when called without nil/empty string arguments" do
349
+ lambda { @ec2.reboot_instances() }.should.raise(AWS::ArgumentError)
350
+ lambda { @ec2.reboot_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
351
+ lambda { @ec2.reboot_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
352
+ end
353
+
354
+
355
+ specify "should be able to be rebooted when provided with an :instance_id" do
356
+ @ec2.expects(:make_request).with('RebootInstances', {"InstanceId.1"=>"i-2ea64347", "InstanceId.2"=>"i-21a64348"}).
357
+ returns stub(:body => @reboot_instances_response_body, :is_a? => true)
358
+ @ec2.reboot_instances( :instance_id => ["i-2ea64347", "i-21a64348"] ).class.should.equal Hash
359
+ end
360
+
361
+
362
+ specify "method terminate_instances should raise an exception when called without nil/empty string arguments" do
363
+ lambda { @ec2.terminate_instances() }.should.raise(AWS::ArgumentError)
364
+ lambda { @ec2.terminate_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
365
+ lambda { @ec2.terminate_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
366
+ end
367
+
368
+
369
+ specify "should be able to be terminated when provided with an :instance_id" do
370
+ @ec2.stubs(:make_request).with('TerminateInstances', {"InstanceId.1"=>"i-28a64341", "InstanceId.2"=>"i-21a64348"}).
371
+ returns stub(:body => @terminate_instances_response_body, :is_a? => true)
372
+ @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal Hash
373
+
374
+ @response = @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] )
375
+
376
+ @response.instancesSet.item[0].instanceId.should.equal "i-28a64341"
377
+ @response.instancesSet.item[0].shutdownState.code.should.equal "32"
378
+ @response.instancesSet.item[0].shutdownState.name.should.equal "shutting-down"
379
+ @response.instancesSet.item[0].previousState.code.should.equal "0"
380
+ @response.instancesSet.item[0].previousState.name.should.equal "pending"
381
+
382
+ @response.instancesSet.item[1].instanceId.should.equal "i-21a64348"
383
+ @response.instancesSet.item[1].shutdownState.code.should.equal "32"
384
+ @response.instancesSet.item[1].shutdownState.name.should.equal "shutting-down"
385
+ @response.instancesSet.item[1].previousState.code.should.equal "0"
386
+ @response.instancesSet.item[1].previousState.name.should.equal "pending"
387
+ end
388
+
389
+ specify "method monitor_instances should raise an exception when called without nil/empty string arguments" do
390
+ lambda { @ec2.monitor_instances() }.should.raise(AWS::ArgumentError)
391
+ lambda { @ec2.monitor_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
392
+ lambda { @ec2.monitor_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
393
+ end
394
+
395
+ specify "should be able to be monitored when provided with an :instance_id" do
396
+ @ec2.stubs(:make_request).with('MonitorInstances', {"InstanceId.1"=>"i-138fc47a", "InstanceId.2"=>"i-33457a5a"}).
397
+ returns stub(:body => @monitor_instances_response_body, :is_a? => true)
398
+ @ec2.monitor_instances( :instance_id => ["i-138fc47a", "i-33457a5a"] ).class.should.equal Hash
399
+
400
+ @response = @ec2.monitor_instances( :instance_id => ["i-138fc47a", "i-33457a5a"] )
401
+
402
+ @response.instancesSet.item[0].instanceId.should.equal "i-138fc47a"
403
+ @response.instancesSet.item[0].monitoring.state.should.equal "pending"
404
+
405
+ @response.instancesSet.item[1].instanceId.should.equal "i-33457a5a"
406
+ @response.instancesSet.item[1].monitoring.state.should.equal "pending"
407
+ end
408
+
409
+ specify "method unmonitor_instances should raise an exception when called without nil/empty string arguments" do
410
+ lambda { @ec2.unmonitor_instances() }.should.raise(AWS::ArgumentError)
411
+ lambda { @ec2.unmonitor_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
412
+ lambda { @ec2.unmonitor_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
413
+ end
414
+
415
+ specify "should be able to be unmonitored when provided with an :instance_id" do
416
+ @ec2.stubs(:make_request).with('UnmonitorInstances', {"InstanceId.1"=>"i-138fc47a", "InstanceId.2"=>"i-33457a5a"}).
417
+ returns stub(:body => @unmonitor_instances_response_body, :is_a? => true)
418
+ @ec2.unmonitor_instances( :instance_id => ["i-138fc47a", "i-33457a5a"] ).class.should.equal Hash
419
+
420
+ @response = @ec2.unmonitor_instances( :instance_id => ["i-138fc47a", "i-33457a5a"] )
421
+
422
+ @response.instancesSet.item[0].instanceId.should.equal "i-138fc47a"
423
+ @response.instancesSet.item[0].monitoring.state.should.equal "disabling"
424
+
425
+ @response.instancesSet.item[1].instanceId.should.equal "i-33457a5a"
426
+ @response.instancesSet.item[1].monitoring.state.should.equal "disabling"
427
+ end
428
+
429
+ 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
+ before do
16
+ @ec2 = AWS::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(AWS::ArgumentError)
87
+ lambda { @ec2.create_keypair() }.should.raise(AWS::ArgumentError)
88
+ lambda { @ec2.create_keypair( :key_name => nil ) }.should.raise(AWS::ArgumentError)
89
+ lambda { @ec2.create_keypair( :key_name => "" ) }.should.raise(AWS::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(AWS::ArgumentError)
117
+ lambda { @ec2.delete_keypair() }.should.raise(AWS::ArgumentError)
118
+ lambda { @ec2.delete_keypair( :key_name => nil ) }.should.raise(AWS::ArgumentError)
119
+ lambda { @ec2.delete_keypair( :key_name => "" ) }.should.raise(AWS::ArgumentError)
120
+ end
121
+
122
+
123
+ end