grempe-amazon-ec2 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/History.txt +230 -0
  2. data/License.txt +66 -0
  3. data/Manifest.txt +46 -0
  4. data/README.txt +154 -0
  5. data/Rakefile +4 -0
  6. data/bin/ec2-gem-example.rb +61 -0
  7. data/bin/ec2sh +73 -0
  8. data/bin/setup.rb +19 -0
  9. data/config/hoe.rb +76 -0
  10. data/config/requirements.rb +17 -0
  11. data/lib/EC2.rb +254 -0
  12. data/lib/EC2/console.rb +44 -0
  13. data/lib/EC2/elastic_ips.rb +153 -0
  14. data/lib/EC2/exceptions.rb +136 -0
  15. data/lib/EC2/image_attributes.rb +166 -0
  16. data/lib/EC2/images.rb +134 -0
  17. data/lib/EC2/instances.rb +206 -0
  18. data/lib/EC2/keypairs.rb +94 -0
  19. data/lib/EC2/products.rb +43 -0
  20. data/lib/EC2/responses.rb +175 -0
  21. data/lib/EC2/security_groups.rb +232 -0
  22. data/lib/EC2/version.rb +18 -0
  23. data/script/destroy +14 -0
  24. data/script/generate +14 -0
  25. data/script/txt2html +74 -0
  26. data/setup.rb +1585 -0
  27. data/tasks/deployment.rake +27 -0
  28. data/tasks/environment.rake +7 -0
  29. data/tasks/website.rake +17 -0
  30. data/test/test_EC2.rb +52 -0
  31. data/test/test_EC2_console.rb +54 -0
  32. data/test/test_EC2_elastic_ips.rb +144 -0
  33. data/test/test_EC2_image_attributes.rb +238 -0
  34. data/test/test_EC2_images.rb +197 -0
  35. data/test/test_EC2_instances.rb +325 -0
  36. data/test/test_EC2_keypairs.rb +123 -0
  37. data/test/test_EC2_products.rb +48 -0
  38. data/test/test_EC2_responses.rb +102 -0
  39. data/test/test_EC2_security_groups.rb +205 -0
  40. data/test/test_EC2_version.rb +44 -0
  41. data/test/test_helper.rb +20 -0
  42. data/website/index.txt +427 -0
  43. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  44. data/website/stylesheets/screen.css +138 -0
  45. data/website/template.rhtml +55 -0
  46. metadata +174 -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:grempe@rubyforge.org)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "An EC2 image " do
