grempe-amazon-ec2 0.2.9

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