nirvdrum-amazon-ec2 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gitignore +9 -0
  2. data/.yardopts +1 -0
  3. data/ChangeLog +304 -0
  4. data/LICENSE +66 -0
  5. data/README.rdoc +359 -0
  6. data/README_dev.rdoc +10 -0
  7. data/Rakefile +70 -0
  8. data/VERSION +1 -0
  9. data/amazon-ec2.gemspec +142 -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 +29 -0
  14. data/deps.rip +1 -0
  15. data/lib/AWS.rb +321 -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 +80 -0
  20. data/lib/AWS/EC2.rb +33 -0
  21. data/lib/AWS/EC2/availability_zones.rb +29 -0
  22. data/lib/AWS/EC2/console.rb +25 -0
  23. data/lib/AWS/EC2/devpay.rb +18 -0
  24. data/lib/AWS/EC2/elastic_ips.rb +86 -0
  25. data/lib/AWS/EC2/image_attributes.rb +133 -0
  26. data/lib/AWS/EC2/images.rb +117 -0
  27. data/lib/AWS/EC2/instances.rb +234 -0
  28. data/lib/AWS/EC2/keypairs.rb +47 -0
  29. data/lib/AWS/EC2/products.rb +21 -0
  30. data/lib/AWS/EC2/security_groups.rb +164 -0
  31. data/lib/AWS/EC2/snapshots.rb +102 -0
  32. data/lib/AWS/EC2/spot_instance_requests.rb +105 -0
  33. data/lib/AWS/EC2/volumes.rb +100 -0
  34. data/lib/AWS/ELB.rb +71 -0
  35. data/lib/AWS/ELB/load_balancers.rb +178 -0
  36. data/lib/AWS/RDS.rb +73 -0
  37. data/lib/AWS/RDS/rds.rb +522 -0
  38. data/lib/AWS/exceptions.rb +200 -0
  39. data/lib/AWS/responses.rb +21 -0
  40. data/perftools/ec2prof +0 -0
  41. data/perftools/ec2prof-results.dot +132 -0
  42. data/perftools/ec2prof-results.txt +100 -0
  43. data/perftools/ec2prof.symbols +102 -0
  44. data/test/test_Autoscaling_groups.rb +337 -0
  45. data/test/test_EC2.rb +68 -0
  46. data/test/test_EC2_availability_zones.rb +49 -0
  47. data/test/test_EC2_console.rb +54 -0
  48. data/test/test_EC2_elastic_ips.rb +144 -0
  49. data/test/test_EC2_image_attributes.rb +238 -0
  50. data/test/test_EC2_images.rb +229 -0
  51. data/test/test_EC2_instances.rb +611 -0
  52. data/test/test_EC2_keypairs.rb +123 -0
  53. data/test/test_EC2_products.rb +48 -0
  54. data/test/test_EC2_responses.rb +53 -0
  55. data/test/test_EC2_s3_xmlsimple.rb +80 -0
  56. data/test/test_EC2_security_groups.rb +205 -0
  57. data/test/test_EC2_snapshots.rb +83 -0
  58. data/test/test_EC2_spot_instance_requests.rb +178 -0
  59. data/test/test_EC2_volumes.rb +142 -0
  60. data/test/test_ELB_load_balancers.rb +239 -0
  61. data/test/test_RDS.rb +354 -0
  62. data/test/test_helper.rb +23 -0
  63. data/wsdl/2007-08-29.ec2.wsdl +1269 -0
  64. data/wsdl/2008-02-01.ec2.wsdl +1614 -0
  65. data/wsdl/2008-05-05.ec2.wsdl +2052 -0
  66. data/wsdl/2008-12-01.ec2.wsdl +2354 -0
  67. data/wsdl/2009-10-31.ec2.wsdl +4261 -0
  68. data/wsdl/2009-11-30.ec2.wsdl +4668 -0
  69. metadata +199 -0
