amazon-ec2 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,19 +9,19 @@
9
9
  #++
10
10
 
11
11
  module EC2
12
-
12
+
13
13
  class Base
14
-
14
+
15
15
  #Amazon Developer Guide Docs:
16
- #
16
+ #
17
17
  # The ModifyImageAttribute operation modifies an attribute of an AMI. The following attributes may
18
- # currently be modified:
18
+ # currently be modified:
19
19
  #
20
- # 'launchPermission' : Controls who has permission to launch the AMI. Launch permissions can be
20
+ # 'launchPermission' : Controls who has permission to launch the AMI. Launch permissions can be
21
21
  # granted to specific users by adding userIds. The AMI can be made public by adding the 'all' group.
22
22
  #
23
- # 'productCodes' : Associates product codes with AMIs. This allows a developer to charge a user extra
24
- # for using the AMIs. productCodes is a write once attribute - once it has been set it can not be
23
+ # 'productCodes' : Associates product codes with AMIs. This allows a developer to charge a user extra
24
+ # for using the AMIs. productCodes is a write once attribute - once it has been set it can not be
25
25
  # changed or removed. Currently only one product code is supported per AMI.
26
26
  #
27
27
  #Required Arguments:
@@ -37,37 +37,37 @@ module EC2
37
37
  # :product_code => Array (default : [])
38
38
  #
39
39
  def modify_image_attribute( options = {} )
40
-
40
+
41
41
  # defaults
