aws-sdk 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/lib/aws.rb +2 -0
  2. data/lib/aws/api_config/ELB-2011-08-15.yml +380 -0
  3. data/lib/aws/api_config/SNS-2010-03-31.yml +2 -2
  4. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +5 -5
  5. data/lib/aws/core.rb +18 -3
  6. data/lib/aws/core/client_logging.rb +5 -6
  7. data/lib/aws/core/collection.rb +241 -0
  8. data/lib/aws/core/collection/batchable.rb +133 -0
  9. data/lib/aws/core/collection/limitable.rb +92 -0
  10. data/lib/aws/core/collection/simple.rb +89 -0
  11. data/lib/aws/core/configuration.rb +23 -0
  12. data/lib/aws/core/option_grammar.rb +2 -0
  13. data/lib/aws/core/page_result.rb +73 -0
  14. data/lib/aws/ec2/security_group.rb +154 -89
  15. data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +1 -2
  16. data/lib/aws/ec2/security_group/{ip_permission_collection.rb → ingress_ip_permission_collection.rb} +4 -1
  17. data/lib/aws/ec2/security_group/ip_permission.rb +23 -45
  18. data/lib/aws/elb.rb +65 -0
  19. data/lib/aws/elb/availability_zone_collection.rb +138 -0
  20. data/lib/aws/elb/backend_server_policy_collection.rb +150 -0
  21. data/lib/aws/elb/client.rb +35 -0
  22. data/lib/aws/elb/client/xml.rb +33 -0
  23. data/lib/aws/elb/config.rb +18 -0
  24. data/lib/aws/elb/errors.rb +30 -0
  25. data/lib/aws/elb/instance_collection.rb +174 -0
  26. data/lib/aws/elb/listener.rb +189 -0
  27. data/lib/aws/elb/listener_collection.rb +119 -0
  28. data/lib/aws/elb/listener_opts.rb +45 -0
  29. data/lib/aws/elb/listener_spec.rb +14 -0
  30. data/lib/aws/elb/load_balancer.rb +255 -0
  31. data/lib/aws/elb/load_balancer_collection.rb +113 -0
  32. data/lib/aws/elb/load_balancer_policy.rb +93 -0
  33. data/lib/aws/elb/load_balancer_policy_collection.rb +208 -0
  34. data/lib/aws/elb/request.rb +23 -0
  35. data/lib/aws/iam/collection.rb +24 -26
  36. data/lib/aws/iam/group_user_collection.rb +21 -28
  37. data/lib/aws/iam/server_certificate_collection.rb +1 -37
  38. data/lib/aws/record.rb +1 -1
  39. data/lib/aws/record/base.rb +14 -1
  40. data/lib/aws/record/finder_methods.rb +4 -1
  41. data/lib/aws/record/validations.rb +73 -32
  42. data/lib/aws/{core/api_config_transform.rb → record/validators/method.rb} +9 -12
  43. data/lib/aws/s3/bucket_collection.rb +6 -4
  44. data/lib/aws/s3/client.rb +37 -6
  45. data/lib/aws/s3/config.rb +3 -1
  46. data/lib/aws/s3/prefixed_collection.rb +1 -2
  47. data/lib/aws/s3/presigned_post.rb +37 -4
  48. data/lib/aws/s3/s3_object.rb +93 -1
  49. data/lib/aws/simple_db/domain.rb +8 -0
  50. data/lib/aws/simple_db/item.rb +15 -0
  51. data/lib/aws/simple_db/item_collection.rb +255 -201
  52. data/lib/aws/simple_db/item_data.rb +1 -1
  53. data/lib/aws/simple_email_service/client.rb +0 -1
  54. data/lib/aws/sns/client.rb +0 -1
  55. metadata +107 -55
  56. data/lib/aws/core/collections.rb +0 -229
  57. data/lib/aws/simple_email_service/client/options.rb +0 -21
  58. data/lib/aws/sns/client/options.rb +0 -21
