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
@@ -0,0 +1,72 @@
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
+ class ScalingPolicyCollection
17
+
18
+ include Core::Collection::Limitable
19
+ include ScalingPolicyOptions
20
+
21
+ def initialize auto_scaling_group, options = {}
22
+ @group = auto_scaling_group
23
+ super
24
+ end
25
+
26
+ # @return [Group]
27
+ attr_reader :group
28
+
29
+ alias_method :auto_scaling_group, :group
30
+
31
+
32
+ # @param [String] name The name of the policy you want to create or update.
33
+ # @param (see ScalingPolicyOptions#scaling_policy_options)
34
+ # @option (see ScalingPolicyOptions#scaling_policy_options)
35
+ # @return [ScalingPolicy]
36
+ def create name, options = {}
37
+ scaling_policy = self[name]
38
+ scaling_policy.put(options)
39
+ scaling_policy
40
+ end
41
+ alias_method :put, :create
42
+
43
+ # @param [String] policy_name
44
+ # @return [ScalingPolicy]
45
+ def [] policy_name
46
+ ScalingPolicy.new(group, policy_name)
47
+ end
48
+
49
+ protected
50
+
51
+ def _each_item next_token, limit, options = {}, &block
52
+
53
+ options[:next_token] = next_token if next_token
54
+ options[:max_records] = limit if limit
55
+ options[:auto_scaling_group_name] = group.name
56
+
57
+ resp = client.describe_policies(options)
58
+ resp.scaling_policies.each do |details|
59
+
60
+ scaling_policy = ScalingPolicy.new_from(
61
+ :describe_policies, details,
62
+ group, details.policy_name)
63
+
64
+ yield(scaling_policy)
65
+
66
+ end
67
+ resp.next_token if resp.respond_to?(:next_token)
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,61 @@
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
+ # Provides a hepler method for parsing scaling policy options.
18
+ # @private
19
+ module ScalingPolicyOptions
20
+
21
+ protected
22
+
23
+ # @param [Hash] options
24
+ #
25
+ # @option options [required,String] :adjustment_type Specifies whether
26
+ # the adjustment is an absolute number or a percentage of the current
27
+ # capacity. Valid values are:
28
+ # * 'ChangeInCapacity'
29
+ # * 'ExactCapacity'
30
+ # * 'PercentChangeInCapacity'
31
+ #
32
+ # @option options [required,Integer] :scaling_adjustment The number of
33
+ # instances by which to scale. +:adjustment_type+ determines the
34
+ # interpretation of this umber (e.g., as an absolute number or as a
35
+ # percentage of the existing Auto Scaling group size). A positive
36
+ # increment adds to the current capacity and a negative value
37
+ # removes from the current capacity.
38
+ #
39
+ # @option options [Integer] :cooldown The amount of time, in seconds,
40
+ # after a scaling activity completes before any further
41
+ # trigger-related scaling activities can start.
42
+ #
43
+ # @return [Hash]
44
+ #
45
+ def scaling_policy_options auto_scaling_group, policy_name, options
46
+ opts = {}
47
+ opts[:auto_scaling_group_name] = auto_scaling_group.name
48
+ opts[:policy_name] = policy_name
49
+ [
50
+ :cooldown,
51
+ :adjustment_type,
52
+ :scaling_adjustment,
53
+ ].each do |opt|
54
+ opts[opt] = options[opt] if options.key?(opt)
55
+ end
56
+ opts
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,145 @@
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
+ require 'time'
15
+
16
+ module AWS
17
+ class AutoScaling
18
+
19
+ # @attr_reader [String] auto_scaling_group_name
20
+ #
21
+ # @attr_reader [Integer] desired_capacity
22
+ #
23
+ # @attr_reader [String] recurrence
24
+ #
25
+ # @attr_reader [Time] start_time
26
+ #
27
+ # @attr_reader [Time] end_time
28
+ #
29
+ # @attr_reader [Integer] min_size
30
+ #
31
+ # @attr_reader [Integer] max_size
32
+ #
33
+ # @attr_reader [String] arn
34
+ #
35
+ class ScheduledAction < Core::Resource
36
+
37
+ # @private
38
+ def initialize name, options = {}
39
+ @name = name
40
+ super
41
+ end
42
+
43
+ # @return [String]
44
+ attr_reader :name
45
+
46
+ attribute :arn, :as => :scheduled_action_arn
47
+
48
+ attribute :auto_scaling_group_name, :static => true
49
+
50
+ attribute :desired_capacity
51
+
52
+ attribute :recurrence
53
+
54
+ attribute :start_time
55
+
56
+ attribute :end_time
57
+
58
+ attribute :max_size
59
+
60
+ attribute :min_size
61
+
62
+ populates_from(:describe_scheduled_actions) do |resp|
63
+ resp.scheduled_update_group_actions.find do |action|
64
+ action.scheduled_action_name == name
65
+ end
66
+ end
67
+
68
+ # @return [Group]
69
+ def group
70
+ Group.new(auto_scaling_group_name, :config => config)
71
+ end
72
+
73
+ # Updates the scheduled action. If you omit an option,
74
+ # the corresponding value remains unchanged in the Auto
75
+ # Scaling group.
76
+ #
77
+ # @param [Hash] options
78
+ #
79
+ # @option options [Integer] :desired_capacity
80
+ #
81
+ # @option options [String] :recurrence
82
+ #
83
+ # @option options [Time,String] :start_time
84
+ #
85
+ # @option options [Time,String] :end_time
86
+ #
87
+ # @option options [Integer] :min_size
88
+ #
89
+ # @option options [Integer] :max_size
90
+ #
91
+ # @return [nil]
92
+ #
93
+ def update options = {}
94
+
95
+ client_opts = options.dup
96
+ client_opts[:scheduled_action_name] = name
97
+ client_opts[:auto_scaling_group_name] = auto_scaling_group_name
98
+
99
+ # convert these options to timestamps
100
+ [:start_time, :end_time].each do |opt|
101
+ if client_opts[opt].is_a?(Time)
102
+ client_opts[opt] = client_opts[opt].iso8601
103
+ end
104
+ end
105
+
106
+ client.put_scheduled_update_group_action(client_opts)
107
+
108
+ nil
109
+
110
+ end
111
+ alias_method :put, :update
112
+
113
+ # @return [Boolean]
114
+ def exists?
115
+ client_opts = {}
116
+ client_opts[:scheduled_action_names] = [name]
117
+ resp = client.describe_scheduled_actions(client_opts)
118
+ !resp.scheduled_update_group_actions.empty?
119
+ end
120
+
121
+ # Deletes the current scheduled action.
122
+ # @return [nil]
123
+ def delete
124
+ client_opts = {}
125
+ client_opts[:scheduled_action_name] = name
126
+ client_opts[:auto_scaling_group_name] = auto_scaling_group_name
127
+ client.delete_scheduled_action(client_opts)
128
+ nil
129
+ end
130
+
131
+ protected
132
+
133
+ def resource_identifiers
134
+ [[:name, name]]
135
+ end
136
+
137
+ def get_resource attr_name = nil
138
+ client_opts = {}
139
+ client_opts[:scheduled_action_names] = [name]
140
+ client.describe_scheduled_actions(client_opts)
141
+ end
142
+
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,195 @@
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
+ require 'time'
15
+
16
+ module AWS
17
+ class AutoScaling
18
+
19
+ class ScheduledActionCollection
20
+
21
+ include Core::Collection::Limitable
22
+
23
+ # @private
24
+ def initialize options = {}
25
+ @filters = options[:filters] || {}
26
+ super
27
+ end
28
+
29
+ # Creates a scheduled scaling action for an Auto Scaling group.
30
+ # If you leave a parameter unspecified, the corresponding attribute
31
+ # remains unchanged in the group.
32
+ #
33
+ # You must specify an Auto Scaling group. This can be implicit
34
+ # or explicit:
35
+ #
36
+ # # given explicity
37
+ # auto_scaling.secheduled_actions.create('action-name', :group => 'group-name')
38
+ #
39
+ # # implied by the group
40
+ # group = auto_scaling.groups.first
41
+ # group.secheduled_actions.create('action-name')
42
+ #
43
+ # @param [String] name
44
+ #
45
+ # @param [Hash] options
46
+ #
47
+ # @option options [Group,String] :group
48
+ #
49
+ # @option options [Integer] :desired_capacity
50
+ #
51
+ # @option options [Integer] :max_size
52
+ #
53
+ # @option options [Integer] :min_size
54
+ #
55
+ # @option options [String] :recurrence
56
+ #
57
+ # @option options [Time] :start_time
58
+ #
59
+ # @option options [Time] :end_time
60
+ #
61
+ # @return [ScheduledAction]
62
+ #
63
+ def create name, options = {}
64
+
65
+ scheduled_action = ScheduledAction.new(name,
66
+ :auto_scaling_group_name => auto_scaling_group_name_opt(options),
67
+ :config => config)
68
+
69
+ scheduled_action.update(options)
70
+ scheduled_action
71
+
72
+ end
73
+ alias_method :put, :create
74
+
75
+ # @param [String] name The name of the scheduled action.
76
+ # @return [ScheduledAction]
77
+ def [] name
78
+ options = {}
79
+ options[:config] = config
80
+ if group = @filters[:auto_scaling_group_name]
81
+ options[:auto_scaling_group_name] = group
82
+ end
83
+ ScheduledAction.new(name, options)
84
+ end
85
+
86
+ # Returns a new {ScheduledActionCollection} filtered
87
+ # by the given options.
88
+ #
89
+ # auto_scaling.scheduled_actions.filter(:end_time => Time.now).each do |a|
90
+ # # ...
91
+ # end
92
+ #
93
+ # You can chain filter calls:
94
+ #
95
+ # actions = auto_scaling.scheduled_actions.
96
+ # filter(:group => 'auto-scaling-group-name').
97
+ # filter(:start_time => Time.now - 3600).
98
+ # filter(:end_time => Time.now)
99
+ #
100
+ # actions.each {|scheduled_action| ... }
101
+ #
102
+ # @param [Hash] filters
103
+ #
104
+ # @option filters [Group,String] :group
105
+ #
106
+ # @option filters [Array<String>] :scheduled_actions
107
+ # A list of scheduled actions to be described. If this list is
108
+ # omitted, all scheduled actions are described. The list of
109
+ # requested scheduled actions cannot contain more than 50 items.
110
+ # If an Auto Scaling group name is provided,
111
+ # the results are limited to that group. If unknown scheduled
112
+ # actions are requested, they are ignored with no error.
113
+ #
114
+ # @option opitons [Time,String] :start_time The earliest scheduled
115
+ # start time to return. If +:scheduled_actions+ is provided,
116
+ # this field will be ignored. Should be a Time object or
117
+ # an iso8601 string.
118
+ #
119
+ # @option filters [Time,String] :end_time
120
+ #
121
+ # @return [ScheduledActionCollection] Returns a scheduled action
122
+ # collection that will filter the actions returned by the
123
+ # given criteria.
124
+ #
125
+ def filter options = {}
126
+ init_opts = {}
127
+ init_opts[:config] = config
128
+ init_opts[:filters] = @filters
129
+ init_opts[:filters].merge!(filter_opts(options))
130
+ ScheduledActionCollection.new(init_opts)
131
+ end
132
+
133
+ protected
134
+
135
+ def auto_scaling_group_name_opt options
136
+
137
+ group = options.delete(:group)
138
+ group ||= @filters[:auto_scaling_group_name]
139
+ group = group.name if group.is_a?(Group)
140
+
141
+ unless group
142
+ raise ArgumentError, 'missing required option :group'
143
+ end
144
+
145
+ group
146
+
147
+ end
148
+
149
+ def filter_opts options
150
+
151
+ opts = {}
152
+
153
+ if g = options[:group]
154
+ opts[:auto_scaling_group_name] = g.is_a?(Group) ? g.name : g
155
+ end
156
+
157
+ if actions = options[:scheduled_actions]
158
+ opts[:scheduled_action_names] = actions
159
+ end
160
+
161
+ [:end_time, :start_time].each do |opt|
162
+ if options[opt].is_a?(Time)
163
+ opts[opt] = options[opt].iso8601
164
+ end
165
+ end
166
+
167
+ opts
168
+
169
+ end
170
+
171
+ def _each_item next_token, limit, options = {}, &block
172
+
173
+ options[:next_token] = next_token if next_token
174
+ options[:max_records] = limit if limit
175
+
176
+ resp = client.describe_scheduled_actions(options.merge(@filters))
177
+ resp.scheduled_update_group_actions.each do |details|
178
+
179
+ scheduled_action = ScheduledAction.new_from(
180
+ :describe_scheduled_actions,
181
+ details,
182
+ details.scheduled_action_name,
183
+ :config => config)
184
+
185
+ yield(scheduled_action)
186
+
187
+ end
188
+
189
+ resp.next_token if resp.respond_to?(:next_token)
190
+
191
+ end
192
+
193
+ end
194
+ end
195
+ end