krisr-amazon-ec2 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +6 -0
  2. data/ChangeLog +284 -0
  3. data/LICENSE +66 -0
  4. data/README.rdoc +329 -0
  5. data/Rakefile +101 -0
  6. data/VERSION +1 -0
  7. data/amazon-ec2.gemspec +123 -0
  8. data/bin/ec2-gem-example.rb +66 -0
  9. data/bin/ec2-gem-profile.rb +10 -0
  10. data/bin/ec2sh +62 -0
  11. data/bin/setup.rb +26 -0
  12. data/deps.rip +1 -0
  13. data/lib/AWS.rb +239 -0
  14. data/lib/AWS/EC2.rb +67 -0
  15. data/lib/AWS/EC2/availability_zones.rb +43 -0
  16. data/lib/AWS/EC2/console.rb +46 -0
  17. data/lib/AWS/EC2/elastic_ips.rb +154 -0
  18. data/lib/AWS/EC2/image_attributes.rb +168 -0
  19. data/lib/AWS/EC2/images.rb +136 -0
  20. data/lib/AWS/EC2/instances.rb +218 -0
  21. data/lib/AWS/EC2/keypairs.rb +96 -0
  22. data/lib/AWS/EC2/products.rb +45 -0
  23. data/lib/AWS/EC2/security_groups.rb +234 -0
  24. data/lib/AWS/EC2/snapshots.rb +96 -0
  25. data/lib/AWS/EC2/volumes.rb +172 -0
  26. data/lib/AWS/ELB.rb +57 -0
  27. data/lib/AWS/ELB/load_balancers.rb +201 -0
  28. data/lib/AWS/exceptions.rb +169 -0
  29. data/lib/AWS/responses.rb +61 -0
  30. data/lib/EC2.rb +31 -0
  31. data/perftools/ec2prof +0 -0
  32. data/perftools/ec2prof-results.dot +193 -0
  33. data/perftools/ec2prof-results.txt +126 -0
  34. data/perftools/ec2prof.symbols +129 -0
  35. data/test/test_EC2.rb +68 -0
  36. data/test/test_EC2_availability_zones.rb +49 -0
  37. data/test/test_EC2_console.rb +54 -0
  38. data/test/test_EC2_elastic_ips.rb +144 -0
  39. data/test/test_EC2_image_attributes.rb +238 -0
  40. data/test/test_EC2_images.rb +197 -0
  41. data/test/test_EC2_instances.rb +348 -0
  42. data/test/test_EC2_keypairs.rb +123 -0
  43. data/test/test_EC2_products.rb +48 -0
  44. data/test/test_EC2_responses.rb +52 -0
  45. data/test/test_EC2_s3_xmlsimple.rb +80 -0
  46. data/test/test_EC2_security_groups.rb +205 -0
  47. data/test/test_EC2_snapshots.rb +83 -0
  48. data/test/test_EC2_volumes.rb +142 -0
  49. data/test/test_ELB_load_balancers.rb +238 -0
  50. data/test/test_helper.rb +19 -0
  51. data/wsdl/2007-08-29.ec2.wsdl +1269 -0
  52. data/wsdl/2008-02-01.ec2.wsdl +1614 -0
  53. data/wsdl/2008-05-05.ec2.wsdl +2052 -0
  54. data/wsdl/2008-12-01.ec2.wsdl +2354 -0
  55. metadata +184 -0
