kunley-amazon-ec2 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
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: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 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,213 @@
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 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
+ # 'm1.xlarge' and the high CPU types 'c1.medium' and 'c1.xlarge'. 'm1.small' is the default
32
+ # if no instance_type is specified.
33
+ #
34
+ # You can provide an optional key pair ID for each image in the launch request. All instances
35
+ # that are created from images that use this key pair will have access to the associated public
36
+ # key at boot. You can use this key to provide secure access to an instance of an image on a
37
+ # per-instance basis. Amazon EC2 public images use this feature to provide secure access
38
+ # without passwords.
39
+ #
40
+ # Important! Launching public images without a key pair ID will leave them inaccessible.
41
+ #
42
+ # The public key material is made available to the instance at boot time by placing it in a file named
43
+ # openssh_id.pub on a logical device that is exposed to the instance as /dev/sda2 (the ephemeral
44
+ # store). The format of this file is suitable for use as an entry within ~/.ssh/authorized_keys (the
45
+ # OpenSSH format). This can be done at boot time (as part of rclocal, for example) allowing for secure
46
+ # password-less access.
47
+ #
48
+ # Optional user data can be provided in the launch request. All instances comprising the launch
49
+ # request have access to this data (see Instance Metadata for details).
50
+ #
51
+ # If any of the AMIs have product codes attached for which the user has not subscribed,
52
+ # the RunInstances call will fail.
53
+ #
54
+ #Required Arguments:
55
+ #
56
+ # :image_id => String (Default : "")
57
+ # :min_count => Integer (default : 1 )
58
+ # :max_count => Integer (default : 1 )
59
+ #
60
+ #Optional Arguments:
61
+ #
62
+ # :key_name => String (default : nil)
63
+ # :group_id => Array (default : [])
64
+ # :user_data => String (default : nil)
65
+ # :addressing_type => String (default : "public")
66
+ # :instance_type => String (default : "m1.small")
67
+ # :kernel_id => String (default : nil)
68
+ # :availability_zone => String (default : nil)
69
+ # :base64_encoded => Boolean (default : false)
70
+ #
71
+ def run_instances( options = {} )
72
+
73
+ options = { :image_id => "",
74
+ :min_count => 1,
75
+ :max_count => 1,
76
+ :key_name => nil,
77
+ :group_id => [],
78
+ :user_data => nil,
79
+ :addressing_type => "public",
80
+ :instance_type => "m1.small",
81
+ :kernel_id => nil,
82
+ :availability_zone => nil,
83
+ :base64_encoded => false }.merge(options)
84
+
85
+ # Do some validation on the arguments provided
86
+ raise ArgumentError, ":image_id must be provided" if options[:image_id].nil? || options[:image_id].empty?
87
+ raise ArgumentError, ":min_count is not valid" unless options[:min_count].to_i > 0
88
+ raise ArgumentError, ":max_count is not valid" unless options[:max_count].to_i > 0
89
+ raise ArgumentError, ":addressing_type must be 'direct' or 'public'" unless options[:addressing_type] == "public" || options[:addressing_type] == "direct"
90
+ 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"
91
+ raise ArgumentError, ":base64_encoded must be 'true' or 'false'" unless options[:base64_encoded] == true || options[:base64_encoded] == false
92
+
93
+ # If :user_data is passed in then URL escape and Base64 encode it
94
+ # as needed. Need for URL Escape + Base64 encoding is determined
95
+ # by :base64_encoded param.
96
+ if options[:user_data]
97
+ if options[:base64_encoded]
98
+ user_data = options[:user_data]
99
+ else
100
+ user_data = Base64.encode64(options[:user_data]).gsub(/\n/,"").strip()
101
+ end
102
+ else
103
+ user_data = nil
104
+ end
105
+
106
+ params = {
107
+ "ImageId" => options[:image_id],
108
+ "MinCount" => options[:min_count].to_s,
109
+ "MaxCount" => options[:max_count].to_s,
110
+ }.merge(pathlist("SecurityGroup", options[:group_id]))
111
+
112
+ params["KeyName"] = options[:key_name] unless options[:key_name].nil?
113
+ params["UserData"] = user_data unless user_data.nil?
114
+ params["AddressingType"] = options[:addressing_type]
115
+ params["InstanceType"] = options[:instance_type]
116
+ params["KernelId"] = options[:kernel_id] unless options[:kernel_id].nil?
117
+ params["Placement.AvailabilityZone"] = options[:availability_zone] unless options[:availability_zone].nil?
118
+
119
+ return response_generator(:action => "RunInstances", :params => params)
120
+
121
+ end
122
+
123
+
124
+ #Amazon Developer Guide Docs:
125
+ #
126
+ # The DescribeInstances operation returns information about instances owned by the user
127
+ # making the request.
128
+ #
129
+ # An optional list of instance IDs may be provided to request information for those instances only. If no
130
+ # instance IDs are provided, information of all relevant instances information will be returned. If an
131
+ # instance is specified that does not exist a fault is returned. If an instance is specified that exists but is not
132
+ # owned by the user making the request, then that instance will not be included in the returned results.
133
+ #
134
+ # Recently terminated instances will be included in the returned results for a small interval subsequent to
135
+ # their termination. This interval is typically of the order of one hour
136
+ #
137
+ #Required Arguments:
138
+ #
139
+ # none
140
+ #
141
+ #Optional Arguments:
142
+ #
143
+ # :instance_id => Array (default : [])
144
+ #
145
+ def describe_instances( options = {} )
146
+
147
+ options = { :instance_id => [] }.merge(options)
148
+
149
+ params = pathlist("InstanceId", options[:instance_id])
150
+
151
+ return response_generator(:action => "DescribeInstances", :params => params)
152
+
153
+ end
154
+
155
+
156
+ #Amazon Developer Guide Docs:
157
+ #
158
+ # The RebootInstances operation requests a reboot of one or more instances. This operation is
159
+ # asynchronous; it only queues a request to reboot the specified instance(s). The operation will succeed
160
+ # provided the instances are valid and belong to the user. Terminated instances will be ignored.
161
+ #
162
+ #Required Arguments:
163
+ #
164
+ # :instance_id => Array (default : [])
165
+ #
166
+ #Optional Arguments:
167
+ #
168
+ # none
169
+ #
170
+ def reboot_instances( options = {} )
171
+
172
+ # defaults
173
+ options = { :instance_id => [] }.merge(options)
174
+
175
+ raise ArgumentError, "No instance IDs provided" if options[:instance_id].nil? || options[:instance_id].empty?
176
+
177
+ params = pathlist("InstanceId", options[:instance_id])
178
+
179
+ return response_generator(:action => "RebootInstances", :params => params)
180
+
181
+ end
182
+
183
+
184
+ #Amazon Developer Guide Docs:
185
+ #
186
+ # The TerminateInstances operation shuts down one or more instances. This operation is idempotent
187
+ # and terminating an instance that is in the process of shutting down (or already terminated) will succeed.
188
+ # Terminated instances remain visible for a short period of time (approximately one hour) after
189
+ # termination, after which their instance ID is invalidated.
190
+ #
191
+ #Required Arguments:
192
+ #
193
+ # :instance_id => Array (default : [])
194
+ #
195
+ #Optional Arguments:
196
+ #
197
+ # none
198
+ #
199
+ def terminate_instances( options = {} )
200
+
201
+ options = { :instance_id => [] }.merge(options)
202
+
203
+ raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
204
+
205
+ params = pathlist("InstanceId", options[:instance_id])
206
+
207
+ return response_generator(:action => "TerminateInstances", :params => params)
208
+
209
+ end
210
+
211
+ end
212
+
213
+ 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: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 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: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 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