@@ -0,0 +1,229 @@
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 image " 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_image_response_body = <<-RESPONSE
19
+ <CreateImageResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31/">
20
+ <imageId>ami-4fa54026</imageId>
21
+ </CreateImageResponse>
22
+ RESPONSE
23
+
24
+ @register_image_response_body = <<-RESPONSE
25
+ <RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
26
+ <imageId>ami-61a54008</imageId>
27
+ </RegisterImageResponse>
28
+ RESPONSE
29
+
30
+ @describe_image_response_body = <<-RESPONSE
31
+ <DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
32
+ <imagesSet>
33
+ <item>
34
+ <imageId>ami-61a54008</imageId>
35
+ <imageLocation>foobar1/image.manifest.xml</imageLocation>
36
+ <imageState>available</imageState>
37
+ <imageOwnerId>AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA</imageOwnerId>
38
+ <isPublic>true</isPublic>
39
+ <productCodes>
40
+ <item>
41
+ <productCode>774F4FF8</productCode>
42
+ </item>
43
+ </productCodes>
44
+ </item>
45
+ <item>
46
+ <imageId>ami-61a54009</imageId>
47
+ <imageLocation>foobar2/image.manifest.xml</imageLocation>
48
+ <imageState>deregistered</imageState>
49
+ <imageOwnerId>ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ</imageOwnerId>
50
+ <isPublic>false</isPublic>
51
+ </item>
52
+ </imagesSet>
53
+ </DescribeImagesResponse>
54
+ RESPONSE
55
+
56
+ @deregister_image_response_body = <<-RESPONSE
57
+ <DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
58
+ <return>true</return>
59
+ </DeregisterImageResponse>
60
+ RESPONSE
61
+
62
+ end
63
+
64
+
65
+ specify "should be able to be created" do
66
+ @ec2.stubs(:make_request).with('CreateImage', {"InstanceId"=>"fooid", "Name" => "fooname", "Description" => "foodesc", "NoReboot" => "true"}).
67
+ returns stub(:body => @create_image_response_body, :is_a? => true)
68
+ @ec2.create_image(:instance_id => "fooid", :name => "fooname", :description => "foodesc", :no_reboot => true).should.be.an.instance_of Hash
69
+ @ec2.create_image(:instance_id => "fooid", :name => "fooname", :description => "foodesc", :no_reboot => true).imageId.should.equal "ami-4fa54026"
70
+ end
71
+
72
+
73
+ specify "method create_image should raise an exception when called with nil/empty string arguments" do
74
+ lambda { @ec2.create_image() }.should.raise(AWS::ArgumentError)
75
+ lambda { @ec2.create_image(:instance_id => "", :name => "fooname") }.should.raise(AWS::ArgumentError)
76
+ lambda { @ec2.create_image(:instance_id => "fooid", :name => "") }.should.raise(AWS::ArgumentError)
77
+ lambda { @ec2.create_image(:instance_id => nil, :name => "fooname") }.should.raise(AWS::ArgumentError)
78
+ lambda { @ec2.create_image(:instance_id => "fooid", :name => nil) }.should.raise(AWS::ArgumentError)
79
+ end
80
+
81
+
82
+ specify "method create_image should raise an exception when called with bad arguments" do
83
+ lambda { @ec2.create_image(:instance_id => "fooid", :name => "f"*2) }.should.raise(AWS::ArgumentError)
84
+ lambda { @ec2.create_image(:instance_id => "fooid", :name => "f"*129) }.should.raise(AWS::ArgumentError)
85
+ lambda { @ec2.create_image(:instance_id => "fooid", :name => "f"*128, :description => "f"*256) }.should.raise(AWS::ArgumentError)
86
+ lambda { @ec2.create_image(:instance_id => "fooid", :name => "f"*128, :no_reboot => "true") }.should.raise(AWS::ArgumentError)
87
+ lambda { @ec2.create_image(:instance_id => "fooid", :name => "f"*128, :no_reboot => "false") }.should.raise(AWS::ArgumentError)
88
+ end
89
+
90
+
91
+ specify "should be able to be registered" do
92
+ @ec2.stubs(:make_request).with('RegisterImage', {"ImageLocation"=>"mybucket-myimage.manifest.xml"}).
93
+ returns stub(:body => @register_image_response_body, :is_a? => true)
94
+ @ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").imageId.should.equal "ami-61a54008"
95
+ @ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").should.be.an.instance_of Hash
96
+ end
97
+
98
+
99
+ specify "method register_image should raise an exception when called without nil/empty string arguments" do
100
+ lambda { @ec2.register_image() }.should.raise(AWS::ArgumentError)
101
+ lambda { @ec2.register_image(:image_location => "") }.should.raise(AWS::ArgumentError)
102
+ end
103
+
104
+
105
+ specify "should be able to be described and return the correct Ruby response class for parent and members" do
106
+ @ec2.stubs(:make_request).with('DescribeImages', {}).
107
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
108
+ @ec2.describe_images.should.be.an.instance_of Hash
109
+ response = @ec2.describe_images
110
+ response.should.be.an.instance_of Hash
111
+ end
112
+
113
+
114
+ specify "should be able to be described with no params and return an imagesSet" do
115
+ @ec2.stubs(:make_request).with('DescribeImages', {}).
116
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
117
+ @ec2.describe_images.imagesSet.item.length.should.equal 2
118
+ end
119
+
120
+ specify "should be able to be described by an Array of ImageId.N ID's and return an array of Items" do
121
+ @ec2.stubs(:make_request).with('DescribeImages', {"ImageId.1"=>"ami-61a54008", "ImageId.2"=>"ami-61a54009"}).
122
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
123
+ @ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] ).imagesSet.item.length.should.equal 2
124
+
125
+ response = @ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] )
126
+
127
+ # test first 'Item' object returned
128
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
129
+ response.imagesSet.item[0].imageLocation.should.equal "foobar1/image.manifest.xml"
130
+ response.imagesSet.item[0].imageState.should.equal "available"
131
+ response.imagesSet.item[0].imageOwnerId.should.equal "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA"
132
+ response.imagesSet.item[0].isPublic.should.equal "true"
133
+ response.imagesSet.item[0].productCodes.item[0].productCode.should.equal "774F4FF8"
134
+
135
+ # test second 'Item' object returned
136
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
137
+ response.imagesSet.item[1].imageLocation.should.equal "foobar2/image.manifest.xml"
138
+ response.imagesSet.item[1].imageState.should.equal "deregistered"
139
+ response.imagesSet.item[1].imageOwnerId.should.equal "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"
140
+ response.imagesSet.item[1].isPublic.should.equal "false"
141
+ end
142
+
143
+
144
+ specify "should be able to be described by an owners with Owner.N ID's and return an array of Items" do
145
+ @ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "Owner.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
146
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
147
+ @ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
148
+
149
+ # owner ID's
150
+ response = @ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
151
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
152
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
153
+ end
154
+
155
+
156
+ specify "should be able to be described by an owner of 'self' and return an array of Items that I own" do
157
+ @ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "self").
158
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
159
+ @ec2.describe_images( :owner_id => "self" ).imagesSet.item.length.should.equal 2
160
+
161
+ # 'self' - Those that I own
162
+ response = @ec2.describe_images( :owner_id => "self" )
163
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
164
+ end
165
+
166
+
167
+ specify "should be able to be described by an owner of 'amazon' and return an array of Items that are Amazon Public AMI's" do
168
+ @ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "amazon").
169
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
170
+ @ec2.describe_images( :owner_id => "amazon" ).imagesSet.item.length.should.equal 2
171
+
172
+ # 'amazon' - Those that are owned and created by AWS
173
+ response = @ec2.describe_images( :owner_id => "amazon" )
174
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
175
+ end
176
+
177
+
178
+ specify "should be able to be described by an owners with Owner.N ID's who can execute AMI's and return an array of Items" do
179
+ @ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ExecutableBy.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
180
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
181
+ @ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
182
+
183
+ # executable by owner ID's
184
+ response = @ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
185
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
186
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
187
+ end
188
+
189
+
190
+ specify "should be able to be described by an owners with Owner.N of 'self' who can execute AMI's and return an array of Items" do
191
+ @ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "self").
192
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
193
+ @ec2.describe_images( :executable_by => "self" ).imagesSet.item.length.should.equal 2
194
+
195
+ # executable by owner ID's
196
+ response = @ec2.describe_images( :executable_by => "self" )
197
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
198
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
199
+ end
200
+
201
+
202
+ specify "should be able to be described by an owners with Owner.N of 'all' who can execute AMI's and return an array of Items" do
203
+ @ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "all").
204
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
205
+ @ec2.describe_images( :executable_by => "all" ).imagesSet.item.length.should.equal 2
206
+
207
+ # executable by owner ID's
208
+ response = @ec2.describe_images( :executable_by => "all" )
209
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
210
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
211
+ end
212
+
213
+
214
+ specify "should be able to be de-registered" do
215
+ @ec2.stubs(:make_request).with('DeregisterImage', {"ImageId"=>"ami-61a54008"}).
216
+ returns stub(:body => @deregister_image_response_body, :is_a? => true)
217
+ @ec2.deregister_image(:image_id => "ami-61a54008" ).should.be.an.instance_of Hash
218
+ @ec2.deregister_image(:image_id => "ami-61a54008" ).return.should.equal "true"
219
+ end
220
+
221
+
222
+ specify "method deregister_image should raise an exception when called without nil/empty string arguments" do
223
+ lambda { @ec2.deregister_image() }.should.raise(AWS::ArgumentError)
224
+ lambda { @ec2.deregister_image( :image_id => nil ) }.should.raise(AWS::ArgumentError)
225
+ lambda { @ec2.deregister_image( :image_id => "" ) }.should.raise(AWS::ArgumentError)
226
+ end
227
+
228
+
229
+ end
@@ -0,0 +1,611 @@
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
+ @start_instances_response_body = <<-RESPONSE
115
+ <StartInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31/">
116
+ <instancesSet>
117
+ <item>
118
+ <instanceId>i-10a64379</instanceId>
119
+ <currentState>
120
+ <code>0</code>
121
+ <name>pending</name>
122
+ </currentState>
123
+ <previousState>
124
+ <code>80</code>
125
+ <name>stopped</name>
126
+ </previousState>
127
+ </item>
128
+ </instancesSet>
129
+ </StartInstancesResponse>
130
+ RESPONSE
131
+
132
+
133
+ @stop_instances_response_body = <<-RESPONSE
134
+ <StopInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31/">
135
+ <instancesSet>
136
+ <item>
137
+ <instanceId>i-28a64341</instanceId>
138
+ <currentState>
139
+ <code>64</code>
140
+ <name>stopping</name>
141
+ </currentState>
142
+ <previousState>
143
+ <code>16</code>
144
+ <name>running</name>
145
+ </previousState>
146
+ </item>
147
+ </instancesSet>
148
+ </StopInstancesResponse>
149
+ RESPONSE
150
+
151
+ @terminate_instances_response_body = <<-RESPONSE
152
+ <TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
153
+ <instancesSet>
154
+ <item>
155
+ <instanceId>i-28a64341</instanceId>
156
+ <shutdownState>
157
+ <code>32</code>
158
+ <name>shutting-down</name>
159
+ </shutdownState>
160
+ <previousState>
161
+ <code>0</code>
162
+ <name>pending</name>
163
+ </previousState>
164
+ </item>
165
+ <item>
166
+ <instanceId>i-21a64348</instanceId>
167
+ <shutdownState>
168
+ <code>32</code>
169
+ <name>shutting-down</name>
170
+ </shutdownState>
171
+ <previousState>
172
+ <code>0</code>
173
+ <name>pending</name>
174
+ </previousState>
175
+ </item>
176
+ </instancesSet>
177
+ </TerminateInstancesResponse>
178
+ RESPONSE
179
+
180
+ @monitor_instances_response_body = <<-RESPONSE
181
+ <MonitorInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/">
182
+ <requestId>fe62a64c-49fb-4a3c-8d9b-61aba146d390</requestId>
183
+ <instancesSet>
184
+ <item>
185
+ <instanceId>i-138fc47a</instanceId>
186
+ <monitoring>
187
+ <state>pending</state>
188
+ </monitoring>
189
+ </item>
190
+ <item>
191
+ <instanceId>i-33457a5a</instanceId>
192
+ <monitoring>
193
+ <state>pending</state>
194
+ </monitoring>
195
+ </item>
196
+ </instancesSet>
197
+ </MonitorInstancesResponse>
198
+ RESPONSE
199
+
200
+ @unmonitor_instances_response_body = <<-RESPONSE
201
+ <UnmonitorInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/">
202
+ <requestId>7dbc5095-f3ae-46d8-a5b1-19df118ceb05</requestId>
203
+ <instancesSet>
204
+ <item>
205
+ <instanceId>i-138fc47a</instanceId>
206
+ <monitoring>
207
+ <state>disabling</state>
208
+ </monitoring>
209
+ </item>
210
+ <item>
211
+ <instanceId>i-33457a5a</instanceId>
212
+ <monitoring>
213
+ <state>disabling</state>
214
+ </monitoring>
215
+ </item>
216
+ </instancesSet>
217
+ </UnmonitorInstancesResponse>
218
+
219
+ RESPONSE
220
+ end
221
+
222
+
223
+ specify "should be able to be run" do
224
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1').
225
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
226
+
227
+ @ec2.run_instances( :image_id => "ami-60a54009" ).should.be.an.instance_of Hash
228
+
229
+ response = @ec2.run_instances( :image_id => "ami-60a54009" )
230
+
231
+ response.reservationId.should.equal "r-47a5402e"
232
+ response.ownerId.should.equal "495219933132"
233
+
234
+ response.instancesSet.item.length.should.equal 3
235
+
236
+ response.instancesSet.item[0].instanceId.should.equal "i-2ba64342"
237
+ response.instancesSet.item[0].imageId.should.equal "ami-60a54009"
238
+ response.instancesSet.item[0].instanceState.code.should.equal "0"
239
+ response.instancesSet.item[0].instanceState.name.should.equal "pending"
240
+ response.instancesSet.item[0].privateDnsName
241
+ response.instancesSet.item[0].dnsName.should.be.nil
242
+ response.instancesSet.item[0].keyName.should.equal "example-key-name"
243
+ response.instancesSet.item[0].instanceType.should.equal "m1.small"
244
+ response.instancesSet.item[0].launchTime.should.equal "2007-08-07T11:51:50.000Z"
245
+
246
+ response.instancesSet.item[1].instanceId.should.equal "i-2bc64242"
247
+ response.instancesSet.item[1].imageId.should.equal "ami-60a54009"
248
+ response.instancesSet.item[1].instanceState.code.should.equal "0"
249
+ response.instancesSet.item[1].instanceState.name.should.equal "pending"
250
+ response.instancesSet.item[1].privateDnsName
251
+ response.instancesSet.item[1].dnsName.should.be.nil
252
+ response.instancesSet.item[1].keyName.should.equal "example-key-name"
253
+ response.instancesSet.item[1].instanceType.should.equal "m1.small"
254
+ response.instancesSet.item[1].launchTime.should.equal "2007-08-07T11:51:50.000Z"
255
+
256
+ response.instancesSet.item[2].instanceId.should.equal "i-2be64332"
257
+ response.instancesSet.item[2].imageId.should.equal "ami-60a54009"
258
+ response.instancesSet.item[2].instanceState.code.should.equal "0"
259
+ response.instancesSet.item[2].instanceState.name.should.equal "pending"
260
+ response.instancesSet.item[2].privateDnsName
261
+ response.instancesSet.item[2].dnsName.should.be.nil
262
+ response.instancesSet.item[2].keyName.should.equal "example-key-name"
263
+ response.instancesSet.item[2].instanceType.should.equal "m1.small"
264
+ response.instancesSet.item[2].launchTime.should.equal "2007-08-07T11:51:50.000Z"
265
+ end
266
+
267
+
268
+ specify "method 'run_instances' should reject invalid arguments" do
269
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1').
270
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
271
+
272
+ lambda { @ec2.run_instances() }.should.raise(AWS::ArgumentError)
273
+
274
+ # :addressing_type is deprecated
275
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => nil ) }.should.not.raise(AWS::ArgumentError)
276
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "" ) }.should.raise(AWS::ArgumentError)
277
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "foo" ) }.should.raise(AWS::ArgumentError)
278
+
279
+ # :group_id is deprecated
280
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :group_id => nil ) }.should.not.raise(AWS::ArgumentError)
281
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :group_id => "" ) }.should.raise(AWS::ArgumentError)
282
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :group_id => "foo" ) }.should.raise(AWS::ArgumentError)
283
+
284
+ # :image_id
285
+ lambda { @ec2.run_instances( :image_id => nil ) }.should.raise(AWS::ArgumentError)
286
+ lambda { @ec2.run_instances( :image_id => "" ) }.should.raise(AWS::ArgumentError)
287
+
288
+ # :min_count
289
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1 ) }.should.not.raise(AWS::ArgumentError)
290
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 0 ) }.should.raise(AWS::ArgumentError)
291
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => nil ) }.should.raise(AWS::ArgumentError)
292
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => "" ) }.should.raise(AWS::ArgumentError)
293
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => "foo" ) }.should.raise(AWS::ArgumentError)
294
+
295
+ # :max_count
296
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 1 ) }.should.not.raise(AWS::ArgumentError)
297
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 0 ) }.should.raise(AWS::ArgumentError)
298
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => nil ) }.should.raise(AWS::ArgumentError)
299
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => "" ) }.should.raise(AWS::ArgumentError)
300
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => "foo" ) }.should.raise(AWS::ArgumentError)
301
+
302
+ # :min_count & :max_count
303
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1 ) }.should.not.raise(AWS::ArgumentError)
304
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 2, :max_count => 1 ) }.should.raise(AWS::ArgumentError)
305
+
306
+ # :instance_type
307
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "InstanceType" => 'm1.small').
308
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
309
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :instance_type => "m1.small" ) }.should.not.raise(AWS::ArgumentError)
310
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :instance_type => "m1.notarealsize" ) }.should.raise(AWS::ArgumentError)
311
+
312
+ # :monitoring_enabled
313
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Monitoring.Enabled" => 'true').
314
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
315
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :monitoring_enabled => true ) }.should.not.raise(AWS::ArgumentError)
316
+
317
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Monitoring.Enabled" => 'false').
318
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
319
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :monitoring_enabled => false ) }.should.not.raise(AWS::ArgumentError)
320
+
321
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Monitoring.Enabled" => 'false').
322
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
323
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :monitoring_enabled => "foo" ) }.should.raise(AWS::ArgumentError)
324
+
325
+ # :disable_api_termination
326
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "DisableApiTermination" => 'true').
327
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
328
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :disable_api_termination => true ) }.should.not.raise(AWS::ArgumentError)
329
+
330
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "DisableApiTermination" => 'false').
331
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
332
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :disable_api_termination => false ) }.should.not.raise(AWS::ArgumentError)
333
+
334
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "DisableApiTermination" => 'false').
335
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
336
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :disable_api_termination => "foo" ) }.should.raise(AWS::ArgumentError)
337
+
338
+ # :instance_initiated_shutdown_behavior
339
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "InstanceInitiatedShutdownBehavior" => 'stop').
340
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
341
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :instance_initiated_shutdown_behavior => 'stop' ) }.should.not.raise(AWS::ArgumentError)
342
+
343
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "InstanceInitiatedShutdownBehavior" => 'terminate').
344
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
345
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :instance_initiated_shutdown_behavior => 'terminate' ) }.should.not.raise(AWS::ArgumentError)
346
+
347
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "InstanceInitiatedShutdownBehavior" => 'stop').
348
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
349
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :instance_initiated_shutdown_behavior => "foo" ) }.should.raise(AWS::ArgumentError)
350
+
351
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "InstanceInitiatedShutdownBehavior" => 'stop').
352
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
353
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :instance_initiated_shutdown_behavior => true ) }.should.raise(AWS::ArgumentError)
354
+
355
+ # :base64_encoded
356
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => true ) }.should.not.raise(AWS::ArgumentError)
357
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => false ) }.should.not.raise(AWS::ArgumentError)
358
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => nil ) }.should.raise(AWS::ArgumentError)
359
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "" ) }.should.raise(AWS::ArgumentError)
360
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "foo" ) }.should.raise(AWS::ArgumentError)
361
+ end
362
+
363
+ specify "should be able specify a key_name" do
364
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "KeyName" => 'foo').
365
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
366
+ @ec2.run_instances( :image_id => "ami-60a54009", :key_name => "foo" ).should.be.an.instance_of Hash
367
+ end
368
+
369
+ specify "should be able specify a security_group" do
370
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "SecurityGroup.1" => 'foo', "SecurityGroup.2" => 'bar').
371
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
372
+ @ec2.run_instances( :image_id => "ami-60a54009", :security_group => ["foo","bar"] ).should.be.an.instance_of Hash
373
+ end
374
+
375
+ specify "should be able specify additional_info" do
376
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AdditionalInfo" => 'foo').
377
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
378
+ @ec2.run_instances( :image_id => "ami-60a54009", :additional_info => "foo" ).should.be.an.instance_of Hash
379
+ end
380
+
381
+ specify "should be able to call run_instances with :user_data and :base64_encoded => true (default is false)" do
382
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "Zm9v").
383
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
384
+ @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of Hash
385
+ end
386
+
387
+ specify "should be able to call run_instances with :user_data and :base64_encoded => false" do
388
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "foo").
389
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
390
+ @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :user_data => "foo", :base64_encoded => false ).should.be.an.instance_of Hash
391
+ end
392
+
393
+ specify "should be able specify instance_type" do
394
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "InstanceType" => 'm1.small').
395
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
396
+ @ec2.run_instances( :image_id => "ami-60a54009", :instance_type => "m1.small" ).should.be.an.instance_of Hash
397
+ end
398
+
399
+ specify "should be able specify an availability_zone (Placement.AvailabilityZone)" do
400
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123").
401
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
402
+ @ec2.run_instances( :image_id => "ami-60a54009", :availability_zone => "zone123" ).should.be.an.instance_of Hash
403
+ end
404
+
405
+ specify "should be able specify an kernel_id" do
406
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', 'KernelId' => 'kernfoo').
407
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
408
+ @ec2.run_instances( :image_id => "ami-60a54009", :kernel_id => 'kernfoo' ).should.be.an.instance_of Hash
409
+ end
410
+
411
+ specify "should be able specify an ramdisk_id" do
412
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', 'RamdiskId' => 'foo').
413
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
414
+ @ec2.run_instances( :image_id => "ami-60a54009", :ramdisk_id => 'foo' ).should.be.an.instance_of Hash
415
+ end
416
+
417
+ specify "should be able specify monitoring_enabled" do
418
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', 'Monitoring.Enabled' => 'true').
419
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
420
+ @ec2.run_instances( :image_id => "ami-60a54009", :monitoring_enabled => true ).should.be.an.instance_of Hash
421
+ end
422
+
423
+ specify "should be able specify an subnet_id" do
424
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', 'SubnetId' => 'foo').
425
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
426
+ @ec2.run_instances( :image_id => "ami-60a54009", :subnet_id => 'foo' ).should.be.an.instance_of Hash
427
+ end
428
+
429
+ specify "should be able specify disable_api_termination" do
430
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', 'DisableApiTermination' => 'true').
431
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
432
+ @ec2.run_instances( :image_id => "ami-60a54009", :disable_api_termination => true ).should.be.an.instance_of Hash
433
+ end
434
+
435
+ specify "should be able specify instance_initiated_shutdown_behavior" do
436
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', 'InstanceInitiatedShutdownBehavior' => 'stop').
437
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
438
+ @ec2.run_instances( :image_id => "ami-60a54009", :instance_initiated_shutdown_behavior => 'stop' ).should.be.an.instance_of Hash
439
+ end
440
+
441
+ specify "should be able specify block_device_mapping" do
442
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', 'BlockDeviceMapping.1.DeviceName' => '/dev/sdh', 'BlockDeviceMapping.1.VirtualName' => 'foo', 'BlockDeviceMapping.1.Ebs.SnapshotId' => 'foosnap', 'BlockDeviceMapping.1.Ebs.VolumeSize' => 'foovolsize', 'BlockDeviceMapping.1.Ebs.DeleteOnTermination' => 'true', 'BlockDeviceMapping.2.DeviceName' => '/dev/sdi', 'BlockDeviceMapping.2.VirtualName' => 'foo2', 'BlockDeviceMapping.2.Ebs.SnapshotId' => 'foosnap2', 'BlockDeviceMapping.2.Ebs.VolumeSize' => 'foovolsize2', 'BlockDeviceMapping.2.Ebs.DeleteOnTermination' => 'false').
443
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
444
+ @ec2.run_instances( :image_id => "ami-60a54009", :block_device_mapping => [{:device_name => '/dev/sdh', :virtual_name => 'foo', :ebs_snapshot_id => 'foosnap', :ebs_volume_size => 'foovolsize', :ebs_delete_on_termination => true},{:device_name => '/dev/sdi', :virtual_name => 'foo2', :ebs_snapshot_id => 'foosnap2', :ebs_volume_size => 'foovolsize2', :ebs_delete_on_termination => false}] ).should.be.an.instance_of Hash
445
+ end
446
+
447
+ specify "should get no user data for when options has no user_data key" do
448
+ @ec2.extract_user_data({}).should == nil
449
+ end
450
+
451
+ specify "should get plain string user data when options has user_data and no base64 key" do
452
+ @ec2.extract_user_data({:user_data => "foo\nbar"}).should == "foo\nbar"
453
+ end
454
+
455
+ specify "should strip new lines and base64 encode when options has both user_data and base64" do
456
+ @ec2.extract_user_data({:user_data => "binary\ndata\nhere\n", :base64_encoded => true}).should == "YmluYXJ5CmRhdGEKaGVyZQo="
457
+ end
458
+
459
+
460
+ specify "should be able to be described and return the correct Ruby response class" do
461
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
462
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
463
+ @ec2.describe_instances.should.be.an.instance_of Hash
464
+ response = @ec2.describe_instances
465
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
466
+ end
467
+
468
+
469
+ specify "should be able to be described with no params and return an array of Items" do
470
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
471
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
472
+ @ec2.describe_instances.reservationSet.item.length.should.equal 1
473
+ response = @ec2.describe_instances
474
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
475
+ response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
476
+ response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
477
+ response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
478
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
479
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
480
+ response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
481
+ response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
482
+ response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
483
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
484
+ end
485
+
486
+
487
+ specify "should be able to be described with params of Array of :instance_id's and return an array of Items" do
488
+ @ec2.stubs(:make_request).with('DescribeInstances', {"InstanceId.1" => "i-28a64341"}).
489
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
490
+ @ec2.describe_instances( :instance_id => "i-28a64341" ).reservationSet.item.length.should.equal 1
491
+ response = @ec2.describe_instances( :instance_id => "i-28a64341" )
492
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
493
+ response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
494
+ response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
495
+ response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
496
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
497
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
498
+ response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
499
+ response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
500
+ response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
501
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
502
+ end
503
+
504
+
505
+ specify "method reboot_instances should raise an exception when called without nil/empty string arguments" do
506
+ lambda { @ec2.reboot_instances() }.should.raise(AWS::ArgumentError)
507
+ lambda { @ec2.reboot_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
508
+ lambda { @ec2.reboot_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
509
+ end
510
+
511
+
512
+ specify "should be able to be rebooted when provided with an :instance_id" do
513
+ @ec2.expects(:make_request).with('RebootInstances', {"InstanceId.1"=>"i-2ea64347", "InstanceId.2"=>"i-21a64348"}).
514
+ returns stub(:body => @reboot_instances_response_body, :is_a? => true)
515
+ @ec2.reboot_instances( :instance_id => ["i-2ea64347", "i-21a64348"] ).class.should.equal Hash
516
+ end
517
+
518
+
519
+ specify "method start_instances should raise an exception when called without nil/empty string arguments" do
520
+ lambda { @ec2.start_instances() }.should.raise(AWS::ArgumentError)
521
+ lambda { @ec2.start_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
522
+ lambda { @ec2.start_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
523
+ end
524
+
525
+
526
+ specify "should be able to be started when provided with an :instance_id" do
527
+ @ec2.stubs(:make_request).with('StartInstances', {"InstanceId.1"=>"i-28a64341", "InstanceId.2"=>"i-21a64348"}).
528
+ returns stub(:body => @start_instances_response_body, :is_a? => true)
529
+ @ec2.start_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal Hash
530
+ end
531
+
532
+
533
+ specify "method stop_instances should raise an exception when called without nil/empty string arguments" do
534
+ lambda { @ec2.stop_instances() }.should.raise(AWS::ArgumentError)
535
+ lambda { @ec2.stop_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
536
+ lambda { @ec2.stop_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
537
+ end
538
+
539
+ specify "should be able to be stopped when provided with an :instance_id" do
540
+ @ec2.stubs(:make_request).with('StopInstances', {"InstanceId.1"=>"i-28a64341", "InstanceId.2"=>"i-21a64348"}).
541
+ returns stub(:body => @stop_instances_response_body, :is_a? => true)
542
+ @ec2.stop_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal Hash
543
+ end
544
+
545
+ specify "method terminate_instances should raise an exception when called without nil/empty string arguments" do
546
+ lambda { @ec2.terminate_instances() }.should.raise(AWS::ArgumentError)
547
+ lambda { @ec2.terminate_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
548
+ lambda { @ec2.terminate_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
549
+ end
550
+
551
+ specify "should be able to be terminated when provided with an :instance_id" do
552
+ @ec2.stubs(:make_request).with('TerminateInstances', {"InstanceId.1"=>"i-28a64341", "InstanceId.2"=>"i-21a64348"}).
553
+ returns stub(:body => @terminate_instances_response_body, :is_a? => true)
554
+ @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal Hash
555
+
556
+ @response = @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] )
557
+
558
+ @response.instancesSet.item[0].instanceId.should.equal "i-28a64341"
559
+ @response.instancesSet.item[0].shutdownState.code.should.equal "32"
560
+ @response.instancesSet.item[0].shutdownState.name.should.equal "shutting-down"
561
+ @response.instancesSet.item[0].previousState.code.should.equal "0"
562
+ @response.instancesSet.item[0].previousState.name.should.equal "pending"
563
+
564
+ @response.instancesSet.item[1].instanceId.should.equal "i-21a64348"
565
+ @response.instancesSet.item[1].shutdownState.code.should.equal "32"
566
+ @response.instancesSet.item[1].shutdownState.name.should.equal "shutting-down"
567
+ @response.instancesSet.item[1].previousState.code.should.equal "0"
568
+ @response.instancesSet.item[1].previousState.name.should.equal "pending"
569
+ end
570
+
571
+ specify "method monitor_instances should raise an exception when called without nil/empty string arguments" do
572
+ lambda { @ec2.monitor_instances() }.should.raise(AWS::ArgumentError)
573
+ lambda { @ec2.monitor_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
574
+ lambda { @ec2.monitor_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
575
+ end
576
+
577
+ specify "should be able to be monitored when provided with an :instance_id" do
578
+ @ec2.stubs(:make_request).with('MonitorInstances', {"InstanceId.1"=>"i-138fc47a", "InstanceId.2"=>"i-33457a5a"}).
579
+ returns stub(:body => @monitor_instances_response_body, :is_a? => true)
580
+ @ec2.monitor_instances( :instance_id => ["i-138fc47a", "i-33457a5a"] ).class.should.equal Hash
581
+
582
+ @response = @ec2.monitor_instances( :instance_id => ["i-138fc47a", "i-33457a5a"] )
583
+
584
+ @response.instancesSet.item[0].instanceId.should.equal "i-138fc47a"
585
+ @response.instancesSet.item[0].monitoring.state.should.equal "pending"
586
+
587
+ @response.instancesSet.item[1].instanceId.should.equal "i-33457a5a"
588
+ @response.instancesSet.item[1].monitoring.state.should.equal "pending"
589
+ end
590
+
591
+ specify "method unmonitor_instances should raise an exception when called without nil/empty string arguments" do
592
+ lambda { @ec2.unmonitor_instances() }.should.raise(AWS::ArgumentError)
593
+ lambda { @ec2.unmonitor_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
594
+ lambda { @ec2.unmonitor_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
595
+ end
596
+
597
+ specify "should be able to be unmonitored when provided with an :instance_id" do
598
+ @ec2.stubs(:make_request).with('UnmonitorInstances', {"InstanceId.1"=>"i-138fc47a", "InstanceId.2"=>"i-33457a5a"}).
599
+ returns stub(:body => @unmonitor_instances_response_body, :is_a? => true)
600
+ @ec2.unmonitor_instances( :instance_id => ["i-138fc47a", "i-33457a5a"] ).class.should.equal Hash
601
+
602
+ @response = @ec2.unmonitor_instances( :instance_id => ["i-138fc47a", "i-33457a5a"] )
603
+
604
+ @response.instancesSet.item[0].instanceId.should.equal "i-138fc47a"
605
+ @response.instancesSet.item[0].monitoring.state.should.equal "disabling"
606
+
607
+ @response.instancesSet.item[1].instanceId.should.equal "i-33457a5a"
608
+ @response.instancesSet.item[1].monitoring.state.should.equal "disabling"
609
+ end
610
+
611
+ end