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,68 @@
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 "The EC2 method " do
14
+
15
+ before do
16
+ end
17
+
18
+ specify "AWS::EC2::Base attribute readers should be available" do
19
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key",
20
+ :secret_access_key => "not a secret",
21
+ :use_ssl => true,
22
+ :server => "foo.example.com" )
23
+
24
+ @ec2.use_ssl.should.equal true
25
+ @ec2.port.should.equal 443
26
+ @ec2.server.should.equal "foo.example.com"
27
+ end
28
+
29
+ specify "AWS::EC2::Base should work with insecure connections as well" do
30
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key",
31
+ :secret_access_key => "not a secret",
32
+ :use_ssl => false,
33
+ :server => "foo.example.com" )
34
+
35
+ @ec2.use_ssl.should.equal false
36
+ @ec2.port.should.equal 80
37
+ @ec2.server.should.equal "foo.example.com"
38
+ end
39
+
40
+ specify "AWS::EC2::Base should allow specification of port" do
41
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key",
42
+ :secret_access_key => "not a secret",
43
+ :use_ssl => true,
44
+ :server => "foo.example.com",
45
+ :port => 8443 )
46
+
47
+ @ec2.use_ssl.should.equal true
48
+ @ec2.port.should.equal 8443
49
+ @ec2.server.should.equal "foo.example.com"
50
+ end
51
+
52
+ specify "AWS.canonical_string(path) should conform to Amazon's requirements " do
53
+ path = {"name1" => "value1", "name2" => "value2", "name3" => "value3"}
54
+ if ENV['EC2_URL'].nil? || ENV['EC2_URL'] == 'https://ec2.amazonaws.com'
55
+ AWS.canonical_string(path, 'ec2.amazonaws.com').should.equal "POST\nec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
56
+ elsif ENV['EC2_URL'] == 'https://us-east-1.ec2.amazonaws.com'
57
+ AWS.canonical_string(path, 'ec2.amazonaws.com').should.equal "POST\nus-east-1.ec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
58
+ elsif ENV['EC2_URL'] == 'https://eu-west-1.ec2.amazonaws.com'
59
+ AWS.canonical_string(path, 'ec2.amazonaws.com').should.equal "POST\neu-west-1.ec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
60
+ end
61
+ end
62
+
63
+ specify "AWS.encode should return the expected string" do
64
+ AWS.encode("secretaccesskey", "foobar123", urlencode=true).should.equal "e3jeuDc3DIX2mW8cVqWiByj4j5g%3D"
65
+ AWS.encode("secretaccesskey", "foobar123", urlencode=false).should.equal "e3jeuDc3DIX2mW8cVqWiByj4j5g="
66
+ end
67
+
68
+ end
@@ -0,0 +1,49 @@
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 availability zones" 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_availability_zones_response_body = <<-RESPONSE
19
+ <DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01/">
20
+ <availabilityZoneInfo>
21
+ <item>
22
+ <zoneName>us-east-1a</zoneName>
23
+ <zoneState>available</zoneState>
24
+ </item>
25
+ <item>
26
+ <zoneName>us-east-1b</zoneName>
27
+ <zoneState>available</zoneState>
28
+ </item>
29
+ </availabilityZoneInfo>
30
+ </DescribeAvailabilityZonesResponse>
31
+ RESPONSE
32
+
33
+ end
34
+
35
+ specify "should be able to be described with describe_availability_zones" do
36
+ @ec2.stubs(:make_request).with('DescribeAvailabilityZones', { "ZoneName.1" => "us-east-1a", "ZoneName.2" => "us-east-1b" }).
37
+ returns stub(:body => @describe_availability_zones_response_body, :is_a? => true)
38
+ @ec2.describe_availability_zones( :zone_name => ["us-east-1a", "us-east-1b"] ).should.be.an.instance_of Hash
39
+
40
+ response = @ec2.describe_availability_zones( :zone_name => ["us-east-1a", "us-east-1b"] )
41
+
42
+ response.availabilityZoneInfo.item[0].zoneName.should.equal "us-east-1a"
43
+ response.availabilityZoneInfo.item[0].zoneState.should.equal "available"
44
+
45
+ response.availabilityZoneInfo.item[1].zoneName.should.equal "us-east-1b"
46
+ response.availabilityZoneInfo.item[1].zoneState.should.equal "available"
47
+ end
48
+
49
+ end
@@ -0,0 +1,54 @@
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 "The EC2 console " 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
+ @get_console_output_response_body = <<-RESPONSE
19
+ <GetConsoleOutputResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
20
+ <instanceId>i-28a64341</instanceId>
21
+ <timestamp>2007-01-03 15:00:00</timestamp>
22
+ <output>
23
+ YyB2ZXJzaW9uIDQuMC4xIDIwMDUwNzI3IChSZWQgSGF0IDQuMC4xLTUpKSAjMSBTTVAgVGh1IE9j
24
+ dCAyNiAwODo0MToyNiBTQVNUIDIwMDYKQklPUy1wcm92aWRlZCBwaHlzaWNhbCBSQU0gbWFwOgpY
25
+ ZW46IDAwMDAwMDAwMDAwMDAwMDAgLSAwMDAwMDAwMDZhNDAwMDAwICh1c2FibGUpCjk4ME1CIEhJ
26
+ R0hNRU0gYXZhaWxhYmxlLgo3MjdNQiBMT1dNRU0gYXZhaWxhYmxlLgpOWCAoRXhlY3V0ZSBEaXNh
27
+ YmxlKSBwcm90ZWN0aW9uOiBhY3RpdmUKSVJRIGxvY2t1cCBkZXRlY3Rpb24gZGlzYWJsZWQKQnVp
28
+ bHQgMSB6b25lbGlzdHMKS2VybmVsIGNvbW1hbmQgbGluZTogcm9vdD0vZGV2L3NkYTEgcm8gNApF
29
+ bmFibGluZyBmYXN0IEZQVSBzYXZlIGFuZCByZXN0b3JlLi4uIGRvbmUuCg==
30
+ </output>
31
+ </GetConsoleOutputResponse>
32
+ RESPONSE
33
+
34
+ end
35
+
36
+
37
+ specify "should return info written to a specific instances console" do
38
+ @ec2.stubs(:make_request).with('GetConsoleOutput', {"InstanceId"=>"i-2ea64347"}).
39
+ returns stub(:body => @get_console_output_response_body, :is_a? => true)
40
+ @ec2.get_console_output( :instance_id => "i-2ea64347" ).should.be.an.instance_of Hash
41
+ response = @ec2.get_console_output( :instance_id => "i-2ea64347" )
42
+ response.instanceId.should.equal "i-28a64341"
43
+ response.timestamp.should.equal "2007-01-03 15:00:00"
44
+ end
45
+
46
+
47
+ specify "method get_console_output should raise an exception when called without nil/empty string arguments" do
48
+ lambda { @ec2.get_console_output() }.should.raise(AWS::ArgumentError)
49
+ lambda { @ec2.get_console_output(:instance_id => nil) }.should.raise(AWS::ArgumentError)
50
+ lambda { @ec2.get_console_output(:instance_id => "") }.should.raise(AWS::ArgumentError)
51
+ end
52
+
53
+
54
+ end
@@ -0,0 +1,144 @@
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 elastic IP addresses " 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
+ @allocate_address_body = <<-RESPONSE
19
+ <AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01">
20
+ <publicIp>67.202.55.255</publicIp>
21
+ </AllocateAddressResponse>
22
+ RESPONSE
23
+
24
+ @describe_addresses_response_body = <<-RESPONSE
25
+ <DescribeAddressesResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01">
26
+ <addressesSet>
27
+ <item>
28
+ <instanceId>i-28a64341</instanceId>
29
+ <publicIp>67.202.55.255</publicIp>
30
+ </item>
31
+ </addressesSet>
32
+ </DescribeAddressesResponse>
33
+ RESPONSE
34
+
35
+ @release_address_response_body = <<-RESPONSE
36
+ <ReleaseAddressResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01">
37
+ <return>true</return>
38
+ </ReleaseAddressResponse>
39
+ RESPONSE
40
+
41
+ @associate_address_response_body = <<-RESPONSE
42
+ <AssociateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01">
43
+ <return>true</return>
44
+ </AssociateAddressResponse>
45
+ RESPONSE
46
+
47
+ @disassociate_address_response_body = <<-RESPONSE
48
+ <DisassociateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01">
49
+ <return>true</return>
50
+ </DisassociateAddressResponse>
51
+ RESPONSE
52
+
53
+ end
54
+
55
+
56
+ specify "should be able to be created" do
57
+ @ec2.stubs(:make_request).with('AllocateAddress', {}).
58
+ returns stub(:body => @allocate_address_body, :is_a? => true)
59
+
60
+ @ec2.allocate_address.should.be.an.instance_of Hash
61
+
62
+ response = @ec2.allocate_address
63
+ response.publicIp.should.equal "67.202.55.255"
64
+ end
65
+
66
+
67
+ #specify "method create_keypair should reject bad arguments" do
68
+ # @ec2.stubs(:make_request).with('CreateKeyPair', {"KeyName"=>"example-key-name"}).
69
+ # returns stub(:body => @create_keypair_response_body, :is_a? => true)
70
+ #
71
+ # lambda { @ec2.create_keypair( :key_name => "example-key-name" ) }.should.not.raise(AWS::ArgumentError)
72
+ # lambda { @ec2.create_keypair() }.should.raise(AWS::ArgumentError)
73
+ # lambda { @ec2.create_keypair( :key_name => nil ) }.should.raise(AWS::ArgumentError)
74
+ # lambda { @ec2.create_keypair( :key_name => "" ) }.should.raise(AWS::ArgumentError)
75
+ #end
76
+
77
+
78
+ specify "should be able to be described with describe_addresses" do
79
+ @ec2.stubs(:make_request).with('DescribeAddresses', {"PublicIp.1"=>"67.202.55.255"}).
80
+ returns stub(:body => @describe_addresses_response_body, :is_a? => true)
81
+
82
+ @ec2.describe_addresses( :public_ip => "67.202.55.255" ).should.be.an.instance_of Hash
83
+
84
+ response = @ec2.describe_addresses( :public_ip => "67.202.55.255" )
85
+ response.addressesSet.item[0].instanceId.should.equal "i-28a64341"
86
+ response.addressesSet.item[0].publicIp.should.equal "67.202.55.255"
87
+ end
88
+
89
+
90
+ specify "should be able to be released with release_address" do
91
+ @ec2.stubs(:make_request).with('ReleaseAddress', {"PublicIp" => "67.202.55.255"}).
92
+ returns stub(:body => @release_address_response_body, :is_a? => true)
93
+
94
+ @ec2.release_address( :public_ip => "67.202.55.255" ).should.be.an.instance_of Hash
95
+
96
+ response = @ec2.release_address( :public_ip => "67.202.55.255" )
97
+ response.return.should.equal "true"
98
+ end
99
+
100
+
101
+ specify "should be able to be associated with an instance with associate_address" do
102
+ @ec2.stubs(:make_request).with('AssociateAddress', {"InstanceId" => "i-2ea64347", "PublicIp"=>"67.202.55.255"}).
103
+ returns stub(:body => @associate_address_response_body, :is_a? => true)
104
+
105
+ @ec2.associate_address( :instance_id => "i-2ea64347", :public_ip => "67.202.55.255" ).should.be.an.instance_of Hash
106
+
107
+ response = @ec2.associate_address( :instance_id => "i-2ea64347", :public_ip => "67.202.55.255" )
108
+ response.return.should.equal "true"
109
+ end
110
+
111
+
112
+ specify "method associate_address should reject bad arguments" do
113
+ @ec2.stubs(:make_request).with('AssociateAddress', {"InstanceId" => "i-2ea64347", "PublicIp"=>"67.202.55.255"}).
114
+ returns stub(:body => @associate_address_response_body, :is_a? => true)
115
+
116
+ lambda { @ec2.associate_address( :instance_id => "i-2ea64347", :public_ip => "67.202.55.255" ) }.should.not.raise(AWS::ArgumentError)
117
+ lambda { @ec2.associate_address() }.should.raise(AWS::ArgumentError)
118
+ lambda { @ec2.associate_address( :instance_id => nil ) }.should.raise(AWS::ArgumentError)
119
+ lambda { @ec2.associate_address( :public_ip => "" ) }.should.raise(AWS::ArgumentError)
120
+ end
121
+
122
+
123
+ specify "should be able to be disassociated with an instance with disassociate_address" do
124
+ @ec2.stubs(:make_request).with('DisassociateAddress', {'PublicIp' => '67.202.55.255'}).
125
+ returns stub(:body => @disassociate_address_response_body, :is_a? => true)
126
+
127
+ @ec2.disassociate_address( :public_ip => "67.202.55.255" ).should.be.an.instance_of Hash
128
+
129
+ response = @ec2.disassociate_address( :public_ip => "67.202.55.255" )
130
+ response.return.should.equal "true"
131
+ end
132
+
133
+
134
+ specify "method disassociate_address should reject bad arguments" do
135
+ @ec2.stubs(:make_request).with('DisassociateAddress', {'PublicIp' => '67.202.55.255'}).
136
+ returns stub(:body => @disassociate_address_response_body, :is_a? => true)
137
+
138
+ lambda { @ec2.disassociate_address( :public_ip => "67.202.55.255" ) }.should.not.raise(AWS::ArgumentError)
139
+ lambda { @ec2.disassociate_address() }.should.raise(AWS::ArgumentError)
140
+ lambda { @ec2.disassociate_address( :public_ip => "" ) }.should.raise(AWS::ArgumentError)
141
+ end
142
+
143
+
144
+ end
@@ -0,0 +1,238 @@
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 image_attributes " 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
+ @modify_image_attribute_response_body = <<-RESPONSE
19
+ <ModifyImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
20
+ <return>true</return>
21
+ </ModifyImageAttributeResponse>
22
+ RESPONSE
23
+
24
+ @reset_image_attribute_response_body = <<-RESPONSE
25
+ <ResetImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
26
+ <return>true</return>
27
+ </ResetImageAttributeResponse>
28
+ RESPONSE
29
+
30
+ @describe_image_attribute_response_body_launch_permissions = <<-RESPONSE
31
+ <DescribeImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
32
+ <imageId>ami-61a54008</imageId>
33
+ <launchPermission>
34
+ <item>
35
+ <group>all</group>
36
+ </item>
37
+ <item>
38
+ <userId>495219933132</userId>
39
+ </item>
40
+ </launchPermission>
41
+ </DescribeImageAttributeResponse>
42
+ RESPONSE
43
+
44
+ @describe_image_attribute_response_body_product_codes = <<-RESPONSE
45
+ <DescribeImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-03">
46
+ <imageId>ami-61a54008</imageId>
47
+ <productCodes>
48
+ <item>
49
+ <productCode>774F4FF8</productCode>
50
+ </item>
51
+ </productCodes>
52
+ </DescribeImageAttributeResponse>
53
+ RESPONSE
54
+
55
+ end
56
+
57
+
58
+ specify "should be able to be changed with modify_image_attribute (with :attribute and single value :user_id and :group)" do
59
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
60
+ "Attribute"=>"launchPermission",
61
+ "OperationType"=>"add",
62
+ "UserId.1"=>"123",
63
+ "Group.1"=>"all"}).
64
+ returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
65
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id=>["123"], :group=>["all"]).should.be.an.instance_of Hash
66
+ end
67
+
68
+
69
+ specify "should be able to be changed with modify_image_attribute ( with :attribute but specifying :group only)" do
70
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
71
+ "Attribute"=>"launchPermission",
72
+ "OperationType"=>"add",
73
+ "Group.1"=>"all"}).
74
+ returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
75
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]).should.be.an.instance_of Hash
76
+ end
77
+
78
+
79
+ specify "should be able to be changed with modify_image_attribute ( with :operation_type 'remove')" do
80
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
81
+ "Attribute"=>"launchPermission",
82
+ "OperationType"=>"remove",
83
+ "Group.1"=>"all"}).
84
+ returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
85
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"remove", :group=>["all"]).should.be.an.instance_of Hash
86
+ end
87
+
88
+
89
+ specify "should be able to be changed with modify_image_attribute ( with :attribute but specifying :user_id only)" do
90
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
91
+ "Attribute"=>"launchPermission",
92
+ "OperationType"=>"add",
93
+ "UserId.1"=>"123"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
94
+
95
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008",
96
+ :attribute=>"launchPermission",
97
+ :operation_type=>"add",
98
+ :user_id=>["123"]).should.be.an.instance_of Hash
99
+ end
100
+
101
+
102
+ specify "should be able to be changed with modify_image_attribute ( with :attribute=>'productCodes')" do
103
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
104
+ "Attribute"=>"productCodes",
105
+ "OperationType"=>"",
106
+ "ProductCode.1"=>"774F4FF8"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
107
+
108
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008",
109
+ :attribute=>"productCodes",
110
+ :product_code=>["774F4FF8"]).should.be.an.instance_of Hash
111
+ end
112
+
113
+
114
+ specify "should be able to be changed with modify_image_attribute ( with :attribute and multiple :user_id and :group elements)" do
115
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
116
+ "Attribute"=>"launchPermission",
117
+ "OperationType"=>"add",
118
+ "UserId.1"=>"123",
119
+ "UserId.2"=>"345",
120
+ "Group.1"=>"123",
121
+ "Group.2"=>"all"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
122
+
123
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008",
124
+ :attribute=>"launchPermission",
125
+ :operation_type=>"add",
126
+ :user_id=>["123", "345"],
127
+ :group=>["123", "all"]).should.be.an.instance_of Hash
128
+ end
129
+
130
+
131
+ specify "should raise an exception when modify_image_attribute is called with incorrect arguments" do
132
+ # method args can't be nil or empty
133
+ lambda { @ec2.modify_image_attribute() }.should.raise(AWS::ArgumentError)
134
+ lambda { @ec2.modify_image_attribute(:image_id=>"") }.should.raise(AWS::ArgumentError)
135
+
136
+ # :image_id option must be not be empty or nil
137
+ lambda { @ec2.modify_image_attribute(:image_id=>nil, :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]) }.should.raise(AWS::ArgumentError)
138
+ lambda { @ec2.modify_image_attribute(:image_id=>"", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]) }.should.raise(AWS::ArgumentError)
139
+
140
+ # :attribute currently has two options which are 'launchPermission' and 'productCodes, it should fail with any other value, nil, or empty
141
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil, :operation_type=>"add", :group=>["all"]) }.should.raise(AWS::ArgumentError)
142
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"", :operation_type=>"add", :group=>["all"]) }.should.raise(AWS::ArgumentError)
143
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo", :operation_type=>"add", :group=>["all"]) }.should.raise(AWS::ArgumentError)
144
+
145
+ # :attribute => 'launchPermission' option should fail if neither :group nor :user_id are also provided
146
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add") }.should.raise(AWS::ArgumentError)
147
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => nil) }.should.raise(AWS::ArgumentError)
148
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => "") }.should.raise(AWS::ArgumentError)
149
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => nil) }.should.raise(AWS::ArgumentError)
150
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => "") }.should.raise(AWS::ArgumentError)
151
+
152
+ # :attribute => 'productCodes' option should fail if :product_code isn't also provided
153
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes", :product_code=>nil) }.should.raise(AWS::ArgumentError)
154
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes", :product_code=>"") }.should.raise(AWS::ArgumentError)
155
+
156
+ # :operation_type currently has two options which are 'add' and 'remove', and it should fail with any other, nil or empty
157
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>nil, :group=>["all"]) }.should.raise(AWS::ArgumentError)
158
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"", :group=>["all"]) }.should.raise(AWS::ArgumentError)
159
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"foo", :group=>["all"]) }.should.raise(AWS::ArgumentError)
160
+ end
161
+
162
+
163
+ specify "method describe_image_attribute should return the proper attributes when called with launchPermission" do
164
+ @ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
165
+ "Attribute"=>"launchPermission" }).
166
+ returns stub(:body => @describe_image_attribute_response_body_launch_permissions, :is_a? => true)
167
+
168
+ @ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "launchPermission").
169
+ should.be.an.instance_of Hash
170
+
171
+ response = @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission")
172
+ response.imageId.should.equal "ami-61a54008"
173
+ response.launchPermission.item[0].group.should.equal "all"
174
+ response.launchPermission.item[1].userId.should.equal "495219933132"
175
+ end
176
+
177
+
178
+ specify "method describe_image_attribute should return the proper attributes when called with productCodes" do
179
+ @ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
180
+ "Attribute"=>"productCodes" }).
181
+ returns stub(:body => @describe_image_attribute_response_body_product_codes, :is_a? => true)
182
+
183
+ @ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "productCodes").
184
+ should.be.an.instance_of Hash
185
+
186
+ response = @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes")
187
+ response.imageId.should.equal "ami-61a54008"
188
+ response.productCodes.item[0].productCode.should.equal "774F4FF8"
189
+ end
190
+
191
+
192
+ specify "should raise an exception when describe_image_attribute is called with incorrect arguments" do
193
+ # method args can't be nil or empty
194
+ lambda { @ec2.describe_image_attribute() }.should.raise(AWS::ArgumentError)
195
+ lambda { @ec2.describe_image_attribute(:image_id=>"") }.should.raise(AWS::ArgumentError)
196
+
197
+ # :image_id option must be not be empty or nil w/ launchPermission
198
+ lambda { @ec2.describe_image_attribute(:image_id=>nil, :attribute=>"launchPermission") }.should.raise(AWS::ArgumentError)
199
+ lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"launchPermission") }.should.raise(AWS::ArgumentError)
200
+
201
+ # :image_id option must be not be empty or nil w/ productCodes
202
+ lambda { @ec2.describe_image_attribute(:image_id=>nil, :attribute=>"productCodes") }.should.raise(AWS::ArgumentError)
203
+ lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"productCodes") }.should.raise(AWS::ArgumentError)
204
+
205
+ # :attribute currently has two options which are 'launchPermission' and 'productCodes', it should fail with any other values,
206
+ # nil, or empty
207
+ lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil) }.should.raise(AWS::ArgumentError)
208
+ lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"") }.should.raise(AWS::ArgumentError)
209
+ lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo") }.should.raise(AWS::ArgumentError)
210
+ end
211
+
212
+
213
+ specify "should be able to reset attributes with reset_image_attribute " do
214
+ @ec2.stubs(:make_request).with('ResetImageAttribute', {"ImageId"=>"ami-61a54008",
215
+ "Attribute"=>"launchPermission"}).
216
+ returns stub(:body => @reset_image_attribute_response_body, :is_a? => true)
217
+ @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission").should.be.an.instance_of Hash
218
+ @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission").return.should.equal "true"
219
+ end
220
+
221
+
222
+ specify "should raise an exception when reset_image_attribute is called with incorrect arguments" do
223
+ # method args can't be nil or empty
224
+ lambda { @ec2.reset_image_attribute() }.should.raise(AWS::ArgumentError)
225
+ lambda { @ec2.reset_image_attribute(:image_id=>"") }.should.raise(AWS::ArgumentError)
226
+
227
+ # :image_id option must be not be empty or nil
228
+ lambda { @ec2.reset_image_attribute(:image_id=>nil, :attribute=>"launchPermission") }.should.raise(AWS::ArgumentError)
229
+ lambda { @ec2.reset_image_attribute(:image_id=>"", :attribute=>"launchPermission") }.should.raise(AWS::ArgumentError)
230
+
231
+ # :attribute currently has one option which is 'launchPermission', it should fail with any other value, nil, or empty
232
+ lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil) }.should.raise(AWS::ArgumentError)
233
+ lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"") }.should.raise(AWS::ArgumentError)
234
+ lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo") }.should.raise(AWS::ArgumentError)
235
+ end
236
+
237
+
238
+ end