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,146 @@
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
+ # This mixin provides a method for parsing Auto Scaling group options
18
+ # (for create and upate methods).
19
+ # @private
20
+ module GroupOptions
21
+
22
+ protected
23
+
24
+ # @param [Hash] options
25
+ #
26
+ # @option options [required,Integer] :min_size
27
+ # The maximum size of the Auto Scaling group.
28
+ #
29
+ # @option options [required,Integer] :max_size
30
+ # The minimum size of the Auto Scaling group.
31
+ #
32
+ # @option options [required,LaunchConfiguration,String] :launch_configuration
33
+ # The launch configuration to use with the Auto Scaling group.
34
+ # This may be a {LaunchConfiguration} object or a launch configuration
35
+ # name string.
36
+ #
37
+ # @option options [required,Array<String>] :availability_zones
38
+ # A list of Availability Zones for the Auto Scaling group.
39
+ # This can be {EC2::AvailabilityZone} objects or availability
40
+ # zone names.
41
+ #
42
+ # @option options [Integer] :default_cooldown
43
+ # The amount of time, in seconds, after a scaling activity completes
44
+ # before any further trigger-related scaling activities can start.
45
+ #
46
+ # @option options [Integer] :desired_capacity
47
+ # The number of Amazon EC2 instances that should be running in
48
+ # the group.
49
+ #
50
+ # @option options [Integer] :health_check_grace_period
51
+ # Length of time in seconds after a new Amazon EC2 instance comes
52
+ # into service that Auto Scaling starts checking its health.
53
+ #
54
+ # @option options [Symbol] :health_check_type
55
+ # The service you want the health status from,
56
+ # Amazon EC2 or Elastic Load Balancer. Valid values are
57
+ # +:ec2+ or +:elb+.
58
+ #
59
+ # @option options [String] :placement_group
60
+ # Physical location of your cluster placement group created in
61
+ # Amazon EC2. For more information about cluster placement group, see
62
+ # {Using Cluster Instances}[http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using_cluster_computing.html].
63
+ #
64
+ # @option options [Array<Hash>] :tags A list of tags to apply launched
65
+ # instances. Each tag hash may have the following keys:
66
+ #
67
+ # * +:key+ - (required,String) The tag name.
68
+ # * +:value+ - (String) The optional tag value.
69
+ # * +:propagate_at_launch+ - (Boolean) Whether or not to propagate
70
+ # to instances, defaults to true.
71
+ #
72
+ # @option options [Array<EC2::Subnet>,Array<String>] :subnets
73
+ # A list of subnet identifiers of Amazon Virtual Private Clouds
74
+ # (Amazon VPCs). Ensure the subnets' Availability Zones match the
75
+ # Availability Zones specified.
76
+ #
77
+ # @return [Hash]
78
+ #
79
+ def group_options options
80
+
81
+ group_opts = {}
82
+
83
+ group_opts[:launch_configuration_name] = launch_config_opt(options) if
84
+ options.key?(:launch_configuration)
85
+
86
+ group_opts[:availability_zones] = az_opt(options) if
87
+ options.key?(:availability_zones)
88
+
89
+ group_opts[:vpc_zone_identifier] = subnets_opt(options) if
90
+ options.key?(:subnets)
91
+
92
+ group_opts[:health_check_type] = health_check_type_opt(options) if
93
+ options.key?(:health_check_type)
94
+
95
+ group_opts[:tags] = tags_opt(options) if
96
+ options.key?(:tags)
97
+
98
+ [
99
+ :min_size,
100
+ :max_size,
101
+ :default_cooldown,
102
+ :desired_capacity,
103
+ :health_check_grace_period,
104
+ :placement_group,
105
+ ].each do |opt|
106
+ group_opts[opt] = options[opt] if options.key?(opt)
107
+ end
108
+
109
+ group_opts
110
+ end
111
+
112
+ def launch_config_opt options
113
+ lc = options[:launch_configuration]
114
+ lc.is_a?(LaunchConfiguration) ? lc.name : lc
115
+ end
116
+
117
+ def az_opt options
118
+ zones = options[:availability_zones]
119
+ zones.map {|zone| zone.is_a?(EC2::AvailabilityZone) ? zone.name : zone }
120
+ end
121
+
122
+ def load_balancers_opt options
123
+ options[:load_balancers].collect do |lb|
124
+ lb.is_a?(ELB::LoadBalancer) ? lb.name : lb
125
+ end
126
+ end
127
+
128
+ def subnets_opt options
129
+ options[:subnets].collect do |subnet|
130
+ subnet.is_a?(EC2::Subnet) ? subnet.id : subnet
131
+ end.join(',')
132
+ end
133
+
134
+ def health_check_type_opt options
135
+ options[:health_check_type].to_s.upcase
136
+ end
137
+
138
+ def tags_opt options
139
+ options[:tags].map(&:to_hash).each do |tag|
140
+ tag[:propagate_at_launch] = true unless tag.key?(:propagate_at_launch)
141
+ end
142
+ end
143
+
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,192 @@
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
+ # A small wrapper around an {EC2::Instance}.
18
+ #
19
+ # == Getting Auto Scaling Instances
20
+ #
21
+ # If you know the EC2 instance id, you can use {#[]} to get the
22
+ # Auto Scaling instance.
23
+ #
24
+ # instance = auto_scaling.instance['i-1234578']
25
+ # instance.health_statue #=> :healthy
26
+ # instance.ec2_instance #=> <AWS::EC2::Instance instance_id:i-1234578>
27
+ #
28
+ # == Enumerating Auto Scaling Instances
29
+ #
30
+ # You can enumerate *ALL* instances like so:
31
+ #
32
+ # auto_scaling = AWS::AutoScaling.new
33
+ # auto_scaling.instances.each do |auto_scaling_instance|
34
+ # # ...
35
+ # end
36
+ #
37
+ # If you want the instances for a single auto scaling group:
38
+ #
39
+ # group = auto_scaling.groups['group-name']
40
+ # group.auto_scaling_instances.each do |instance|
41
+ # # ...
42
+ # end
43
+ #
44
+ # If you prefer {EC2::Instance} objects you should use
45
+ # {Group#ec2_instances} instead.
46
+ #
47
+ # @attr_reader [String] auto_scaling_group_name
48
+ #
49
+ # @attr_reader [String] launch_configuration_name
50
+ #
51
+ # @attr_reader [String] health_status Returns the instance health status
52
+ # (e.g. 'Healthly' or 'Unhealthly').
53
+ #
54
+ # @attr_reader [String] availability_zone_name
55
+ #
56
+ # @attr_reader [String] lifecycle_state
57
+ #
58
+ class Instance < Core::Resource
59
+
60
+ # @private
61
+ def initialize instance_id, options = {}
62
+ @instance_id = instance_id
63
+ super
64
+ end
65
+
66
+ # @return [String] instance_id Returns the EC2 id instance.
67
+ attr_reader :instance_id
68
+
69
+ alias_method :id, :instance_id
70
+
71
+ attribute :auto_scaling_group_name, :static => true
72
+
73
+ attribute :availability_zone_name,
74
+ :as => :availability_zone,
75
+ :static => true
76
+
77
+ attribute :health_status
78
+
79
+ attribute :launch_configuration_name, :static => true
80
+
81
+ attribute :lifecycle_state
82
+
83
+ populates_from(:describe_auto_scaling_instances) do |resp|
84
+ resp.auto_scaling_instances.find do |i|
85
+ i.instance_id == instance_id
86
+ end
87
+ end
88
+
89
+ # describe auto scaling groups returns ALL attributes
90
+ # except :auto_scaling_group_name
91
+ provider(:describe_auto_scaling_groups) do |provider|
92
+ provider.find do |resp|
93
+ instance = nil
94
+ resp.auto_scaling_groups.each do |group|
95
+ group.instances.each do |i|
96
+ instance = i if i.instance_id == instance_id
97
+ end
98
+ end
99
+ instance
100
+ end
101
+ provider.provides(*(attributes.keys - [:auto_scaling_group_name]))
102
+ end
103
+
104
+ # @return [EC2::Instance]
105
+ def ec2_instance
106
+ EC2::Instance.new(instance_id, :config => config)
107
+ end
108
+
109
+ # @return [AutoScaling::Group]
110
+ def auto_scaling_group
111
+ Group.new(auto_scaling_group_name, :config => config)
112
+ end
113
+ alias_method :group, :auto_scaling_group
114
+
115
+ # @return [EC2::AvailabilityZone]
116
+ def availability_zone
117
+ EC2::AvailabilityZone.new(availability_zone_name, :config => config)
118
+ end
119
+
120
+ # @return [LaunchConfiguration]
121
+ def launch_configuration
122
+ LaunchConfiguration.new(launch_configuration_name, :config => config)
123
+ end
124
+
125
+ # @param [String] status Sets the health status of an instance.
126
+ # Valid values inculde 'Healthy' and 'Unhealthy'
127
+ #
128
+ # @param [Hash] options
129
+ #
130
+ # @option options [Boolean] :respect_grace_period (false) If true,
131
+ # this call should respect the grace period associated with
132
+ # this instance's Auto Scaling group.
133
+ #
134
+ # @return [nil]
135
+ #
136
+ def set_health status, options = {}
137
+ client_opts = {}
138
+ client_opts[:instance_id] = instance_id
139
+ client_opts[:health_status] = status
140
+ client_opts[:should_respect_grace_period] =
141
+ options[:respect_grace_period] == true
142
+ client.set_instance_health(client_opts)
143
+ end
144
+
145
+ # @return [Boolean] Returns true if there exists an Auto Scaling
146
+ # instance with this instance id.
147
+ def exists?
148
+ !get_resource.auto_scaling_instances.empty?
149
+ end
150
+
151
+ # Terminates the current Auto Scaling instance.
152
+ #
153
+ # @params [Boolean] decrement_desired_capacity Specifies whether or not
154
+ # terminating this instance should also decrement the size of
155
+ # the AutoScalingGroup.
156
+ #
157
+ # @return [Activity] Returns an activity that represents the
158
+ # termination of the instance.
159
+ #
160
+ def terminate decrement_desired_capacity
161
+
162
+ client_opts = {}
163
+ client_opts[:instance_id] = instance_id
164
+ client_opts[:should_decrement_desired_capacity] =
165
+ decrement_desired_capacity
166
+
167
+ resp = client.terminate_instance_in_auto_scaling_group(client_opts)
168
+
169
+ Activity.new_from(
170
+ :terminate_instance_in_auto_scaling_group,
171
+ resp.activity,
172
+ resp.activity.activity_id,
173
+ :config => config)
174
+
175
+ end
176
+ alias_method :delete, :terminate
177
+
178
+ protected
179
+
180
+ def resource_identifiers
181
+ [[:instance_id, instance_id]]
182
+ end
183
+
184
+ def get_resource attr_name = nil
185
+ client_opts = {}
186
+ client_opts[:instance_ids] = [instance_id]
187
+ client.describe_auto_scaling_instances(client_opts)
188
+ end
189
+
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,63 @@
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 Auto Scaling instances.
18
+ #
19
+ # auto_scaling = AWS::AutoScaling.new
20
+ # auto_scaling.instances.each do |instance|
21
+ # # ...
22
+ # end
23
+ #
24
+ # You can also get an Auto Scaling instance by its EC2 instance id.
25
+ #
26
+ # auto_scaling_instance = auto_scaling.instances['i-12345678']
27
+ # auto_scaling_instance.class #=> AWS::AutoScaling::Instance
28
+ #
29
+ class InstanceCollection
30
+
31
+ include Core::Collection::Limitable
32
+
33
+ # @param [String] instance_id An {EC2::Instance} id string.
34
+ # @return [AutoScaling::Instance]
35
+ def [] instance_id
36
+ Instance.new(instance_id, :config => config)
37
+ end
38
+
39
+ protected
40
+
41
+ def _each_item next_token, limit, options = {}, &block
42
+
43
+ options[:next_token] = next_token if next_token
44
+ options[:max_records] = limit if limit
45
+
46
+ resp = client.describe_auto_scaling_instances(options)
47
+ resp.auto_scaling_instances.each do |details|
48
+
49
+ instance = Instance.new_from(
50
+ :describe_auto_scaling_instances,
51
+ details,
52
+ details.instance_id,
53
+ :config => config)
54
+
55
+ yield(instance)
56
+
57
+ end
58
+ resp.next_token if resp.respond_to?(:next_token)
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,150 @@
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
+
19
+ # @attr_reader [String] name
20
+ #
21
+ # @attr_reader [Time] created_time
22
+ #
23
+ # @attr_reader [String] image_id
24
+ #
25
+ # @attr_reader [Boolean] detailed_instance_monitoring
26
+ #
27
+ # @attr_reader [String] instance_type
28
+ #
29
+ # @attr_reader [String,nil] kernel_id
30
+ #
31
+ # @attr_reader [String,nil] key_name
32
+ #
33
+ # @attr_reader [String] arn
34
+ #
35
+ # @attr_reader [String,nil] ramdisk_id
36
+ #
37
+ # @attr_reader [String,nil] user_data
38
+ #
39
+ # @attr_reader [Array<Hash>] block_device_mappings
40
+ #
41
+ class LaunchConfiguration < Core::Resource
42
+
43
+ # @private
44
+ def initialize name, options = {}
45
+ super(options.merge(:name => name))
46
+ end
47
+
48
+ attribute :name, :as => :launch_configuration_name, :static => true
49
+
50
+ attribute :created_time, :static => true
51
+
52
+ alias_method :created_at, :created_time
53
+
54
+ attribute :image_id, :static => true
55
+
56
+ attribute :detailed_instance_monitoring,
57
+ :as => :instance_monitoring,
58
+ :static => true do
59
+ translates_output {|value| value.enabled? }
60
+ end
61
+
62
+ alias_method :detailed_instance_monitoring?, :detailed_instance_monitoring
63
+
64
+ attribute :instance_type, :static => true
65
+
66
+ attribute :kernel_id, :static => true
67
+
68
+ attribute :key_name, :static => true
69
+
70
+ attribute :arn, :as => :launch_configuration_arn, :static => true
71
+
72
+ attribute :ramdisk_id, :static => true
73
+
74
+ attribute :user_data, :static => true do
75
+ translates_output{|v| Base64.decode64(v) }
76
+ end
77
+
78
+ attribute :block_device_mappings,
79
+ :static => true do
80
+ translates_output{|mappings| mappings.map(&:to_hash) }
81
+ end
82
+
83
+ attribute :security_group_details,
84
+ :as => :security_groups,
85
+ :static => true
86
+
87
+ protected :security_group_details
88
+
89
+ populates_from(:describe_launch_configurations) do |resp|
90
+ resp.launch_configurations.find do |lc|
91
+ lc.launch_configuration_name == name
92
+ end
93
+ end
94
+
95
+ # @return [EC2::Image]
96
+ def image
97
+ EC2::Image.new(image_id, :config => config)
98
+ end
99
+
100
+ # @return [KeyPair,nil]
101
+ def key_pair
102
+ if key_name
103
+ EC2::KeyPair.new(key_name, :config => config)
104
+ end
105
+ end
106
+
107
+ # @return [Array<EC2::SecurityGroup>]
108
+ def security_groups
109
+ names_or_ids = security_group_details
110
+ if names_or_ids.all?{|str| str.match(/^sg-[0-9a-f]{8}$/) }
111
+ names_or_ids.collect do |security_group_id|
112
+ EC2::SecurityGroup.new(security_group_id, :config => config)
113
+ end
114
+ else
115
+ begin
116
+ ec2 = EC2.new(:config => config)
117
+ ec2.security_groups.filter('group-name', *names_or_ids).to_a
118
+ rescue
119
+ names_or_ids
120
+ end
121
+ end
122
+ end
123
+
124
+ # @return [Boolean] Returns true if this launch configuration exists.
125
+ def exists?
126
+ !!get_resource.launch_configurations.first
127
+ end
128
+
129
+ # Deletes the current launch configuration.
130
+ # @return [nil]
131
+ def delete
132
+ client.delete_launch_configuration(resource_options)
133
+ nil
134
+ end
135
+
136
+ protected
137
+
138
+ def resource_identifiers
139
+ [[:launch_configuration_name, name]]
140
+ end
141
+
142
+ def get_resource attr_name = nil
143
+ client_opts = {}
144
+ client_opts[:launch_configuration_names] = [name]
145
+ client.describe_launch_configurations(client_opts)
146
+ end
147
+
148
+ end
149
+ end
150
+ end