42
- options = { :image_id => "",
43
- :attribute => "launchPermission",
44
- :operation_type => "",
45
- :user_id => [],
42
+ options = { :image_id => "",
43
+ :attribute => "launchPermission",
44
+ :operation_type => "",
45
+ :user_id => [],
46
46
  :group => [],
47
47
  :product_code => [] }.merge(options)
48
-
48
+
49
49
  raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
50
50
  raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
51
-
51
+
52
52
  # OperationType is not required if modifying a product code.
53
53
  unless options[:attribute] == 'productCodes'
54
54
  raise ArgumentError, "No ':operation_type' provided" if options[:operation_type].nil? || options[:operation_type].empty?
55
55
  end
56
-
56
+
57
57
  params = {
58
58
  "ImageId" => options[:image_id],
59
59
  "Attribute" => options[:attribute],
60
60
  "OperationType" => options[:operation_type]
61
61
  }
62
-
62
+
63
63
  # test options provided and make sure they are valid
64
64
  case options[:attribute]
65
65
  when "launchPermission"
66
-
66
+
67
67
  unless options[:operation_type] == "add" || options[:operation_type] == "remove"
68
68
  raise ArgumentError, ":operation_type was #{options[:operation_type].to_s} but must be either 'add' or 'remove'"
69
69
  end
70
-
70
+
71
71
  if (options[:user_id].nil? || options[:user_id].empty?) && (options[:group].nil? || options[:group].empty?)
72
72
  raise ArgumentError, "Option :attribute=>'launchPermission' requires ':user_id' or ':group' options to also be specified"
73
73
  end
@@ -81,11 +81,11 @@ module EC2
81
81
  else
82
82
  raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
83
83
  end
84
-
84
+
85
85
  return response_generator(:action => "ModifyImageAttribute", :params => params)
86
-
86
+
87
87
  end
88
-
88
+
89
89
  #Amazon Developer Guide Docs:
90
90
  #
91
91
  # The DescribeImageAttribute operation returns information about an attribute of an AMI.
@@ -100,17 +100,17 @@ module EC2
100
100
  # none
101
101
  #
102
102
  def describe_image_attribute( options = {} )
103
-
103
+
104
104
  # defaults
105
- options = {:image_id => "",
105
+ options = {:image_id => "",
106
106
  :attribute => "launchPermission"
107
107
  }.merge(options)
108
-
108
+
109
109
  raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
110
110
  raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
111
-
111
+
112
112
  params = { "ImageId" => options[:image_id], "Attribute" => options[:attribute] }
113
-
113
+
114
114
  # test options provided and make sure they are valid
115
115
  case options[:attribute]
116
116
  when "launchPermission", "productCodes"
@@ -118,12 +118,12 @@ module EC2
118
118
  else
119
119
  raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
120
120
  end
121
-
121
+
122
122
  return response_generator(:action => "DescribeImageAttribute", :params => params)
123
-
123
+
124
124
  end
125
-
126
-
125
+
126
+
127
127
  #Amazon Developer Guide Docs:
128
128
  #
129
129
  # The ResetImageAttribute operation resets an attribute of an AMI to its default value.
@@ -138,17 +138,17 @@ module EC2
138
138
  # none
139
139
  #
140
140
  def reset_image_attribute( options = {} )
141
-
141
+
142
142
  # defaults
143
143
  options = {:image_id => "",
144
144
  :attribute => "launchPermission"}.merge(options)
145
-
145
+
146
146
  raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
147
147
  raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
148
-
149
- params = {"ImageId" => options[:image_id],
148
+
149
+ params = {"ImageId" => options[:image_id],
150
150
  "Attribute" => options[:attribute] }
151
-
151
+
152
152
  # test options provided and make sure they are valid
153
153
  case options[:attribute]
154
154
  when "launchPermission"
@@ -156,11 +156,11 @@ module EC2
156
156
  else
157
157
  raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
158
158
  end
159
-
159
+
160
160
  return response_generator(:action => "ResetImageAttribute", :params => params)
161
-
161
+
162
162
  end
163
-
163
+
164
164
  end
165
-
165
+
166
166
  end
@@ -9,18 +9,18 @@
9
9
  #++
10
10
 
11
11
  module EC2
12
-
12
+
13
13
  class Base
14
-
14
+
15
15
  #Amazon Developer Guide Docs:
16
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
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
24
  # the new image.
25
25
  #
26
26
  #Required Arguments:
@@ -32,54 +32,54 @@ module EC2
32
32
  # none
33
33
  #
34
34
  def register_image( options = {} )
35
-
35
+
36
36
  options = {:image_location => ""}.merge(options)
37
-
37
+
38
38
  raise ArgumentError, "No :image_location provided" if options[:image_location].nil? || options[:image_location].empty?
39
-
39
+
40
40
  params = { "ImageLocation" => options[:image_location] }
41
-
41
+
42
42
  return response_generator(:action => "RegisterImage", :params => params)
43
-
43
+
44
44
  end
45
-
45
+
46
46
  #Amazon Developer Guide Docs:
47
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
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
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
- #
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
57
  # Launch Permission Description
58
58
  #
59
59
  # public - The all group has launch permissions for the AMI. All users have launch permissions for these AMIs.
60
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.
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
83
  #
84
84
  #Required Arguments:
85
85
  #
@@ -92,20 +92,20 @@ module EC2
92
92
  # :executable_by => Array (default : [])
93
93
  #
94
94
  def describe_images( options = {} )
95
-
95
+
96
96
  options = { :image_id => [], :owner_id => [], :executable_by => [] }.merge(options)
97
-
97
+
98
98
  params = pathlist( "ImageId", options[:image_id] )
99
99
  params.merge!(pathlist( "Owner", options[:owner_id] ))
100
100
  params.merge!(pathlist( "ExecutableBy", options[:executable_by] ))
101
-
101
+
102
102
  return response_generator(:action => "DescribeImages", :params => params)
103
-
103
+
104
104
  end
105
-
105
+
106
106
  #Amazon Developer Guide Docs:
107
107
  #
108
- # The DeregisterImage operation deregisters an AMI. Once deregistered, instances of the AMI may no
108
+ # The DeregisterImage operation deregisters an AMI. Once deregistered, instances of the AMI may no
109
109
  # longer be launched.
110
110
  #
111
111
  #Required Arguments:
@@ -117,18 +117,18 @@ module EC2
117
117
  # none
118
118
  #
119
119
  def deregister_image( options = {} )
120
-
120
+
121
121
  # defaults
122
122
  options = { :image_id => "" }.merge(options)
123
-
123
+
124
124
  raise ArgumentError, "No :image_id provided" if options[:image_id].nil? || options[:image_id].empty?
125
-
125
+
126
126
  params = { "ImageId" => options[:image_id] }
127
-
127
+
128
128
  return response_generator(:action => "DeregisterImage", :params => params)
129
-
129
+
130
130
  end
131
-
131
+
132
132
  end
133
-
133
+
134
134
  end
@@ -9,37 +9,46 @@
9
9
  #++
10
10
 
11
11
  module EC2
12
-
12
+
13
13
  class Base
14
-
14
+
15
15
  #Amazon Developer Guide Docs:
16
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
- # A call to RunInstances is guaranteed to start no fewer than the requested minimum. If there is
24
- # insufficient capacity available then no instances will be started. Amazon EC2 will make a best effort
25
- # attempt to satisfy the requested maximum values.
26
- #
27
- # Every instance is launched in a security group. This may be specified as part of the launch request. If a
28
- # security group is not indicated then instances are started in a the default security group.
29
- # An optional keypair ID may be provided for each image in the launch request. All instances that are
30
- # created from images for which this is provided will have access to the associated public key at boot time
31
- # (detailed below). This key may be used to provide secure access to an instance of an image on a
32
- # per-instance basis. Amazon EC2 public images make use of this functionality to provide secure
33
- # passwordless access to instances (and launching those images without a keypair ID will leave them
34
- # inaccessible).
35
- #
36
- # The public key material is made available to the instance at boot time by placing it in a file named
37
- # openssh_id.pub on a logical device that is exposed to the instance as /dev/sda2 (the ephemeral
38
- # store). The format of this file is suitable for use as an entry within ~/.ssh/authorized_keys (the
39
- # OpenSSH format). This can be done at boot time (as part of rclocal, for example) allowing for secure
40
- # password-less access. As the need arises, other formats will also be considered.
41
- #
42
- # If the AMI has a product code attached for which the user has not subscribed, the RunInstances call will fail.
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.
43
52
  #
44
53
  #Required Arguments:
45
54
  #
@@ -53,28 +62,31 @@ module EC2
53
62
  # :group_id => Array (default : [])
54
63
  # :user_data => String (default : nil)
55
64
  # :addressing_type => String (default : "public")
65
+ # :instance_type => String (default : "m1.small")
56
66
  # :base64_encoded => Boolean (default : false)
57
67
  #
58
68
  def run_instances( options = {} )
59
-
69
+
60
70
  options = { :image_id => "",
61
- :min_count => 1,
71
+ :min_count => 1,
62
72
  :max_count => 1,
63
73
  :key_name => nil,
64
74
  :group_id => [],
65
75
  :user_data => nil,
66
76
  :addressing_type => "public",
77
+ :instance_type => "m1.small",
67
78
  :base64_encoded => false }.merge(options)
68
-
79
+
69
80
  # Do some validation on the arguments provided
70
81
  raise ArgumentError, ":image_id must be provided" if options[:image_id].nil? || options[:image_id].empty?
71
82
  raise ArgumentError, ":min_count is not valid" unless options[:min_count].to_i > 0
72
83
  raise ArgumentError, ":max_count is not valid" unless options[:max_count].to_i > 0
73
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"
74
86
  raise ArgumentError, ":base64_encoded must be 'true' or 'false'" unless options[:base64_encoded] == true || options[:base64_encoded] == false
75
-
87
+
76
88
  # If :user_data is passed in then URL escape and Base64 encode it
77
- # as needed. Need for URL Escape + Base64 encoding is determined
89
+ # as needed. Need for URL Escape + Base64 encoding is determined
78
90
  # by :base64_encoded param.
79
91
  if options[:user_data]
80
92
  if options[:base64_encoded]
@@ -85,33 +97,34 @@ module EC2
85
97
  else
86
98
  user_data = nil
87
99
  end
88
-
100
+
89
101
  params = {
90
102
  "ImageId" => options[:image_id],
91
103
  "MinCount" => options[:min_count].to_s,
92
104
  "MaxCount" => options[:max_count].to_s,
93
- }.merge(pathlist("SecurityGroup", options[:group_id]))
94
-
95
- params["KeyName"] = options[:key_name] unless options[:key_name].nil?
105
+ }.merge(pathlist("SecurityGroup", options[:group_id]))
106
+
107
+ params["KeyName"] = options[:key_name] unless options[:key_name].nil?
96
108
  params["UserData"] = user_data unless user_data.nil?
97
109
  params["AddressingType"] = options[:addressing_type]
98
-
110
+ params["InstanceType"] = options[:instance_type]
111
+
99
112
  return response_generator(:action => "RunInstances", :params => params)
100
-
113
+
101
114
  end
102
-
103
-
115
+
116
+
104
117
  #Amazon Developer Guide Docs:
105
118
  #
106
- # The DescribeInstances operation returns information about instances owned by the user
119
+ # The DescribeInstances operation returns information about instances owned by the user
107
120
  # making the request.
108
121
  #
109
- # An optional list of instance IDs may be provided to request information for those instances only. If no
110
- # instance IDs are provided, information of all relevant instances information will be returned. If an
111
- # instance is specified that does not exist a fault is returned. If an instance is specified that exists but is not
112
- # owned by the user making the request, then that instance will not be included in the returned results.
113
- #
114
- # Recently terminated instances will be included in the returned results for a small interval subsequent to
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
115
128
  # their termination. This interval is typically of the order of one hour
116
129
  #
117
130
  #Required Arguments:
@@ -123,20 +136,20 @@ module EC2
123
136
  # :instance_id => Array (default : [])
124
137
  #
125
138
  def describe_instances( options = {} )
126
-
139
+
127
140
  options = { :instance_id => [] }.merge(options)
128
-
141
+
129
142
  params = pathlist("InstanceId", options[:instance_id])
130
-
143
+
131
144
  return response_generator(:action => "DescribeInstances", :params => params)
132
-
145
+
133
146
  end
134
-
135
-
147
+
148
+
136
149
  #Amazon Developer Guide Docs:
137
150
  #
138
- # The RebootInstances operation requests a reboot of one or more instances. This operation is
139
- # asynchronous; it only queues a request to reboot the specified instance(s). The operation will succeed
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
140
153
  # provided the instances are valid and belong to the user. Terminated instances will be ignored.
141
154
  #
142
155
  #Required Arguments:
@@ -148,24 +161,24 @@ module EC2
148
161
  # none
149
162
  #
150
163
  def reboot_instances( options = {} )
151
-
164
+
152
165
  # defaults
153
166
  options = { :instance_id => [] }.merge(options)
154
-
167
+
155
168
  raise ArgumentError, "No instance IDs provided" if options[:instance_id].nil? || options[:instance_id].empty?
156
-
169
+
157
170
  params = pathlist("InstanceId", options[:instance_id])
158
-
171
+
159
172
  return response_generator(:action => "RebootInstances", :params => params)
160
-
173
+
161
174
  end
162
-
163
-
175
+
176
+
164
177
  #Amazon Developer Guide Docs:
165
178
  #
166
- # The TerminateInstances operation shuts down one or more instances. This operation is idempotent
167
- # and terminating an instance that is in the process of shutting down (or already terminated) will succeed.
168
- # Terminated instances remain visible for a short period of time (approximately one hour) after
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
169
182
  # termination, after which their instance ID is invalidated.
170
183
  #
171
184
  #Required Arguments:
@@ -177,17 +190,17 @@ module EC2
177
190
  # none
178
191
  #
179
192
  def terminate_instances( options = {} )
180
-
193
+
181
194
  options = { :instance_id => [] }.merge(options)
182
-
195
+
183
196
  raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
184
-
197
+
185
198
  params = pathlist("InstanceId", options[:instance_id])
186
-
199
+
187
200
  return response_generator(:action => "TerminateInstances", :params => params)
188
-
201
+
189
202
  end
190
-
203
+
191
204
  end
192
-
205
+
193
206
  end