nirvdrum-amazon-ec2 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gitignore +9 -0
  2. data/.yardopts +1 -0
  3. data/ChangeLog +304 -0
  4. data/LICENSE +66 -0
  5. data/README.rdoc +359 -0
  6. data/README_dev.rdoc +10 -0
  7. data/Rakefile +70 -0
  8. data/VERSION +1 -0
  9. data/amazon-ec2.gemspec +142 -0
  10. data/bin/ec2-gem-example.rb +137 -0
  11. data/bin/ec2-gem-profile.rb +10 -0
  12. data/bin/ec2sh +62 -0
  13. data/bin/setup.rb +29 -0
  14. data/deps.rip +1 -0
  15. data/lib/AWS.rb +321 -0
  16. data/lib/AWS/Autoscaling.rb +70 -0
  17. data/lib/AWS/Autoscaling/autoscaling.rb +273 -0
  18. data/lib/AWS/Cloudwatch.rb +32 -0
  19. data/lib/AWS/Cloudwatch/monitoring.rb +80 -0
  20. data/lib/AWS/EC2.rb +33 -0
  21. data/lib/AWS/EC2/availability_zones.rb +29 -0
  22. data/lib/AWS/EC2/console.rb +25 -0
  23. data/lib/AWS/EC2/devpay.rb +18 -0
  24. data/lib/AWS/EC2/elastic_ips.rb +86 -0
  25. data/lib/AWS/EC2/image_attributes.rb +133 -0
  26. data/lib/AWS/EC2/images.rb +117 -0
  27. data/lib/AWS/EC2/instances.rb +234 -0
  28. data/lib/AWS/EC2/keypairs.rb +47 -0
  29. data/lib/AWS/EC2/products.rb +21 -0
  30. data/lib/AWS/EC2/security_groups.rb +164 -0
  31. data/lib/AWS/EC2/snapshots.rb +102 -0
  32. data/lib/AWS/EC2/spot_instance_requests.rb +105 -0
  33. data/lib/AWS/EC2/volumes.rb +100 -0
  34. data/lib/AWS/ELB.rb +71 -0
  35. data/lib/AWS/ELB/load_balancers.rb +178 -0
  36. data/lib/AWS/RDS.rb +73 -0
  37. data/lib/AWS/RDS/rds.rb +522 -0
  38. data/lib/AWS/exceptions.rb +200 -0
  39. data/lib/AWS/responses.rb +21 -0
  40. data/perftools/ec2prof +0 -0
  41. data/perftools/ec2prof-results.dot +132 -0
  42. data/perftools/ec2prof-results.txt +100 -0
  43. data/perftools/ec2prof.symbols +102 -0
  44. data/test/test_Autoscaling_groups.rb +337 -0
  45. data/test/test_EC2.rb +68 -0
  46. data/test/test_EC2_availability_zones.rb +49 -0
  47. data/test/test_EC2_console.rb +54 -0
  48. data/test/test_EC2_elastic_ips.rb +144 -0
  49. data/test/test_EC2_image_attributes.rb +238 -0
  50. data/test/test_EC2_images.rb +229 -0
  51. data/test/test_EC2_instances.rb +611 -0
  52. data/test/test_EC2_keypairs.rb +123 -0
  53. data/test/test_EC2_products.rb +48 -0
  54. data/test/test_EC2_responses.rb +53 -0
  55. data/test/test_EC2_s3_xmlsimple.rb +80 -0
  56. data/test/test_EC2_security_groups.rb +205 -0
  57. data/test/test_EC2_snapshots.rb +83 -0
  58. data/test/test_EC2_spot_instance_requests.rb +178 -0
  59. data/test/test_EC2_volumes.rb +142 -0
  60. data/test/test_ELB_load_balancers.rb +239 -0
  61. data/test/test_RDS.rb +354 -0
  62. data/test/test_helper.rb +23 -0
  63. data/wsdl/2007-08-29.ec2.wsdl +1269 -0
  64. data/wsdl/2008-02-01.ec2.wsdl +1614 -0
  65. data/wsdl/2008-05-05.ec2.wsdl +2052 -0
  66. data/wsdl/2008-12-01.ec2.wsdl +2354 -0
  67. data/wsdl/2009-10-31.ec2.wsdl +4261 -0
  68. data/wsdl/2009-11-30.ec2.wsdl +4668 -0
  69. metadata +199 -0
