amazon-ec2 0.2.15 → 0.3.1

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.
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  require File.dirname(__FILE__) + '/test_helper.rb'
@@ -69,7 +69,7 @@ context "EC2 keypairs " do
69
69
  @ec2.stubs(:make_request).with('CreateKeyPair', {"KeyName"=>"example-key-name"}).
70
70
  returns stub(:body => @create_keypair_response_body, :is_a? => true)
71
71
 
72
- @ec2.create_keypair( :key_name => "example-key-name" ).should.be.an.instance_of EC2::Response
72
+ @ec2.create_keypair( :key_name => "example-key-name" ).should.be.an.instance_of Hash
73
73
 
74
74
  response = @ec2.create_keypair( :key_name => "example-key-name" )
75
75
  response.keyName.should.equal "example-key-name"
@@ -93,7 +93,7 @@ context "EC2 keypairs " do
93
93
  specify "should be able to be described with describe_keypairs" do
94
94
  @ec2.stubs(:make_request).with('DescribeKeyPairs', {"KeyName.1"=>"example-key-name"}).
95
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
96
+ @ec2.describe_keypairs( :key_name => "example-key-name" ).should.be.an.instance_of Hash
97
97
  response = @ec2.describe_keypairs( :key_name => "example-key-name" )
98
98
  response.keySet.item[0].keyName.should.equal "example-key-name"
99
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"
@@ -103,7 +103,7 @@ context "EC2 keypairs " do
103
103
  specify "should be able to be deleted with delete_keypairs" do
104
104
  @ec2.stubs(:make_request).with('DeleteKeyPair', {"KeyName"=>"example-key-name"}).
105
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
106
+ @ec2.delete_keypair( :key_name => "example-key-name" ).should.be.an.instance_of Hash
107
107
  response = @ec2.delete_keypair( :key_name => "example-key-name" )
108
108
  response.return.should.equal "true"
109
109
  end
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  require File.dirname(__FILE__) + '/test_helper.rb'
@@ -29,7 +29,7 @@ context "An EC2 instance " do
29
29
  @ec2.stubs(:make_request).with('ConfirmProductInstance', {"ProductCode"=>"774F4FF8", "InstanceId"=>"i-10a64379"}).
30
30
  returns stub(:body => @confirm_product_instance_response_body, :is_a? => true)
31
31
 
32
- @ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" ).should.be.an.instance_of EC2::Response
32
+ @ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" ).should.be.an.instance_of Hash
33
33
  response = @ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" )
34
34
  response.ownerId.should.equal "254933287430"
35
35
  response.result.should.equal "true"
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  require File.dirname(__FILE__) + '/test_helper.rb'
@@ -21,82 +21,32 @@ context "The Response classes " do
21
21
  RESPONSE
22
22
 
23
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
24
  end
37
25
 
38
26
 
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\"/
27
+ specify "should show the response as a formatted string when calling #inspect" do
28
+ @response.inspect.should.equal %{{"return"=>"true", "xmlns"=>"http://ec2.amazonaws.com/doc/2007-03-01"}}
41
29
  end
42
30
 
43
31
 
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
32
+ specify "should be a Hash" do
33
+ @response.kind_of?(Hash).should.equal true
57
34
  end
58
35
 
59
36
 
60
37
  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"
38
+ @response.keys.length.should.equal 2
39
+ test_array = ["return", "xmlns"].sort
40
+ @response.keys.sort.should.equal test_array
76
41
  end
77
42
 
78
43
 
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
44
+ # Note: since we are now returning a hash of the xml, there should be no need for anyone to re-parse the xml.
45
+ # Therefore storing the xml on the object is a waste of memory, and is not done.
46
+ #
47
+ # specify "should return the original amazon XML response in the 'xml' attribute of the response object." do
48
+ # @response.xml.should.equal @http_xml
49
+ # end
100
50
 
101
51
 
102
52
  end
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  require File.dirname(__FILE__) + '/test_helper.rb'
@@ -84,7 +84,7 @@ context "EC2 security groups " do
84
84
  specify "should be able to be created" do