@@ -0,0 +1,119 @@
1
+ # Copyright 2011 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 ELB
16
+
17
+ class ListenerCollection
18
+
19
+ include ListenerOpts
20
+ include Core::Collection::Simple
21
+
22
+ def initialize load_balancer, options = {}
23
+ @load_balancer = load_balancer
24
+ super
25
+ end
26
+
27
+ # @return [LoadBalancer]
28
+ attr_reader :load_balancer
29
+
30
+ # @param [Hash] options
31
+ #
32
+ # @option options [Integer] :port Specifies the external
33
+ # load balancer port number. This property cannot be modified for
34
+ # the life of the LoadBalancer.
35
+ #
36
+ # @option options [String,Symbol] :protocol Specifies the load balancer
37
+ # transport protocol to use for routing. Valid values include:
38
+ #
39
+ # @option options [Integer] :instance_port Specifies the TCP port on
40
+ # which the instance server is listening. This property cannot be
41
+ # modified for the life of the load balancer.
42
+ #
43
+ # @option options [String,Symbol] :instance_protocol Specifies the
44
+ # protocol to use for routing traffic to back-end instances. Valid
45
+ # values include:
46
+ #
47
+ # * :http, 'HTTP'
48
+ # * :https, 'HTTPS'
49
+ # * :tcp, 'TCP'
50
+ # * :ssl, 'SSL'
51
+ #
52
+ # This property cannot be modified for the life of the load balacner.
53
+ #
54
+ # NOTE: If the front-end protocol is HTTP or HTTPS, +:instance_protocol+
55
+ # has to be at the same protocol layer, i.e., HTTP or HTTPS. Likewise,
56
+ # if the front-end protocol is TCP or SSL, +:instance_protocol+ has
57
+ # to be TCP or SSL.
58
+ #
59
+ # NOTE: If there is another listener with the same +:instance_port+
60
+ # whose +:instance_protocol+ is secure, i.e., HTTPS or SSL, the
61
+ # listener's +:instance_protocol+ has to be secure, i.e., HTTPS
62
+ # or SSL. If there is another listener with the same +:instance_port+
63
+ # whose +:instance_protocol+ is HTTP or TCP, the listener's
64
+ # +:instance_protocol+ must be either HTTP or TCP.
65
+ #
66
+ # * :tcp, 'TCP'
67
+ # * :http, 'HTTP'
68
+ #
69
+ # This property cannot be modified for the life of the load balancer.
70
+ #
71
+ # @option options [String,IAM::ServerCertificate] :server_certificate The
72
+ # ARN string of an IAM::ServerCertifcate or an IAM::ServerCertificate
73
+ # object. Reqruied for HTTPs listeners.
74
+ #
75
+ # @return [Listener]
76
+ def create options = {}
77
+
78
+ format_listener_opts(options)
79
+
80
+ client.create_load_balancer_listeners(
81
+ :load_balancer_name => load_balancer.name,
82
+ :listeners => [options])
83
+
84
+ Listener.new(load_balancer,
85
+ options[:load_balancer_port],
86
+ options.merge(:config => config))
87
+
88
+ end
89
+
90
+ # @return [Listener]
91
+ def [] port
92
+ Listener.new(load_balancer, port, :config => config)
93
+ end
94
+
95
+ protected
96
+ def _each_item options = {}
97
+ load_balancer.listener_descriptions.each do |desc|
98
+
99
+ desc = desc.listener
100
+
101
+ opts = {}
102
+ opts[:config] = config
103
+ opts[:protocol] = desc.protocol
104
+ opts[:instance_port] = desc.instance_port
105
+ opts[:instance_protocol] = desc.instance_protocol
106
+ opts[:ssl_certificate_id] = desc.ssl_certificate_id if
107
+ desc.respond_to?(:ssl_certificate_id)
108
+
109
+ listener = Listener.new(load_balancer, desc.load_balancer_port, opts)
110
+
111
+ yield(listener)
112
+
113
+ end
114
+ end
115
+
116
+ end
117
+
118
+ end
119
+ end
@@ -0,0 +1,45 @@
1
+ # Copyright 2011 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 ELB
16
+
17
+ # @private
18
+ module ListenerOpts
19
+
20
+ # convert protocols from symbols to strings (e.g. :http to 'HTTP')
21
+ protected
22
+ def format_listener_opts options
23
+
24
+ # accept the :load_balancer_port option by :port
25
+ options[:load_balancer_port] = options.delete(:port) if
26
+ options[:port]
27
+
28
+ # convert symbolized protocol names into upper-cased strings
29
+ [:protocol, :instance_protocol].each do |opt|
30
+ options[opt] = options[opt].to_s.upcase if options[opt]
31
+ end
32
+
33
+ # convert iam server certificates into the ssl certificate id
34
+ if cert = options.delete(:server_certificate)
35
+ options[:ssl_certificate_id] = cert.is_a?(IAM::ServerCertificate) ?
36
+ cert.arn : cert
37
+ end
38
+
39
+ options
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright 2011 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
+
@@ -0,0 +1,255 @@
1
+ # Copyright 2011 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 ELB
16
+
17
+
18
+ #
19
+ # @attr_reader [String] name The name of the load balancer.
20
+ #
21
+ # @attr_reader [Array<String>] availability_zone_names Return the names of
22
+ # the availability zones this load balancer routes traffic to.
23
+ #
24
+ # @attr_reader [String] canonical_hosted_zone_name Provides the name of
25
+ # the Amazon Route 53 hosted zone that is associated with the load
26
+ # balancer. For more information: {http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/index.html?using-domain-names-with-elb.html}.
27
+ #
28
+ # @attr_reader [String] canonical_hosted_zone_name_id Provides the ID of
29
+ # the Amazon Route 53 hosted zone name that is associated with the
30
+ # load balancer. For more information: {http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/index.html?using-domain-names-with-elb.html}.
31
+ #
32
+ # @attr_reader [String] dns_name Specifies the external DNS name
33
+ # associated with this load balancer.
34
+ #
35
+ class LoadBalancer < Core::Resource
36
+
37
+ def initialize name, options = {}
38
+ super(options.merge(:name => name.to_s))
39
+ end
40
+
41
+ attribute :name, :as => :load_balancer_name, :static => true
42
+
43
+ #availability_zones
44
+ attribute :availability_zone_names, :as => :availability_zones
45
+
46
+ #backend_server_policies
47
+ attribute :backend_server_descriptions
48
+
49
+ attribute :canonical_hosted_zone_name, :static => true
50
+
51
+ attribute :canonical_hosted_zone_name_id, :static => true
52
+
53
+ attribute :created_time, :static => true
54
+
55
+ attribute :dns_name, :static => true
56
+
57
+ #health_check_configuration
58
+ attribute :health_check_description, :as => :health_check
59
+
60
+ #instances
61
+ attribute :instance_descriptions, :as => :instances
62
+
63
+ #listeners
64
+ attribute :listener_descriptions
65
+
66
+ #source_security_group
67
+ attribute :security_group_description,
68
+ :as => :source_security_group,
69
+ :static => true
70
+
71
+ populates_from(:describe_load_balancers) do |resp|
72
+ resp.load_balancer_descriptions.find do |lb|
73
+ lb.load_balancer_name == name
74
+ end
75
+ end
76
+
77
+ # A collection that help maanage the availability zones for
78
+ # this load balancer.
79
+ #
80
+ # @example enable an availability zone
81
+ #
82
+ # load_balancer.availability_zones.enable('us-east-1b')
83
+ #
84
+ # @example disable an availability zone
85
+ #
86
+ # load_balancer.availability_zones.disable('us-east-1b')
87
+ #
88
+ # @example list enabled availability zoens
89
+ #
90
+ # load_balancer.availability_zones.each do |zone|
91
+ # puts zone.name
92
+ # end
93
+ #
94
+ # @return [AvailabilityZoneCollection] Returns a collection that
95
+ # represents this load balancer's availability zones. You can
96
+ # use this collection to enable and disable availability zones.
97
+ def availability_zones
98
+ AvailabilityZoneCollection.new(self)
99
+ end
100
+
101
+ # @return [ListenerCollection]
102
+ def listeners
103
+ ListenerCollection.new(self)
104
+ end
105
+
106
+ # @return [PolicyCollection]
107
+ def policies
108
+ LoadBalancerPolicyCollection.new(self)
109
+ end
110
+
111
+ # @return [InstanceCollection]
112
+ def instances
113
+ InstanceCollection.new(self)
114
+ end
115
+
116
+ # @return [BackendServerPolicyCollection]
117
+ def backend_server_policies
118
+ BackendServerPolicyCollection.new(self)
119
+ end
120
+
121
+ # Updates the configuration that drives the instance health checks.
122
+ #
123
+ # You only need to pass the options you want to change. You can
124
+ # call {#health_check_configuration} if you want to see what the
125
+ # current configuration values are.
126
+ #
127
+ # @param [Hash] options
128
+ #
129
+ # @option options [Integer] :healthy_threshold Specifies the number of
130
+ # consecutive health probe successes required before moving the
131
+ # instance to the Healthy state.
132
+ #
133
+ # @option options [Integer] :unhealthy_threshold Specifies the number
134
+ # of consecutive health probe failures required before moving the
135
+ # instance to the Unhealthy state.
136
+ #
137
+ # @option options [Integer] :interval Specifies the approximate
138
+ # interval, in seconds, between health checks of an individual
139
+ # instance.
140
+ #
141
+ # @option options [Integer] :timeout Specifies the amount of time, in
142
+ # seconds, during which no response means a failed health probe.
143
+ # This value must be less than the +:interval+ value.
144
+ #
145
+ # @option options [String] :target Specifies the instance being checked.
146
+ #
147
+ # This option should be formatted like: "TCP:80"
148
+ #
149
+ # * The protocol is either TCP, HTTP, HTTPS, or SSL.
150
+ # * The range of valid ports is one (1) through 65535.
151
+ #
152
+ # TCP is the default, specified as a TCP: port pair, for example
153
+ # "TCP:5000". In this case a healthcheck simply attempts to open a
154
+ # TCP connection to the instance on the specified port. Failure to
155
+ # connect within the configured timeout is considered unhealthy.
156
+ #
157
+ # SSL is also specified as SSL: port pair, for example, SSL:5000.
158
+ # For HTTP or HTTPS protocol, the situation is different. You have
159
+ # to include a ping path in the string. HTTP is specified as a
160
+ # HTTP:port;/;PathToPing; grouping, for example
161
+ # "HTTP:80/weather/us/wa/seattle". In this case, a HTTP GET request
162
+ # is issued to the instance on the given port and path. Any answer
163
+ # other than "200 OK" within the timeout period is considered
164
+ # unhealthy.
165
+ #
166
+ # The total length of the HTTP ping target needs to be 1024 16-bit
167
+ # Unicode characters or less.
168
+ #
169
+ def configure_health_check options = {}
170
+
171
+ new_config = health_check_configuration.merge(options)
172
+
173
+ response = client.configure_health_check(
174
+ :load_balancer_name => name,
175
+ :health_check => new_config)
176
+
177
+ new_config
178
+
179
+ end
180
+
181
+ # Returns a hash of the various health probes conducted on the
182
+ # load balancer instances. The following entries are returned:
183
+ #
184
+ # * +:healthy_threshold+
185
+ # * +:unhealthy_threshold+
186
+ # * +:interval+
187
+ # * +:target+
188
+ # * +:timeout+
189
+ #
190
+ # See {#configure_health_check} for more details on what each of the
191
+ # configuration values mean.
192
+ #
193
+ # @return [Hash]
194
+ #
195
+ def health_check_configuration
196
+ cfg = health_check_description
197
+ {
198
+ :healthy_threshold => cfg.healthy_threshold,
199
+ :unhealthy_threshold => cfg.unhealthy_threshold,
200
+ :interval => cfg.interval,
201
+ :target => cfg.target,
202
+ :timeout => cfg.timeout,
203
+ }
204
+ end
205
+
206
+ # Generally you don't need to call this method, rather you can
207
+ # just pass the load balancer as a source to the various
208
+ # authorize and revoke methods of {SecurityGroup}:
209
+ #
210
+ # security_group.authorize_ingress(load_balancer)
211
+ #
212
+ # security_group.revoke_ingress(load_balancer)
213
+ #
214
+ # @return [Hash] Returns a hash that can be passed to the following
215
+ # {SecurityGroup} methods as a source:
216
+ #
217
+ # * {SecurityGroup#authorize_ingress}
218
+ # * {SecurityGroup#authorize_egress}
219
+ #
220
+ def source_security_group
221
+ {
222
+ :group_name => security_group_description.group_name,
223
+ :user_id => security_group_description.owner_alias,
224
+ }
225
+ end
226
+
227
+ # @return [Boolean] Returns true if the load balancer exists.
228
+ def exists?
229
+ client.describe_load_balancers(:load_balancer_names => [name])
230
+ true
231
+ rescue Errors::LoadBalancerNotFound
232
+ false
233
+ end
234
+
235
+ # Deletes the load balancer.
236
+ # @return [nil]
237
+ def delete
238
+ client.delete_load_balancer(:load_balancer_name => name)
239
+ nil
240
+ end
241
+
242
+ protected
243
+ def resource_identifiers
244
+ [[:load_balancer_name,name]]
245
+ end
246
+
247
+ protected
248
+ def get_resource attr_name
249
+ # describing all, makes memoization more efficient
250
+ client.describe_load_balancers
251
+ end
252
+
253
+ end
254
+ end
255
+ end
@@ -0,0 +1,113 @@
1
+ # Copyright 2011 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 ELB
16
+
17
+ class LoadBalancerCollection
18
+
19
+ include ListenerOpts
20
+ include Core::Collection::Simple
21
+
22
+ # Creates and returns a load balancer. A load balancer requires:
23
+ #
24
+ # * a unique name
25
+ # * at least one availability zone
26
+ # * at least one listener
27
+ #
28
+ # An example that creates a load balancer in two availability zones
29
+ # with a single listener:
30
+ #
31
+ # load_balancer = elb.load_balancers.create('my-load-balancer',
32
+ # :availability_zones => %w(us-east-1a us-east-1b),
33
+ # :listeners => [{
34
+ # :port => 80,
35
+ # :protocol => :http,
36
+ # :instance_port => 80,
37
+ # :instance_protocol => :http,
38
+ # }])
39
+ #
40
+ # @param [String] name The name of your load balancer. The name must
41
+ # be unique within your set of load balancers.
42
+ #
43
+ # @param [Hash] options
44
+ #
45
+ # @option options [required,Array] :availability_zones An array of
46
+ # one or more availability zones. Values may be availability zone
47
+ # name strings, or {AWS::EC2::AvabilityZone} objects.
48
+ #
49
+ # @option options [required,Array] :listeners An array of load balancer
50
+ # listener options. Each value must be an array with the following
51
+ # keys:
52
+ #
53
+ # +:port+
54
+ # +:protocol+
55
+ # +:instance_port+
56
+ # +:instance_protocol+
57
+ #
58
+ # Port values should be integers, and protocols should be symbols or
59
+ # strings (e.g. :http, or 'HTTP'). See {ListenerCollection#create}
60
+ # for more detailed description of each option.
61
+ #
62
+ # @option options [String,IAM::ServerCertificate] :server_certificate (nil)
63
+ # The ARN string of an IAM::ServerCertifcate or an
64
+ # IAM::ServerCertificate object. Reqruied for HTTPs listeners.
65
+ #
66
+ def create name, options = {}
67
+
68
+ zones = [options[:availability_zones]].flatten.collect do |zone|
69
+ zone.is_a?(EC2::AvailabilityZone) ? zone.name : zone
70
+ end
71
+
72
+ listeners = [options[:listeners]].flatten.collect do |listener_opts|
73
+ format_listener_opts(listener_opts)
74
+ end
75
+
76
+ response = client.create_load_balancer(
77
+ :load_balancer_name => name.to_s,
78
+ :availability_zones => zones,
79
+ :listeners => listeners)
80
+
81
+ opts = {}
82
+ opts[:config] = config
83
+ opts[:dns_name] = response.dns_name
84
+
85
+ LoadBalancer.new(name, opts)
86
+
87
+ end
88
+
89
+ # @return [LoadBalancer] Returns the load balancer with the given
90
+ # name. This does not make a request, just returns a reference.
91
+ def [] name
92
+ LoadBalancer.new(name, :config => config)
93
+ end
94
+
95
+ protected
96
+ def _each_item options = {}, &block
97
+ response = client.describe_load_balancers
98
+ response.load_balancer_descriptions.each do |description|
99
+
100
+ load_balancer = LoadBalancer.new_from(
101
+ :describe_load_balancers,
102
+ description,
103
+ description.load_balancer_name,
104
+ :config => config)
105
+
106
+ yield(load_balancer)
107
+
108
+ end
109
+ end
110
+
111
+ end
112
+ end
113
+ end