grempe-amazon-ec2 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +230 -0
- data/License.txt +66 -0
- data/Manifest.txt +46 -0
- data/README.txt +154 -0
- data/Rakefile +4 -0
- data/bin/ec2-gem-example.rb +61 -0
- data/bin/ec2sh +73 -0
- data/bin/setup.rb +19 -0
- data/config/hoe.rb +76 -0
- data/config/requirements.rb +17 -0
- data/lib/EC2.rb +254 -0
- data/lib/EC2/console.rb +44 -0
- data/lib/EC2/elastic_ips.rb +153 -0
- data/lib/EC2/exceptions.rb +136 -0
- data/lib/EC2/image_attributes.rb +166 -0
- data/lib/EC2/images.rb +134 -0
- data/lib/EC2/instances.rb +206 -0
- data/lib/EC2/keypairs.rb +94 -0
- data/lib/EC2/products.rb +43 -0
- data/lib/EC2/responses.rb +175 -0
- data/lib/EC2/security_groups.rb +232 -0
- data/lib/EC2/version.rb +18 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +27 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_EC2.rb +52 -0
- data/test/test_EC2_console.rb +54 -0
- data/test/test_EC2_elastic_ips.rb +144 -0
- data/test/test_EC2_image_attributes.rb +238 -0
- data/test/test_EC2_images.rb +197 -0
- data/test/test_EC2_instances.rb +325 -0
- data/test/test_EC2_keypairs.rb +123 -0
- data/test/test_EC2_products.rb +48 -0
- data/test/test_EC2_responses.rb +102 -0
- data/test/test_EC2_security_groups.rb +205 -0
- data/test/test_EC2_version.rb +44 -0
- data/test/test_helper.rb +20 -0
- data/website/index.txt +427 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +55 -0
- metadata +174 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|
data/tasks/website.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
desc 'Generate website files'
|
2
|
+
task :website_generate => :ruby_env do
|
3
|
+
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
4
|
+
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Upload website files to rubyforge'
|
9
|
+
task :website_upload do
|
10
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
11
|
+
remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
|
12
|
+
local_dir = 'website'
|
13
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate and upload website files'
|
17
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/test/test_EC2.rb
ADDED
@@ -0,0 +1,52 @@
|
|
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 "The EC2 method " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "EC2::Base attribute readers should be available" do
|
19
|
+
@ec2 = 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
|
+
|
30
|
+
specify "EC2::Base should work with insecure connections as well" do
|
31
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key",
|
32
|
+
:secret_access_key => "not a secret",
|
33
|
+
:use_ssl => false,
|
34
|
+
:server => "foo.example.com" )
|
35
|
+
|
36
|
+
@ec2.use_ssl.should.equal false
|
37
|
+
@ec2.port.should.equal 80
|
38
|
+
@ec2.server.should.equal "foo.example.com"
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
specify "EC2.canonical_string(path) should data that is stripped of ?,&,= " do
|
43
|
+
path = "?name1=value1&name2=value2&name3=value3"
|
44
|
+
EC2.canonical_string(path).should.equal "name1value1name2value2name3value3"
|
45
|
+
end
|
46
|
+
|
47
|
+
specify "EC2.encode should return the expected string" do
|
48
|
+
EC2.encode("secretaccesskey", "foobar123", urlencode=true).should.equal "e3jeuDc3DIX2mW8cVqWiByj4j5g%3D"
|
49
|
+
EC2.encode("secretaccesskey", "foobar123", urlencode=false).should.equal "e3jeuDc3DIX2mW8cVqWiByj4j5g="
|
50
|
+
end
|
51
|
+
|
52
|
+
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: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 "The EC2 console " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = 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 EC2::Response
|
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(EC2::ArgumentError)
|
49
|
+
lambda { @ec2.get_console_output(:instance_id => nil) }.should.raise(EC2::ArgumentError)
|
50
|
+
lambda { @ec2.get_console_output(:instance_id => "") }.should.raise(EC2::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: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 elastic IP addresses " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = 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 EC2::Response
|
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(EC2::ArgumentError)
|
72
|
+
# lambda { @ec2.create_keypair() }.should.raise(EC2::ArgumentError)
|
73
|
+
# lambda { @ec2.create_keypair( :key_name => nil ) }.should.raise(EC2::ArgumentError)
|
74
|
+
# lambda { @ec2.create_keypair( :key_name => "" ) }.should.raise(EC2::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 EC2::Response
|
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 EC2::Response
|
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 EC2::Response
|
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(EC2::ArgumentError)
|
117
|
+
lambda { @ec2.associate_address() }.should.raise(EC2::ArgumentError)
|
118
|
+
lambda { @ec2.associate_address( :instance_id => nil ) }.should.raise(EC2::ArgumentError)
|
119
|
+
lambda { @ec2.associate_address( :public_ip => "" ) }.should.raise(EC2::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 EC2::Response
|
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(EC2::ArgumentError)
|
139
|
+
lambda { @ec2.disassociate_address() }.should.raise(EC2::ArgumentError)
|
140
|
+
lambda { @ec2.disassociate_address( :public_ip => "" ) }.should.raise(EC2::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: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 image_attributes " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = 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 EC2::Response
|
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 EC2::Response
|
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 EC2::Response
|
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 EC2::Response
|
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 EC2::Response
|
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 EC2::Response
|
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(EC2::ArgumentError)
|
134
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"") }.should.raise(EC2::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(EC2::ArgumentError)
|
138
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::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(EC2::ArgumentError)
|
142
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
143
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::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(EC2::ArgumentError)
|
147
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => nil) }.should.raise(EC2::ArgumentError)
|
148
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => "") }.should.raise(EC2::ArgumentError)
|
149
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => nil) }.should.raise(EC2::ArgumentError)
|
150
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => "") }.should.raise(EC2::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(EC2::ArgumentError)
|
154
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes", :product_code=>"") }.should.raise(EC2::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(EC2::ArgumentError)
|
158
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"", :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
159
|
+
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"foo", :group=>["all"]) }.should.raise(EC2::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 EC2::Response
|
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 EC2::Response
|
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(EC2::ArgumentError)
|
195
|
+
lambda { @ec2.describe_image_attribute(:image_id=>"") }.should.raise(EC2::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(EC2::ArgumentError)
|
199
|
+
lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"launchPermission") }.should.raise(EC2::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(EC2::ArgumentError)
|
203
|
+
lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"productCodes") }.should.raise(EC2::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(EC2::ArgumentError)
|
208
|
+
lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"") }.should.raise(EC2::ArgumentError)
|
209
|
+
lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo") }.should.raise(EC2::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 EC2::Response
|
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(EC2::ArgumentError)
|
225
|
+
lambda { @ec2.reset_image_attribute(:image_id=>"") }.should.raise(EC2::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(EC2::ArgumentError)
|
229
|
+
lambda { @ec2.reset_image_attribute(:image_id=>"", :attribute=>"launchPermission") }.should.raise(EC2::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(EC2::ArgumentError)
|
233
|
+
lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"") }.should.raise(EC2::ArgumentError)
|
234
|
+
lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo") }.should.raise(EC2::ArgumentError)
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
end
|