krisr-amazon-ec2 0.5.0

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.
Files changed (55) hide show
  1. data/.gitignore +6 -0
  2. data/ChangeLog +284 -0
  3. data/LICENSE +66 -0
  4. data/README.rdoc +329 -0
  5. data/Rakefile +101 -0
  6. data/VERSION +1 -0
  7. data/amazon-ec2.gemspec +123 -0
  8. data/bin/ec2-gem-example.rb +66 -0
  9. data/bin/ec2-gem-profile.rb +10 -0
  10. data/bin/ec2sh +62 -0
  11. data/bin/setup.rb +26 -0
  12. data/deps.rip +1 -0
  13. data/lib/AWS.rb +239 -0
  14. data/lib/AWS/EC2.rb +67 -0
  15. data/lib/AWS/EC2/availability_zones.rb +43 -0
  16. data/lib/AWS/EC2/console.rb +46 -0
  17. data/lib/AWS/EC2/elastic_ips.rb +154 -0
  18. data/lib/AWS/EC2/image_attributes.rb +168 -0
  19. data/lib/AWS/EC2/images.rb +136 -0
  20. data/lib/AWS/EC2/instances.rb +218 -0
  21. data/lib/AWS/EC2/keypairs.rb +96 -0
  22. data/lib/AWS/EC2/products.rb +45 -0
  23. data/lib/AWS/EC2/security_groups.rb +234 -0
  24. data/lib/AWS/EC2/snapshots.rb +96 -0
  25. data/lib/AWS/EC2/volumes.rb +172 -0
  26. data/lib/AWS/ELB.rb +57 -0
  27. data/lib/AWS/ELB/load_balancers.rb +201 -0
  28. data/lib/AWS/exceptions.rb +169 -0
  29. data/lib/AWS/responses.rb +61 -0
  30. data/lib/EC2.rb +31 -0
  31. data/perftools/ec2prof +0 -0
  32. data/perftools/ec2prof-results.dot +193 -0
  33. data/perftools/ec2prof-results.txt +126 -0
  34. data/perftools/ec2prof.symbols +129 -0
  35. data/test/test_EC2.rb +68 -0
  36. data/test/test_EC2_availability_zones.rb +49 -0
  37. data/test/test_EC2_console.rb +54 -0
  38. data/test/test_EC2_elastic_ips.rb +144 -0
  39. data/test/test_EC2_image_attributes.rb +238 -0
  40. data/test/test_EC2_images.rb +197 -0
  41. data/test/test_EC2_instances.rb +348 -0
  42. data/test/test_EC2_keypairs.rb +123 -0
  43. data/test/test_EC2_products.rb +48 -0
  44. data/test/test_EC2_responses.rb +52 -0
  45. data/test/test_EC2_s3_xmlsimple.rb +80 -0
  46. data/test/test_EC2_security_groups.rb +205 -0
  47. data/test/test_EC2_snapshots.rb +83 -0
  48. data/test/test_EC2_volumes.rb +142 -0
  49. data/test/test_ELB_load_balancers.rb +238 -0
  50. data/test/test_helper.rb +19 -0
  51. data/wsdl/2007-08-29.ec2.wsdl +1269 -0
  52. data/wsdl/2008-02-01.ec2.wsdl +1614 -0
  53. data/wsdl/2008-05-05.ec2.wsdl +2052 -0
  54. data/wsdl/2008-12-01.ec2.wsdl +2354 -0
  55. metadata +184 -0
