aws-sdk 1.6.4 → 1.6.5

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.
@@ -30,18 +30,18 @@ module AWS
30
30
  # @param [Hash] options
31
31
  #
32
32
  # @option options [Integer] :port Specifies the external
33
- # load balancer port number. This property cannot be modified for
33
+ # load balancer port number. This property cannot be modified for
34
34
  # the life of the LoadBalancer.
35
35
  #
36
36
  # @option options [String,Symbol] :protocol Specifies the load balancer
37
37
  # transport protocol to use for routing. Valid values include:
38
38
  #
39
- # @option options [Integer] :instance_port Specifies the TCP port on
40
- # which the instance server is listening. This property cannot be
39
+ # @option options [Integer] :instance_port Specifies the TCP port on
40
+ # which the instance server is listening. This property cannot be
41
41
  # modified for the life of the load balancer.
42
42
  #
43
- # @option options [String,Symbol] :instance_protocol Specifies the
44
- # protocol to use for routing traffic to back-end instances. Valid
43
+ # @option options [String,Symbol] :instance_protocol Specifies the
44
+ # protocol to use for routing traffic to back-end instances. Valid
45
45
  # values include:
46
46
  #
47
47
  # * :http, 'HTTP'
@@ -53,14 +53,14 @@ module AWS
53
53
  #
54
54
  # NOTE: If the front-end protocol is HTTP or HTTPS, +:instance_protocol+
55
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
56
+ # if the front-end protocol is TCP or SSL, +:instance_protocol+ has
57
57
  # to be TCP or SSL.
58
58
  #
59
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
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
62
  # or SSL. If there is another listener with the same +:instance_port+
63
- # whose +:instance_protocol+ is HTTP or TCP, the listener's
63
+ # whose +:instance_protocol+ is HTTP or TCP, the listener's
64
64
  # +:instance_protocol+ must be either HTTP or TCP.
65
65
  #
66
66
  # * :tcp, 'TCP'
@@ -69,20 +69,20 @@ module AWS
69
69
  # This property cannot be modified for the life of the load balancer.
70
70
  #
71
71
  # @option options [String,IAM::ServerCertificate] :server_certificate The
72
- # ARN string of an IAM::ServerCertifcate or an IAM::ServerCertificate
72
+ # ARN string of an IAM::ServerCertifcate or an IAM::ServerCertificate
73
73
  # object. Reqruied for HTTPs listeners.
74
74
  #
75
75
  # @return [Listener]
76
76
  def create options = {}
77
-
77
+
78
78
  format_listener_opts(options)
79
79
 
80
80
  client.create_load_balancer_listeners(
81
81
  :load_balancer_name => load_balancer.name,
82
82
  :listeners => [options])
83
83
 
84
- Listener.new(load_balancer,
85
- options[:load_balancer_port],
84
+ Listener.new(load_balancer,
85
+ options[:load_balancer_port],
86
86
  options.merge(:config => config))
87
87
 
88
88
  end
@@ -94,25 +94,19 @@ module AWS
94
94
 
95
95
  protected
96
96
  def _each_item options = {}
97
- load_balancer.listener_descriptions.each do |desc|
98
-
99
- desc = desc.listener
97
+ load_balancer.listener_descriptions.each do |description|
100
98
 
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)
99
+ port = description[:listener][:load_balancer_port]
108
100
 
109
- listener = Listener.new(load_balancer, desc.load_balancer_port, opts)
101
+ options = {}
102
+ options[:config] = config
103
+ options.merge!(description[:listener])
110
104
 
111
- yield(listener)
105
+ yield(Listener.new(load_balancer, port, options))
112
106
 
113
107
  end
114
108
  end
115
-
109
+
116
110
  end
117
111
 
118
112
  end
@@ -19,17 +19,45 @@ module AWS
19
19
  # @attr_reader [Array<String>] availability_zone_names Return the names of
20
20
  # the availability zones this load balancer routes traffic to.
21
21
  #
22
- # @attr_reader [String] canonical_hosted_zone_name Provides the name of
22
+ # @attr_reader [String] canonical_hosted_zone_name Provides the name of
23
23
  # the Amazon Route 53 hosted zone that is associated with the load
24
24
  # balancer. For more information: {http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/index.html?using-domain-names-with-elb.html}.
25
25
  #
26
- # @attr_reader [String] canonical_hosted_zone_name_id Provides the ID of
27
- # the Amazon Route 53 hosted zone name that is associated with the
26
+ # @attr_reader [String] canonical_hosted_zone_name_id Provides the ID of
27
+ # the Amazon Route 53 hosted zone name that is associated with the
28
28
  # load balancer. For more information: {http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/index.html?using-domain-names-with-elb.html}.
29
29
  #
