newrelic-amazon-ec2 0.6.2
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/.gitignore +8 -0
- data/.yardopts +1 -0
- data/ChangeLog +293 -0
- data/LICENSE +66 -0
- data/README.rdoc +354 -0
- data/README_dev.rdoc +12 -0
- data/Rakefile +101 -0
- data/VERSION +1 -0
- data/amazon-ec2.gemspec +134 -0
- data/bin/ec2-gem-example.rb +137 -0
- data/bin/ec2-gem-profile.rb +10 -0
- data/bin/ec2sh +62 -0
- data/bin/setup.rb +28 -0
- data/deps.rip +1 -0
- data/lib/AWS.rb +292 -0
- data/lib/AWS/Autoscaling.rb +70 -0
- data/lib/AWS/Autoscaling/autoscaling.rb +273 -0
- data/lib/AWS/Cloudwatch.rb +32 -0
- data/lib/AWS/Cloudwatch/monitoring.rb +89 -0
- data/lib/AWS/EC2.rb +33 -0
- data/lib/AWS/EC2/availability_zones.rb +21 -0
- data/lib/AWS/EC2/console.rb +23 -0
- data/lib/AWS/EC2/elastic_ips.rb +81 -0
- data/lib/AWS/EC2/image_attributes.rb +133 -0
- data/lib/AWS/EC2/images.rb +101 -0
- data/lib/AWS/EC2/instances.rb +212 -0
- data/lib/AWS/EC2/keypairs.rb +61 -0
- data/lib/AWS/EC2/products.rb +21 -0
- data/lib/AWS/EC2/security_groups.rb +183 -0
- data/lib/AWS/EC2/snapshots.rb +59 -0
- data/lib/AWS/EC2/volumes.rb +115 -0
- data/lib/AWS/ELB.rb +71 -0
- data/lib/AWS/ELB/load_balancers.rb +178 -0
- data/lib/AWS/exceptions.rb +122 -0
- data/lib/AWS/responses.rb +21 -0
- data/newrelic-amazon-ec2.gemspec +136 -0
- data/perftools/ec2prof +0 -0
- data/perftools/ec2prof-results.dot +132 -0
- data/perftools/ec2prof-results.txt +100 -0
- data/perftools/ec2prof.symbols +102 -0
- data/test/test_Autoscaling_groups.rb +336 -0
- data/test/test_EC2.rb +68 -0
- data/test/test_EC2_availability_zones.rb +49 -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 +429 -0
- data/test/test_EC2_keypairs.rb +123 -0
- data/test/test_EC2_products.rb +48 -0
- data/test/test_EC2_responses.rb +53 -0
- data/test/test_EC2_s3_xmlsimple.rb +80 -0
- data/test/test_EC2_security_groups.rb +205 -0
- data/test/test_EC2_snapshots.rb +83 -0
- data/test/test_EC2_volumes.rb +142 -0
- data/test/test_ELB_load_balancers.rb +239 -0
- data/test/test_helper.rb +23 -0
- data/wsdl/2007-08-29.ec2.wsdl +1269 -0
- data/wsdl/2008-02-01.ec2.wsdl +1614 -0
- data/wsdl/2008-05-05.ec2.wsdl +2052 -0
- data/wsdl/2008-12-01.ec2.wsdl +2354 -0
- metadata +218 -0
@@ -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
|
@@ -0,0 +1,197 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Glenn Rempe (mailto:glenn@rempe.us)
|
6
|
+
# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://github.com/grempe/amazon-ec2/tree/master
|
9
|
+
#++
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
|
+
|
13
|
+
context "An EC2 image " do
|
14
|
+
|
15
|
+
before do
|
16
|
+
@ec2 = AWS::EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
+
|
18
|
+
@register_image_response_body = <<-RESPONSE
|
19
|
+
<RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
|
+
<imageId>ami-61a54008</imageId>
|
21
|
+
</RegisterImageResponse>
|
22
|
+
RESPONSE
|
23
|
+
|
24
|
+
@describe_image_response_body = <<-RESPONSE
|
25
|
+
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
26
|
+
<imagesSet>
|
27
|
+
<item>
|
28
|
+
<imageId>ami-61a54008</imageId>
|
29
|
+
<imageLocation>foobar1/image.manifest.xml</imageLocation>
|
30
|
+
<imageState>available</imageState>
|
31
|
+
<imageOwnerId>AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA</imageOwnerId>
|
32
|
+
<isPublic>true</isPublic>
|
33
|
+
<productCodes>
|
34
|
+
<item>
|
35
|
+
<productCode>774F4FF8</productCode>
|
36
|
+
</item>
|
37
|
+
</productCodes>
|
38
|
+
</item>
|
39
|
+
<item>
|
40
|
+
<imageId>ami-61a54009</imageId>
|
41
|
+
<imageLocation>foobar2/image.manifest.xml</imageLocation>
|
42
|
+
<imageState>deregistered</imageState>
|
43
|
+
<imageOwnerId>ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ</imageOwnerId>
|
44
|
+
<isPublic>false</isPublic>
|
45
|
+
</item>
|
46
|
+
</imagesSet>
|
47
|
+
</DescribeImagesResponse>
|
48
|
+
RESPONSE
|
49
|
+
|
50
|
+
@deregister_image_response_body = <<-RESPONSE
|
51
|
+
<DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
52
|
+
<return>true</return>
|
53
|
+
</DeregisterImageResponse>
|
54
|
+
RESPONSE
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
specify "should be able to be registered" do
|
60
|
+
@ec2.stubs(:make_request).with('RegisterImage', {"ImageLocation"=>"mybucket-myimage.manifest.xml"}).
|
61
|
+
returns stub(:body => @register_image_response_body, :is_a? => true)
|
62
|
+
@ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").imageId.should.equal "ami-61a54008"
|
63
|
+
@ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").should.be.an.instance_of Hash
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
specify "method register_image should raise an exception when called without nil/empty string arguments" do
|
68
|
+
lambda { @ec2.register_image() }.should.raise(AWS::ArgumentError)
|
69
|
+
lambda { @ec2.register_image(:image_location => "") }.should.raise(AWS::ArgumentError)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
specify "should be able to be described and return the correct Ruby response class for parent and members" do
|
74
|
+
@ec2.stubs(:make_request).with('DescribeImages', {}).
|
75
|
+
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
76
|
+
@ec2.describe_images.should.be.an.instance_of Hash
|
77
|
+
response = @ec2.describe_images
|
78
|
+
response.should.be.an.instance_of Hash
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
specify "should be able to be described with no params and return an imagesSet" do
|
83
|
+
@ec2.stubs(:make_request).with('DescribeImages', {}).
|
84
|
+
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
85
|
+
@ec2.describe_images.imagesSet.item.length.should.equal 2
|
86
|
+
end
|
87
|
+
|
88
|
+
specify "should be able to be described by an Array of ImageId.N ID's and return an array of Items" do
|
89
|
+
@ec2.stubs(:make_request).with('DescribeImages', {"ImageId.1"=>"ami-61a54008", "ImageId.2"=>"ami-61a54009"}).
|
90
|
+
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
91
|
+
@ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] ).imagesSet.item.length.should.equal 2
|
92
|
+
|
93
|
+
response = @ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] )
|
94
|
+
|
95
|
+
# test first 'Item' object returned
|
96
|
+
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
97
|
+
response.imagesSet.item[0].imageLocation.should.equal "foobar1/image.manifest.xml"
|
98
|
+
response.imagesSet.item[0].imageState.should.equal "available"
|
99
|
+
response.imagesSet.item[0].imageOwnerId.should.equal "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA"
|
100
|
+
response.imagesSet.item[0].isPublic.should.equal "true"
|
101
|
+
response.imagesSet.item[0].productCodes.item[0].productCode.should.equal "774F4FF8"
|
102
|
+
|
103
|
+
# test second 'Item' object returned
|
104
|
+
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
105
|
+
response.imagesSet.item[1].imageLocation.should.equal "foobar2/image.manifest.xml"
|
106
|
+
response.imagesSet.item[1].imageState.should.equal "deregistered"
|
107
|
+
response.imagesSet.item[1].imageOwnerId.should.equal "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"
|
108
|
+
response.imagesSet.item[1].isPublic.should.equal "false"
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
specify "should be able to be described by an owners with Owner.N ID's and return an array of Items" do
|
113
|
+
@ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "Owner.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
|
114
|
+
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
115
|
+
@ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
|
116
|
+
|
117
|
+
# owner ID's
|
118
|
+
response = @ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
|
119
|
+
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
120
|
+
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
specify "should be able to be described by an owner of 'self' and return an array of Items that I own" do
|
125
|
+
@ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "self").
|
126
|
+
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
127
|
+
@ec2.describe_images( :owner_id => "self" ).imagesSet.item.length.should.equal 2
|
128
|
+
|
129
|
+
# 'self' - Those that I own
|
130
|
+
response = @ec2.describe_images( :owner_id => "self" )
|
131
|
+
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
specify "should be able to be described by an owner of 'amazon' and return an array of Items that are Amazon Public AMI's" do
|
136
|
+
@ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "amazon").
|
137
|
+
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
138
|
+
@ec2.describe_images( :owner_id => "amazon" ).imagesSet.item.length.should.equal 2
|
139
|
+
|
140
|
+
# 'amazon' - Those that are owned and created by AWS
|
141
|
+
response = @ec2.describe_images( :owner_id => "amazon" )
|
142
|
+
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
specify "should be able to be described by an owners with Owner.N ID's who can execute AMI's and return an array of Items" do
|
147
|
+
@ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ExecutableBy.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
|
148
|
+
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
149
|
+
@ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
|
150
|
+
|
151
|
+
# executable by owner ID's
|
152
|
+
response = @ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
|
153
|
+
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
154
|
+
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
specify "should be able to be described by an owners with Owner.N of 'self' who can execute AMI's and return an array of Items" do
|
159
|
+
@ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "self").
|
160
|
+
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
161
|
+
@ec2.describe_images( :executable_by => "self" ).imagesSet.item.length.should.equal 2
|
162
|
+
|
163
|
+
# executable by owner ID's
|
164
|
+
response = @ec2.describe_images( :executable_by => "self" )
|
165
|
+
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
166
|
+
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
specify "should be able to be described by an owners with Owner.N of 'all' who can execute AMI's and return an array of Items" do
|
171
|
+
@ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "all").
|
172
|
+
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
173
|
+
@ec2.describe_images( :executable_by => "all" ).imagesSet.item.length.should.equal 2
|
174
|
+
|
175
|
+
# executable by owner ID's
|
176
|
+
response = @ec2.describe_images( :executable_by => "all" )
|
177
|
+
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
178
|
+
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
specify "should be able to be de-registered" do
|
183
|
+
@ec2.stubs(:make_request).with('DeregisterImage', {"ImageId"=>"ami-61a54008"}).
|
184
|
+
returns stub(:body => @deregister_image_response_body, :is_a? => true)
|
185
|
+
@ec2.deregister_image(:image_id => "ami-61a54008" ).should.be.an.instance_of Hash
|
186
|
+
@ec2.deregister_image(:image_id => "ami-61a54008" ).return.should.equal "true"
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
specify "method deregister_image should raise an exception when called without nil/empty string arguments" do
|
191
|
+
lambda { @ec2.deregister_image() }.should.raise(AWS::ArgumentError)
|
192
|
+
lambda { @ec2.deregister_image( :image_id => nil ) }.should.raise(AWS::ArgumentError)
|
193
|
+
lambda { @ec2.deregister_image( :image_id => "" ) }.should.raise(AWS::ArgumentError)
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
end
|