aws-sdk 1.3.8 → 1.3.9

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 (47) hide show
  1. data/lib/aws.rb +2 -0
  2. data/lib/aws/api_config/AutoScaling-2011-01-01.yml +563 -0
  3. data/lib/aws/auto_scaling.rb +162 -0
  4. data/lib/aws/auto_scaling/activity.rb +102 -0
  5. data/lib/aws/auto_scaling/activity_collection.rb +82 -0
  6. data/lib/aws/auto_scaling/client.rb +50 -0
  7. data/lib/aws/auto_scaling/client/xml.rb +32 -0
  8. data/lib/aws/auto_scaling/config.rb +18 -0
  9. data/lib/aws/auto_scaling/errors.rb +26 -0
  10. data/lib/aws/auto_scaling/group.rb +420 -0
  11. data/lib/aws/auto_scaling/group_collection.rb +96 -0
  12. data/lib/aws/auto_scaling/group_options.rb +146 -0
  13. data/lib/aws/auto_scaling/instance.rb +192 -0
  14. data/lib/aws/auto_scaling/instance_collection.rb +63 -0
  15. data/lib/aws/auto_scaling/launch_configuration.rb +150 -0
  16. data/lib/aws/auto_scaling/launch_configuration_collection.rb +144 -0
  17. data/lib/aws/auto_scaling/notification_configuration.rb +89 -0
  18. data/lib/aws/auto_scaling/notification_configuration_collection.rb +184 -0
  19. data/lib/aws/auto_scaling/request.rb +24 -0
  20. data/lib/aws/auto_scaling/scaling_policy.rb +125 -0
  21. data/lib/aws/auto_scaling/scaling_policy_collection.rb +72 -0
  22. data/lib/aws/auto_scaling/scaling_policy_options.rb +61 -0
  23. data/lib/aws/auto_scaling/scheduled_action.rb +145 -0
  24. data/lib/aws/auto_scaling/scheduled_action_collection.rb +195 -0
  25. data/lib/aws/auto_scaling/tag.rb +59 -0
  26. data/lib/aws/auto_scaling/tag_collection.rb +112 -0
  27. data/lib/aws/core.rb +40 -8
  28. data/lib/aws/core/client.rb +28 -3
  29. data/lib/aws/core/configuration.rb +38 -31
  30. data/lib/aws/core/http/request.rb +3 -3
  31. data/lib/aws/core/http/response.rb +2 -1
  32. data/lib/aws/core/log_formatter.rb +454 -0
  33. data/lib/aws/core/resource.rb +2 -1
  34. data/lib/aws/core/response.rb +5 -0
  35. data/lib/aws/core/uri_escape.rb +1 -1
  36. data/lib/aws/core/xml_grammar.rb +21 -0
  37. data/lib/aws/dynamo_db/request.rb +1 -1
  38. data/lib/aws/ec2/network_acl_collection.rb +1 -2
  39. data/lib/aws/ec2/route_table_collection.rb +1 -2
  40. data/lib/aws/ec2/vpn_gateway_collection.rb +1 -1
  41. data/lib/aws/elb/load_balancer.rb +0 -2
  42. data/lib/aws/errors.rb +2 -2
  43. data/lib/aws/s3/object_version_collection.rb +1 -1
  44. data/lib/aws/s3/s3_object.rb +4 -4
  45. data/lib/aws/sqs/queue.rb +2 -2
  46. metadata +52 -27
  47. data/lib/aws/core/client_logging.rb +0 -133
