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,83 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library, EBS snapshots support
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Yann Klis (mailto:yann.klis@novelys.com)
6
+ # Copyright:: Copyright (c) 2008 Yann Klis
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 snaphots " 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
+ @describe_snapshots_response_body = <<-RESPONSE
19
+ <DescribeSnapshotsResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
20
+ <snapshotId>snap-78a54011</snapshotId>
21
+ <volumeId>vol-4d826724</volumeId>
22
+ <status>pending</status>
23
+ <startTime>2008-05-07T12:51:50.000Z</startTime>
24
+ <progress>80%</progress>
25
+ </DescribeSnapshotsResponse>
26
+ RESPONSE
27
+
28
+ @create_snapshot_response_body = <<-RESPONSE
29
+ <CreateSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
30
+ <snapshotId>snap-78a54011</snapshotId>
31
+ <volumeId>vol-4d826724</volumeId>
32
+ <status>pending</status>
33
+ <startTime>2008-05-07T12:51:50.000Z</startTime>
34
+ <progress></progress>
35
+ </CreateSnapshotResponse>
36
+ RESPONSE
37
+
38
+ @delete_snapshot_response_body = <<-RESPONSE
39
+ <DeleteSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
40
+ <return>true</return>
41
+ </DeleteSnapshotResponse>
42
+ RESPONSE
43
+
44
+ end
45
+
46
+
47
+ specify "should be able to be described with describe_snapshots" do
48
+ @ec2.stubs(:make_request).with('DescribeSnapshots', {'SnapshotId.1' => 'snap-78a54011'}).
49
+ returns stub(:body => @describe_snapshots_response_body, :is_a? => true)
50
+
51
+ @ec2.describe_snapshots( :snapshot_id => "snap-78a54011" ).should.be.an.instance_of Hash
52
+
53
+ response = @ec2.describe_snapshots( :snapshot_id => "snap-78a54011" )
54
+ response.snapshotId.should.equal "snap-78a54011"
55
+ response.volumeId.should.equal "vol-4d826724"
56
+ response.status.should.equal "pending"
57
+ response.progress.should.equal "80%"
58
+ end
59
+
60
+ specify "should be able to be created with a volume_id" do
61
+ @ec2.stubs(:make_request).with('CreateSnapshot', {"VolumeId" => "vol-4d826724"}).
62
+ returns stub(:body => @create_snapshot_response_body, :is_a? => true)
63
+
64
+ @ec2.create_snapshot( :volume_id => "vol-4d826724" ).should.be.an.instance_of Hash
65
+
66
+ response = @ec2.create_snapshot( :volume_id => "vol-4d826724" )
67
+ response.snapshotId.should.equal "snap-78a54011"
68
+ response.volumeId.should.equal "vol-4d826724"
69
+ response.status.should.equal "pending"
70
+ response.progress.should.equal nil
71
+ end
72
+
73
+ specify "should be able to be deleted with a snapsot_id" do
74
+ @ec2.stubs(:make_request).with('DeleteSnapshot', {"SnapshotId" => "snap-78a54011"}).
75
+ returns stub(:body => @delete_snapshot_response_body, :is_a? => true)
76
+
77
+ @ec2.delete_snapshot( :snapshot_id => "snap-78a54011" ).should.be.an.instance_of Hash
78
+
79
+ response = @ec2.delete_snapshot( :snapshot_id => "snap-78a54011" )
80
+ response.return.should.equal "true"
81
+ end
82
+
83
+ end
@@ -0,0 +1,178 @@
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 spot instances request " 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_spot_instances_request_response_body = <<-RESPONSE
19
+ <RequestSpotInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
20
+ <spotInstanceRequestSet>
21
+ <item>
22
+ <spotInstanceRequestId>sir-f102a405</spotInstanceRequestId>
23
+ <spotPrice>0.50</spotPrice>
24
+ <type>one-time</type>
25
+ <state>open</state>
26
+ <fault/>
27
+ <validFrom/>
28
+ <validUntil/>
29
+ <launchGroup/>
30
+ <availabilityZoneGroup>MyAzGroup</availabilityZoneGroup>
31
+ <launchSpecification>
32
+ <imageId> i-43a4412a</imageId>
33
+ <keyName>MyKeypair</keyName>
34
+ <groupSet>websrv</groupSet>
35
+ <instanceType>m1.small</instanceType>
36
+ </launchSpecification>
37
+ <instanceId>i-123345678</instanceId>
38
+ <createTime>2009-10-19T00:00:00+0000</createTime>
39
+ <productDescription/>
40
+ </item>
41
+ </spotInstanceRequestSet>
42
+ </RequestSpotInstancesResponse>
43
+ RESPONSE
44
+
45
+ @describe_spot_instance_requests_response_body = <<-RESPONSE
46
+ <DescribeSpotInstanceRequestsResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
47
+ <spotInstanceRequestSet>
48
+ <item>
49
+ <spotInstanceRequestId>sir-e95fae02</spotInstanceRequestId>
50
+ <spotPrice>0.01</spotPrice>
51
+ <type>one-time</type>
52
+ <state>open</state>
53
+ <createTime>2009-12-04T22:51:14.000Z</createTime>
54
+ <productDescription>Linux/UNIX</productDescription>
55
+ <launchSpecification>
56
+ <imageId>ami-235fba4a</imageId>
57
+ <groupSet>
58
+ <item>
59
+ <groupId>default</groupId>
60
+ </item>
61
+ </groupSet>
62
+ <instanceType>m1.small</instanceType>
63
+ <blockDeviceMapping/>
64
+ <monitoring>
65
+ <enabled>false</enabled>
66
+ </monitoring>
67
+ </launchSpecification>
68
+ <instanceId>i-2fd4ca67</instanceId>
69
+ </item>
70
+ <item>
71
+ <spotInstanceRequestId>sir-e95fae03</spotInstanceRequestId>
72
+ <spotPrice>0.10</spotPrice>
73
+ <type>persistent</type>
74
+ <state>open</state>
75
+ <createTime>2009-12-04T22:51:14.000Z</createTime>
76
+ <productDescription>Linux/UNIX</productDescription>
77
+ <launchSpecification>
78
+ <imageId>ami-235fba4a</imageId>
79
+ <groupSet>
80
+ <item>
81
+ <groupId>default</groupId>
82
+ </item>
83
+ </groupSet>
84
+ <instanceType>m1.medium</instanceType>
85
+ <blockDeviceMapping/>
86
+ <monitoring>
87
+ <enabled>false</enabled>
88
+ </monitoring>
89
+ </launchSpecification>
90
+ <instanceId>i-2fd4ca90</instanceId>
91
+ </item>
92
+ </spotInstanceRequestSet>
93
+ </DescribeSpotInstanceRequestsResponse>
94
+ RESPONSE
95
+
96
+ @cancel_spot_instance_requests_response_body = <<-RESPONSE
97
+ <CancelSpotInstanceRequestsResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
98
+ <requestId>59dbff89-35bd-4eac-99ed-be587ed81825</requestId>
99
+ <spotInstanceRequestSet>
100
+ <item>
101
+ <spotInstanceRequestId>sir-e95fae02</spotInstanceRequestId>
102
+ <state>cancelled</state>
103
+ </item>
104
+ </spotInstanceRequestSet>
105
+ </CancelSpotInstanceRequestsResponse>
106
+ RESPONSE
107
+
108
+ end
109
+
110
+
111
+ specify "should be able to be created" do
112
+ @ec2.stubs(:make_request).with('RequestSpotInstances', {"SpotPrice"=>"0.50", "InstanceCount"=>"1"}).
113
+ returns stub(:body => @create_spot_instances_request_response_body, :is_a? => true)
114
+ @ec2.create_spot_instances_request(:spot_price => "0.50").should.be.an.instance_of Hash
115
+ @ec2.create_spot_instances_request(:spot_price => "0.50").spotInstanceRequestSet.item[0].spotInstanceRequestId.should.equal "sir-f102a405"
116
+ end
117
+
118
+
119
+ specify "method create_spot_instances_request should raise an exception when called with nil/empty string arguments" do
120
+ lambda { @ec2.create_spot_instances_request() }.should.raise(AWS::ArgumentError)
121
+ lambda { @ec2.create_spot_instances_request(:spot_price => "") }.should.raise(AWS::ArgumentError)
122
+ lambda { @ec2.create_spot_instances_request(:spot_price => nil) }.should.raise(AWS::ArgumentError)
123
+ end
124
+
125
+
126
+ specify "should be able to be described and return the correct Ruby response class for parent and members" do
127
+ @ec2.stubs(:make_request).with('DescribeSpotInstanceRequests', {}).
128
+ returns stub(:body => @describe_spot_instance_requests_response_body, :is_a? => true)
129
+ @ec2.describe_spot_instance_requests.should.be.an.instance_of Hash
130
+ response = @ec2.describe_spot_instance_requests
131
+ response.should.be.an.instance_of Hash
132
+ end
133
+
134
+
135
+ specify "should be able to be described with no params and return a spotInstanceRequestSet" do
136
+ @ec2.stubs(:make_request).with('DescribeSpotInstanceRequests', {}).
137
+ returns stub(:body => @describe_spot_instance_requests_response_body, :is_a? => true)
138
+ @ec2.describe_spot_instance_requests.spotInstanceRequestSet.item.length.should.equal 2
139
+ end
140
+
141
+ specify "should be able to be described by an Array of SpotInstanceRequestId.N ID's and return an array of Items" do
142
+ @ec2.stubs(:make_request).with('DescribeSpotInstanceRequests', {"SpotInstanceRequestId.1"=>"sir-e95fae02", "SpotInstanceRequestId.2"=>"sir-e95fae03"}).
143
+ returns stub(:body => @describe_spot_instance_requests_response_body, :is_a? => true)
144
+ @ec2.describe_spot_instance_requests( :spot_instance_request_id => ["sir-e95fae02", "sir-e95fae03"] ).spotInstanceRequestSet.item.length.should.equal 2
145
+
146
+ response = @ec2.describe_spot_instance_requests( :spot_instance_request_id => ["sir-e95fae02", "sir-e95fae03"] )
147
+
148
+ # test first 'Item' object returned
149
+ response.spotInstanceRequestSet.item[0].spotInstanceRequestId.should.equal "sir-e95fae02"
150
+ response.spotInstanceRequestSet.item[0].spotPrice.should.equal "0.01"
151
+ response.spotInstanceRequestSet.item[0].type.should.equal "one-time"
152
+ response.spotInstanceRequestSet.item[0].state.should.equal "open"
153
+ response.spotInstanceRequestSet.item[0].createTime.should.equal "2009-12-04T22:51:14.000Z"
154
+ response.spotInstanceRequestSet.item[0].productDescription.should.equal "Linux/UNIX"
155
+ response.spotInstanceRequestSet.item[0].launchSpecification.imageId.should.equal "ami-235fba4a"
156
+ response.spotInstanceRequestSet.item[0].launchSpecification.instanceType.should.equal "m1.small"
157
+ response.spotInstanceRequestSet.item[0].instanceId.should.equal "i-2fd4ca67"
158
+
159
+ # test second 'Item' object returned
160
+ response.spotInstanceRequestSet.item[1].spotInstanceRequestId.should.equal "sir-e95fae03"
161
+ response.spotInstanceRequestSet.item[1].spotPrice.should.equal "0.10"
162
+ response.spotInstanceRequestSet.item[1].type.should.equal "persistent"
163
+ response.spotInstanceRequestSet.item[1].state.should.equal "open"
164
+ response.spotInstanceRequestSet.item[1].createTime.should.equal "2009-12-04T22:51:14.000Z"
165
+ response.spotInstanceRequestSet.item[1].productDescription.should.equal "Linux/UNIX"
166
+ response.spotInstanceRequestSet.item[1].launchSpecification.imageId.should.equal "ami-235fba4a"
167
+ response.spotInstanceRequestSet.item[1].launchSpecification.instanceType.should.equal "m1.medium"
168
+ response.spotInstanceRequestSet.item[1].instanceId.should.equal "i-2fd4ca90"
169
+ end
170
+
171
+ specify "should be able to be destroyed" do
172
+ @ec2.stubs(:make_request).with('CancelSpotInstanceRequests', {"SpotInstanceRequestId.1"=>"sir-e95fae02"}).
173
+ returns stub(:body => @cancel_spot_instance_requests_response_body, :is_a? => true)
174
+ @ec2.destroy_spot_instance_requests(:spot_instance_request_id => "sir-e95fae02" ).should.be.an.instance_of Hash
175
+ @ec2.destroy_spot_instance_requests(:spot_instance_request_id => "sir-e95fae02" ).spotInstanceRequestSet.item[0].state.should.equal "cancelled"
176
+ end
177
+
178
+ end
@@ -0,0 +1,142 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library, EBS volumes support
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Yann Klis (mailto:yann.klis@novelys.com)
6
+ # Copyright:: Copyright (c) 2008 Yann Klis
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 volumes " 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
+ @describe_volumes_response_body = <<-RESPONSE
19
+ <DescribeVolumesResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
20
+ <volumeSet>
21
+ <item>
22
+ <volumeId>vol-4282672b</volumeId>
23
+ <size>800</size>
24
+ <status>in-use</status>
25
+ <createTime>2008-05-07T11:51:50.000Z</createTime>
26
+ <attachmentSet>
27
+ <item>
28
+ <volumeId>vol-4282672b</volumeId>
29
+ <instanceId>i-6058a509</instanceId>
30
+ <size>800</size>
31
+ <status>attached</status>
32
+ <attachTime>2008-05-07T12:51:50.000Z</attachTime>
33
+ </item>
34
+ </attachmentSet>
35
+ </item>
36
+ </volumeSet>
37
+ </DescribeVolumesResponse>
38
+ RESPONSE
39
+
40
+ @create_volume_response_body = <<-RESPONSE
41
+ <CreateVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
42
+ <volumeId>vol-4d826724</volumeId>
43
+ <size>800</size>
44
+ <status>creating</status>
45
+ <createTime>2008-05-07T11:51:50.000Z</createTime>
46
+ <zone>us-east-1a</zone>
47
+ <snapshotId></snapshotId>
48
+ </CreateVolumeResponse>
49
+ RESPONSE
50
+
51
+ @delete_volume_response_body = <<-RESPONSE
52
+ <ReleaseAddressResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
53
+ <return>true</return>
54
+ </ReleaseAddressResponse>
55
+ RESPONSE
56
+
57
+ @attach_volume_response_body = <<-RESPONSE
58
+ <AttachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
59
+ <volumeId>vol-4d826724</volumeId>
60
+ <instanceId>i-6058a509</instanceId>
61
+ <device>/dev/sdh</device>
62
+ <status>attaching</status>
63
+ <attachTime>2008-05-07T11:51:50.000Z</attachTime>
64
+ </AttachVolumeResponse>
65
+ RESPONSE
66
+
67
+ @detach_volume_response_body = <<-RESPONSE
68
+ <DetachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
69
+ <volumeId>vol-4d826724</volumeId>
70
+ <instanceId>i-6058a509</instanceId>
71
+ <device>/dev/sdh</device>
72
+ <status>detaching</status>
73
+ <attachTime>2008-05-08T11:51:50.000Z</attachTime>
74
+ </DetachVolumeResponse>
75
+ RESPONSE
76
+
77
+ end
78
+
79
+
80
+ specify "should be able to be described with describe_volumes" do
81
+ @ec2.stubs(:make_request).with('DescribeVolumes', {"VolumeId.1"=>"vol-4282672b"}).
82
+ returns stub(:body => @describe_volumes_response_body, :is_a? => true)
83
+
84
+ @ec2.describe_volumes( :volume_id => ["vol-4282672b"] ).should.be.an.instance_of Hash
85
+
86
+ response = @ec2.describe_volumes( :volume_id => ["vol-4282672b"] )
87
+ response.volumeSet.item[0].volumeId.should.equal "vol-4282672b"
88
+ response.volumeSet.item[0].attachmentSet.item[0]['size'].should.equal "800"
89
+ response.volumeSet.item[0].attachmentSet.item[0].volumeId.should.equal "vol-4282672b"
90
+ response.volumeSet.item[0].attachmentSet.item[0].instanceId.should.equal "i-6058a509"
91
+ end
92
+
93
+ specify "should be able to be created with an availability_zone with size" do
94
+ @ec2.stubs(:make_request).with('CreateVolume', {"AvailabilityZone" => "us-east-1a", "Size"=>"800", "SnapshotId"=>""}).
95
+ returns stub(:body => @create_volume_response_body, :is_a? => true)
96
+
97
+ @ec2.create_volume( :availability_zone => "us-east-1a", :size => "800" ).should.be.an.instance_of Hash
98
+
99
+ response = @ec2.create_volume( :availability_zone => "us-east-1a", :size => "800" )
100
+ response.volumeId.should.equal "vol-4d826724"
101
+ response['size'].should.equal "800"
102
+ response.status.should.equal "creating"
103
+ response.zone.should.equal "us-east-1a"
104
+ end
105
+
106
+ specify "should be able to be deleted with a volume_id" do
107
+ @ec2.stubs(:make_request).with('DeleteVolume', {"VolumeId" => "vol-4282672b"}).
108
+ returns stub(:body => @delete_volume_response_body, :is_a? => true)
109
+
110
+ @ec2.delete_volume( :volume_id => "vol-4282672b" ).should.be.an.instance_of Hash
111
+
112
+ response = @ec2.delete_volume( :volume_id => "vol-4282672b" )
113
+ response.return.should.equal "true"
114
+ end
115
+
116
+ specify "should be able to be attached with a volume_id with an instance_id with a device" do
117
+ @ec2.stubs(:make_request).with('AttachVolume', {"VolumeId" => "vol-4d826724", "InstanceId"=>"i-6058a509", "Device"=>"/dev/sdh"}).
118
+ returns stub(:body => @attach_volume_response_body, :is_a? => true)
119
+
120
+ @ec2.attach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509", :device => "/dev/sdh" ).should.be.an.instance_of Hash
121
+
122
+ response = @ec2.attach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509", :device => "/dev/sdh" )
123
+ response.volumeId.should.equal "vol-4d826724"
124
+ response.instanceId.should.equal "i-6058a509"
125
+ response.device.should.equal "/dev/sdh"
126
+ response.status.should.equal "attaching"
127
+ end
128
+
129
+ specify "should be able to be detached with a volume_id with an instance_id" do
130
+ @ec2.stubs(:make_request).with('DetachVolume', {"VolumeId" => "vol-4d826724", "InstanceId"=>"i-6058a509", "Device"=>"", "Force"=>""}).
131
+ returns stub(:body => @detach_volume_response_body, :is_a? => true)
132
+
133
+ @ec2.detach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509" ).should.be.an.instance_of Hash
134
+
135
+ response = @ec2.detach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509" )
136
+ response.volumeId.should.equal "vol-4d826724"
137
+ response.instanceId.should.equal "i-6058a509"
138
+ response.device.should.equal "/dev/sdh"
139
+ response.status.should.equal "detaching"
140
+ end
141
+
142
+ end
@@ -0,0 +1,239 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ context "elb load balancers " do
4
+ before do
5
+ @elb = AWS::ELB::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
6
+
7
+ @valid_create_load_balancer_params = {
8
+ :load_balancer_name => 'Test Name',
9
+ :availability_zones => ['east-1a'],
10
+ :listeners => [{:protocol => 'HTTP', :load_balancer_port => '80', :instance_port => '80'}]
11
+ }
12
+
13
+ @create_load_balancer_response_body = <<-RESPONSE
14
+ <CreateLoadBalancerResult>
15
+ <DNSName>TestLoadBalancer-380544827.us-east-1.ec2.amazonaws.com</DNSName>
16
+ </CreateLoadBalancerResult>
17
+ RESPONSE
18
+
19
+ @valid_delete_load_balancer_params = {
20
+ :load_balancer_name => 'Test Name'
21
+ }
22
+
23
+ @delete_load_balancer_response_body = <<-RESPONSE
24
+ <DeleteLoadBalancerResult>
25
+ <return>true</return>
26
+ </DeleteLoadBalancerResult>
27
+ RESPONSE
28
+
29
+ @valid_describe_load_balancer_params = {
30
+ }
31
+
32
+ @describe_load_balancer_response_body = <<-RESPONSE
33
+ <DescribeLoadBalancersResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2009-05-15/">
34
+ <DescribeLoadBalancersResult>
35
+ <LoadBalancerDescriptions>
36
+ <member>
37
+ <Listeners>
38
+ <member>
39
+ <Protocol>HTTP</Protocol>
40
+ <LoadBalancerPort>80</LoadBalancerPort>
41
+ <InstancePort>80</InstancePort>
42
+ </member>
43
+ </Listeners>
44
+ <CreatedTime>2009-07-02T01:07:55.080Z</CreatedTime>
45
+ <LoadBalancerName>TestLB</LoadBalancerName>
46
+ <DNSName>TestLB-1459724896.us-east-1.elb.amazonaws.com</DNSName>
47
+ <HealthCheck>
48
+ <Interval>30</Interval>
49
+ <Target>TCP:80</Target>
50
+ <HealthyThreshold>10</HealthyThreshold>
51
+ <Timeout>5</Timeout>
52
+ <UnhealthyThreshold>2</UnhealthyThreshold>
53
+ </HealthCheck>
54
+ <Instances/>
55
+ <AvailabilityZones>
56
+ <member>us-east-1a</member>
57
+ </AvailabilityZones>
58
+ </member>
59
+ </LoadBalancerDescriptions>
60
+ </DescribeLoadBalancersResult>
61
+ <ResponseMetadata>
62
+ <RequestId>67dd800e-66a5-11de-b844-07deabfcc881</RequestId>
63
+ </ResponseMetadata>
64
+ </DescribeLoadBalancersResponse>
65
+ RESPONSE
66
+
67
+ @valid_register_instances_with_load_balancer_params = {
68
+ :load_balancer_name => 'Test Name',
69
+ :instances => ['i-6055fa09']
70
+ }
71
+
72
+ @register_instances_with_load_balancer_response_body = <<-RESPONSE
73
+ <RegisterInstancesWithLoadBalancerResult>
74
+ <Instances>
75
+ <member>
76
+ <InstanceId>i-6055fa09</InstanceId>
77
+ </member>
78
+ </Instances>
79
+ </RegisterInstancesWithLoadBalancerResult>
80
+ RESPONSE
81
+
82
+ @valid_deregister_instances_from_load_balancer_params = @valid_register_instances_with_load_balancer_params
83
+ @deregister_instances_from_load_balancer_response_body = <<-RESPONSE
84
+ <DeregisterInstancesFromLoadBalancerResult>
85
+ <Instances/>
86
+ </DeregisterInstancesFromLoadBalancerResult>
87
+ RESPONSE
88
+
89
+ @valid_configure_health_check_params = {
90
+ :load_balancer_name => 'Test Name',
91
+ :health_check => {
92
+ :target => 'HTTP:80/servlets-examples/servlet/',
93
+ :timeout => '2',
94
+ :interval => '5',
95
+ :unhealthy_threshold => '2',
96
+ :healthy_threshold => '2'
97
+ }
98
+ }
99
+ @configure_health_check_response_body = <<-RESPONSE
100
+ <ConfigureHealthCheckResult>
101
+ <HealthCheck>
102
+ <Interval>5</Interval>
103
+ <Target>HTTP:80/servlets-examples/servlet/</Target>
104
+ <HealthyThreshold>2</HealthyThreshold>
105
+ <Timeout>2</Timeout>
106
+ <UnhealthyThreshold>2</UnhealthyThreshold>
107
+ </HealthCheck>
108
+ </ConfigureHealthCheckResult>
109
+ RESPONSE
110
+ end
111
+
112
+ specify "should be able to be created" do
113
+ @elb.stubs(:make_request).with('CreateLoadBalancer', {
114
+ 'LoadBalancerName' => 'Test Name',
115
+ 'AvailabilityZones.member.1' => 'east-1a',
116
+ 'Listeners.member.1.Protocol' => 'HTTP',
117
+ 'Listeners.member.1.LoadBalancerPort' => '80',
118
+ 'Listeners.member.1.InstancePort' => '80'
119
+ }).returns stub(:body => @create_load_balancer_response_body, :is_a? => true)
120
+
121
+ response = @elb.create_load_balancer(@valid_create_load_balancer_params)
122
+ response.should.be.an.instance_of Hash
123
+ response.DNSName.should.equal "TestLoadBalancer-380544827.us-east-1.ec2.amazonaws.com"
124
+ end
125
+
126
+ specify "method create_load_balancer should reject bad arguments" do
127
+ @elb.stubs(:make_request).with('CreateLoadBalancer', {
128
+ 'LoadBalancerName' => 'Test Name',
129
+ 'AvailabilityZones.member.1' => 'east-1a',
130
+ 'Listeners.member.1.Protocol' => 'HTTP',
131
+ 'Listeners.member.1.LoadBalancerPort' => '80',
132
+ 'Listeners.member.1.InstancePort' => '80'
133
+ }).returns stub(:body => @create_load_balancer_response_body, :is_a? => true)
134
+
135
+ lambda { @elb.create_load_balancer(@valid_create_load_balancer_params) }.should.not.raise(AWS::ArgumentError)
136
+ lambda { @elb.create_load_balancer(@valid_create_load_balancer_params.merge(:load_balancer_name=>nil)) }.should.raise(AWS::ArgumentError)
137
+ lambda { @elb.create_load_balancer(@valid_create_load_balancer_params.merge(:load_balancer_name=>'')) }.should.raise(AWS::ArgumentError)
138
+ lambda { @elb.create_load_balancer(@valid_create_load_balancer_params.merge(:availability_zones=>'')) }.should.raise(AWS::ArgumentError)
139
+ lambda { @elb.create_load_balancer(@valid_create_load_balancer_params.merge(:availability_zones=>[])) }.should.raise(AWS::ArgumentError)
140
+ lambda { @elb.create_load_balancer(@valid_create_load_balancer_params.merge(:listeners=>[])) }.should.raise(AWS::ArgumentError)
141
+ lambda { @elb.create_load_balancer(@valid_create_load_balancer_params.merge(:listeners=>nil)) }.should.raise(AWS::ArgumentError)
142
+ end
143
+
144
+ specify "should be able to be deleted with delete_load_balancer" do
145
+ @elb.stubs(:make_request).with('DeleteLoadBalancer', {'LoadBalancerName' => 'Test Name'}).
146
+ returns stub(:body => @delete_load_balancer_response_body, :is_a? => true)
147
+
148
+ response = @elb.delete_load_balancer( :load_balancer_name => "Test Name" )
149
+ response.should.be.an.instance_of Hash
150
+ response.return.should.equal "true"
151
+ end
152
+
153
+ specify "should be able to be described with describe_load_balancer" do
154
+ @elb.stubs(:make_request).with('DescribeLoadBalancers', {}).
155
+ returns stub(:body => @describe_load_balancer_response_body, :is_a? => true)
156
+
157
+ response = @elb.describe_load_balancers()
158
+ response.should.be.an.instance_of Hash
159
+
160
+ response.DescribeLoadBalancersResult.LoadBalancerDescriptions.member.length.should == 1
161
+ end
162
+
163
+ specify "should be able to be register instances to load balancers with register_instances_with_load_balancer" do
164
+ @elb.stubs(:make_request).with('RegisterInstancesWithLoadBalancer', {
165
+ 'LoadBalancerName' => 'Test Name',
166
+ 'Instances.member.1.InstanceId' => 'i-6055fa09'
167
+ }).returns stub(:body => @register_instances_with_load_balancer_response_body, :is_a? => true)
168
+
169
+ response = @elb.register_instances_with_load_balancer(@valid_register_instances_with_load_balancer_params)
170
+ response.should.be.an.instance_of Hash
171
+
172
+ response.Instances.member.length.should == 1
173
+ end
174
+
175
+ specify "method register_instances_with_load_balancer should reject bad arguments" do
176
+ @elb.stubs(:make_request).with('RegisterInstancesWithLoadBalancer', {
177
+ 'LoadBalancerName' => 'Test Name',
178
+ 'Instances.member.1.InstanceId' => 'i-6055fa09'
179
+ }).returns stub(:body => @register_instances_with_load_balancer_response_body, :is_a? => true)
180
+
181
+ lambda { @elb.register_instances_with_load_balancer(@valid_register_instances_with_load_balancer_params) }.should.not.raise(AWS::ArgumentError)
182
+ lambda { @elb.register_instances_with_load_balancer(@valid_register_instances_with_load_balancer_params.merge(:load_balancer_name=>nil)) }.should.raise(AWS::ArgumentError)
183
+ lambda { @elb.register_instances_with_load_balancer(@valid_register_instances_with_load_balancer_params.merge(:instances=>nil)) }.should.raise(AWS::ArgumentError)
184
+ lambda { @elb.register_instances_with_load_balancer(@valid_register_instances_with_load_balancer_params.merge(:instances=>[])) }.should.raise(AWS::ArgumentError)
185
+ end
186
+
187
+ specify "should be able to degresiter instances from load balancers with degregister_instances_from_load_balancer" do
188
+ @elb.stubs(:make_request).with('DeregisterInstancesFromLoadBalancer', {
189
+ 'LoadBalancerName' => 'Test Name',
190
+ 'Instances.member.1' => 'i-6055fa09'
191
+ }).returns stub(:body => @deregister_instances_from_load_balancer_response_body, :is_a? => true)
192
+
193
+ response = @elb.deregister_instances_from_load_balancer(@valid_deregister_instances_from_load_balancer_params)
194
+ response.should.be.an.instance_of Hash
195
+ end
196
+
197
+ specify "method deregister_instances_from_load_balancer should reject bad arguments" do
198
+ @elb.stubs(:make_request).with('DeregisterInstancesFromLoadBalancer', {
199
+ 'LoadBalancerName' => 'Test Name',
200
+ 'Instances.member.1' => 'i-6055fa09'
201
+ }).returns stub(:body => @deregister_instances_from_load_balancer_response_body, :is_a? => true)
202
+
203
+ lambda { @elb.deregister_instances_from_load_balancer(@valid_deregister_instances_from_load_balancer_params) }.should.not.raise(AWS::ArgumentError)
204
+ lambda { @elb.deregister_instances_from_load_balancer(@valid_deregister_instances_from_load_balancer_params.merge(:load_balancer_name=>nil)) }.should.raise(AWS::ArgumentError)
205
+ lambda { @elb.deregister_instances_from_load_balancer(@valid_deregister_instances_from_load_balancer_params.merge(:instances=>nil)) }.should.raise(AWS::ArgumentError)
206
+ lambda { @elb.deregister_instances_from_load_balancer(@valid_deregister_instances_from_load_balancer_params.merge(:instances=>[])) }.should.raise(AWS::ArgumentError)
207
+ end
208
+
209
+ specify "should be able to degresiter instances from load balancers with degregister_instances_from_load_balancer" do
210
+ @elb.stubs(:make_request).with('ConfigureHealthCheck', {
211
+ 'LoadBalancerName' => 'Test Name',
212
+ 'HealthCheck.Interval' => '5',
213
+ 'HealthCheck.Target' => 'HTTP:80/servlets-examples/servlet/',
214
+ 'HealthCheck.HealthyThreshold' => '2',
215
+ 'HealthCheck.Timeout' => '2',
216
+ 'HealthCheck.UnhealthyThreshold' => '2'
217
+ }).returns stub(:body => @configure_health_check_response_body, :is_a? => true)
218
+
219
+ response = @elb.configure_health_check(@valid_configure_health_check_params)
220
+ response.should.be.an.instance_of Hash
221
+ end
222
+
223
+ specify "method degregister_instances_from_load_balancer should reject bad arguments" do
224
+ @elb.stubs(:make_request).with('ConfigureHealthCheck', {
225
+ 'LoadBalancerName' => 'Test Name',
226
+ 'HealthCheck.Interval' => '5',
227
+ 'HealthCheck.Target' => 'HTTP:80/servlets-examples/servlet/',
228
+ 'HealthCheck.HealthyThreshold' => '2',
229
+ 'HealthCheck.Timeout' => '2',
230
+ 'HealthCheck.UnhealthyThreshold' => '2'
231
+ }).returns stub(:body => @configure_health_check_response_body, :is_a? => true)
232
+
233
+ lambda { @elb.configure_health_check(@valid_configure_health_check_params) }.should.not.raise(AWS::ArgumentError)
234
+ lambda { @elb.configure_health_check(@valid_configure_health_check_params.merge(:load_balancer_name=>nil)) }.should.raise(AWS::ArgumentError)
235
+ lambda { @elb.configure_health_check(@valid_configure_health_check_params.merge(:health_check=>nil)) }.should.raise(AWS::ArgumentError)
236
+ end
237
+
238
+ end
239
+