85
85
  @ec2.stubs(:make_request).with('CreateSecurityGroup', {"GroupName"=>"WebServers", "GroupDescription"=>"Web"}).
86
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
87
+ @ec2.create_security_group( :group_name => "WebServers", :group_description => "Web" ).should.be.an.instance_of Hash
88
88
  end
89
89
 
90
90
 
@@ -108,7 +108,7 @@ context "EC2 security groups " do
108
108
  specify "should be able to be deleted" do
109
109
  @ec2.stubs(:make_request).with('DeleteSecurityGroup', {"GroupName"=>"WebServers"}).
110
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
111
+ @ec2.delete_security_group( :group_name => "WebServers" ).should.be.an.instance_of Hash
112
112
  end
113
113
 
114
114
 
@@ -128,7 +128,7 @@ context "EC2 security groups " do
128
128
  specify "should be able to be described with describe_security_groups" do
129
129
  @ec2.stubs(:make_request).with('DescribeSecurityGroups', { "GroupName.1" => "WebServers", "GroupName.2" => "RangedPortsBySource" }).
130
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
131
+ @ec2.describe_security_groups( :group_name => ["WebServers", "RangedPortsBySource"] ).should.be.an.instance_of Hash
132
132
 
133
133
  response = @ec2.describe_security_groups( :group_name => ["WebServers", "RangedPortsBySource"] )
134
134
 
@@ -178,7 +178,7 @@ context "EC2 security groups " do
178
178
  :cidr_ip => "0.0.0.0/24",
179
179
  :source_security_group_name => "Source SG Name",
180
180
  :source_security_group_owner_id => "123"
181
- ).should.be.an.instance_of EC2::Response
181
+ ).should.be.an.instance_of Hash
182
182
  end
183
183
 
184
184
 
@@ -199,7 +199,7 @@ context "EC2 security groups " do
199
199
  :cidr_ip => "0.0.0.0/24",
200
200
  :source_security_group_name => "Source SG Name",
201
201
  :source_security_group_owner_id => "123"
202
- ).should.be.an.instance_of EC2::Response
202
+ ).should.be.an.instance_of Hash
203
203
  end
204
204
 
205
205
  end