@@ -0,0 +1,26 @@
1
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ module AWS
15
+ class AutoScaling
16
+
17
+ # @private
18
+ module Errors
19
+
20
+ BASE_ERROR_GRAMMAR = Client::XML::BaseError
21
+
22
+ include Core::LazyErrorClasses
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,420 @@
1
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ module AWS
15
+ class AutoScaling
16
+
17
+ # @attr_reader [String] arn
18
+ #
19
+ # @attr_reader [Array<String>] availability_zone_names
20
+ #
21
+ # @attr_reader [Time] created_time
22
+ #
23
+ # @attr_reader [Integer] default_cooldown
24
+ #
25
+ # @attr_reader [Integer] desired_capacity
26
+ #
27
+ # @attr_reader [Array<Hash>] enabled_metrics Returns a hash of enabled
28
+ # metric names (keys) and granularities (values).
29
+ #
30
+ # @attr_reader [Integer] health_check_grace_period
31
+ #
32
+ # @attr_reader [Symbol] health_check_type Returns :ec2 or :vpc.
33
+ #
34
+ # @attr_reader [String] launch_configuraiton_name
35
+ #
36
+ # @attr_reader [Array<String>] load_balancer_names
37
+ #
38
+ # @attr_reader [Integer] min_size
39
+ #
40
+ # @attr_reader [Integer] max_size
41
+ #
42
+ # @attr_reader [String,nil] placement_group
43
+ #
44
+ # @attr_reader [Hash] suspended_processes A hash of suspended process
45
+ # names (keys) and reasons (values).
46
+ #
47
+ class Group < Core::Resource
48
+
49
+ include GroupOptions
50
+
51
+ def initialize name, options = {}
52
+ @name = name
53
+ super
54
+ end
55
+
56
+ # @return [String]
57
+ attr_reader :name
58
+
59
+ attribute :auto_scaling_group_arn, :static => true
60
+
61
+ alias_method :arn, :auto_scaling_group_arn
62
+
63
+ attribute :availability_zone_names, :as => :availability_zones
64
+
65
+ attribute :created_time, :static => true
66
+
67
+ attribute :default_cooldown
68
+
69
+ attribute :desired_capacity
70
+
71
+ attribute :enabled_metrics do
72
+ translates_output do |metrics|
73
+ metrics.inject({}) do |hash,metric|
74
+ hash.merge(metric.metric => metric.granularity)
75
+ end
76
+ end
77
+ end
78
+
79
+ attribute :health_check_grace_period
80
+
81
+ attribute :health_check_type, :to_sym => true
82
+
83
+ attribute :instances
84
+
85
+ protected :instances
86
+
87
+ attribute :launch_configuration_name
88
+
89
+ attribute :load_balancer_names, :static => true
90
+
91
+ attribute :min_size
92
+
93
+ attribute :max_size
94
+
95
+ attribute :placement_group
96
+
97
+ attribute :suspended_processes do
98
+ translates_output do |processes|
99
+ processes.inject({}) do |hash,process|
100
+ hash.merge(process.process_name => process.suspension_reason)
101
+ end
102
+ end
103
+ end
104
+
105
+ attribute :tag_details, :as => :tags
106
+
107
+ protected :tag_details
108
+
109
+ attribute :vpc_zone_identifier
110
+
111
+ protected :vpc_zone_identifier
112
+
113
+ populates_from(:describe_auto_scaling_groups) do |resp|
114
+ resp.auto_scaling_groups.find{|g| g.auto_scaling_group_name == name }
115
+ end
116
+
117
+ # @return [ScalingPolicyCollection]
118
+ def scaling_policies
119
+ ScalingPolicyCollection.new(self)
120
+ end
121
+
122
+ # @return [NotificationConfigurationCollection]
123
+ def notification_configurations
124
+ NotificationConfigurationCollection.new(:group => self)
125
+ end
126
+
127
+ # @return [ScheduledActionCollection]
128
+ def scheduled_actions
129
+ actions = ScheduledActionCollection.new(:config => config)
130
+ actions.filter(:group => self)
131
+ end
132
+
133
+ # @return [Tag]
134
+ def tags
135
+ tag_details.collect do |tag|
136
+ Tag.new(tag.to_hash.merge(:config => config))
137
+ end
138
+ end
139
+
140
+ # @return [LaunchConfiguration]
141
+ def launch_configuration
142
+ LaunchConfiguration.new(launch_configuration_name, :config => config)
143
+ end
144
+
145
+ # @return [ActivityCollection]
146
+ def activities
147
+ ActivityCollection.new(:group => self)
148
+ end
149
+
150
+ # @return [Array<AutoScaling::Instance>]
151
+ def auto_scaling_instances
152
+ instances.collect do |details|
153
+ Instance.new_from(
154
+ :describe_auto_scaling_groups,
155
+ details,
156
+ details.instance_id,
157
+ :auto_scaling_group_name => name, # not provided by the response
158
+ :config => config)
159
+ end
160
+ end
161
+
162
+ # Returns a collection that represents the instances belonging to this
163
+ # Auto Scaling group. You can use this collection to further refine
164
+ # the instances you are interested in:
165
+ #
166
+ # group.ec2_instances.filter('availability-zone', 'us-east-1a').each do |i|
167
+ # puts instance.id
168
+ # end
169
+ #
170
+ # @return [EC2::InstanceCollection] Returns an instance collection
171
+ # (without making a request) that represents the instances
172
+ # belonging to this Auto Scaling group.
173
+ #
174
+ def ec2_instances
175
+ instances = EC2::InstanceCollection.new(:config => config)
176
+ instances.tagged('aws:autoscaling:groupName').tagged_values(name)
177
+ end
178
+
179
+ # @return [Array<EC2::Subnet>]
180
+ def subnets
181
+ vpc_zone_identifier.to_s.split(/,/).collect do |subnet_id|
182
+ EC2::Subnet.new(subnet_id, :config => config)
183
+ end
184
+ end
185
+
186
+ # @return [Array<EC2::AvailabilityZone>]
187
+ def availability_zones
188
+ availability_zone_names.collect do |az_name|
189
+ EC2::AvailabilityZone.new(az_name, :config => config)
190
+ end
191
+ end
192
+
193
+ # @return [Array,<ELB::LoadBalancer>]
194
+ def load_balancers
195
+ load_balancer_names.collect do |name|
196
+ ELB::LoadBalancer.new(name, :config => config)
197
+ end
198
+ end
199
+
200
+ # Adjusts the desired size of the Auto Scaling group by initiating
201
+ # scaling activities. When reducing the size of the group, it is
202
+ # not possible to define which Amazon EC2 instances will be
203
+ # terminated. This applies to any Auto Scaling decisions that might
204
+ # result in terminating instances.
205
+ #
206
+ # @param [Integer] Capacity The new capacity setting for this Auto
207
+ # Scaling group.
208
+ #
209
+ # @param [Hash] options
210
+ #
211
+ # @option options [Boolean] :honor_cooldown (false)
212
+ #
213
+ # @return [nil]
214
+ #
215
+ def set_desired_capacity capacity, options = {}
216
+ client_opts = {}
217
+ client_opts[:auto_scaling_group_name] = name
218
+ client_opts[:desired_capacity] = capacity
219
+ client_opts[:honor_cooldown] = options[:honor_cooldown] == true
220
+ client.set_desired_capacity(client_opts)
221
+ nil
222
+ end
223
+
224
+ # Suspends processes for this Auto Scaling group.
225
+ #
226
+ # # suspend two processes by name
227
+ # auto_scaling_group.suspend_processes 'Launch', 'AZRebalance'
228
+ #
229
+ # @param [Array<String>] processes A list of process to suspend.
230
+ #
231
+ # @return [nil]
232
+ #
233
+ def suspend_processes *processes
234
+ client_opts = {}
235
+ client_opts[:auto_scaling_group_name] = name
236
+ client_opts[:scaling_processes] = processes.flatten
237
+ client.suspend_processes(client_opts)
238
+ nil
239
+ end
240
+
241
+ # Suspends all processes for this Auto Scaling group.
242
+ # @return [nil]
243
+ def suspend_all_processes
244
+ suspend_processes
245
+ end
246
+
247
+ # Resumes processes for this Auto Scaling group.
248
+ #
249
+ # # resume two processes by name
250
+ # auto_scaling_group.suspend_processes 'Launch', 'AZRebalance'
251
+ #
252
+ # @param [Array<String>] processes A list of process to resume.
253
+ #
254
+ # @return [nil]
255
+ #
256
+ def resume_processes *processes
257
+ client_opts = {}
258
+ client_opts[:auto_scaling_group_name] = name
259
+ client_opts[:scaling_processes] = processes.flatten
260
+ client.resume_processes(client_opts)
261
+ nil
262
+ end
263
+
264
+ # Resumes all processes for this Auto Scaling group.
265
+ # @return [nil]
266
+ def resume_all_processes
267
+ resume_processes
268
+ end
269
+
270
+ # @param [Array<String>] metrics A list of metrics to collect.
271
+ # @return [nil]
272
+ def enable_metrics_collection *metrics
273
+ client_opts = {}
274
+ client_opts[:auto_scaling_group_name] = name
275
+ client_opts[:granularity] = '1Minute'
276
+ client_opts[:metrics] = metrics.flatten
277
+ client.enable_metrics_collection(client_opts)
278
+ nil
279
+ end
280
+
281
+ # Enables all metrics collection for the Auto Scaling group.
282
+ # @return [nil]
283
+ def enable_all_metrics_collection
284
+ enable_metrics_collection
285
+ end
286
+
287
+ # @param [Array<String>] metrics A list of metrics to collect.
288
+ # @return [nil]
289
+ def disable_metrics_collection *metrics
290
+ client_opts = {}
291
+ client_opts[:auto_scaling_group_name] = name
292
+ client_opts[:metrics] = metrics.flatten
293
+ client.disable_metrics_collection(client_opts)
294
+ nil
295
+ end
296
+
297
+ # Disables all metrics collection for the Auto Scaling group.
298
+ # @return [nil]
299
+ def disable_all_metrics_collection
300
+ disable_metrics_collection
301
+ end
302
+
303
+ # Update one or more attributes on the Auto Scaling group.
304
+ #
305
+ # @param (see GroupOptions#group_options)
306
+ #
307
+ # @option (see GroupOptions#group_options)
308
+ #
309
+ # @return [nil]
310
+ #
311
+ def update options = {}
312
+
313
+ group_opts = group_options(options)
314
+
315
+ # tags must be updated using a separate request from the
316
+ # other attributes, *sigh*
317
+ if tags = group_opts.delete(:tags)
318
+ tags.map(&:to_hash).each do |tag|
319
+ tag[:resource_type] = 'auto-scaling-group'
320
+ tag[:resource_id] = name
321
+ end
322
+ client.create_or_update_tags(:tags => tags)
323
+ end
324
+
325
+ unless group_opts.empty?
326
+ client_opts = group_opts.merge(:auto_scaling_group_name => name)
327
+ client.update_auto_scaling_group(client_opts)
328
+ end
329
+
330
+ nil
331
+
332
+ end
333
+
334
+ # Deletes specific tags from this Auto Scaling group.
335
+ #
336
+ # group.delete_tags([
337
+ # { :key => 'role', :value => 'webserver' },
338
+ # ])
339
+ #
340
+ # You may also pass {Tag} objects.
341
+ #
342
+ # @param [Array<Tag,Hash>] tags An array of {Tag} objects or
343
+ # tag hashes to remove. If you pass hashes they should have
344
+ # the following keys:
345
+ #
346
+ # * +:key+
347
+ # * +:value+
348
+ # * +:propagate_at_launch+
349
+ #
350
+ # @return [nil]
351
+ #
352
+ def delete_tags *tags
353
+ tags = tags.flatten.collect do |tag|
354
+ tag.to_hash.merge(
355
+ :resource_type => 'auto-scaling-group',
356
+ :resource_id => name)
357
+ end
358
+ client.delete_tags(:tags => tags)
359
+ nil
360
+ end
361
+
362
+ # Removes all tags from this Auto Scaling group.
363
+ # @return [nil]
364
+ def delete_all_tags
365
+ delete_tags(self.tags)
366
+ nil
367
+ end
368
+
369
+ # Deletes the Auto Scaling group. If you pass +:force+ as true
370
+ # then all the instances associated with this group will also
371
+ # be terminated.
372
+ #
373
+ # @see #delete!
374
+ #
375
+ # @params [Hash] options
376
+ #
377
+ # @option options [Boolean] :force (false) When true, the Auto Scaling
378
+ # group will be deleted along with all instances associated with
379
+ # the group, without waiting for all instances to be terminated.
380
+ #
381
+ # @return [nil]
382
+ #
383
+ def delete options = {}
384
+ client_opts = {}
385
+ client_opts[:force_delete] = options[:force] == true
386
+ client_opts[:auto_scaling_group_name] = name
387
+ client.delete_auto_scaling_group(client_opts)
388
+ nil
389
+ end
390
+
391
+ # Deletes the Auto Scaling group along with all instances
392
+ # associated with the group, without waiting for all instances
393
+ # to be terminated.
394
+ # @return [nil]
395
+ def delete!
396
+ delete(:force => true)
397
+ nil
398
+ end
399
+
400
+ # @return [Boolean]
401
+ def exists?
402
+ client_opts = {}
403
+ client_opts[:auto_scaling_group_names] = [name]
404
+ resp = client.describe_auto_scaling_groups(client_opts)
405
+ !resp.auto_scaling_groups.empty?
406
+ end
407
+
408
+ protected
409
+
410
+ def resource_identifiers
411
+ [[:name, name]]
412
+ end
413
+
414
+ def get_resource attr_name = nil
415
+ client.describe_auto_scaling_groups(:auto_scaling_group_names => [name])
416
+ end
417
+
418
+ end
419
+ end
420
+ end
@@ -0,0 +1,96 @@
1
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ module AWS
15
+ class AutoScaling
16
+
17
+ class GroupCollection
18
+
19
+ include GroupOptions
20
+ include Core::Collection::Limitable
21
+
22
+ # Creates an Auto Scaling Group.
23
+ #
24
+ # group = auto_scaling.groups.create('group-name',
25
+ # :launch_configuration => 'launch-config-name',
26
+ # :availability_zones => %(us-east-1a us-east-1b),
27
+ # :min_size => 1,
28
+ # :max_size => 4)
29
+ #
30
+ # @param [String] name The name of the Auto Scaling group.
31
+ # Must be unique within the scope of your AWS account.
32
+ #
33
+ # @param [Hash] options
34
+ #
35
+ # @option (see GroupOptions#group_options)
36
+ #
37
+ # @option options [Array<ELB::LoadBalancer>,Array<String>] :load_balancers
38
+ # A list of load balancers to use. This can be an array of
39
+ # {ELB::LoadBalancer} objects or an array of load balancer names.
40
+ #
41
+ # @return [Group]
42
+ #
43
+ def create name, options = {}
44
+
45
+ unless options[:launch_configuration]
46
+ raise ArgumentError, 'missing required option :launch_configuration'
47
+ end
48
+
49
+ group_opts = group_options(options)
50
+ group_opts[:auto_scaling_group_name] = name
51
+
52
+ if balancers = options[:load_balancers]
53
+ group_opts[:load_balancer_names] = balancers.collect do |balancer|
54
+ balancer.is_a?(ELB::LoadBalancer) ? balancer.name : balancer
55
+ end
56
+ end
57
+
58
+ client.create_auto_scaling_group(group_opts)
59
+
60
+ self[name]
61
+
62
+ end
63
+
64
+ # @param [String] name The name of the Auto Scaling group.
65
+ # @return [Group]
66
+ def [] name
67
+ Group.new(name, :config => config)
68
+ end
69
+
70
+ protected
71
+
72
+ def _each_item next_token, limit, options = {}, &block
73
+
74
+ options[:next_token] = next_token if next_token
75
+ options[:max_records] = limit if limit
76
+
77
+ resp = client.describe_auto_scaling_groups(options)
78
+ resp.auto_scaling_groups.each do |details|
79
+
80
+ group = Group.new_from(
81
+ :describe_auto_scaling_groups,
82
+ details,
83
+ details.auto_scaling_group_name,
84
+ :config => config)
85
+
86
+ yield(group)
87
+
88
+ end
89
+
90
+ resp.next_token if resp.respond_to?(:next_token)
91
+
92
+ end
93
+
94
+ end
95
+ end
96
+ end