30
- # @attr_reader [String] dns_name Specifies the external DNS name
30
+ # @attr_reader [String] dns_name Specifies the external DNS name
31
31
  # associated with this load balancer.
32
32
  #
33
+ # @attr_reader [Hash] policy_descriptions Returns a hash of
34
+ # +:app_cookie_stickiness_policies+, +:lb_cookie_stickiness_policies+
35
+ # and +:other_policies+. See also {#policies}.
36
+ #
37
+ # @attr_reader [String,nil] scheme Specifies the type of LoadBalancer.
38
+ # This attribute it set only for LoadBalancers attached to an Amazon VPC.
39
+ # If the Scheme is 'internet-facing', the LoadBalancer has a publicly
40
+ # resolvable DNS name that resolves to public IP addresses.
41
+ # If the Scheme is 'internal', the LoadBalancer has a publicly
42
+ # resolvable DNS name that resolves to private IP addresses.
43
+ #
44
+ # @attr_reader [Array<String>] subnet_ids Provides a list of VPC subnet IDs
45
+ # for the LoadBalancer.
46
+ #
47
+ # @attr_reader [Hash] health_check
48
+ # Returns a hash of the various health probes conducted on the
49
+ # load balancer instances. The following entries are returned:
50
+ # * +:healthy_threshold+
51
+ # * +:unhealthy_threshold+
52
+ # * +:interval+
53
+ # * +:target+
54
+ # * +:timeout+
55
+ # See {#configure_health_check} for more details on what each of the
56
+ # configuration values mean.
57
+ #
58
+ # @return [Hash]
59
+ #
60
+ #
33
61
  class LoadBalancer < Core::Resource
34
62
 
35
63
  def initialize name, options = {}
@@ -38,10 +66,10 @@ module AWS
38
66
 
39
67
  attribute :name, :from => :load_balancer_name, :static => true
40
68
 
41
- #availability_zones
69
+ # see #availability_zones
42
70
  attribute :availability_zone_names, :from => :availability_zones
43
71
 
44
- #backend_server_policies
72
+ # see #backend_server_policies
45
73
  attribute :backend_server_descriptions
46
74
 
47
75
  attribute :canonical_hosted_zone_name, :static => true
@@ -52,27 +80,37 @@ module AWS
52
80
 
53
81
  attribute :dns_name, :static => true
54
82
 
55
- #health_check_configuration
56
- attribute :health_check_description, :from => :health_check
83
+ attribute :health_check, :alias => :health_check_configuration
57
84
 
58
- #instances
85
+ # see #instances
59
86
  attribute :instance_descriptions, :from => :instances
60
87
 
61
- #listeners
88
+ # see #listeners
62
89
  attribute :listener_descriptions
63
90
 
64
- #source_security_group
65
- attribute :security_group_description,
66
- :from => :source_security_group,
91
+ attribute :policy_descriptions, :from => :policies
92
+
93
+ attribute :scheme, :static => true
94
+
95
+ attribute :subnet_ids, :from => :subnets, :static => true
96
+
97
+ attribute :security_group_ids, :from => :security_groups, :static => true
98
+
99
+ attribute :source_security_group_owner_alias,
100
+ :from => [:source_security_group, :owner_alias],
101
+ :static => true
102
+
103
+ attribute :source_security_group_name,
104
+ :from => [:source_security_group, :group_name],
67
105
  :static => true
68
106
 
69
107
  populates_from(:describe_load_balancers) do |resp|
70
- resp.load_balancer_descriptions.find do |lb|
71
- lb.load_balancer_name == name
108
+ resp.data[:load_balancer_descriptions].find do |lb|
109
+ lb[:load_balancer_name] == name
72
110
  end
73
111
  end
74
112
 
75
- # A collection that help maanage the availability zones for
113
+ # A collection that help maanage the availability zones for
76
114
  # this load balancer.
77
115
  #
78
116
  # @example enable an availability zone
@@ -89,7 +127,7 @@ module AWS
89
127
  # puts zone.name
90
128
  # end
91
129
  #
92
- # @return [AvailabilityZoneCollection] Returns a collection that
130
+ # @return [AvailabilityZoneCollection] Returns a collection that
93
131
  # represents this load balancer's availability zones. You can
94
132
  # use this collection to enable and disable availability zones.
95
133
  def availability_zones
@@ -118,55 +156,55 @@ module AWS
118
156
 
119
157
  # Updates the configuration that drives the instance health checks.
120
158
  #
121
- # You only need to pass the options you want to change. You can
122
- # call {#health_check_configuration} if you want to see what the
159
+ # You only need to pass the options you want to change. You can
160
+ # call {#health_check} if you want to see what the
123
161
  # current configuration values are.
124
162
  #
125
163
  # @param [Hash] options
126
164
  #
127
165
  # @option options [Integer] :healthy_threshold Specifies the number of