@@ -0,0 +1,136 @@
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 RegisterImage operation registers an AMI with Amazon EC2. Images must be registered before
19
+ # they can be launched. Each AMI is associated with an unique ID which is provided by the EC2
20
+ # service via the Registerimage operation. As part of the registration process, Amazon EC2 will
21
+ # retrieve the specified image manifest from Amazon S3 and verify that the image is owned by the
22
+ # user requesting image registration. The image manifest is retrieved once and stored within the
23
+ # Amazon EC2 network. Any modifications to an image in Amazon S3 invalidate this registration.
24
+ # If you do have to make changes and upload a new image deregister the previous image and register
25
+ # the new image.
26
+ #
27
+ #Required Arguments:
28
+ #
29
+ # :image_location => String (default : "")
30
+ #
31
+ #Optional Arguments:
32
+ #
33
+ # none
34
+ #
35
+ def register_image( options = {} )
36
+
37
+ options = {:image_location => ""}.merge(options)
38
+
39
+ raise ArgumentError, "No :image_location provided" if options[:image_location].nil? || options[:image_location].empty?
40
+
41
+ params = { "ImageLocation" => options[:image_location] }
42
+
43
+ return response_generator(:action => "RegisterImage", :params => params)
44
+
45
+ end
46
+
47
+ #Amazon Developer Guide Docs:
48
+ #
49
+ # The DescribeImages operation returns information about AMIs available for use by the user. This
50
+ # includes both public AMIs (those available for any user to launch) and private AMIs (those owned by
51
+ # the user making the request and those owned by other users that the user making the request has explicit
52
+ # launch permissions for).
53
+ #
54
+ # The list of AMIs returned can be modified via optional lists of AMI IDs, owners or users with launch
55
+ # permissions. If all three optional lists are empty all AMIs the user has launch permissions for are
56
+ # returned. Launch permissions fall into three categories:
57
+ #
58
+ # Launch Permission Description
59
+ #
60
+ # public - The all group has launch permissions for the AMI. All users have launch permissions for these AMIs.
61
+ # explicit - The owner of the AMIs has granted a specific user launch permissions for the AMI.
62
+ # implicit - A user has implicit launch permissions for all AMIs he or she owns.
63
+ #
64
+ # If one or more of the lists are specified the result set is the intersection of AMIs matching the criteria of
65
+ # the individual lists.
66
+ #
67
+ # Providing the list of AMI IDs requests information for those AMIs only. If no AMI IDs are provided,
68
+ # information of all relevant AMIs will be returned. If an AMI is specified that does not exist a fault is
69
+ # returned. If an AMI is specified that exists but the user making the request does not have launch
70
+ # permissions for, then that AMI will not be included in the returned results.
71
+ #
72
+ # Providing the list of owners requests information for AMIs owned by the specified owners only. Only
73
+ # AMIs the user has launch permissions for are returned. The items of the list may be account ids for
74
+ # AMIs owned by users with those account ids, amazon for AMIs owned by Amazon or self for AMIs
75
+ # owned by the user making the request.
76
+ #
77
+ # The executable list may be provided to request information for AMIs that only the specified users have
78
+ # launch permissions for. The items of the list may be account ids for AMIs owned by the user making the
79
+ # request that the users with the specified account ids have explicit launch permissions for, self for AMIs
80
+ # the user making the request has explicit launch permissions for or all for public AMIs.
81
+ #
82
+ # Deregistered images will be included in the returned results for an unspecified interval subsequent to
83
+ # deregistration.
84
+ #
85
+ #Required Arguments:
86
+ #
87
+ # none
88
+ #
89
+ #Optional Arguments:
90
+ #
91
+ # :image_id => Array (default : [])
92
+ # :owner_id => Array (default : [])
93
+ # :executable_by => Array (default : [])
94
+ #
95
+ def describe_images( options = {} )
96
+
97
+ options = { :image_id => [], :owner_id => [], :executable_by => [] }.merge(options)
98
+
99
+ params = pathlist( "ImageId", options[:image_id] )
100
+ params.merge!(pathlist( "Owner", options[:owner_id] ))
101
+ params.merge!(pathlist( "ExecutableBy", options[:executable_by] ))
102
+
103
+ return response_generator(:action => "DescribeImages", :params => params)
104
+
105
+ end
106
+
107
+ #Amazon Developer Guide Docs:
108
+ #
109
+ # The DeregisterImage operation deregisters an AMI. Once deregistered, instances of the AMI may no
110
+ # longer be launched.
111
+ #
112
+ #Required Arguments:
113
+ #
114
+ # :image_id => String (default : "")
115
+ #
116
+ #Optional Arguments:
117
+ #
118
+ # none
119
+ #
120
+ def deregister_image( options = {} )
121
+
122
+ # defaults
123
+ options = { :image_id => "" }.merge(options)
124
+
125
+ raise ArgumentError, "No :image_id provided" if options[:image_id].nil? || options[:image_id].empty?
126
+
127
+ params = { "ImageId" => options[:image_id] }
128
+
129
+ return response_generator(:action => "DeregisterImage", :params => params)
130
+
131
+ end
132
+
133
+ end
134
+
135
+ end
136
+ end
@@ -0,0 +1,218 @@
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 RunInstances operation launches a specified number of instances.
19
+ #
20
+ # Note : The Query version of RunInstances only allows instances of a single AMI to be launched in
21
+ # one call. This is different from the SOAP API call of the same name but similar to the
22
+ # ec2-run-instances command line tool.
23
+ #
24
+ # If Amazon EC2 cannot launch the minimum number AMIs you request, no instances launch. If there
25
+ # is insufficient capacity to launch the maximum number of AMIs you request, Amazon EC2 launches
26
+ # as many as possible to satisfy the requested maximum values.
27
+ #
28
+ # Every instance is launched in a security group. If you do not specify a security group at
29
+ # launch, the instances start in the default security group.
30
+ #
31
+ # An optional instance type can be specified. Currently supported types are 'm1.small', 'm1.large',
32
+ # 'm1.xlarge' and the high CPU types 'c1.medium' and 'c1.xlarge'. 'm1.small' is the default
33
+ # if no instance_type is specified.
34
+ #
35
+ # You can provide an optional key pair ID for each image in the launch request. All instances
36
+ # that are created from images that use this key pair will have access to the associated public
37
+ # key at boot. You can use this key to provide secure access to an instance of an image on a
38
+ # per-instance basis. Amazon EC2 public images use this feature to provide secure access
39
+ # without passwords.
40
+ #
41
+ # Important! Launching public images without a key pair ID will leave them inaccessible.
42
+ #
43
+ # The public key material is made available to the instance at boot time by placing it in a file named
44
+ # openssh_id.pub on a logical device that is exposed to the instance as /dev/sda2 (the ephemeral
45
+ # store). The format of this file is suitable for use as an entry within ~/.ssh/authorized_keys (the
46
+ # OpenSSH format). This can be done at boot time (as part of rclocal, for example) allowing for secure
47
+ # password-less access.
48
+ #
49
+ # Optional user data can be provided in the launch request. All instances comprising the launch
50
+ # request have access to this data (see Instance Metadata for details).
51
+ #
52
+ # If any of the AMIs have product codes attached for which the user has not subscribed,
53
+ # the RunInstances call will fail.
54
+ #
55
+ #Required Arguments:
56
+ #
57
+ # :image_id => String (Default : "")
58
+ # :min_count => Integer (default : 1 )
59
+ # :max_count => Integer (default : 1 )
60
+ #
61
+ #Optional Arguments:
62
+ #
63
+ # :key_name => String (default : nil)
64
+ # :group_id => Array (default : [])
65
+ # :user_data => String (default : nil)
66
+ # :addressing_type => String (default : "public")
67
+ # :instance_type => String (default : "m1.small")
68
+ # :kernel_id => String (default : nil)
69
+ # :availability_zone => String (default : nil)
70
+ # :base64_encoded => Boolean (default : false)
71
+ #
72
+ def run_instances( options = {} )
73
+
74
+ options = { :image_id => "",
75
+ :min_count => 1,
76
+ :max_count => 1,
77
+ :key_name => nil,
78
+ :group_id => [],
79
+ :user_data => nil,
80
+ :addressing_type => "public",
81
+ :instance_type => "m1.small",
82
+ :kernel_id => nil,
83
+ :availability_zone => nil,
84
+ :base64_encoded => false }.merge(options)
85
+
86
+ # Do some validation on the arguments provided
87
+ raise ArgumentError, ":image_id must be provided" if options[:image_id].nil? || options[:image_id].empty?
88
+ raise ArgumentError, ":min_count is not valid" unless options[:min_count].to_i > 0
89
+ raise ArgumentError, ":max_count is not valid" unless options[:max_count].to_i > 0
90
+ raise ArgumentError, ":addressing_type must be 'direct' or 'public'" unless options[:addressing_type] == "public" || options[:addressing_type] == "direct"
91
+ raise ArgumentError, ":instance_type must be 'm1.small', 'm1.large', 'm1.xlarge', 'c1.medium', or 'c1.xlarge'" unless options[:instance_type] == "m1.small" || options[:instance_type] == "m1.large" || options[:instance_type] == "m1.xlarge" || options[:instance_type] == "c1.medium" || options[:instance_type] == "c1.xlarge"
92
+ raise ArgumentError, ":base64_encoded must be 'true' or 'false'" unless options[:base64_encoded] == true || options[:base64_encoded] == false
93
+
94
+ user_data = extract_user_data(options)
95
+
96
+ params = {
97
+ "ImageId" => options[:image_id],
98
+ "MinCount" => options[:min_count].to_s,
99
+ "MaxCount" => options[:max_count].to_s,
100
+ }.merge(pathlist("SecurityGroup", options[:group_id]))
101
+
102
+ params["KeyName"] = options[:key_name] unless options[:key_name].nil?
103
+ params["UserData"] = user_data unless user_data.nil?
104
+ params["AddressingType"] = options[:addressing_type]
105
+ params["InstanceType"] = options[:instance_type]
106
+ params["KernelId"] = options[:kernel_id] unless options[:kernel_id].nil?
107
+ params["Placement.AvailabilityZone"] = options[:availability_zone] unless options[:availability_zone].nil?
108
+
109
+ return response_generator(:action => "RunInstances", :params => params)
110
+
111
+ end
112
+
113
+ # If :user_data is passed in then URL escape and Base64 encode it
114
+ # as needed. Need for URL Escape + Base64 encoding is determined
115
+ # by :base64_encoded param.
116
+ def extract_user_data(options)
117
+ return unless options[:user_data]
118
+ if options[:user_data]
119
+ if options[:base64_encoded]
120
+ Base64.encode64(options[:user_data]).gsub(/\n/,"").strip()
121
+ else
122
+ options[:user_data]
123
+ end
124
+ end
125
+ end
126
+
127
+
128
+ #Amazon Developer Guide Docs:
129
+ #
130
+ # The DescribeInstances operation returns information about instances owned by the user
131
+ # making the request.
132
+ #
133
+ # An optional list of instance IDs may be provided to request information for those instances only. If no
134
+ # instance IDs are provided, information of all relevant instances information will be returned. If an
135
+ # instance is specified that does not exist a fault is returned. If an instance is specified that exists but is not
136
+ # owned by the user making the request, then that instance will not be included in the returned results.
137
+ #
138
+ # Recently terminated instances will be included in the returned results for a small interval subsequent to
139
+ # their termination. This interval is typically of the order of one hour
140
+ #
141
+ #Required Arguments:
142
+ #
143
+ # none
144
+ #
145
+ #Optional Arguments:
146
+ #
147
+ # :instance_id => Array (default : [])
148
+ #
149
+ def describe_instances( options = {} )
150
+
151
+ options = { :instance_id => [] }.merge(options)
152
+
153
+ params = pathlist("InstanceId", options[:instance_id])
154
+
155
+ return response_generator(:action => "DescribeInstances", :params => params)
156
+
157
+ end
158
+
159
+
160
+ #Amazon Developer Guide Docs:
161
+ #
162
+ # The RebootInstances operation requests a reboot of one or more instances. This operation is
163
+ # asynchronous; it only queues a request to reboot the specified instance(s). The operation will succeed
164
+ # provided the instances are valid and belong to the user. Terminated instances will be ignored.
165
+ #
166
+ #Required Arguments:
167
+ #
168
+ # :instance_id => Array (default : [])
169
+ #
170
+ #Optional Arguments:
171
+ #
172
+ # none
173
+ #
174
+ def reboot_instances( options = {} )
175
+
176
+ # defaults
177
+ options = { :instance_id => [] }.merge(options)
178
+
179
+ raise ArgumentError, "No instance IDs provided" if options[:instance_id].nil? || options[:instance_id].empty?
180
+
181
+ params = pathlist("InstanceId", options[:instance_id])
182
+
183
+ return response_generator(:action => "RebootInstances", :params => params)
184
+
185
+ end
186
+
187
+
188
+ #Amazon Developer Guide Docs:
189
+ #
190
+ # The TerminateInstances operation shuts down one or more instances. This operation is idempotent
191
+ # and terminating an instance that is in the process of shutting down (or already terminated) will succeed.
192
+ # Terminated instances remain visible for a short period of time (approximately one hour) after
193
+ # termination, after which their instance ID is invalidated.
194
+ #
195
+ #Required Arguments:
196
+ #
197
+ # :instance_id => Array (default : [])
198
+ #
199
+ #Optional Arguments:
200
+ #
201
+ # none
202
+ #
203
+ def terminate_instances( options = {} )
204
+
205
+ options = { :instance_id => [] }.merge(options)
206
+
207
+ raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
208
+
209
+ params = pathlist("InstanceId", options[:instance_id])
210
+
211
+ return response_generator(:action => "TerminateInstances", :params => params)
212
+
213
+ end
214
+
215
+ end
216
+
217
+ end
218
+ end
@@ -0,0 +1,96 @@
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 CreateKeyPair operation creates a new 2048 bit RSA keypair and returns a unique ID that can be
20
+ # used to reference this keypair when launching new instances.
21
+ #
22
+ #Required Arguments:
23
+ #
24
+ # :key_name => String (default : "")
25
+ #
26
+ #Optional Arguments:
27
+ #
28
+ # none
29
+ #
30
+ def create_keypair( options = {} )
31
+
32
+ # defaults
33
+ options = { :key_name => "" }.merge(options)
34
+
35
+ raise ArgumentError, "No :key_name provided" if options[:key_name].nil? || options[:key_name].empty?
36
+
37
+ params = { "KeyName" => options[:key_name] }
38
+
39
+ return response_generator(:action => "CreateKeyPair", :params => params)
40
+
41
+ end
42
+
43
+
44
+ #Amazon Developer Guide Docs:
45
+ #
46
+ # The DescribeKeyPairs operation returns information about keypairs available for use by the user
47
+ # making the request. Selected keypairs may be specified or the list may be left empty if information for
48
+ # all registered keypairs is required.
49
+ #
50
+ #Required Arguments:
51
+ #
52
+ # :key_name => Array (default : [])
53
+ #
54
+ #Optional Arguments:
55
+ #
56
+ # none
57
+ #
58
+ def describe_keypairs( options = {} )
59
+
60
+ options = { :key_name => [] }.merge(options)
61
+
62
+ params = pathlist("KeyName", options[:key_name] )
63
+
64
+ return response_generator(:action => "DescribeKeyPairs", :params => params)
65
+
66
+ end
67
+
68
+
69
+ #Amazon Developer Guide Docs:
70
+ #
71
+ # The DeleteKeyPair operation deletes a keypair.
72
+ #
73
+ #Required Arguments:
74
+ #
75
+ # :key_name => String (default : "")
76
+ #
77
+ #Optional Arguments:
78
+ #
79
+ # none
80
+ #
81
+ def delete_keypair( options = {} )
82
+
83
+ options = { :key_name => "" }.merge(options)
84
+
85
+ raise ArgumentError, "No :key_name provided" if options[:key_name].nil? || options[:key_name].empty?
86
+
87
+ params = { "KeyName" => options[:key_name] }
88
+
89
+ return response_generator(:action => "DeleteKeyPair", :params => params)
90
+
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+ end