amazon-ec2 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/ChangeLog +7 -4
  2. data/README.rdoc +12 -12
  3. data/README_dev.rdoc +6 -0
  4. data/Rakefile +2 -1
  5. data/VERSION +1 -1
  6. data/amazon-ec2.gemspec +25 -18
  7. data/bin/ec2-gem-example.rb +3 -3
  8. data/bin/ec2-gem-profile.rb +2 -2
  9. data/bin/ec2sh +4 -4
  10. data/bin/setup.rb +4 -2
  11. data/lib/{EC2.rb → AWS.rb} +33 -67
  12. data/lib/AWS/EC2.rb +67 -0
  13. data/lib/AWS/EC2/availability_zones.rb +43 -0
  14. data/lib/AWS/EC2/console.rb +46 -0
  15. data/lib/AWS/EC2/elastic_ips.rb +154 -0
  16. data/lib/AWS/EC2/image_attributes.rb +168 -0
  17. data/lib/AWS/EC2/images.rb +136 -0
  18. data/lib/AWS/EC2/instances.rb +218 -0
  19. data/lib/AWS/EC2/keypairs.rb +96 -0
  20. data/lib/AWS/EC2/products.rb +45 -0
  21. data/lib/AWS/EC2/security_groups.rb +234 -0
  22. data/lib/AWS/EC2/snapshots.rb +96 -0
  23. data/lib/AWS/EC2/volumes.rb +172 -0
  24. data/lib/AWS/ELB.rb +67 -0
  25. data/lib/AWS/ELB/load_balancers.rb +198 -0
  26. data/lib/{EC2 → AWS}/exceptions.rb +21 -2
  27. data/lib/{EC2 → AWS}/responses.rb +4 -5
  28. data/perftools/ec2prof-results.txt +4 -4
  29. data/perftools/ec2prof.symbols +4 -4
  30. data/test/test_EC2.rb +14 -14
  31. data/test/test_EC2_availability_zones.rb +2 -2
  32. data/test/test_EC2_console.rb +5 -5
  33. data/test/test_EC2_elastic_ips.rb +13 -13
  34. data/test/test_EC2_image_attributes.rb +35 -35
  35. data/test/test_EC2_images.rb +7 -7
  36. data/test/test_EC2_instances.rb +35 -35
  37. data/test/test_EC2_keypairs.rb +10 -10
  38. data/test/test_EC2_products.rb +7 -7
  39. data/test/test_EC2_responses.rb +2 -2
  40. data/test/test_EC2_s3_xmlsimple.rb +2 -2
  41. data/test/test_EC2_security_groups.rb +13 -13
  42. data/test/test_EC2_snapshots.rb +2 -2
  43. data/test/test_EC2_volumes.rb +2 -2
  44. data/test/test_ELB_load_balancers.rb +239 -0
  45. data/test/test_helper.rb +1 -1
  46. metadata +24 -17
  47. data/lib/EC2/availability_zones.rb +0 -41
  48. data/lib/EC2/console.rb +0 -44
  49. data/lib/EC2/elastic_ips.rb +0 -153
  50. data/lib/EC2/image_attributes.rb +0 -166
  51. data/lib/EC2/images.rb +0 -134
  52. data/lib/EC2/instances.rb +0 -216
  53. data/lib/EC2/keypairs.rb +0 -94
  54. data/lib/EC2/products.rb +0 -43
  55. data/lib/EC2/security_groups.rb +0 -232
  56. data/lib/EC2/snapshots.rb +0 -94
  57. data/lib/EC2/volumes.rb +0 -170