128
- # consecutive health probe successes required before moving the
166
+ # consecutive health probe successes required before moving the
129
167
  # instance to the Healthy state.
130
168
  #
131
- # @option options [Integer] :unhealthy_threshold Specifies the number
132
- # of consecutive health probe failures required before moving the
169
+ # @option options [Integer] :unhealthy_threshold Specifies the number
170
+ # of consecutive health probe failures required before moving the
133
171
  # instance to the Unhealthy state.
134
172
  #
135
- # @option options [Integer] :interval Specifies the approximate
136
- # interval, in seconds, between health checks of an individual
173
+ # @option options [Integer] :interval Specifies the approximate
174
+ # interval, in seconds, between health checks of an individual
137
175
  # instance.
138
176
  #
139
- # @option options [Integer] :timeout Specifies the amount of time, in
140
- # seconds, during which no response means a failed health probe.
177
+ # @option options [Integer] :timeout Specifies the amount of time, in
178
+ # seconds, during which no response means a failed health probe.
141
179
  # This value must be less than the +:interval+ value.
142
180
  #
143
- # @option options [String] :target Specifies the instance being checked.
181
+ # @option options [String] :target Specifies the instance being checked.
144
182
  #
145
183
  # This option should be formatted like: "TCP:80"
146
184
  #
147
- # * The protocol is either TCP, HTTP, HTTPS, or SSL.
185
+ # * The protocol is either TCP, HTTP, HTTPS, or SSL.
148
186
  # * The range of valid ports is one (1) through 65535.
149
187
  #
150
- # TCP is the default, specified as a TCP: port pair, for example
151
- # "TCP:5000". In this case a healthcheck simply attempts to open a
152
- # TCP connection to the instance on the specified port. Failure to
188
+ # TCP is the default, specified as a TCP: port pair, for example
189
+ # "TCP:5000". In this case a healthcheck simply attempts to open a
190
+ # TCP connection to the instance on the specified port. Failure to
153
191
  # connect within the configured timeout is considered unhealthy.
154
192
  #
155
193
  # SSL is also specified as SSL: port pair, for example, SSL:5000.
156
- # For HTTP or HTTPS protocol, the situation is different. You have
157
- # to include a ping path in the string. HTTP is specified as a
158
- # HTTP:port;/;PathToPing; grouping, for example
159
- # "HTTP:80/weather/us/wa/seattle". In this case, a HTTP GET request
160
- # is issued to the instance on the given port and path. Any answer
161
- # other than "200 OK" within the timeout period is considered
194
+ # For HTTP or HTTPS protocol, the situation is different. You have
195
+ # to include a ping path in the string. HTTP is specified as a
196
+ # HTTP:port;/;PathToPing; grouping, for example
197
+ # "HTTP:80/weather/us/wa/seattle". In this case, a HTTP GET request
198
+ # is issued to the instance on the given port and path. Any answer
199
+ # other than "200 OK" within the timeout period is considered
162
200
  # unhealthy.
163
201
  #
164
- # The total length of the HTTP ping target needs to be 1024 16-bit
202
+ # The total length of the HTTP ping target needs to be 1024 16-bit
165
203
  # Unicode characters or less.
166
204
  #
167
205
  def configure_health_check options = {}
168
206
 
169
- new_config = health_check_configuration.merge(options)
207
+ new_config = health_check.merge(options)
170
208
 
