grempe-amazon-ec2 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- 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,123 @@
|
|
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 keypairs " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
+
|
18
|
+
@create_keypair_response_body = <<-RESPONSE
|
19
|
+
<CreateKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
|
+
<keyName>example-key-name</keyName>
|
21
|
+
<keyFingerprint>1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f</keyFingerprint>
|
22
|
+
<keyMaterial>-----BEGIN RSA PRIVATE KEY-----
|
23
|
+
MIIEoQIBAAKCAQBuLFg5ujHrtm1jnutSuoO8Xe56LlT+HM8v/xkaa39EstM3/aFxTHgElQiJLChp
|
24
|
+
HungXQ29VTc8rc1bW0lkdi23OH5eqkMHGhvEwqa0HWASUMll4o3o/IX+0f2UcPoKCOVUR+jx71Sg
|
25
|
+
5AU52EQfanIn3ZQ8lFW7Edp5a3q4DhjGlUKToHVbicL5E+g45zfB95wIyywWZfeW/UUF3LpGZyq/
|
26
|
+
ebIUlq1qTbHkLbCC2r7RTn8vpQWp47BGVYGtGSBMpTRP5hnbzzuqj3itkiLHjU39S2sJCJ0TrJx5
|
27
|
+
i8BygR4s3mHKBj8l+ePQxG1kGbF6R4yg6sECmXn17MRQVXODNHZbAgMBAAECggEAY1tsiUsIwDl5
|
28
|
+
91CXirkYGuVfLyLflXenxfI50mDFms/mumTqloHO7tr0oriHDR5K7wMcY/YY5YkcXNo7mvUVD1pM
|
29
|
+
ZNUJs7rw9gZRTrf7LylaJ58kOcyajw8TsC4e4LPbFaHwS1d6K8rXh64o6WgW4SrsB6ICmr1kGQI7
|
30
|
+
3wcfgt5ecIu4TZf0OE9IHjn+2eRlsrjBdeORi7KiUNC/pAG23I6MdDOFEQRcCSigCj+4/mciFUSA
|
31
|
+
SWS4dMbrpb9FNSIcf9dcLxVM7/6KxgJNfZc9XWzUw77Jg8x92Zd0fVhHOux5IZC+UvSKWB4dyfcI
|
32
|
+
tE8C3p9bbU9VGyY5vLCAiIb4qQKBgQDLiO24GXrIkswF32YtBBMuVgLGCwU9h9HlO9mKAc2m8Cm1
|
33
|
+
jUE5IpzRjTedc9I2qiIMUTwtgnw42auSCzbUeYMURPtDqyQ7p6AjMujp9EPemcSVOK9vXYL0Ptco
|
34
|
+
xW9MC0dtV6iPkCN7gOqiZXPRKaFbWADp16p8UAIvS/a5XXk5jwKBgQCKkpHi2EISh1uRkhxljyWC
|
35
|
+
iDCiK6JBRsMvpLbc0v5dKwP5alo1fmdR5PJaV2qvZSj5CYNpMAy1/EDNTY5OSIJU+0KFmQbyhsbm
|
36
|
+
rdLNLDL4+TcnT7c62/aH01ohYaf/VCbRhtLlBfqGoQc7+sAc8vmKkesnF7CqCEKDyF/dhrxYdQKB
|
37
|
+
gC0iZzzNAapayz1+JcVTwwEid6j9JqNXbBc+Z2YwMi+T0Fv/P/hwkX/ypeOXnIUcw0Ih/YtGBVAC
|
38
|
+
DQbsz7LcY1HqXiHKYNWNvXgwwO+oiChjxvEkSdsTTIfnK4VSCvU9BxDbQHjdiNDJbL6oar92UN7V
|
39
|
+
rBYvChJZF7LvUH4YmVpHAoGAbZ2X7XvoeEO+uZ58/BGKOIGHByHBDiXtzMhdJr15HTYjxK7OgTZm
|
40
|
+
gK+8zp4L9IbvLGDMJO8vft32XPEWuvI8twCzFH+CsWLQADZMZKSsBasOZ/h1FwhdMgCMcY+Qlzd4
|
41
|
+
JZKjTSu3i7vhvx6RzdSedXEMNTZWN4qlIx3kR5aHcukCgYA9T+Zrvm1F0seQPbLknn7EqhXIjBaT
|
42
|
+
P8TTvW/6bdPi23ExzxZn7KOdrfclYRph1LHMpAONv/x2xALIf91UB+v5ohy1oDoasL0gij1houRe
|
43
|
+
2ERKKdwz0ZL9SWq6VTdhr/5G994CK72fy5WhyERbDjUIdHaK3M849JJuf8cSrvSb4g==
|
44
|
+
-----END RSA PRIVATE KEY-----</keyMaterial>
|
45
|
+
</CreateKeyPairResponse>
|
46
|
+
RESPONSE
|
47
|
+
|
48
|
+
@describe_keypairs_response_body = <<-RESPONSE
|
49
|
+
<DescribeKeyPairsResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
50
|
+
<keySet>
|
51
|
+
<item>
|
52
|
+
<keyName>example-key-name</keyName>
|
53
|
+
<keyFingerprint>1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f</keyFingerprint>
|
54
|
+
</item>
|
55
|
+
</keySet>
|
56
|
+
</DescribeKeyPairsResponse>
|
57
|
+
RESPONSE
|
58
|
+
|
59
|
+
@delete_keypair_body = <<-RESPONSE
|
60
|
+
<DeleteKeyPair xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
61
|
+
<return>true</return>
|
62
|
+
</DeleteKeyPair>
|
63
|
+
RESPONSE
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
specify "should be able to be created" do
|
69
|
+
@ec2.stubs(:make_request).with('CreateKeyPair', {"KeyName"=>"example-key-name"}).
|
70
|
+
returns stub(:body => @create_keypair_response_body, :is_a? => true)
|
71
|
+
|
72
|
+
@ec2.create_keypair( :key_name => "example-key-name" ).should.be.an.instance_of EC2::Response
|
73
|
+
|
74
|
+
response = @ec2.create_keypair( :key_name => "example-key-name" )
|
75
|
+
response.keyName.should.equal "example-key-name"
|
76
|
+
response.keyFingerprint.should.equal "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f"
|
77
|
+
response.keyMaterial.should.not.equal ""
|
78
|
+
response.keyMaterial.should.not.be.nil
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
specify "method create_keypair should reject bad arguments" do
|
83
|
+
@ec2.stubs(:make_request).with('CreateKeyPair', {"KeyName"=>"example-key-name"}).
|
84
|
+
returns stub(:body => @create_keypair_response_body, :is_a? => true)
|
85
|
+
|
86
|
+
lambda { @ec2.create_keypair( :key_name => "example-key-name" ) }.should.not.raise(EC2::ArgumentError)
|
87
|
+
lambda { @ec2.create_keypair() }.should.raise(EC2::ArgumentError)
|
88
|
+
lambda { @ec2.create_keypair( :key_name => nil ) }.should.raise(EC2::ArgumentError)
|
89
|
+
lambda { @ec2.create_keypair( :key_name => "" ) }.should.raise(EC2::ArgumentError)
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
specify "should be able to be described with describe_keypairs" do
|
94
|
+
@ec2.stubs(:make_request).with('DescribeKeyPairs', {"KeyName.1"=>"example-key-name"}).
|
95
|
+
returns stub(:body => @describe_keypairs_response_body, :is_a? => true)
|
96
|
+
@ec2.describe_keypairs( :key_name => "example-key-name" ).should.be.an.instance_of EC2::Response
|
97
|
+
response = @ec2.describe_keypairs( :key_name => "example-key-name" )
|
98
|
+
response.keySet.item[0].keyName.should.equal "example-key-name"
|
99
|
+
response.keySet.item[0].keyFingerprint.should.equal "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f"
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
specify "should be able to be deleted with delete_keypairs" do
|
104
|
+
@ec2.stubs(:make_request).with('DeleteKeyPair', {"KeyName"=>"example-key-name"}).
|
105
|
+
returns stub(:body => @delete_keypair_body, :is_a? => true)
|
106
|
+
@ec2.delete_keypair( :key_name => "example-key-name" ).should.be.an.instance_of EC2::Response
|
107
|
+
response = @ec2.delete_keypair( :key_name => "example-key-name" )
|
108
|
+
response.return.should.equal "true"
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
specify "method delete_keypair should reject bad argument" do
|
113
|
+
@ec2.stubs(:make_request).with('DeleteKeyPair', {"KeyName"=>"example-key-name"}).
|
114
|
+
returns stub(:body => @delete_keypair_body, :is_a? => true)
|
115
|
+
|
116
|
+
lambda { @ec2.delete_keypair( :key_name => "example-key-name" ) }.should.not.raise(EC2::ArgumentError)
|
117
|
+
lambda { @ec2.delete_keypair() }.should.raise(EC2::ArgumentError)
|
118
|
+
lambda { @ec2.delete_keypair( :key_name => nil ) }.should.raise(EC2::ArgumentError)
|
119
|
+
lambda { @ec2.delete_keypair( :key_name => "" ) }.should.raise(EC2::ArgumentError)
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
|
6
|
+
# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://amazon-ec2.rubyforge.org
|
9
|
+
#++
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
|
+
|
13
|
+
context "An EC2 instance " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
+
|
18
|
+
@confirm_product_instance_response_body = <<-RESPONSE
|
19
|
+
<ConfirmProductInstanceResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
|
+
<result>true</result>
|
21
|
+
<ownerId>254933287430</ownerId>
|
22
|
+
</ConfirmProductInstanceResponse>
|
23
|
+
RESPONSE
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
specify "should indicate whether a product code is attached to an instance" do
|
29
|
+
@ec2.stubs(:make_request).with('ConfirmProductInstance', {"ProductCode"=>"774F4FF8", "InstanceId"=>"i-10a64379"}).
|
30
|
+
returns stub(:body => @confirm_product_instance_response_body, :is_a? => true)
|
31
|
+
|
32
|
+
@ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" ).should.be.an.instance_of EC2::Response
|
33
|
+
response = @ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" )
|
34
|
+
response.ownerId.should.equal "254933287430"
|
35
|
+
response.result.should.equal "true"
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
specify "method get_console_output should raise an exception when called without nil/empty string arguments" do
|
40
|
+
lambda { @ec2.confirm_product_instance() }.should.raise(EC2::ArgumentError)
|
41
|
+
lambda { @ec2.confirm_product_instance(:product_code => "774F4FF8", :instance_id => nil) }.should.raise(EC2::ArgumentError)
|
42
|
+
lambda { @ec2.confirm_product_instance(:product_code => "774F4FF8", :instance_id => "") }.should.raise(EC2::ArgumentError)
|
43
|
+
lambda { @ec2.confirm_product_instance(:product_code => nil, :instance_id => "i-10a64379") }.should.raise(EC2::ArgumentError)
|
44
|
+
lambda { @ec2.confirm_product_instance(:product_code => "", :instance_id => "i-10a64379") }.should.raise(EC2::ArgumentError)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,102 @@
|
|
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 Response classes " do
|
14
|
+
|
15
|
+
|
16
|
+
setup do
|
17
|
+
@http_xml = <<-RESPONSE
|
18
|
+
<RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
19
|
+
<return>true</return>
|
20
|
+
</RebootInstancesResponse>
|
21
|
+
RESPONSE
|
22
|
+
|
23
|
+
@response = EC2::Response.parse(:xml => @http_xml)
|
24
|
+
|
25
|
+
# test out adding arbitrary new values to the OpenStruct
|
26
|
+
@response.name = "foo"
|
27
|
+
@response.number = '123'
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
specify "should properly run the to_string(short) method for the short version" do
|
32
|
+
# sample response looks like: "#<EC2::Response:0x100A45F2E ...>". Our response should look
|
33
|
+
# exactly the same, except it should have different hex digits in the middle (after 0x)
|
34
|
+
# that are nine chars long.
|
35
|
+
@response.to_string(true).should =~ /^#<EC2::Response:0x[0-9A-F]{1,9} ...>/
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
specify "should properly run the to_string(false) method for the long version" do
|
40
|
+
@response.to_string(false).should =~ /^#<EC2::Response:0x[0-9A-F]{1,9} name=\"foo\" number=\"123\" parent=nil return=\"true\"/
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
specify "should properly run the to_string(false) method for the long version when called with no params" do
|
45
|
+
@response.to_string.should =~ /^#<EC2::Response:0x[0-9A-F]{1,9} name=\"foo\" number=\"123\" parent=nil return=\"true\"/
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
specify "should provide the same results from to_s as from to_string(false) " do
|
50
|
+
@response.to_s.should =~ /^#<EC2::Response:0x[0-9A-F]{1,9} name=\"foo\" number=\"123\" parent=nil return=\"true\"/
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
specify "should be a kind of type OpenStruct" do
|
55
|
+
@response.kind_of?(OpenStruct).should.equal true
|
56
|
+
@response.kind_of?(Enumerable).should.equal true
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
specify "should return its members" do
|
61
|
+
@response.members.length.should.equal 6
|
62
|
+
test_array = ["return", "xmlns", "number", "name", "parent", "xml"].sort
|
63
|
+
@response.members.sort.should.equal test_array
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
specify "should properly respond to its 'each' method" do
|
68
|
+
answer = @response.each do |f| f ; end
|
69
|
+
answer.name.should.equal "foo"
|
70
|
+
answer.number.should.equal '123'
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
specify "should respond to the '[]' method" do
|
75
|
+
@response[:name].should.equal "foo"
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
specify "should respond correctly to the '[]=' method and set a variable" do
|
80
|
+
@response[:name].should.equal "foo"
|
81
|
+
@response[:name]="bar"
|
82
|
+
@response[:name].should.equal "bar"
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
specify "should respond correctly to the 'each_pair' method" do
|
87
|
+
@response.each_pair {|k,v|
|
88
|
+
case k
|
89
|
+
when "name"
|
90
|
+
v.should.equal "foo"
|
91
|
+
when "number"
|
92
|
+
v.should.equal '123'
|
93
|
+
end
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
specify "should return the original amazon XML response in the 'xml' attribute of the response object." do
|
98
|
+
@response.xml.should.equal @http_xml
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,205 @@
|
|
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 security groups " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
+
|
18
|
+
@create_security_group_response_body = <<-RESPONSE
|
19
|
+
<CreateSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
|
+
<return>true</return>
|
21
|
+
</CreateSecurityGroupResponse>
|
22
|
+
RESPONSE
|
23
|
+
|
24
|
+
@delete_security_group_response_body = <<-RESPONSE
|
25
|
+
<DeleteSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
26
|
+
<return>true</return>
|
27
|
+
</DeleteSecurityGroupResponse>
|
28
|
+
RESPONSE
|
29
|
+
|
30
|
+
@describe_security_groups_response_body = <<-RESPONSE
|
31
|
+
<DescribeSecurityGroupsResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
|
32
|
+
<securityGroupInfo>
|
33
|
+
<item>
|
34
|
+
<ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
|
35
|
+
<groupName>WebServers</groupName>
|
36
|
+
<groupDescription>Web</groupDescription>
|
37
|
+
<ipPermissions>
|
38
|
+
<item>
|
39
|
+
<ipProtocol>tcp</ipProtocol>
|
40
|
+
<fromPort>80</fromPort>
|
41
|
+
<toPort>80</toPort>
|
42
|
+
<groups/>
|
43
|
+
<ipRanges>
|
44
|
+
<item>
|
45
|
+
<cidrIp>0.0.0.0/0</cidrIp>
|
46
|
+
</item>
|
47
|
+
</ipRanges>
|
48
|
+
</item>
|
49
|
+
</ipPermissions>
|
50
|
+
</item>
|
51
|
+
<item>
|
52
|
+
<ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
|
53
|
+
<groupName>RangedPortsBySource</groupName>
|
54
|
+
<groupDescription>A</groupDescription>
|
55
|
+
<ipPermissions>
|
56
|
+
<item>
|
57
|
+
<ipProtocol>tcp</ipProtocol>
|
58
|
+
<fromPort>6000</fromPort>
|
59
|
+
<toPort>7000</toPort>
|
60
|
+
<groups/>
|
61
|
+
<ipRanges/>
|
62
|
+
</item>
|
63
|
+
</ipPermissions>
|
64
|
+
</item>
|
65
|
+
</securityGroupInfo>
|
66
|
+
</DescribeSecurityGroupsResponse>
|
67
|
+
RESPONSE
|
68
|
+
|
69
|
+
@authorize_security_group_ingress_response_body = <<-RESPONSE
|
70
|
+
<AuthorizeSecurityGroupIngressResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
|
71
|
+
<return>true</return>
|
72
|
+
</AuthorizeSecurityGroupIngressResponse>
|
73
|
+
RESPONSE
|
74
|
+
|
75
|
+
@revoke_security_group_ingress_response_body = <<-RESPONSE
|
76
|
+
<RevokeSecurityGroupIngressResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
|
77
|
+
<return>true</return>
|
78
|
+
</RevokeSecurityGroupIngressResponse>
|
79
|
+
RESPONSE
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
specify "should be able to be created" do
|
85
|
+
@ec2.stubs(:make_request).with('CreateSecurityGroup', {"GroupName"=>"WebServers", "GroupDescription"=>"Web"}).
|
86
|
+
returns stub(:body => @create_security_group_response_body, :is_a? => true)
|
87
|
+
@ec2.create_security_group( :group_name => "WebServers", :group_description => "Web" ).should.be.an.instance_of EC2::Response
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
specify "method create_security_group should reject bad arguments" do
|
92
|
+
@ec2.stubs(:make_request).with('CreateSecurityGroup', {"GroupName"=>"WebServers", "GroupDescription"=>"Web"}).
|
93
|
+
returns stub(:body => @create_security_group_response_body, :is_a? => true)
|
94
|
+
|
95
|
+
lambda { @ec2.create_security_group( :group_name => "WebServers", :group_description => "Web" ) }.should.not.raise(EC2::ArgumentError)
|
96
|
+
lambda { @ec2.create_security_group() }.should.raise(EC2::ArgumentError)
|
97
|
+
|
98
|
+
# :group_name can't be nil or empty
|
99
|
+
lambda { @ec2.create_security_group( :group_name => "", :group_description => "Web" ) }.should.raise(EC2::ArgumentError)
|
100
|
+
lambda { @ec2.create_security_group( :group_name => nil, :group_description => "Web" ) }.should.raise(EC2::ArgumentError)
|
101
|
+
|
102
|
+
# :group_description can't be nil or empty
|
103
|
+
lambda { @ec2.create_security_group( :group_name => "WebServers", :group_description => "" ) }.should.raise(EC2::ArgumentError)
|
104
|
+
lambda { @ec2.create_security_group( :group_name => "WebServers", :group_description => nil ) }.should.raise(EC2::ArgumentError)
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
specify "should be able to be deleted" do
|
109
|
+
@ec2.stubs(:make_request).with('DeleteSecurityGroup', {"GroupName"=>"WebServers"}).
|
110
|
+
returns stub(:body => @delete_security_group_response_body, :is_a? => true)
|
111
|
+
@ec2.delete_security_group( :group_name => "WebServers" ).should.be.an.instance_of EC2::Response
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
specify "method delete_security_group should reject bad arguments" do
|
116
|
+
@ec2.stubs(:make_request).with('DeleteSecurityGroup', {"GroupName"=>"WebServers"}).
|
117
|
+
returns stub(:body => @delete_security_group_response_body, :is_a? => true)
|
118
|
+
|
119
|
+
lambda { @ec2.delete_security_group( :group_name => "WebServers" ) }.should.not.raise(EC2::ArgumentError)
|
120
|
+
lambda { @ec2.delete_security_group() }.should.raise(EC2::ArgumentError)
|
121
|
+
|
122
|
+
# :group_name can't be nil or empty
|
123
|
+
lambda { @ec2.delete_security_group( :group_name => "" ) }.should.raise(EC2::ArgumentError)
|
124
|
+
lambda { @ec2.delete_security_group( :group_name => nil ) }.should.raise(EC2::ArgumentError)
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
specify "should be able to be described with describe_security_groups" do
|
129
|
+
@ec2.stubs(:make_request).with('DescribeSecurityGroups', { "GroupName.1" => "WebServers", "GroupName.2" => "RangedPortsBySource" }).
|
130
|
+
returns stub(:body => @describe_security_groups_response_body, :is_a? => true)
|
131
|
+
@ec2.describe_security_groups( :group_name => ["WebServers", "RangedPortsBySource"] ).should.be.an.instance_of EC2::Response
|
132
|
+
|
133
|
+
response = @ec2.describe_security_groups( :group_name => ["WebServers", "RangedPortsBySource"] )
|
134
|
+
|
135
|
+
response.securityGroupInfo.item[0].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
|
136
|
+
response.securityGroupInfo.item[0].groupName.should.equal "WebServers"
|
137
|
+
response.securityGroupInfo.item[0].groupDescription.should.equal "Web"
|
138
|
+
response.securityGroupInfo.item[0].ipPermissions.item[0].ipProtocol.should.equal "tcp"
|
139
|
+
response.securityGroupInfo.item[0].ipPermissions.item[0].fromPort.should.equal "80"
|
140
|
+
response.securityGroupInfo.item[0].ipPermissions.item[0].toPort.should.equal "80"
|
141
|
+
response.securityGroupInfo.item[0].ipPermissions.item[0].groups.should.be.nil
|
142
|
+
response.securityGroupInfo.item[0].ipPermissions.item[0].ipRanges.item[0].cidrIp.should.equal "0.0.0.0/0"
|
143
|
+
|
144
|
+
response.securityGroupInfo.item[1].ownerId.should.equal "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM"
|
145
|
+
response.securityGroupInfo.item[1].groupName.should.equal "RangedPortsBySource"
|
146
|
+
response.securityGroupInfo.item[1].groupDescription.should.equal "A"
|
147
|
+
response.securityGroupInfo.item[1].ipPermissions.item[0].ipProtocol.should.equal "tcp"
|
148
|
+
response.securityGroupInfo.item[1].ipPermissions.item[0].fromPort.should.equal "6000"
|
149
|
+
response.securityGroupInfo.item[1].ipPermissions.item[0].toPort.should.equal "7000"
|
150
|
+
response.securityGroupInfo.item[1].ipPermissions.item[0].groups.should.be.nil
|
151
|
+
response.securityGroupInfo.item[1].ipPermissions.item[0].ipRanges.should.be.nil
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
specify "method describe_security_groups should reject bad arguments" do
|
156
|
+
@ec2.stubs(:make_request).with('DescribeSecurityGroups', {"GroupName.1"=>"WebServers"}).
|
157
|
+
returns stub(:body => @describe_security_groups_response_body, :is_a? => true)
|
158
|
+
|
159
|
+
lambda { @ec2.describe_security_groups( :group_name => "WebServers" ) }.should.not.raise(EC2::ArgumentError)
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
specify "permissions should be able to be added to a security group with authorize_security_group_ingress." do
|
165
|
+
@ec2.stubs(:make_request).with('AuthorizeSecurityGroupIngress', { "GroupName"=>"WebServers",
|
166
|
+
"IpProtocol"=>"tcp",
|
167
|
+
"FromPort"=>"8000",
|
168
|
+
"ToPort"=>"80",
|
169
|
+
"CidrIp"=>"0.0.0.0/24",
|
170
|
+
"SourceSecurityGroupName"=>"Source SG Name",
|
171
|
+
"SourceSecurityGroupOwnerId"=>"123"}).
|
172
|
+
returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
|
173
|
+
|
174
|
+
@ec2.authorize_security_group_ingress( :group_name => "WebServers",
|
175
|
+
:ip_protocol => "tcp",
|
176
|
+
:from_port => "8000",
|
177
|
+
:to_port => "80",
|
178
|
+
:cidr_ip => "0.0.0.0/24",
|
179
|
+
:source_security_group_name => "Source SG Name",
|
180
|
+
:source_security_group_owner_id => "123"
|
181
|
+
).should.be.an.instance_of EC2::Response
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
specify "permissions should be able to be revoked from a security group with revoke_security_group_ingress." do
|
186
|
+
@ec2.stubs(:make_request).with('RevokeSecurityGroupIngress', { "GroupName"=>"WebServers",
|
187
|
+
"IpProtocol"=>"tcp",
|
188
|
+
"FromPort"=>"8000",
|
189
|
+
"ToPort"=>"80",
|
190
|
+
"CidrIp"=>"0.0.0.0/24",
|
191
|
+
"SourceSecurityGroupName"=>"Source SG Name",
|
192
|
+
"SourceSecurityGroupOwnerId"=>"123"}).
|
193
|
+
returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
|
194
|
+
|
195
|
+
@ec2.revoke_security_group_ingress( :group_name => "WebServers",
|
196
|
+
:ip_protocol => "tcp",
|
197
|
+
:from_port => "8000",
|
198
|
+
:to_port => "80",
|
199
|
+
:cidr_ip => "0.0.0.0/24",
|
200
|
+
:source_security_group_name => "Source SG Name",
|
201
|
+
:source_security_group_owner_id => "123"
|
202
|
+
).should.be.an.instance_of EC2::Response
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|