@@ -0,0 +1,123 @@
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 keypairs " do
14
+
15
+ before do
16
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
+
18
+ @create_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 Hash
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(AWS::ArgumentError)
87
+ lambda { @ec2.create_keypair() }.should.raise(AWS::ArgumentError)
88
+ lambda { @ec2.create_keypair( :key_name => nil ) }.should.raise(AWS::ArgumentError)
89
+ lambda { @ec2.create_keypair( :key_name => "" ) }.should.raise(AWS::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 Hash
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 Hash
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(AWS::ArgumentError)
117
+ lambda { @ec2.delete_keypair() }.should.raise(AWS::ArgumentError)
118
+ lambda { @ec2.delete_keypair( :key_name => nil ) }.should.raise(AWS::ArgumentError)
119
+ lambda { @ec2.delete_keypair( :key_name => "" ) }.should.raise(AWS::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: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 instance " 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
+ @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 Hash
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(AWS::ArgumentError)
41
+ lambda { @ec2.confirm_product_instance(:product_code => "774F4FF8", :instance_id => nil) }.should.raise(AWS::ArgumentError)
42
+ lambda { @ec2.confirm_product_instance(:product_code => "774F4FF8", :instance_id => "") }.should.raise(AWS::ArgumentError)
43
+ lambda { @ec2.confirm_product_instance(:product_code => nil, :instance_id => "i-10a64379") }.should.raise(AWS::ArgumentError)
44
+ lambda { @ec2.confirm_product_instance(:product_code => "", :instance_id => "i-10a64379") }.should.raise(AWS::ArgumentError)
45
+ end
46
+
47
+
48
+ end
@@ -0,0 +1,53 @@
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 Response classes " do
14
+
15
+
16
+ before 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 = AWS::Response.parse(:xml => @http_xml)
24
+ end
25
+
26
+
27
+ specify "should show the response as a formatted string when calling #inspect" do
28
+ # sorting the response hash first since ruby 1.8.6 and ruby 1.9.1 sort the hash differently before the inspect
29
+ @response.sort.inspect.should.equal %{[[\"return\", \"true\"], [\"xmlns\", \"http://ec2.amazonaws.com/doc/2007-03-01\"]]}
30
+ end
31
+
32
+
33
+ specify "should be a Hash" do
34
+ @response.kind_of?(Hash).should.equal true
35
+ end
36
+
37
+
38
+ specify "should return its members" do
39
+ @response.keys.length.should.equal 2
40
+ test_array = ["return", "xmlns"].sort
41
+ @response.keys.sort.should.equal test_array
42
+ end
43
+
44
+
45
+ # Note: since we are now returning a hash of the xml, there should be no need for anyone to re-parse the xml.
46
+ # Therefore storing the xml on the object is a waste of memory, and is not done.
47
+ #
48
+ # specify "should return the original amazon XML response in the 'xml' attribute of the response object." do
49
+ # @response.xml.should.equal @http_xml
50
+ # end
51
+
52
+
53
+ end
@@ -0,0 +1,80 @@
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
+ # NOTE : These tests exercise amazon-ec2 when used with the aws/s3 gem
14
+ # which was demonstrating some breaking behavior. The fix was to
15
+ # add the XmlSimple option "'keeproot' => false" in responses.rb
16
+
17
+ context "EC2 aws-s3 compat test" do
18
+
19
+ before do
20
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
21
+
22
+ @describe_instances_response_body = <<-RESPONSE
23
+ <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-08-29">
24
+ <reservationSet>
25
+ <item>
26
+ <reservationId>r-44a5402d</reservationId>
27
+ <ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
28
+ <groupSet>
29
+ <item>
30
+ <groupId>default</groupId>
31
+ </item>
32
+ </groupSet>
33
+ <instancesSet>
34
+ <item>
35
+ <instanceId>i-28a64341</instanceId>
36
+ <imageId>ami-6ea54007</imageId>
37
+ <instanceState>
38
+ <code>0</code>
39
+ <name>running</name>
40
+ </instanceState>
41
+ <privateDnsName>domU-12-31-35-00-1E-01.z-2.compute-1.internal</privateDnsName>
42
+ <dnsName>ec2-72-44-33-4.z-2.compute-1.amazonaws.com</dnsName>
43
+ <keyName>example-key-name</keyName>
44
+ <productCodesSet>
45
+ <item><productCode>774F4FF8</productCode></item>
46
+ </productCodesSet>
47
+ <instanceType>m1.small</instanceType>
48
+ <launchTime>2007-08-07T11:54:42.000Z</launchTime>
49
+ </item>
50
+ </instancesSet>
51
+ </item>
52
+ </reservationSet>
53
+ </DescribeInstancesResponse>
54
+ RESPONSE
55
+
56
+ end
57
+
58
+ specify "should be able to be described and return the correct Ruby response class" do
59
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
60
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
61
+ @ec2.describe_instances.should.be.an.instance_of Hash
62
+ response = @ec2.describe_instances
63
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
64
+ end
65
+
66
+ specify "should be able to be described and return the correct Ruby response class when the aws/s3 lib is required" do
67
+ begin
68
+ require 'aws/s3s'
69
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
70
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
71
+ @ec2.describe_instances.should.be.an.instance_of Hash
72
+ response = @ec2.describe_instances
73
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
74
+ rescue LoadError
75
+ # do nothing. no aws/s3 gem installed to test against
76
+ end
77
+ end
78
+
79
+ end
80
+
@@ -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: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 security groups " do
14
+
15
+ before do
16
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
+
18
+ @create_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 Hash
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(AWS::ArgumentError)
96
+ lambda { @ec2.create_security_group() }.should.raise(AWS::ArgumentError)
97
+
98
+ # :group_name can't be nil or empty
99
+ lambda { @ec2.create_security_group( :group_name => "", :group_description => "Web" ) }.should.raise(AWS::ArgumentError)
100
+ lambda { @ec2.create_security_group( :group_name => nil, :group_description => "Web" ) }.should.raise(AWS::ArgumentError)
101
+
102
+ # :group_description can't be nil or empty
103
+ lambda { @ec2.create_security_group( :group_name => "WebServers", :group_description => "" ) }.should.raise(AWS::ArgumentError)
104
+ lambda { @ec2.create_security_group( :group_name => "WebServers", :group_description => nil ) }.should.raise(AWS::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 Hash
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(AWS::ArgumentError)
120
+ lambda { @ec2.delete_security_group() }.should.raise(AWS::ArgumentError)
121
+
122
+ # :group_name can't be nil or empty
123
+ lambda { @ec2.delete_security_group( :group_name => "" ) }.should.raise(AWS::ArgumentError)
124
+ lambda { @ec2.delete_security_group( :group_name => nil ) }.should.raise(AWS::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 Hash
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(AWS::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 Hash
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 Hash
203
+ end
204
+
205
+ end