171
209
  response = client.configure_health_check(
172
210
  :load_balancer_name => name,
@@ -176,29 +214,20 @@ module AWS
176
214
 
177
215
  end
178
216
 
179
- # Returns a hash of the various health probes conducted on the
180
- # load balancer instances. The following entries are returned:
181
- #
182
- # * +:healthy_threshold+
183
- # * +:unhealthy_threshold+
184
- # * +:interval+
185
- # * +:target+
186
- # * +:timeout+
187
- #
188
- # See {#configure_health_check} for more details on what each of the
189
- # configuration values mean.
190
- #
191
- # @return [Hash]
192
- #
193
- def health_check_configuration
194
- cfg = health_check_description
195
- {
196
- :healthy_threshold => cfg.healthy_threshold,
197
- :unhealthy_threshold => cfg.unhealthy_threshold,
198
- :interval => cfg.interval,
199
- :target => cfg.target,
200
- :timeout => cfg.timeout,
201
- }
217
+ # @note VPC only
218
+ # @return [Array<EC2::Subnet>] Returns an array of VPC subnets
219
+ # for this load balancer.
220
+ def subnets
221
+ subnet_ids.map{|id| EC2::Subnet.new(id, :config => config) }
222
+ end
223
+
224
+ # @note VPC only
225
+ # Returns the VPC security groups assigned to this load balancer.
226
+ # @return [Array<EC2::SecurityGroup>]
227
+ def security_groups
228
+ security_group_ids.collect do |id|
229
+ EC2::SecurityGroup.new(id, :config => config)
230
+ end
202
231
  end
203
232
 
204
233
  # Generally you don't need to call this method, rather you can
@@ -216,9 +245,9 @@ module AWS
216
245
  # * {EC2::SecurityGroup#authorize_egress}
217
246
  #
218
247
  def source_security_group
219
- {
220
- :group_name => security_group_description.group_name,
221
- :user_id => security_group_description.owner_alias,
248
+ {
249
+ :group_name => source_security_group_name,
250
+ :user_id => source_security_group_owner_alias,
222
251
  }
223
252
  end
224
253
 
@@ -238,14 +267,13 @@ module AWS
238
267
  end
239
268
 
240
269
  protected
270
+
241
271
  def resource_identifiers
242
- [[:load_balancer_name,name]]
272
+ [[:load_balancer_name, name]]
243
273
  end
244
274
 
245
- protected
246
275
  def get_resource attr_name
247
- # describing all, makes memoization more efficient
248
- client.describe_load_balancers
276
+ client.describe_load_balancers(:load_balancer_names => [name])
249
277
  end
250
278
 
251
279
  end
@@ -46,14 +46,13 @@ module AWS
46
46
  # one or more availability zones. Values may be availability zone
47
47
  # name strings, or {AWS::EC2::AvailabilityZone} objects.
48
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+
49
+ # @option options [required,Array<Hash>] :listeners An array of load
50
+ # balancer listener options. Each value must be an array with the
51
+ # following keys:
52
+ # * +:port+
53
+ # * +:protocol+
54
+ # * +:instance_port+
55
+ # * +:instance_protocol+
57
56
  #
58
57
  # Port values should be integers, and protocols should be symbols or
59
58
  # strings (e.g. :http, or 'HTTP'). See {ListenerCollection#create}
@@ -63,34 +62,48 @@ module AWS
63
62
  # The ARN string of an IAM::ServerCertifcate or an
64
63
  # IAM::ServerCertificate object. Reqruied for HTTPs listeners.
65
64
  #
65
+ # @option options [Array] :subnets An list of VPC subets to attach the
66
+ # load balancer to. This can be an array of subnet ids (strings) or
67
+ # {EC2::Subnet} objects. VPC only.
68
+ #
69
+ # @option options [Array] :security_groups The security groups assigned to
70
+ # your load balancer within your VPC. This can be an array of
71
+ # security group ids or {EC2::SecurityGroup} objects. VPC only.
72
+ #
73
+ # @option options [String] :scheme ('internal' The type of a load
74
+ # balancer. Accepts 'internet-facing' or 'internal'. VPC only.
75
+ #
66
76
  def create name, options = {}
67
77
 
68
- unless options[:availability_zones]
69
- raise ArgumentError, "missing required :availability_zones option"
78
+ if listeners = options[:listeners]
79
+ options[:listeners] = [listeners].flatten.map do |listener|
80
+ format_listener_opts(listener)
81
+ end
70
82
  end
71
83
 
72
- unless options[:listeners]
73
- raise ArgumentError, "missing required :listeners option"
84
+ if zones = options[:availability_zones]
85
+ options[:availability_zones] = [zones].flatten.map do |zone|
86
+ zone.is_a?(EC2::AvailabilityZone) ? zone.name : zone
87
+ end
74
88
  end
75
89
 
76
- zones = [options[:availability_zones]].flatten.collect do |zone|
77
- zone.is_a?(EC2::AvailabilityZone) ? zone.name : zone
90
+ if groups = options[:security_groups]
91
+ options[:security_groups] = [groups].flatten.map do |group|
92
+ group.is_a?(EC2::SecurityGroup) ? group.id : group
93
+ end
78
94
  end
79
95
 
80
- listeners = [options[:listeners]].flatten.collect do |listener_opts|
81
- format_listener_opts(listener_opts)
96
+ if subnets = options[:subnets]
97
+ options[:subnets] = [subnets].flatten.map do |subnet|
98
+ subnet.is_a?(EC2::Subnet) ? subnet.id : subnet
99
+ end
82
100
  end
83
101
 
84
- response = client.create_load_balancer(
85
- :load_balancer_name => name.to_s,
86
- :availability_zones => zones,
87
- :listeners => listeners)
102
+ options[:load_balancer_name] = name.to_s
88
103
 
89
- opts = {}
90
- opts[:config] = config
91
- opts[:dns_name] = response.dns_name
104
+ resp = client.create_load_balancer(options)
92
105
 
93
- LoadBalancer.new(name, opts)
106
+ LoadBalancer.new(name, :dns_name => resp[:dns_name], :config => config)
94
107
 
95
108
  end
96
109