@@ -0,0 +1,197 @@
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
+ @register_image_response_body = <<-RESPONSE
19
+ <RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
20
+ <imageId>ami-61a54008</imageId>
21
+ </RegisterImageResponse>
22
+ RESPONSE
23
+
24
+ @describe_image_response_body = <<-RESPONSE
25
+ <DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
26
+ <imagesSet>
27
+ <item>
28
+ <imageId>ami-61a54008</imageId>
29
+ <imageLocation>foobar1/image.manifest.xml</imageLocation>
30
+ <imageState>available</imageState>
31
+ <imageOwnerId>AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA</imageOwnerId>
32
+ <isPublic>true</isPublic>
33
+ <productCodes>
34
+ <item>
35
+ <productCode>774F4FF8</productCode>
36
+ </item>
37
+ </productCodes>
38
+ </item>
39
+ <item>
40
+ <imageId>ami-61a54009</imageId>
41
+ <imageLocation>foobar2/image.manifest.xml</imageLocation>
42
+ <imageState>deregistered</imageState>
43
+ <imageOwnerId>ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ</imageOwnerId>
44
+ <isPublic>false</isPublic>
45
+ </item>
46
+ </imagesSet>
47
+ </DescribeImagesResponse>
48
+ RESPONSE
49
+
50
+ @deregister_image_response_body = <<-RESPONSE
51
+ <DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
52
+ <return>true</return>
53
+ </DeregisterImageResponse>
54
+ RESPONSE
55
+
56
+ end
57
+
58
+
59
+ specify "should be able to be registered" do
60
+ @ec2.stubs(:make_request).with('RegisterImage', {"ImageLocation"=>"mybucket-myimage.manifest.xml"}).
61
+ returns stub(:body => @register_image_response_body, :is_a? => true)
62
+ @ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").imageId.should.equal "ami-61a54008"
63
+ @ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").should.be.an.instance_of Hash
64
+ end
65
+
66
+
67
+ specify "method register_image should raise an exception when called without nil/empty string arguments" do
68
+ lambda { @ec2.register_image() }.should.raise(AWS::ArgumentError)
69
+ lambda { @ec2.register_image(:image_location => "") }.should.raise(AWS::ArgumentError)
70
+ end
71
+
72
+
73
+ specify "should be able to be described and return the correct Ruby response class for parent and members" do
74
+ @ec2.stubs(:make_request).with('DescribeImages', {}).
75
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
76
+ @ec2.describe_images.should.be.an.instance_of Hash
77
+ response = @ec2.describe_images
78
+ response.should.be.an.instance_of Hash
79
+ end
80
+
81
+
82
+ specify "should be able to be described with no params and return an imagesSet" do
83
+ @ec2.stubs(:make_request).with('DescribeImages', {}).
84
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
85
+ @ec2.describe_images.imagesSet.item.length.should.equal 2
86
+ end
87
+
88
+ specify "should be able to be described by an Array of ImageId.N ID's and return an array of Items" do
89
+ @ec2.stubs(:make_request).with('DescribeImages', {"ImageId.1"=>"ami-61a54008", "ImageId.2"=>"ami-61a54009"}).
90
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
91
+ @ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] ).imagesSet.item.length.should.equal 2
92
+
93
+ response = @ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] )
94
+
95
+ # test first 'Item' object returned
96
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
97
+ response.imagesSet.item[0].imageLocation.should.equal "foobar1/image.manifest.xml"
98
+ response.imagesSet.item[0].imageState.should.equal "available"
99
+ response.imagesSet.item[0].imageOwnerId.should.equal "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA"
100
+ response.imagesSet.item[0].isPublic.should.equal "true"
101
+ response.imagesSet.item[0].productCodes.item[0].productCode.should.equal "774F4FF8"
102
+
103
+ # test second 'Item' object returned
104
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
105
+ response.imagesSet.item[1].imageLocation.should.equal "foobar2/image.manifest.xml"
106
+ response.imagesSet.item[1].imageState.should.equal "deregistered"
107
+ response.imagesSet.item[1].imageOwnerId.should.equal "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"
108
+ response.imagesSet.item[1].isPublic.should.equal "false"
109
+ end
110
+
111
+
112
+ specify "should be able to be described by an owners with Owner.N ID's and return an array of Items" do
113
+ @ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "Owner.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
114
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
115
+ @ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
116
+
117
+ # owner ID's
118
+ response = @ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
119
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
120
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
121
+ end
122
+
123
+
124
+ specify "should be able to be described by an owner of 'self' and return an array of Items that I own" do
125
+ @ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "self").
126
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
127
+ @ec2.describe_images( :owner_id => "self" ).imagesSet.item.length.should.equal 2
128
+
129
+ # 'self' - Those that I own
130
+ response = @ec2.describe_images( :owner_id => "self" )
131
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
132
+ end
133
+
134
+
135
+ 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
136
+ @ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "amazon").
137
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
138
+ @ec2.describe_images( :owner_id => "amazon" ).imagesSet.item.length.should.equal 2
139
+
140
+ # 'amazon' - Those that are owned and created by AWS
141
+ response = @ec2.describe_images( :owner_id => "amazon" )
142
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
143
+ end
144
+
145
+
146
+ 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
147
+ @ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ExecutableBy.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
148
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
149
+ @ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
150
+
151
+ # executable by owner ID's
152
+ response = @ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
153
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
154
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
155
+ end
156
+
157
+
158
+ 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
159
+ @ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "self").
160
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
161
+ @ec2.describe_images( :executable_by => "self" ).imagesSet.item.length.should.equal 2
162
+
163
+ # executable by owner ID's
164
+ response = @ec2.describe_images( :executable_by => "self" )
165
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
166
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
167
+ end
168
+
169
+
170
+ 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
171
+ @ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "all").
172
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
173
+ @ec2.describe_images( :executable_by => "all" ).imagesSet.item.length.should.equal 2
174
+
175
+ # executable by owner ID's
176
+ response = @ec2.describe_images( :executable_by => "all" )
177
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
178
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
179
+ end
180
+
181
+
182
+ specify "should be able to be de-registered" do
183
+ @ec2.stubs(:make_request).with('DeregisterImage', {"ImageId"=>"ami-61a54008"}).
184
+ returns stub(:body => @deregister_image_response_body, :is_a? => true)
185
+ @ec2.deregister_image(:image_id => "ami-61a54008" ).should.be.an.instance_of Hash
186
+ @ec2.deregister_image(:image_id => "ami-61a54008" ).return.should.equal "true"
187
+ end
188
+
189
+
190
+ specify "method deregister_image should raise an exception when called without nil/empty string arguments" do
191
+ lambda { @ec2.deregister_image() }.should.raise(AWS::ArgumentError)
192
+ lambda { @ec2.deregister_image( :image_id => nil ) }.should.raise(AWS::ArgumentError)
193
+ lambda { @ec2.deregister_image( :image_id => "" ) }.should.raise(AWS::ArgumentError)
194
+ end
195
+
196
+
197
+ end
@@ -0,0 +1,348 @@
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
+ 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(AWS::ArgumentError)
197
+ lambda { @ec2.run_instances( :image_id => "" ) }.should.raise(AWS::ArgumentError)
198
+
199
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1 ) }.should.not.raise(AWS::ArgumentError)
200
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 0 ) }.should.raise(AWS::ArgumentError)
201
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => nil ) }.should.raise(AWS::ArgumentError)
202
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => "" ) }.should.raise(AWS::ArgumentError)
203
+
204
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 1 ) }.should.not.raise(AWS::ArgumentError)
205
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 0 ) }.should.raise(AWS::ArgumentError)
206
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => nil ) }.should.raise(AWS::ArgumentError)
207
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => "" ) }.should.raise(AWS::ArgumentError)
208
+
209
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "public" ) }.should.not.raise(AWS::ArgumentError)
210
+ #lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "direct" ) }.should.not.raise(AWS::ArgumentError)
211
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => nil ) }.should.raise(AWS::ArgumentError)
212
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "" ) }.should.raise(AWS::ArgumentError)
213
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "foo" ) }.should.raise(AWS::ArgumentError)
214
+
215
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => true ) }.should.not.raise(AWS::ArgumentError)
216
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => false ) }.should.not.raise(AWS::ArgumentError)
217
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => nil ) }.should.raise(AWS::ArgumentError)
218
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "" ) }.should.raise(AWS::ArgumentError)
219
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "foo" ) }.should.raise(AWS::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" => "Zm9v", "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" => "Zm9v", "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" => "Zm9v", "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" => "foo", "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
+ specify "should get no user data for when options has no user_data key" do
248
+ @ec2.extract_user_data({}).should == nil
249
+ end
250
+
251
+ specify "should get plain string user data when options has user_data and no base64 key" do
252
+ @ec2.extract_user_data({:user_data => "foo\nbar"}).should == "foo\nbar"
253
+ end
254
+
255
+ specify "should strip new lines and base64 encode when options has both user_data and base64" do
256
+ @ec2.extract_user_data({:user_data => "binary\ndata\nhere\n", :base64_encoded => true}).should == "YmluYXJ5CmRhdGEKaGVyZQo="
257
+ end
258
+
259
+
260
+ specify "should be able to be described and return the correct Ruby response class" do
261
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
262
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
263
+ @ec2.describe_instances.should.be.an.instance_of Hash
264
+ response = @ec2.describe_instances
265
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
266
+ end
267
+
268
+
269
+ specify "should be able to be described with no params and return an array of Items" do
270
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
271
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
272
+ @ec2.describe_instances.reservationSet.item.length.should.equal 1
273
+ response = @ec2.describe_instances
274
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
275
+ response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
276
+ response.reservationSet.item[0].groupSet.item[0].groupId.should.equal "default"
277
+ response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
278
+ response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
279
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
280
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
281
+ response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
282
+ response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
283
+ response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
284
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
285
+ end
286
+
287
+
288
+ specify "should be able to be described with params of Array of :instance_id's and return an array of Items" do
289
+ @ec2.stubs(:make_request).with('DescribeInstances', {"InstanceId.1" => "i-28a64341"}).
290
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
291
+ @ec2.describe_instances( :instance_id => "i-28a64341" ).reservationSet.item.length.should.equal 1
292
+ response = @ec2.describe_instances( :instance_id => "i-28a64341" )
293
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
294
+ response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
295
+ response.reservationSet.item[0].groupSet.item[0].groupId.should.equal "default"
296
+ response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
297
+ response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
298
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
299
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
300
+ response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
301
+ response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
302
+ response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
303
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
304
+ end
305
+
306
+
307
+ specify "method reboot_instances should raise an exception when called without nil/empty string arguments" do
308
+ lambda { @ec2.reboot_instances() }.should.raise(AWS::ArgumentError)
309
+ lambda { @ec2.reboot_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
310
+ lambda { @ec2.reboot_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
311
+ end
312
+
313
+
314
+ specify "should be able to be rebooted when provided with an :instance_id" do
315
+ @ec2.expects(:make_request).with('RebootInstances', {"InstanceId.1"=>"i-2ea64347", "InstanceId.2"=>"i-21a64348"}).
316
+ returns stub(:body => @reboot_instances_response_body, :is_a? => true)
317
+ @ec2.reboot_instances( :instance_id => ["i-2ea64347", "i-21a64348"] ).class.should.equal Hash
318
+ end
319
+
320
+
321
+ specify "method terminate_instances should raise an exception when called without nil/empty string arguments" do
322
+ lambda { @ec2.terminate_instances() }.should.raise(AWS::ArgumentError)
323
+ lambda { @ec2.terminate_instances( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
324
+ lambda { @ec2.terminate_instances( :instance_id => "" ) }.should.raise(AWS::ArgumentError)
325
+ end
326
+
327
+
328
+ specify "should be able to be terminated when provided with an :instance_id" do
329
+ @ec2.stubs(:make_request).with('TerminateInstances', {"InstanceId.1"=>"i-28a64341", "InstanceId.2"=>"i-21a64348"}).
330
+ returns stub(:body => @terminate_instances_response_body, :is_a? => true)
331
+ @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal Hash
332
+
333
+ @response = @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] )
334
+
335
+ @response.instancesSet.item[0].instanceId.should.equal "i-28a64341"
336
+ @response.instancesSet.item[0].shutdownState.code.should.equal "32"
337
+ @response.instancesSet.item[0].shutdownState.name.should.equal "shutting-down"
338
+ @response.instancesSet.item[0].previousState.code.should.equal "0"
339
+ @response.instancesSet.item[0].previousState.name.should.equal "pending"
340
+
341
+ @response.instancesSet.item[1].instanceId.should.equal "i-21a64348"
342
+ @response.instancesSet.item[1].shutdownState.code.should.equal "32"
343
+ @response.instancesSet.item[1].shutdownState.name.should.equal "shutting-down"
344
+ @response.instancesSet.item[1].previousState.code.should.equal "0"
345
+ @response.instancesSet.item[1].previousState.name.should.equal "pending"
346
+ end
347
+
348
+ end