@@ -0,0 +1,45 @@
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
+ module AWS
12
+ module EC2
13
+
14
+ class Base < AWS::Base
15
+
16
+ #Amazon Developer Guide Docs:
17
+ #
18
+ # The ConfirmProductInstance operation returns true if the given product code is attached to the instance
19
+ # with the given instance id. False is returned if the product code is not attached to the instance.
20
+ #
21
+ #Required Arguments:
22
+ #
23
+ # :product_code => String (default : "")
24
+ # :instance_id => String (default : "")
25
+ #
26
+ #Optional Arguments:
27
+ #
28
+ # none
29
+ #
30
+ def confirm_product_instance( options ={} )
31
+
32
+ options = {:product_code => "", :instance_id => ""}.merge(options)
33
+
34
+ raise ArgumentError, "No product code provided" if options[:product_code].nil? || options[:product_code].empty?
35
+ raise ArgumentError, "No instance ID provided" if options[:instance_id].nil? || options[:instance_id].empty?
36
+
37
+ params = { "ProductCode" => options[:product_code], "InstanceId" => options[:instance_id] }
38
+
39
+ return response_generator(:action => "ConfirmProductInstance", :params => params)
40
+
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,234 @@
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
+ module AWS
12
+ module EC2
13
+
14
+ class Base < AWS::Base
15
+
16
+
17
+ #Amazon Developer Guide Docs:
18
+ #
19
+ # The CreateSecurityGroup operation creates a new security group. Every instance is launched
20
+ # in a security group. If none is specified as part of the launch request then instances
21
+ # are launched in the default security group. Instances within the same security group have
22
+ # unrestricted network access to one another. Instances will reject network access attempts from other
23
+ # instances in a different security group. As the owner of instances you may grant or revoke specific
24
+ # permissions using the AuthorizeSecurityGroupIngress and RevokeSecurityGroupIngress operations.
25
+ #
26
+ #Required Arguments:
27
+ #
28
+ # :group_name => String (default : "")
29
+ # :group_description => String (default : "")
30
+ #
31
+ #Optional Arguments:
32
+ #
33
+ # none
34
+ #
35
+ def create_security_group( options = {} )
36
+
37
+ options = {:group_name => "",
38
+ :group_description => ""
39
+ }.merge(options)
40
+
41
+ raise ArgumentError, "No :group_name provided" if options[:group_name].nil? || options[:group_name].empty?
42
+ raise ArgumentError, "No :group_description provided" if options[:group_description].nil? || options[:group_description].empty?
43
+
44
+ params = {
45
+ "GroupName" => options[:group_name],
46
+ "GroupDescription" => options[:group_description]
47
+ }
48
+
49
+ return response_generator(:action => "CreateSecurityGroup", :params => params)
50
+
51
+ end
52
+
53
+
54
+ #Amazon Developer Guide Docs:
55
+ #
56
+ # The DescribeSecurityGroups operation returns information about security groups owned by the
57
+ # user making the request.
58
+ #
59
+ # An optional list of security group names may be provided to request information for those security
60
+ # groups only. If no security group names are provided, information of all security groups will be
61
+ # returned. If a group is specified that does not exist a fault is returned.
62
+ #
63
+ #Required Arguments:
64
+ #
65
+ # none
66
+ #
67
+ #Optional Arguments:
68
+ #
69
+ # :group_name => Array (default : [])
70
+ #
71
+ def describe_security_groups( options = {} )
72
+
73
+ options = { :group_name => [] }.merge(options)
74
+
75
+ params = pathlist("GroupName", options[:group_name] )
76
+
77
+ return response_generator(:action => "DescribeSecurityGroups", :params => params)
78
+
79
+ end
80
+
81
+
82
+ #Amazon Developer Guide Docs:
83
+ #
84
+ # The DeleteSecurityGroup operation deletes a security group.
85
+ #
86
+ # If an attempt is made to delete a security group and any instances exist that are members of that group a
87
+ # fault is returned.
88
+ #
89
+ #Required Arguments:
90
+ #
91
+ # :group_name => String (default : "")
92
+ #
93
+ #Optional Arguments:
94
+ #
95
+ # none
96
+ #
97
+ def delete_security_group( options = {} )
98
+
99
+ options = { :group_name => "" }.merge(options)
100
+
101
+ raise ArgumentError, "No :group_name provided" if options[:group_name].nil? || options[:group_name].empty?
102
+
103
+ params = { "GroupName" => options[:group_name] }
104
+
105
+ return response_generator(:action => "DeleteSecurityGroup", :params => params)
106
+
107
+ end
108
+
109
+
110
+ #Amazon Developer Guide Docs:
111
+ #
112
+ # The AuthorizeSecurityGroupIngress operation adds permissions to a security group.
113
+ #
114
+ # Permissions are specified in terms of the IP protocol (TCP, UDP or ICMP), the source of the request (by
115
+ # IP range or an Amazon EC2 user-group pair), source and destination port ranges (for TCP and UDP),
116
+ # and ICMP codes and types (for ICMP). When authorizing ICMP, -1 may be used as a wildcard in the
117
+ # type and code fields.
118
+ #
119
+ # Permission changes are propagated to instances within the security group being modified as quickly as
120
+ # possible. However, a small delay is likely, depending on the number of instances that are members of
121
+ # the indicated group.
122
+ #
123
+ # When authorizing a user/group pair permission, GroupName, SourceSecurityGroupName and
124
+ # SourceSecurityGroupOwnerId must be specified. When authorizing a CIDR IP permission,
125
+ # GroupName, IpProtocol, FromPort, ToPort and CidrIp must be specified. Mixing these two types
126
+ # of parameters is not allowed.
127
+ #
128
+ #Required Arguments:
129
+ #
130
+ # :group_name => String (default : "")
131
+ #
132
+ #Optional Arguments:
133
+ #
134
+ # :ip_protocol => String (default : nil) : Required when authorizing CIDR IP permission
135
+ # :from_port => Integer (default : nil) : Required when authorizing CIDR IP permission
136
+ # :to_port => Integer (default : nil) : Required when authorizing CIDR IP permission
137
+ # :cidr_ip => String (default : nil): Required when authorizing CIDR IP permission
138
+ # :source_security_group_name => String (default : nil) : Required when authorizing user group pair permissions
139
+ # :source_security_group_owner_id => String (default : nil) : Required when authorizing user group pair permissions
140
+ #
141
+ def authorize_security_group_ingress( options = {} )
142
+
143
+ # defaults
144
+ options = { :group_name => nil,
145
+ :ip_protocol => nil,
146
+ :from_port => nil,
147
+ :to_port => nil,
148
+ :cidr_ip => nil,
149
+ :source_security_group_name => nil,
150
+ :source_security_group_owner_id => nil }.merge(options)
151
+
152
+ # lets not validate the rest of the possible permutations of required params and instead let
153
+ # EC2 sort it out on the server side. We'll only require :group_name as that is always needed.
154
+ raise ArgumentError, "No :group_name provided" if options[:group_name].nil? || options[:group_name].empty?
155
+
156
+ params = { "GroupName" => options[:group_name],
157
+ "IpProtocol" => options[:ip_protocol],
158
+ "FromPort" => options[:from_port].to_s,
159
+ "ToPort" => options[:to_port].to_s,
160
+ "CidrIp" => options[:cidr_ip],
161
+ "SourceSecurityGroupName" => options[:source_security_group_name],
162
+ "SourceSecurityGroupOwnerId" => options[:source_security_group_owner_id]
163
+ }
164
+
165
+ return response_generator(:action => "AuthorizeSecurityGroupIngress", :params => params)
166
+
167
+ end
168
+
169
+
170
+ #Amazon Developer Guide Docs:
171
+ #
172
+ # The RevokeSecurityGroupIngress operation revokes existing permissions that were previously
173
+ # granted to a security group. The permissions to revoke must be specified using the same values
174
+ # originally used to grant the permission.
175
+ #
176
+ # Permissions are specified in terms of the IP protocol (TCP, UDP or ICMP), the source of the request (by
177
+ # IP range or an Amazon EC2 user-group pair), source and destination port ranges (for TCP and UDP),
178
+ # and ICMP codes and types (for ICMP). When authorizing ICMP, -1 may be used as a wildcard in the
179
+ # type and code fields.
180
+ #
181
+ # Permission changes are propagated to instances within the security group being modified as quickly as
182
+ # possible. However, a small delay is likely, depending on the number of instances that are members of
183
+ # the indicated group.
184
+ #
185
+ # When revoking a user/group pair permission, GroupName, SourceSecurityGroupName and
186
+ # SourceSecurityGroupOwnerId must be specified. When authorizing a CIDR IP permission,
187
+ # GroupName, IpProtocol, FromPort, ToPort and CidrIp must be specified. Mixing these two types
188
+ # of parameters is not allowed.
189
+ #
190
+ #Required Arguments:
191
+ #
192
+ # :group_name => String (default : "")
193
+ #
194
+ #Optional Arguments:
195
+ #
196
+ # :ip_protocol => String (default : nil) : Required when revoking CIDR IP permission
197
+ # :from_port => Integer (default : nil) : Required when revoking CIDR IP permission
198
+ # :to_port => Integer (default : nil) : Required when revoking CIDR IP permission
199
+ # :cidr_ip => String (default : nil): Required when revoking CIDR IP permission
200
+ # :source_security_group_name => String (default : nil) : Required when revoking user group pair permissions
201
+ # :source_security_group_owner_id => String (default : nil) : Required when revoking user group pair permissions
202
+ #
203
+ def revoke_security_group_ingress( options = {} )
204
+
205
+ # defaults
206
+ options = { :group_name => nil,
207
+ :ip_protocol => nil,
208
+ :from_port => nil,
209
+ :to_port => nil,
210
+ :cidr_ip => nil,
211
+ :source_security_group_name => nil,
212
+ :source_security_group_owner_id => nil }.merge(options)
213
+
214
+ # lets not validate the rest of the possible permutations of required params and instead let
215
+ # EC2 sort it out on the server side. We'll only require :group_name as that is always needed.
216
+ raise ArgumentError, "No :group_name provided" if options[:group_name].nil? || options[:group_name].empty?
217
+
218
+ params = { "GroupName" => options[:group_name],
219
+ "IpProtocol" => options[:ip_protocol],
220
+ "FromPort" => options[:from_port].to_s,
221
+ "ToPort" => options[:to_port].to_s,
222
+ "CidrIp" => options[:cidr_ip],
223
+ "SourceSecurityGroupName" => options[:source_security_group_name],
224
+ "SourceSecurityGroupOwnerId" => options[:source_security_group_owner_id]
225
+ }
226
+
227
+ return response_generator(:action => "RevokeSecurityGroupIngress", :params => params)
228
+
229
+ end
230
+
231
+ end
232
+
233
+ end
234
+ end
@@ -0,0 +1,96 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library, EBS snaphshots 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
+ module AWS
12
+ module EC2
13
+
14
+ class Base < AWS::Base
15
+
16
+ #Amazon Developer Guide Docs:
17
+ #
18
+ # The DescribeSnapshots operation describes the status of Amazon EBS snapshots.
19
+ #
20
+ #Required Arguments:
21
+ #
22
+ # none
23
+ #
24
+ #Optional Arguments:
25
+ #
26
+ # :snapshot_id => Array (default : [])
27
+ #
28
+
29
+ def describe_snapshots( options = {} )
30
+
31
+ options = { :snapshot_id => [] }.merge(options)
32
+
33
+ params = pathlist("SnapshotId", options[:snapshot_id] )
34
+
35
+ return response_generator(:action => "DescribeSnapshots", :params => params)
36
+
37
+ end
38
+
39
+ #Amazon Developer Guide Docs:
40
+ #
41
+ # The CreateSnapshot operation creates a snapshot of an Amazon EBS volume and stores it in Amazon S3. You can use snapshots for backups, to launch instances from identical snapshots, and to save data before shutting down an instance.
42
+ #
43
+ #Required Arguments:
44
+ #
45
+ # :volume_id => String (default : '')
46
+ #
47
+ #Optional Arguments:
48
+ #
49
+ # none
50
+ #
51
+
52
+ def create_snapshot( options = {} )
53
+
54
+ # defaults
55
+ options = { :volume_id => '' }.merge(options)
56
+
57
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
58
+
59
+ params = {
60
+ "VolumeId" => options[:volume_id]
61
+ }
62
+
63
+ return response_generator(:action => "CreateSnapshot", :params => params)
64
+
65
+ end
66
+
67
+ #Amazon Developer Guide Docs:
68
+ #
69
+ # The DeleteSnapshot operation deletes a snapshot of an Amazon EBS volume that is stored in Amazon S3.
70
+ #
71
+ #Required Arguments:
72
+ #
73
+ # :snapshot_id => String (default : '')
74
+ #
75
+ #Optional Arguments:
76
+ #
77
+ # none
78
+ #
79
+
80
+ def delete_snapshot( options = {} )
81
+
82
+ options = { :snapshot_id => '' }.merge(options)
83
+
84
+ raise ArgumentError, "No :snapshot_id provided" if options[:snapshot_id].nil? || options[:snapshot_id].empty?
85
+
86
+ params = {
87
+ "SnapshotId" => options[:snapshot_id]
88
+ }
89
+
90
+ return response_generator(:action => "DeleteSnapshot", :params => params)
91
+
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,172 @@
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
+ module AWS
12
+ module EC2
13
+
14
+ class Base < AWS::Base
15
+
16
+ #Amazon Developer Guide Docs:
17
+ #
18
+ # The DescribeVolumes operation lists one or more Amazon EBS volumes that you own, If you do not specify any volumes, Amazon EBS returns all volumes that you own.
19
+ #
20
+ #Required Arguments:
21
+ #
22
+ # none
23
+ #
24
+ #Optional Arguments:
25
+ #
26
+ # :volume_id => Array (default : [])
27
+ #
28
+
29
+ def describe_volumes( options = {} )
30
+
31
+ options = { :volume_id => [] }.merge(options)
32
+
33
+ params = pathlist("VolumeId", options[:volume_id] )
34
+
35
+ return response_generator(:action => "DescribeVolumes", :params => params)
36
+
37
+ end
38
+
39
+ #Amazon Developer Guide Docs:
40
+ #
41
+ # The CreateVolume operation creates a new Amazon EBS volume that you can mount from any Amazon EC2 instance.
42
+ #
43
+ #Required Arguments:
44
+ #
45
+ # :availability_zone => String (default : '')
46
+ #
47
+ #Optional Arguments:
48
+ #
49
+ # :size => String (default : '')
50
+ # :snapshot_id => String (default : '')
51
+ #
52
+
53
+ def create_volume( options = {} )
54
+
55
+ # defaults
56
+ options = { :availability_zone => '' }.merge(options)
57
+
58
+ raise ArgumentError, "No :availability_zone provided" if options[:availability_zone].nil? || options[:availability_zone].empty?
59
+
60
+ options = { :size => '' }.merge(options)
61
+ options = { :snapshot_id => '' }.merge(options)
62
+
63
+ params = {
64
+ "AvailabilityZone" => options[:availability_zone],
65
+ "Size" => options[:size],
66
+ "SnapshotId" => options[:snapshot_id]
67
+ }
68
+
69
+ return response_generator(:action => "CreateVolume", :params => params)
70
+
71
+ end
72
+
73
+ #Amazon Developer Guide Docs:
74
+ #
75
+ # The DeleteVolume operation deletes an Amazon EBS volume.
76
+ #
77
+ #Required Arguments:
78
+ #
79
+ # :volume_id => String (default : '')
80
+ #
81
+ #Optional Arguments:
82
+ #
83
+ # none
84
+ #
85
+
86
+ def delete_volume( options = {} )
87
+
88
+ options = { :volume_id => '' }.merge(options)
89
+
90
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
91
+
92
+ params = {
93
+ "VolumeId" => options[:volume_id]
94
+ }
95
+
96
+ return response_generator(:action => "DeleteVolume", :params => params)
97
+
98
+ end
99
+
100
+ #Amazon Developer Guide Docs:
101
+ #
102
+ # The AttachVolume operation attaches an Amazon EBS volume to an instance.
103
+ #
104
+ #Required Arguments:
105
+ #
106
+ # :volume_id => String (default : '')
107
+ # :instance_id => String (default : '')
108
+ # :device => String (default : '')
109
+ #
110
+ #Optional Arguments:
111
+ #
112
+ # none
113
+ #
114
+
115
+ def attach_volume( options = {} )
116
+
117
+ options = { :volume_id => '' }.merge(options)
118
+ options = { :instance_id => '' }.merge(options)
119
+ options = { :device => '' }.merge(options)
120
+
121
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
122
+ raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
123
+ raise ArgumentError, "No :device provided" if options[:device].nil? || options[:device].empty?
124
+
125
+ params = {
126
+ "VolumeId" => options[:volume_id],
127
+ "InstanceId" => options[:instance_id],
128
+ "Device" => options[:device]
129
+ }
130
+
131
+ return response_generator(:action => "AttachVolume", :params => params)
132
+
133
+ end
134
+
135
+ #Amazon Developer Guide Docs:
136
+ #
137
+ # The DetachVolume operation detaches an Amazon EBS volume from an instance.
138
+ #
139
+ #Required Arguments:
140
+ #
141
+ # :volume_id => String (default : '')
142
+ #
143
+ #Optional Arguments:
144
+ #
145
+ # :instance_id => String (default : '')
146
+ # :device => String (default : '')
147
+ # :force => Boolean (default : '')
148
+ #
149
+
150
+ def detach_volume( options = {} )
151
+
152
+ options = { :volume_id => '' }.merge(options)
153
+
154
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
155
+
156
+ options = { :instance_id => '' }.merge(options)
157
+ options = { :device => '' }.merge(options)
158
+ options = { :force => '' }.merge(options)
159
+
160
+ params = {
161
+ "VolumeId" => options[:volume_id],
162
+ "InstanceId" => options[:instance_id],
163
+ "Device" => options[:device],
164
+ "Force" => options[:force]
165
+ }
166
+
167
+ return response_generator(:action => "DetachVolume", :params => params)
168
+
169
+ end
170
+ end
171
+ end
172
+ end