14
+
15
+ setup do
16
+ @ec2 = 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 EC2::Response
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(EC2::ArgumentError)
69
+ lambda { @ec2.register_image(:image_location => "") }.should.raise(EC2::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 EC2::Response
77
+ response = @ec2.describe_images
78
+ response.should.be.an.instance_of EC2::Response
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 EC2::Response
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(EC2::ArgumentError)
192
+ lambda { @ec2.deregister_image( :image_id => nil ) }.should.raise(EC2::ArgumentError)
193
+ lambda { @ec2.deregister_image( :image_id => "" ) }.should.raise(EC2::ArgumentError)
194
+ end
195
+
196
+
197
+ end
@@ -0,0 +1,325 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "EC2 instances " do
14
+
15
+ setup do
16
+ @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
+
18
+ @run_instances_response_body = <<-RESPONSE
19
+ <RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-08-29">
20
+ <reservationId>r-47a5402e</reservationId>
21
+ <ownerId>495219933132</ownerId>
22
+ <groupSet>
23
+ <item>
24
+ <groupId>default</groupId>
25
+ </item>
26
+ </groupSet>
27
+ <instancesSet>
28
+ <item>
29
+ <instanceId>i-2ba64342</instanceId>
30
+ <imageId>ami-60a54009</imageId>
31
+ <instanceState>
32
+ <code>0</code>
33
+ <name>pending</name>
34
+ </instanceState>
35
+ <privateDnsName></privateDnsName>
36
+ <dnsName></dnsName>
37
+ <keyName>example-key-name</keyName>
38
+ <amiLaunchIndex>0</amiLaunchIndex>
39
+ <instanceType>m1.small</instanceType>
40
+ <launchTime>2007-08-07T11:51:50.000Z</launchTime>
41
+ </item>
42
+ <item>
43
+ <instanceId>i-2bc64242</instanceId>
44
+ <imageId>ami-60a54009</imageId>
45
+ <instanceState>
46
+ <code>0</code>
47
+ <name>pending</name>
48
+ </instanceState>
49
+ <privateDnsName></privateDnsName>
50
+ <dnsName></dnsName>
51
+ <keyName>example-key-name</keyName>
52
+ <amiLaunchIndex>1</amiLaunchIndex>
53
+ <instanceType>m1.small</instanceType>
54
+ <launchTime>2007-08-07T11:51:50.000Z</launchTime>
55
+ </item>
56
+ <item>
57
+ <instanceId>i-2be64332</instanceId>
58
+ <imageId>ami-60a54009</imageId>
59
+ <instanceState>
60
+ <code>0</code>
61
+ <name>pending</name>
62
+ </instanceState>
63
+ <privateDnsName></privateDnsName>
64
+ <dnsName></dnsName>
65
+ <keyName>example-key-name</keyName>
66
+ <amiLaunchIndex>2</amiLaunchIndex>
67
+ <instanceType>m1.small</instanceType>
68
+ <launchTime>2007-08-07T11:51:50.000Z</launchTime>
69
+ </item>
70
+ </instancesSet>
71
+ </RunInstancesResponse>
72
+ RESPONSE
73
+
74
+ @describe_instances_response_body = <<-RESPONSE
75
+ <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-08-29">
76
+ <reservationSet>
77
+ <item>
78
+ <reservationId>r-44a5402d</reservationId>
79
+ <ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
80
+ <groupSet>
81
+ <item>
82
+ <groupId>default</groupId>
83
+ </item>
84
+ </groupSet>
85
+ <instancesSet>
86
+ <item>
87
+ <instanceId>i-28a64341</instanceId>
88
+ <imageId>ami-6ea54007</imageId>
89
+ <instanceState>
90
+ <code>0</code>
91
+ <name>running</name>
92
+ </instanceState>
93
+ <privateDnsName>domU-12-31-35-00-1E-01.z-2.compute-1.internal</privateDnsName>
94
+ <dnsName>ec2-72-44-33-4.z-2.compute-1.amazonaws.com</dnsName>
95
+ <keyName>example-key-name</keyName>
96
+ <productCodesSet>
97
+ <item><productCode>774F4FF8</productCode></item>
98
+ </productCodesSet>
99
+ <instanceType>m1.small</instanceType>
100
+ <launchTime>2007-08-07T11:54:42.000Z</launchTime>
101
+ </item>
102
+ </instancesSet>
103
+ </item>
104
+ </reservationSet>
105
+ </DescribeInstancesResponse>
106
+ RESPONSE
107
+
108
+ @reboot_instances_response_body = <<-RESPONSE
109
+ <RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
110
+ <return>true</return>
111
+ </RebootInstancesResponse>
112
+ RESPONSE
113
+
114
+ @terminate_instances_response_body = <<-RESPONSE
115
+ <TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
116
+ <instancesSet>
117
+ <item>
118
+ <instanceId>i-28a64341</instanceId>
119
+ <shutdownState>
120
+ <code>32</code>
121
+ <name>shutting-down</name>
122
+ </shutdownState>
123
+ <previousState>
124
+ <code>0</code>
125
+ <name>pending</name>
126
+ </previousState>
127
+ </item>
128
+ <item>
129
+ <instanceId>i-21a64348</instanceId>
130
+ <shutdownState>
131
+ <code>32</code>
132
+ <name>shutting-down</name>
133
+ </shutdownState>
134
+ <previousState>
135
+ <code>0</code>
136
+ <name>pending</name>
137
+ </previousState>
138
+ </item>
139
+ </instancesSet>
140
+ </TerminateInstancesResponse>
141
+ RESPONSE
142
+ end
143
+
144
+
145
+ specify "should be able to be run" do
146
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public', 'InstanceType' => 'm1.small').
147
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
148
+
149
+ @ec2.run_instances( :image_id => "ami-60a54009" ).should.be.an.instance_of EC2::Response
150
+
151
+ response = @ec2.run_instances( :image_id => "ami-60a54009" )
152
+
153
+ response.reservationId.should.equal "r-47a5402e"
154
+ response.ownerId.should.equal "495219933132"
155
+
156
+ response.groupSet.item[0].groupId.should.equal "default"
157
+
158
+ response.instancesSet.item.length.should.equal 3
159
+
160
+ response.instancesSet.item[0].instanceId.should.equal "i-2ba64342"
161
+ response.instancesSet.item[0].imageId.should.equal "ami-60a54009"
162
+ response.instancesSet.item[0].instanceState.code.should.equal "0"
163
+ response.instancesSet.item[0].instanceState.name.should.equal "pending"
164
+ response.instancesSet.item[0].privateDnsName
165
+ response.instancesSet.item[0].dnsName.should.be.nil
166
+ response.instancesSet.item[0].keyName.should.equal "example-key-name"
167
+ response.instancesSet.item[0].instanceType.should.equal "m1.small"
168
+ response.instancesSet.item[0].launchTime.should.equal "2007-08-07T11:51:50.000Z"
169
+
170
+ response.instancesSet.item[1].instanceId.should.equal "i-2bc64242"
171
+ response.instancesSet.item[1].imageId.should.equal "ami-60a54009"
172
+ response.instancesSet.item[1].instanceState.code.should.equal "0"
173
+ response.instancesSet.item[1].instanceState.name.should.equal "pending"
174
+ response.instancesSet.item[1].privateDnsName
175
+ response.instancesSet.item[1].dnsName.should.be.nil
176
+ response.instancesSet.item[1].keyName.should.equal "example-key-name"
177
+ response.instancesSet.item[1].instanceType.should.equal "m1.small"
178
+ response.instancesSet.item[1].launchTime.should.equal "2007-08-07T11:51:50.000Z"
179
+
180
+ response.instancesSet.item[2].instanceId.should.equal "i-2be64332"
181
+ response.instancesSet.item[2].imageId.should.equal "ami-60a54009"
182
+ response.instancesSet.item[2].instanceState.code.should.equal "0"
183
+ response.instancesSet.item[2].instanceState.name.should.equal "pending"
184
+ response.instancesSet.item[2].privateDnsName
185
+ response.instancesSet.item[2].dnsName.should.be.nil
186
+ response.instancesSet.item[2].keyName.should.equal "example-key-name"
187
+ response.instancesSet.item[2].instanceType.should.equal "m1.small"
188
+ response.instancesSet.item[2].launchTime.should.equal "2007-08-07T11:51:50.000Z"
189
+ end
190
+
191
+
192
+ specify "method 'run_instances' should reject invalid arguments" do
193
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public', 'InstanceType' => 'm1.small').
194
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
195
+
196
+ lambda { @ec2.run_instances() }.should.raise(EC2::ArgumentError)
197
+ lambda { @ec2.run_instances( :image_id => "" ) }.should.raise(EC2::ArgumentError)
198
+
199
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1 ) }.should.not.raise(EC2::ArgumentError)
200
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 0 ) }.should.raise(EC2::ArgumentError)
201
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => nil ) }.should.raise(EC2::ArgumentError)
202
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => "" ) }.should.raise(EC2::ArgumentError)
203
+
204
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 1 ) }.should.not.raise(EC2::ArgumentError)
205
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 0 ) }.should.raise(EC2::ArgumentError)
206
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => nil ) }.should.raise(EC2::ArgumentError)
207
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => "" ) }.should.raise(EC2::ArgumentError)
208
+
209
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "public" ) }.should.not.raise(EC2::ArgumentError)
210
+ #lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "direct" ) }.should.not.raise(EC2::ArgumentError)
211
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => nil ) }.should.raise(EC2::ArgumentError)
212
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "" ) }.should.raise(EC2::ArgumentError)
213
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "foo" ) }.should.raise(EC2::ArgumentError)
214
+
215
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => true ) }.should.not.raise(EC2::ArgumentError)
216
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => false ) }.should.not.raise(EC2::ArgumentError)
217
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => nil ) }.should.raise(EC2::ArgumentError)
218
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "" ) }.should.raise(EC2::ArgumentError)
219
+ lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "foo" ) }.should.raise(EC2::ArgumentError)
220
+ end
221
+
222
+
223
+ specify "should be able to call run_instances with :user_data and :base64_encoded => true (default is false)" do
224
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
225
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
226
+ @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of EC2::Response
227
+ end
228
+
229
+
230
+ specify "should be able to call run_instances with :user_data and :base64_encoded => false" do
231
+ @ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
232
+ returns stub(:body => @run_instances_response_body, :is_a? => true)
233
+ @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 EC2::Response
234
+ end
235
+
236
+
237
+ specify "should be able to be described and return the correct Ruby response class" do
238
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
239
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
240
+ @ec2.describe_instances.should.be.an.instance_of EC2::Response
241
+ response = @ec2.describe_instances
242
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
243
+ end
244
+
245
+
246
+ specify "should be able to be described with no params and return an array of Items" do
247
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
248
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
249
+ @ec2.describe_instances.reservationSet.item.length.should.equal 1
250
+ response = @ec2.describe_instances
251
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
252
+ response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
253
+ response.reservationSet.item[0].groupSet.item[0].groupId.should.equal "default"
254
+ response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
255
+ response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
256
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
257
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
258
+ response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
259
+ response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
260
+ response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
261
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
262
+ end
263
+
264
+
265
+ specify "should be able to be described with params of Array of :instance_id's and return an array of Items" do
266
+ @ec2.stubs(:make_request).with('DescribeInstances', {"InstanceId.1" => "i-28a64341"}).
267
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
268
+ @ec2.describe_instances( :instance_id => "i-28a64341" ).reservationSet.item.length.should.equal 1
269
+ response = @ec2.describe_instances( :instance_id => "i-28a64341" )
270
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
271
+ response.reservationSet.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
272
+ response.reservationSet.item[0].groupSet.item[0].groupId.should.equal "default"
273
+ response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "i-28a64341"
274
+ response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "ami-6ea54007"
275
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "0"
276
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "running"
277
+ response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "domU-12-31-35-00-1E-01.z-2.compute-1.internal"
278
+ response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal "ec2-72-44-33-4.z-2.compute-1.amazonaws.com"
279
+ response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
280
+ response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
281
+ end
282
+
283
+
284
+ specify "method reboot_instances should raise an exception when called without nil/empty string arguments" do
285
+ lambda { @ec2.reboot_instances() }.should.raise(EC2::ArgumentError)
286
+ lambda { @ec2.reboot_instances( :instance_id => nil ) }.should.raise(EC2::ArgumentError)
287
+ lambda { @ec2.reboot_instances( :instance_id => "" ) }.should.raise(EC2::ArgumentError)
288
+ end
289
+
290
+
291
+ specify "should be able to be rebooted when provided with an :instance_id" do
292
+ @ec2.expects(:make_request).with('RebootInstances', {"InstanceId.1"=>"i-2ea64347", "InstanceId.2"=>"i-21a64348"}).
293
+ returns stub(:body => @reboot_instances_response_body, :is_a? => true)
294
+ @ec2.reboot_instances( :instance_id => ["i-2ea64347", "i-21a64348"] ).class.should.equal EC2::Response
295
+ end
296
+
297
+
298
+ specify "method terminate_instances should raise an exception when called without nil/empty string arguments" do
299
+ lambda { @ec2.terminate_instances() }.should.raise(EC2::ArgumentError)
300
+ lambda { @ec2.terminate_instances( :instance_id => nil ) }.should.raise(EC2::ArgumentError)
301
+ lambda { @ec2.terminate_instances( :instance_id => "" ) }.should.raise(EC2::ArgumentError)
302
+ end
303
+
304
+
305
+ specify "should be able to be terminated when provided with an :instance_id" do
306
+ @ec2.stubs(:make_request).with('TerminateInstances', {"InstanceId.1"=>"i-28a64341", "InstanceId.2"=>"i-21a64348"}).
307
+ returns stub(:body => @terminate_instances_response_body, :is_a? => true)
308
+ @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal EC2::Response
309
+
310
+ @response = @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] )
311
+
312
+ @response.instancesSet.item[0].instanceId.should.equal "i-28a64341"
313
+ @response.instancesSet.item[0].shutdownState.code.should.equal "32"
314
+ @response.instancesSet.item[0].shutdownState.name.should.equal "shutting-down"
315
+ @response.instancesSet.item[0].previousState.code.should.equal "0"
316
+ @response.instancesSet.item[0].previousState.name.should.equal "pending"
317
+
318
+ @response.instancesSet.item[1].instanceId.should.equal "i-21a64348"
319
+ @response.instancesSet.item[1].shutdownState.code.should.equal "32"
320
+ @response.instancesSet.item[1].shutdownState.name.should.equal "shutting-down"
321
+ @response.instancesSet.item[1].previousState.code.should.equal "0"
322
+ @response.instancesSet.item[1].previousState.name.should.equal "pending"
323
+ end
324
+
325
+ end