aws-sdk 1.3.8 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -33,9 +33,10 @@ module AWS
33
33
  # @return [String] ('') response http body
34
34
  attr_accessor :body
35
35
 
36
- # @return [String] (false) set to true if the client gives up
36
+ # @return [Boolean] (false) set to true if the client gives up
37
37
  # before getting a response from the service.
38
38
  attr_accessor :timeout
39
+
39
40
  alias_method :timeout?, :timeout
40
41
 
41
42
  # @param [Hash] options
@@ -0,0 +1,454 @@
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
+ module Core
16
+
17
+ # = Log Formatters
18
+ #
19
+ # Log formatters receive a {AWS::Core::Response} object and return
20
+ # a log message. When you construct a {LogFormatter}, you provide
21
+ # a pattern string with substitutions.
22
+ #
23
+ # pattern = '[REQUEST :http_status_code] :service :operation :duration'
24
+ # formatter = AWS::Core::LogFormatter.new(pattern)
25
+ # formatter.format(response)
26
+ # #=> '[AWS 200] EC2 get_bucket 0.0352'
27
+ #
28
+ # = AWS Configuration
29
+ #
30
+ # AWS.config provides a {LogFormatter.default} log formatter. You can
31
+ # repace this formatter by building your own and then passing it
32
+ # to {AWS.config}.
33
+ #
34
+ # pattern = '[REQUEST :http_status_code] :service :operation :duration'
35
+ # AWS.config(:log_formatter => AWS::Core::LogFormatter.new(pattern)
36
+ #
37
+ # == Canned Formatters
38
+ #
39
+ # Instead of providing your own pattern, you can choose a canned log
40
+ # formatter.
41
+ #
42
+ # AWS.config(:log_formatter => AWS::Core::LogFormatter.colored)
43
+ #
44
+ # Here is the list of canned formatters.
45
+ #
46
+ # * {LogFormatter.default}
47
+ # * {LogFormatter.short}
48
+ # * {LogFormatter.debug}
49
+ # * {LogFormatter.colored}
50
+ #
51
+ # = Pattern Substitutions
52
+ #
53
+ # You can put any of these placeholders into you pattern.
54
+ #
55
+ # [+:service+]
56
+ # The AWS service name (e.g. 'S3', 'EC2', 'SimpleDB', etc)
57
+ #
58
+ # [+:region+]
59
+ # The AWS region name (e.g. 'us-east-1', 'us-west-1', etc)
60
+ #
61
+ # [+:operation+]
62
+ # The name of the client request method. This maps to the name of
63
+ # the serivce API operation (e.g. :describe_instances).
64
+ #
65
+ # [+:options+]
66
+ # The hash of options passed to the client request method.
67
+ # Long strings are truncated/summarized if they excede the log
68
+ # formatters {#max_string_size}. Other objects are inspected.
69
+ #
70
+ # [+:retry_count+]
71
+ # The number of times a client request was retried.
72
+ # Throttlings and service errors trigger the automatic retry logic.
73
+ # This value indicates how many extra attempts were made before
74
+ # getting a successful response or giving up.
75
+ #
76
+ # [+:duration+]
77
+ # The time it took to generate a response, expressed
78
+ # in decimal seconds. This time includes everything from
79
+ # calling the client request method, until that method returns
80
+ # a value (event retries and retry delays).
81
+ #
82
+ # [+:error_class+]
83
+ # The class name of the error returned by the
84
+ # service. If no error was returned, this will be replcaed by
85
+ # an empty string.
86
+ #
87
+ # [+:error_message+]
88
+ # The message of the error returned. If
89
+ # no error was returned by the service, this will be an empty
90
+ # string.
91
+ #
92
+ # [+:http_request_method+]
93
+ # The HTTP request verb (e.g. 'POST', 'PUT', 'GET', etc).
94
+ #
95
+ # [+:http_request_protocol+]
96
+ # This is replaced by 'http' or 'https'.
97
+ #
98
+ # [+:http_request_host+]
99
+ # The host name of the http request endpoint (e.g. 's3.amazon.com').
100
+ #
101
+ # [+:http_request_port+]
102
+ # The port number (e.g. '443' or '80').
103
+ #
104
+ # [+:http_request_uri+]
105
+ # The http request uri folling the host (e.g.
106
+ # '/bucket_name/objects/key?versions').
107
+ #
108
+ # [+:http_request_body+]
109
+ # The http request payload.
110
+ #
111
+ # [+:http_request_headers+]
112
+ # The http request headers, inspected.
113
+ #
114
+ # [+:http_request_proxy_uri+]
115
+ # The proxy uri used, or an empty string.
116
+ #
117
+ # [+:http_response_status+]
118
+ # The http response status code (e.g. '200', '404', '500', etc).
119
+ #
120
+ # [+:http_response_headers+]
121
+ # The http response headers, inspected.
122
+ #
123
+ # [+:http_response_body+]
124
+ # The http response body contents.
125
+ #
126
+ class LogFormatter
127
+
128
+ # @param [String] pattern The log format pattern should be a string
129
+ # and may contain any of the following placeholders:
130
+ #
131
+ # * +:service+
132
+ # * +:region+
133
+ # * +:operation+
134
+ # * +:options+
135
+ # * +:retry_count
136
+ # * +:duration+
137
+ # * +:error_class+
138
+ # * +:error_message+
139
+ # * +:http_request_method+
140
+ # * +:http_request_protocol+
141
+ # * +:http_request_host+
142
+ # * +:http_request_port+
143
+ # * +:http_request_uri+
144
+ # * +:http_request_body+
145
+ # * +:http_request_headers+
146
+ # * +:http_request_proxy_uri+
147
+ # * +:http_response_status+
148
+ # * +:http_response_headers+
149
+ # * +:http_response_body+
150
+ #
151
+ # @param [Hash] options
152
+ #
153
+ # @option options [Integer] :max_string_size (1000)
154
+ #
155
+ def initialize pattern, options = {}
156
+ @pattern = pattern
157
+ @max_string_size = options[:max_string_size] || 1000
158
+ end
159
+
160
+ # @return [String]
161
+ attr_reader :pattern
162
+
163
+ # @return [Integer]
164
+ attr_reader :max_string_size
165
+
166
+ # @param [Response] response
167
+ # @return [String]
168
+ def format response
169
+ pattern.gsub(/:(\w+)/) {|sym| send("_#{sym[1..-1]}", response) }
170
+ end
171
+
172
+ protected
173
+
174
+ def method_missing method_name, *args
175
+ if method_name.to_s.chars.first == '_'
176
+ ":#{method_name.to_s[1..-1]}"
177
+ else
178
+ super
179
+ end
180
+ end
181
+
182
+ def _service response
183
+ response.http_request.class.name.split('::')[1]
184
+ end
185
+
186
+ def _region response
187
+ response.http_request.region
188
+ end
189
+
190
+ def _operation response
191
+ response.request_type
192
+ end
193
+
194
+ def _options response
195
+ summarize_hash(response.request_options) if response.request_options
196
+ end
197
+
198
+ def _retry_count response
199
+ response.retry_count
200
+ end
201
+
202
+ def _duration response
203
+ ("%.06f" % response.duration).sub(/0+$/, '')
204
+ end
205
+
206
+ def _error_class response
207
+ response.error.class.name if response.error
208
+ end
209
+
210
+ def _error_message response
211
+ response.error.message if response.error
212
+ end
213
+
214
+ def _http_request_method response
215
+ response.http_request.http_method
216
+ end
217
+
218
+ def _http_request_protocol response
219
+ response.http_request.use_ssl? ? 'https' : 'http'
220
+ end
221
+
222
+ def _http_request_host response
223
+ response.http_request.host
224
+ end
225
+
226
+ def _http_request_port response
227
+ response.http_request.port
228
+ end
229
+
230
+ def _http_request_uri response
231
+ response.http_request.uri
232
+ end
233
+
234
+ def _http_request_headers response
235
+ response.http_request.headers.inspect
236
+ end
237
+
238
+ def _http_request_body response
239
+ response.http_request.body
240
+ end
241
+
242
+ def _http_request_proxy_uri response
243
+ response.http_request.proxy_uri
244
+ end
245
+
246
+ def _http_response_status response
247
+ response.http_response.status
248
+ end
249
+
250
+ def _http_response_headers response
251
+ response.http_response.headers.inspect
252
+ end
253
+
254
+ def _http_response_body response
255
+ response.http_response.body
256
+ end
257
+
258
+ # The following methods are for summarizing request options that have
259
+ # symbolized keys and a mix of values. The summarizing is important
260
+ # because large request options (e.g. s3 data) can cause memory usage
261
+ # to spike if it is inspected.
262
+
263
+ # @param [Hash] hash
264
+ # @return [String]
265
+ def summarize_hash hash
266
+ hash.map do |key,v|
267
+ ":#{key}=>#{summarize_value(v)}"
268
+ end.sort.join(",")
269
+ end
270
+
271
+ # @param [Object] value
272
+ # @return [String]
273
+ def summarize_value value
274
+ case value
275
+ when String then summarize_string(value)
276
+ when Hash then '{' + summarize_hash(value) + '}'
277
+ when Array then summarize_array(value)
278
+ when File then summarize_file(value.path)
279
+ when Pathname then summarize_file(value)
280
+ else value.inspect
281
+ end
282
+ end
283
+
284
+ # @param [String] str
285
+ # @return [String]
286
+ def summarize_string str
287
+ max = max_string_size
288
+ if str.size > max
289
+ "#<String #{str[0...max].inspect} ... (#{str.size} bytes)>"
290
+ else
291
+ str.inspect
292
+ end
293
+ end
294
+
295
+ # Given the path to a file on disk, this method returns a summarized
296
+ # inspecton string that includes the file size.
297
+ # @param [String] path
298
+ # @return [String]
299
+ def summarize_file path
300
+ "#<File:#{path} (#{File.size(path)} bytes)>"
301
+ end
302
+
303
+ # @param [Array] array
304
+ # @return [String]
305
+ def summarize_array array
306
+ "[" + array.map{|v| summarize_value(v) }.join(",") + "]"
307
+ end
308
+
309
+ class << self
310
+
311
+ # The default log format.
312
+ #
313
+ # @example A sample of the default format.
314
+ #
315
+ # [AWS SimpleEmailService 200 0.580066 0 retries] list_verified_email_addresses()
316
+ #
317
+ # @return [LogFormatter]
318
+ #
319
+ def default
320
+
321
+ pattern = []
322
+ pattern << "[AWS"
323
+ pattern << ":service"
324
+ pattern << ":http_response_status"
325
+ pattern << ":duration"
326
+ pattern << ":retry_count retries]"
327
+ pattern << ":operation(:options)"
328
+ pattern << ":error_class"
329
+ pattern << ":error_message"
330
+
331
+ LogFormatter.new(pattern.join(' ') + "\n")
332
+
333
+ end
334
+
335
+ # The short log format. Similar to default, but it does not
336
+ # inspect the request params or report on retries.
337
+ #
338
+ # @example A sample of the short format
339
+ #
340
+ # [AWS SimpleEmailService 200 0.494532] list_verified_email_addresses
341
+ #
342
+ # @return [LogFormatter]
343
+ #
344
+ def short
345
+
346
+ pattern = []
347
+ pattern << "[AWS"
348
+ pattern << ":service"
349
+ pattern << ":http_response_status"
350
+ pattern << ":duration]"
351
+ pattern << ":operation"
352
+ pattern << ":error_class"
353
+
354
+ LogFormatter.new(pattern.join(' ') + "\n")
355
+
356
+ end
357
+
358
+ # A debug format that dumps most of the http request and response
359
+ # data.
360
+ #
361
+ # @example A truncated sample of the debug format.
362
+ #
363
+ # +-------------------------------------------------------------------------------
364
+ # | AWS us-east-1 SimpleEmailService list_verified_email_addresses 0.429189 0 retries
365
+ # +-------------------------------------------------------------------------------
366
+ # | REQUEST
367
+ # +-------------------------------------------------------------------------------
368
+ # | METHOD: POST
369
+ # | URL: https://email.us-east-1.amazonaws.com::443:/
370
+ # | HEADERS: {"content-type"=>"application/x-www-form-urlencoded" ...
371
+ # | BODY: Action=ListVerifiedEmailAddresses&Timestamp= ...
372
+ # +-------------------------------------------------------------------------------
373
+ # | RESPONSE
374
+ # +-------------------------------------------------------------------------------
375
+ # | STATUS: 200
376
+ # | HEADERS: {"x-amzn-requestid"=>["..."], ...
377
+ # | BODY: <ListVerifiedEmailAddressesResponse ...
378
+ #
379
+ # @return [LogFormatter]
380
+ #
381
+ def debug
382
+
383
+ sig_pattern = []
384
+ sig_pattern << ':region'
385
+ sig_pattern << ':service'
386
+ sig_pattern << ':operation'
387
+ sig_pattern << ':duration'
388
+ sig_pattern << ':retry_count retries'
389
+
390
+ uri_pattern = []
391
+ uri_pattern << ':http_request_protocol'
392
+ uri_pattern << '://'
393
+ uri_pattern << ':http_request_host'
394
+ uri_pattern << '::'
395
+ uri_pattern << ':http_request_port'
396
+ uri_pattern << ':'
397
+ uri_pattern << ':http_request_uri'
398
+
399
+ line = "+" + '-' * 79
400
+
401
+ pattern = []
402
+ pattern << line
403
+ pattern << "| AWS #{sig_pattern.join(' ')}"
404
+ pattern << line
405
+ pattern << "| REQUEST"
406
+ pattern << line
407
+ pattern << "| METHOD: :http_request_method"
408
+ pattern << "| URL: #{uri_pattern.join}"
409
+ pattern << "| HEADERS: :http_request_headers"
410
+ pattern << "| BODY: :http_request_body"
411
+ pattern << line
412
+ pattern << "| RESPONSE"
413
+ pattern << line
414
+ pattern << "| STATUS: :http_response_status"
415
+ pattern << "| HEADERS: :http_response_headers"
416
+ pattern << "| BODY: :http_response_body"
417
+
418
+ LogFormatter.new(pattern.join("\n") + "\n")
419
+
420
+ end
421
+
422
+ # The default log format with ANSI colors.
423
+ #
424
+ # @example A sample of the colored format (sans the ansi colors).
425
+ #
426
+ # [AWS SimpleEmailService 200 0.580066 0 retries] list_verified_email_addresses()
427
+ #
428
+ # @return [LogFormatter]
429
+ #
430
+ def colored
431
+
432
+ bold = "\x1b[1m"
433
+ color = "\x1b[34m"
434
+ reset = "\x1b[0m"
435
+
436
+ pattern = []
437
+ pattern << "#{bold}#{color}[AWS"
438
+ pattern << ":service"
439
+ pattern << ":http_response_status"
440
+ pattern << ":duration"
441
+ pattern << ":retry_count retries]#{reset}#{bold}"
442
+ pattern << ":operation(:options)"
443
+ pattern << ":error_class"
444
+ pattern << ":error_message#{reset}"
445
+
446
+ LogFormatter.new(pattern.join(' ') + "\n")
447
+
448
+ end
449
+
450
+ end
451
+
452
+ end
453
+ end
454
+ end