@@ -0,0 +1,83 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library, EBS snapshots support
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Yann Klis (mailto:yann.klis@novelys.com)
6
+ # Copyright:: Copyright (c) 2008 Yann Klis
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 snaphots " do
14
+
15
+ setup do
16
+ @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
+
18
+ @describe_snapshots_response_body = <<-RESPONSE
19
+ <DescribeSnapshotsResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
20
+ <snapshotId>snap-78a54011</snapshotId>
21
+ <volumeId>vol-4d826724</volumeId>
22
+ <status>pending</status>
23
+ <startTime>2008-05-07T12:51:50.000Z</startTime>
24
+ <progress>80%</progress>
25
+ </DescribeSnapshotsResponse>
26
+ RESPONSE
27
+
28
+ @create_snapshot_response_body = <<-RESPONSE
29
+ <CreateSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
30
+ <snapshotId>snap-78a54011</snapshotId>
31
+ <volumeId>vol-4d826724</volumeId>
32
+ <status>pending</status>
33
+ <startTime>2008-05-07T12:51:50.000Z</startTime>
34
+ <progress></progress>
35
+ </CreateSnapshotResponse>
36
+ RESPONSE
37
+
38
+ @delete_snapshot_response_body = <<-RESPONSE
39
+ <DeleteSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
40
+ <return>true</return>
41
+ </DeleteSnapshotResponse>
42
+ RESPONSE
43
+
44
+ end
45
+
46
+
47
+ specify "should be able to be described with describe_snapshots" do
48
+ @ec2.stubs(:make_request).with('DescribeSnapshots', {"SnapshotId.1"=>"snap-78a54011"}).
49
+ returns stub(:body => @describe_snapshots_response_body, :is_a? => true)
50
+
51
+ @ec2.describe_snapshots( :snapshot_id => "snap-78a54011" ).should.be.an.instance_of Hash
52
+
53
+ response = @ec2.describe_snapshots( :snapshot_id => "snap-78a54011" )
54
+ response.snapshotId.should.equal "snap-78a54011"
55
+ response.volumeId.should.equal "vol-4d826724"
56
+ response.status.should.equal "pending"
57
+ response.progress.should.equal "80%"
58
+ end
59
+
60
+ specify "should be able to be created with a volume_id" do
61
+ @ec2.stubs(:make_request).with('CreateSnapshot', {"VolumeId" => "vol-4d826724"}).
62
+ returns stub(:body => @create_snapshot_response_body, :is_a? => true)
63
+
64
+ @ec2.create_snapshot( :volume_id => "vol-4d826724" ).should.be.an.instance_of Hash
65
+
66
+ response = @ec2.create_snapshot( :volume_id => "vol-4d826724" )
67
+ response.snapshotId.should.equal "snap-78a54011"
68
+ response.volumeId.should.equal "vol-4d826724"
69
+ response.status.should.equal "pending"
70
+ response.progress.should.equal nil
71
+ end
72
+
73
+ specify "should be able to be deleted with a snapsot_id" do
74
+ @ec2.stubs(:make_request).with('DeleteSnapshot', {"SnapshotId" => "snap-78a54011"}).
75
+ returns stub(:body => @delete_snapshot_response_body, :is_a? => true)
76
+
77
+ @ec2.delete_snapshot( :snapshot_id => "snap-78a54011" ).should.be.an.instance_of Hash
78
+
79
+ response = @ec2.delete_snapshot( :snapshot_id => "snap-78a54011" )
80
+ response.return.should.equal "true"
81
+ end
82
+
83
+ end
@@ -0,0 +1,142 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library, EBS volumes support
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Yann Klis (mailto:yann.klis@novelys.com)
6
+ # Copyright:: Copyright (c) 2008 Yann Klis
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 volumes " do
14
+
15
+ setup do
16
+ @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
+
18
+ @describe_volumes_response_body = <<-RESPONSE
19
+ <DescribeVolumesResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
20
+ <volumeSet>
21
+ <item>
22
+ <volumeId>vol-4282672b</volumeId>
23
+ <size>800</size>
24
+ <status>in-use</status>
25
+ <createTime>2008-05-07T11:51:50.000Z</createTime>
26
+ <attachmentSet>
27
+ <item>
28
+ <volumeId>vol-4282672b</volumeId>
29
+ <instanceId>i-6058a509</instanceId>
30
+ <size>800</size>
31
+ <status>attached</status>
32
+ <attachTime>2008-05-07T12:51:50.000Z</attachTime>
33
+ </item>
34
+ </attachmentSet>
35
+ </item>
36
+ </volumeSet>
37
+ </DescribeVolumesResponse>
38
+ RESPONSE
39
+
40
+ @create_volume_response_body = <<-RESPONSE
41
+ <CreateVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
42
+ <volumeId>vol-4d826724</volumeId>
43
+ <size>800</size>
44
+ <status>creating</status>
45
+ <createTime>2008-05-07T11:51:50.000Z</createTime>
46
+ <zone>us-east-1a</zone>
47
+ <snapshotId></snapshotId>
48
+ </CreateVolumeResponse>
49
+ RESPONSE
50
+
51
+ @delete_volume_response_body = <<-RESPONSE
52
+ <ReleaseAddressResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
53
+ <return>true</return>
54
+ </ReleaseAddressResponse>
55
+ RESPONSE
56
+
57
+ @attach_volume_response_body = <<-RESPONSE
58
+ <AttachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
59
+ <volumeId>vol-4d826724</volumeId>
60
+ <instanceId>i-6058a509</instanceId>
61
+ <device>/dev/sdh</device>
62
+ <status>attaching</status>
63
+ <attachTime>2008-05-07T11:51:50.000Z</attachTime>
64
+ </AttachVolumeResponse>
65
+ RESPONSE
66
+
67
+ @detach_volume_response_body = <<-RESPONSE
68
+ <DetachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
69
+ <volumeId>vol-4d826724</volumeId>
70
+ <instanceId>i-6058a509</instanceId>
71
+ <device>/dev/sdh</device>
72
+ <status>detaching</status>
73
+ <attachTime>2008-05-08T11:51:50.000Z</attachTime>
74
+ </DetachVolumeResponse>
75
+ RESPONSE
76
+
77
+ end
78
+
79
+
80
+ specify "should be able to be described with describe_volumes" do
81
+ @ec2.stubs(:make_request).with('DescribeVolumes', {"VolumeId.1"=>"vol-4282672b"}).
82
+ returns stub(:body => @describe_volumes_response_body, :is_a? => true)
83
+
84
+ @ec2.describe_volumes( :volume_id => ["vol-4282672b"] ).should.be.an.instance_of Hash
85
+
86
+ response = @ec2.describe_volumes( :volume_id => ["vol-4282672b"] )
87
+ response.volumeSet.item[0].volumeId.should.equal "vol-4282672b"
88
+ response.volumeSet.item[0].attachmentSet.item[0]['size'].should.equal "800"
89
+ response.volumeSet.item[0].attachmentSet.item[0].volumeId.should.equal "vol-4282672b"
90
+ response.volumeSet.item[0].attachmentSet.item[0].instanceId.should.equal "i-6058a509"
91
+ end
92
+
93
+ specify "should be able to be created with an availability_zone with size" do
94
+ @ec2.stubs(:make_request).with('CreateVolume', {"AvailabilityZone" => "us-east-1a", "Size"=>"800", "SnapshotId"=>""}).
95
+ returns stub(:body => @create_volume_response_body, :is_a? => true)
96
+
97
+ @ec2.create_volume( :availability_zone => "us-east-1a", :size => "800" ).should.be.an.instance_of Hash
98
+
99
+ response = @ec2.create_volume( :availability_zone => "us-east-1a", :size => "800" )
100
+ response.volumeId.should.equal "vol-4d826724"
101
+ response['size'].should.equal "800"
102
+ response.status.should.equal "creating"
103
+ response.zone.should.equal "us-east-1a"
104
+ end
105
+
106
+ specify "should be able to be deleted with a volume_id" do
107
+ @ec2.stubs(:make_request).with('DeleteVolume', {"VolumeId" => "vol-4282672b"}).
108
+ returns stub(:body => @delete_volume_response_body, :is_a? => true)
109
+
110
+ @ec2.delete_volume( :volume_id => "vol-4282672b" ).should.be.an.instance_of Hash
111
+
112
+ response = @ec2.delete_volume( :volume_id => "vol-4282672b" )
113
+ response.return.should.equal "true"
114
+ end
115
+
116
+ specify "should be able to be attached with a volume_id with an instance_id with a device" do
117
+ @ec2.stubs(:make_request).with('AttachVolume', {"VolumeId" => "vol-4d826724", "InstanceId"=>"i-6058a509", "Device"=>"/dev/sdh"}).
118
+ returns stub(:body => @attach_volume_response_body, :is_a? => true)
119
+
120
+ @ec2.attach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509", :device => "/dev/sdh" ).should.be.an.instance_of Hash
121
+
122
+ response = @ec2.attach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509", :device => "/dev/sdh" )
123
+ response.volumeId.should.equal "vol-4d826724"
124
+ response.instanceId.should.equal "i-6058a509"
125
+ response.device.should.equal "/dev/sdh"
126
+ response.status.should.equal "attaching"
127
+ end
128
+
129
+ specify "should be able to be detached with a volume_id with an instance_id" do
130
+ @ec2.stubs(:make_request).with('DetachVolume', {"VolumeId" => "vol-4d826724", "InstanceId"=>"i-6058a509", "Device"=>"", "Force"=>""}).
131
+ returns stub(:body => @detach_volume_response_body, :is_a? => true)
132
+
133
+ @ec2.detach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509" ).should.be.an.instance_of Hash
134
+
135
+ response = @ec2.detach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509" )
136
+ response.volumeId.should.equal "vol-4d826724"
137
+ response.instanceId.should.equal "i-6058a509"
138
+ response.device.should.equal "/dev/sdh"
139
+ response.status.should.equal "detaching"
140
+ end
141
+
142
+ end