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,144 @@
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 'base64'
15
+
16
+ module AWS
17
+ class AutoScaling
18
+ class LaunchConfigurationCollection
19
+
20
+ include Core::Collection::Limitable
21
+
22
+ # Creates an Auto Scaling launch configuration.
23
+ #
24
+ # auto_scaling.launch_configurations.create('name', 'ami-12345', 'm1.small')
25
+ #
26
+ # @param [String] name The name of the launch configuration to create.
27
+ #
28
+ # @param [EC2::Image,String] image An {EC2::Image} or image id string.
29
+ #
30
+ # @param [String] instance_type The type of instance (e.g.
31
+ # 't1.micro', 'm1.small', 'm2.4xlarge', etc).
32
+ #
33
+ # @param [Hash] options
34
+ #
35
+ # @option options [Array<Hash>] :block_device_mappings
36
+ #
37
+ # @option options [Boolean] :detailed_instance_monitoring (true)
38
+ # When enabled, CloudWatch will generate metrics every minute
39
+ # and your account will be charged a fee. When you disable
40
+ # detailed monitoring, by specifying False, Cloudwatch will
41
+ # generate metrics every 5 minutes.
42
+ #
43
+ # @option options [String] :kernel_id The ID of the kernel to
44
+ # launch the instances with.
45
+ #
46
+ # @option options [KeyPair,String] :key_pair The keypair to launch
47
+ # instances with. This may be an {EC2::KeyPair} object or
48
+ # or key pair name string.
49
+ #
50
+ # @option options [String] :ramdisk_id The ID of the ramdisk to
51
+ # launch the instances with.
52
+ #
53
+ # @option options [Array<EC2::SecurityGroup>,Array<String>] :security_groups
54
+ # The list of security groups to associate with the instances.
55
+ # This may be an array of {EC2::SecurityGroup} objects, security
56
+ # group names or security group ids.
57
+ #
58
+ # @option options [String] :user_data The user data available to
59
+ # the launched Amazon EC2 instances.
60
+ #
61
+ # @return [LaunchConfiguration]
62
+ #
63
+ def create name, image, instance_type, options = {}
64
+
65
+ client_opts = {}
66
+ client_opts[:launch_configuration_name] = name
67
+ client_opts[:image_id] = image_id_opt(image)
68
+ client_opts[:instance_type] = instance_type
69
+ client_opts[:block_device_mappings] = options[:block_device_mappings] if
70
+ options.key?(:block_device_mappings)
71
+ client_opts[:instance_monitoring] = instance_monitoring_opt(options) if
72
+ options.key?(:detailed_instance_monitoring)
73
+ client_opts[:kernel_id] = options[:kernel_id] if options[:kernel_id]
74
+ client_opts[:key_name] = key_name_opt(options) if options[:key_pair]
75
+ client_opts[:ramdisk_id] = options[:ramdisk_id] if options[:ramdisk_id]
76
+ client_opts[:security_groups] = security_groups_opt(options) if
77
+ options.key?(:security_groups)
78
+ client_opts[:user_data] = user_data_opt(options) if options[:user_data]
79
+
80
+ client.create_launch_configuration(client_opts)
81
+
82
+ LaunchConfiguration.new(name,
83
+ :image_id => client_opts[:image_id],
84
+ :instance_type => client_opts[:instance_type],
85
+ :config => config)
86
+
87
+ end
88
+
89
+ # @param [String] name The name of a launch configuraiton.
90
+ # @return [LaunchConfiguration]
91
+ def [] name
92
+ LaunchConfiguration.new(name, :config => config)
93
+ end
94
+
95
+ protected
96
+
97
+ def _each_item next_token, limit, options = {}, &block
98
+
99
+ options[:next_token] = next_token if next_token
100
+ options[:max_records] = limit if limit
101
+
102
+ resp = client.describe_launch_configurations(options)
103
+ resp.launch_configurations.each do |details|
104
+
105
+ launch_configuration = LaunchConfiguration.new_from(
106
+ :describe_launch_configurations,
107
+ details,
108
+ details.launch_configuration_name,
109
+ :config => config)
110
+
111
+ yield(launch_configuration)
112
+
113
+ end
114
+ resp.next_token if resp.respond_to?(:next_token)
115
+ end
116
+
117
+ def image_id_opt image
118
+ image.is_a?(EC2::Image) ? image.image_id : image
119
+ end
120
+
121
+ def instance_monitoring_opt options
122
+ options[:detailed_instance_monitoring] == true ?
123
+ { :enabled => true } :
124
+ { :enabled => false }
125
+ end
126
+
127
+ def key_name_opt options
128
+ key_pair = options[:key_pair]
129
+ key_pair.is_a?(EC2::KeyPair) ? key_pair.name : key_pair
130
+ end
131
+
132
+ def security_groups_opt options
133
+ options[:security_groups].collect do |sg|
134
+ sg.is_a?(EC2::SecurityGroup) ? sg.id : sg
135
+ end
136
+ end
137
+
138
+ def user_data_opt options
139
+ Base64.encode64(options[:user_data])
140
+ end
141
+
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,89 @@
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 NotificationConfiguration
17
+
18
+ # @private
19
+ def initialize auto_scaling_group, topic_arn, notification_types = []
20
+ @group = auto_scaling_group
21
+ @topic_arn = topic_arn
22
+ @notification_types = notification_types
23
+ end
24
+
25
+ # @return [Group]
26
+ attr_reader :group
27
+
28
+ alias_method :auto_scaling_group, :group
29
+
30
+ # @return [String]
31
+ attr_reader :topic_arn
32
+
33
+ # @return [Arra<String>]
34
+ attr_reader :notification_types
35
+
36
+ # @return [SNS::Topic]
37
+ def topic
38
+ SNS::Topic.new(topic_arn, :config => group.config)
39
+ end
40
+
41
+ # Updates the notification configuration with a new list of types:
42
+ #
43
+ # config = auto_scaling_group.notification_configurations.first
44
+ # config.notification_types = %w(autoscaling:EC2_INSTANCE_LAUNCH)
45
+ #
46
+ # @return [nil]
47
+ #
48
+ def notification_types= *notification_types
49
+
50
+ client_opts = {}
51
+ client_opts[:topic_arn] = topic_arn
52
+ client_opts[:notification_types] = notification_types.flatten
53
+ client_opts[:auto_scaling_group_name] = group.name
54
+
55
+ group.client.put_notification_configuration(client_opts)
56
+
57
+ @notification_types = notification_types.flatten
58
+
59
+ nil
60
+
61
+ end
62
+
63
+ # Deletes this Auto Scaling notification configuration.
64
+ # @return [nil]
65
+ def delete
66
+
67
+ client_opts = {}
68
+ client_opts[:auto_scaling_group_name] = group.name
69
+ client_opts[:topic_arn] = topic_arn
70
+
71
+ group.client.delete_notification_configuration(client_opts)
72
+
73
+ nil
74
+
75
+ end
76
+
77
+ # @private
78
+ def eql? other
79
+ other.is_a?(NotificationConfiguration) and
80
+ other.group == group and
81
+ other.topic_arn == topic_arn and
82
+ other.notification_types == notification_types
83
+ end
84
+
85
+ alias_method :==, :eql?
86
+
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,184 @@
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
+ # Allows you to enumerate and create notification configurations.#
18
+ #
19
+ # == Enumerating Notification Configurations
20
+ #
21
+ # You can enumerated *ALL* configurations from the AWS::AutoScaling class.
22
+ #
23
+ # auto_scaling = AWS::AutoScaling.new
24
+ # auto_scaling.notification_configurations.each do |config|
25
+ # # ...
26
+ # end
27
+ #
28
+ # You can also limit them to a single Auto Scaling group:
29
+ #
30
+ # group = auto_scaling.groups['group-name']
31
+ # group.notification_configurations.each do |config|
32
+ # # ...
33
+ # end
34
+ #
35
+ # == Creating Notification Configurations
36
+ #
37
+ # You can create a notification configuration like so:
38
+ #
39
+ # auto_scaling.notification_configurations.create(
40
+ # :group => 'auto-scaling-group-name',
41
+ # :topic => 'sns-topic-arn')
42
+ #
43
+ # Just like with enumeration, you can create them from the Auto
44
+ # Scaling group:
45
+ #
46
+ # group.notification_configurations.create(:topic => 'sns-topic-arn')
47
+ #
48
+ class NotificationConfigurationCollection
49
+
50
+ include Core::Collection::Limitable
51
+
52
+ # @private
53
+ def initialize options = {}
54
+ @group = options[:group]
55
+ if @group
56
+ super(@group, options)
57
+ else
58
+ super(options)
59
+ end
60
+ end
61
+
62
+ # @return [Group,nil] If this collection was initialized with
63
+ # an Auto Scaling group, then that group is returned, nil otherwise.
64
+ attr_reader :group
65
+
66
+ alias_method :auto_scaling_group, :group
67
+
68
+ # Creates a new notification configuration. To create a notification
69
+ # configuration you need an {SNS::Topic} and an Auto Scaling {Group}.
70
+ #
71
+ # auto_scaling.notification_configurations.create(
72
+ # :group => 'auto-scaling-group-name',
73
+ # :topic => 'sns-topic-arn')
74
+ #
75
+ # You can also create notification configurations from an Auto Scaling
76
+ # group and omit the +:group+ option.
77
+ #
78
+ # auto_scaling_group.notification_configurations.create(
79
+ # :topic => 'sns-topic-arn')
80
+ #
81
+ # You may also pass a list of notification types to publish to the
82
+ # topic. If you omit this option, then all notification types
83
+ # will be configured.
84
+ #
85
+ # # publish only these two specific notification types
86
+ # auto_scaling_group.notification_configurations.create(
87
+ # :topic => 'sns-topic-arn',
88
+ # :types => [
89
+ # 'autoscaling:EC2_INSTANCE_LAUNCH',
90
+ # 'autoscaling:EC2_INSTANCE_TERMINATE',
91
+ # ]
92
+ # )
93
+ #
94
+ # @param [Hash] options
95
+ #
96
+ # @option options [required,SNS::Topic,String] :topic An {SNS::Topic}
97
+ # object or a topic arn string. Notifications will be published
98
+ # to this topic.
99
+ #
100
+ # @option options [Group,String] :group An Auto Scaling {Group} object
101
+ # or the name of an Auto Scaling group. This is required if you
102
+ # this collection is not scoped by a {Group}.
103
+ #
104
+ # @option options [Array<String>] :types A list of notification
105
+ # types that should publish messages to the given topic.
106
+ #
107
+ # @return [NotificationConfiguration]
108
+ #
109
+ def create options = {}
110
+
111
+ topic_arn = options[:topic].is_a?(SNS::Topic) ?
112
+ options[:topic].arn : options[:topic]
113
+
114
+ unless group = @group
115
+ if group = options[:group]
116
+ group = Group.new(group) unless group.is_a?(Group)
117
+ else
118
+ raise ArgumentError, 'missing required :group option'
119
+ end
120
+ end
121
+
122
+ unless types = options[:types]
123
+ types = AutoScaling.new(:config => config).notification_types
124
+ end
125
+
126
+ notification_config = NotificationConfiguration.new(group, topic_arn)
127
+ notification_config.notification_types = types
128
+ notification_config
129
+
130
+ end
131
+ alias_method :put, :create
132
+
133
+ # @yeild [notification_config]
134
+ # @yield_param [NotificationConfiguration] notification_config
135
+ def each &block
136
+
137
+ #
138
+ # <grumble> We can't use the standard pageable collection mixin here.
139
+ # When you provide :max_records it returns each notification
140
+ # type as an individual record, instead of notification configurations
141
+ # with grouped types. This makes it very possible to
142
+ # get a part of a configuration in one page of results with the
143
+ # rest in the next page.
144
+ #
145
+ # So instead we will request and group them all before yielding.
146
+ #
147
+
148
+ next_token = nil
149
+
150
+ groups = {}
151
+
152
+ begin
153
+
154
+ client_opts = {}
155
+ client_opts[:next_token] = next_token if next_token
156
+ client_opts[:auto_scaling_group_names] = [@group.name] if @group
157
+
158
+ resp = client.describe_notification_configurations(client_opts)
159
+ resp.notification_configurations.each do |c|
160
+ group_name = c.auto_scaling_group_name
161
+ groups[group_name] ||= {}
162
+ groups[group_name][c.topic_arn] ||= []
163
+ groups[group_name][c.topic_arn] << c.notification_type
164
+ end
165
+
166
+ next_token = resp.respond_to?(:next_token) ? resp.next_token : nil
167
+
168
+ end while next_token
169
+
170
+ groups.each_pair do |group_name, topics|
171
+ topics.each_pair do |topic_arn, types|
172
+
173
+ notification_config = NotificationConfiguration.new(
174
+ Group.new(group_name, :config => config), topic_arn, types)
175
+
176
+ yield(notification_config)
177
+
178
+ end
179
+ end
180
+
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,24 @@
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
+ class Request < Core::Http::Request
19
+ include Core::AuthorizeV2
20
+ include Core::AuthorizeWithSessionToken
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,125 @@
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 ScalingPolicy < Core::Resource
17
+
18
+ include ScalingPolicyOptions
19
+
20
+ # @private
21
+ def initialize auto_scaling_group, policy_name, options = {}
22
+ @group = auto_scaling_group
23
+ @name = policy_name
24
+ super
25
+ end
26
+
27
+ # @return [Group]
28
+ attr_reader :group
29
+
30
+ alias_method :auto_scaling_group, :group
31
+
32
+ # @return [String]
33
+ attr_reader :name
34
+
35
+ attribute :arn, :as => :policy_arn, :static => true
36
+
37
+ attribute :adjustment_type
38
+
39
+ attribute :scaling_adjustment
40
+
41
+ attribute :alarms do
42
+ translates_output do |alarms|
43
+ alarms.inject({}) do |hash,alarm|
44
+ hash.merge(alarm.alarm_name => alarm.alarm_arn)
45
+ end
46
+ end
47
+ end
48
+
49
+ attribute :cooldown
50
+
51
+ populates_from(:describe_policies) do |resp|
52
+ resp.scaling_policies.find do |p|
53
+ p.policy_name == name and
54
+ p.auto_scaling_group_name == group.name
55
+ end
56
+ end
57
+
58
+ # Updates this scaling policy.
59
+ # @param (see ScalingPolicyOptions#scaling_policy_options)
60
+ # @option (see ScalingPolicyOptions#scaling_policy_options)
61
+ # @return [nil]
62
+ def update options = {}
63
+ client_opts = scaling_policy_options(group, name, options)
64
+ resp = client.put_scaling_policy(client_opts)
65
+ static_attributes[:arn] = resp.policy_arn
66
+ nil
67
+ end
68
+ alias_method :put, :update
69
+
70
+ # Runs this policy against it's Auto Scaling group.
71
+ #
72
+ # @param [Hash] options
73
+ #
74
+ # @option options [Boolean] :honor_cooldown (false) Set to true if you
75
+ # want Auto Scaling to reject this request when the Auto Scaling
76
+ # group is in cooldown.
77
+ #
78
+ # @raise [Errors::ScalingActivityInProgress]
79
+ #
80
+ # @return [nil]
81
+ #
82
+ def execute options = {}
83
+ client_opts = {}
84
+ client_opts[:auto_scaling_group_name] = group.name
85
+ client_opts[:policy_name] = name
86
+ client_opts[:honor_cooldown] = options[:honor_cooldown] == true
87
+ client.execute_policy(client_opts)
88
+ nil
89
+ end
90
+
91
+ # Deletes this scaling policy.
92
+ # @return [nil]
93
+ def delete
94
+ client_opts = {}
95
+ client_opts[:auto_scaling_group_name] = group.name
96
+ client_opts[:policy_name] = name
97
+ client.delete_policy(client_opts)
98
+ nil
99
+ end
100
+
101
+ # @return [Boolean] Returns true if the policy exists.
102
+ def exists?
103
+ client_opts = {}
104
+ client_opts[:auto_scaling_group_name] = group.name
105
+ client_opts[:policy_names] = [name]
106
+ resp = client.describe_policies(client_opts)
107
+ !resp.scaling_policies.empty?
108
+ end
109
+
110
+ protected
111
+
112
+ def get_resource attr_name = nil
113
+ client_opts = {}
114
+ client_opts[:auto_scaling_group_name] = group.name
115
+ client_opts[:policy_names] = [name]
116
+ client.describe_policies(client_opts)
117
+ end
118
+
119
+ def resource_identifiers
120
+ [[:group, group], [:name, name]]
121
+ end
122
+
123
+ end
124
+ end
125
+ end