aws 2.3.34 → 2.4.0
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.
- data/lib/acf/{right_acf_interface.rb → acf_interface.rb} +87 -57
- data/lib/aws.rb +9 -9
- data/lib/awsbase/aws_response_array.rb +21 -21
- data/lib/awsbase/awsbase.rb +579 -0
- data/lib/awsbase/benchmark_fix.rb +2 -2
- data/lib/awsbase/errors.rb +288 -0
- data/lib/awsbase/parsers.rb +227 -0
- data/lib/awsbase/support.rb +114 -114
- data/lib/awsbase/utils.rb +207 -0
- data/lib/ec2/ec2.rb +2070 -0
- data/lib/ec2/mon_interface.rb +243 -0
- data/lib/elb/elb_interface.rb +278 -276
- data/lib/iam/iam.rb +111 -109
- data/lib/rds/rds.rb +3 -1
- data/lib/right_aws.rb +9 -9
- data/lib/s3/bucket.rb +265 -0
- data/lib/s3/grantee.rb +238 -0
- data/lib/s3/key.rb +281 -0
- data/lib/s3/s3.rb +346 -0
- data/lib/s3/s3_interface.rb +1275 -0
- data/lib/sdb/active_sdb.rb +2 -0
- data/lib/sdb/sdb_interface.rb +886 -0
- data/lib/sqs/{right_sqs.rb → sqs.rb} +10 -0
- data/lib/sqs/sqs_interface.rb +483 -0
- data/test/s3/s3_test_base.rb +23 -0
- data/test/s3/test_s3.rb +156 -419
- data/test/s3/test_s3_class.rb +179 -0
- data/test/s3/test_s3_rights.rb +139 -0
- data/test/sqs/test_sqs.rb +19 -0
- metadata +27 -15
- data/lib/awsbase/right_awsbase.rb +0 -1254
- data/lib/ec2/right_ec2.rb +0 -1884
- data/lib/ec2/right_mon_interface.rb +0 -232
- data/lib/s3/right_s3.rb +0 -1115
- data/lib/s3/right_s3_interface.rb +0 -1253
- data/lib/sdb/right_sdb_interface.rb +0 -881
- data/lib/sqs/right_sqs_interface.rb +0 -443
@@ -0,0 +1,243 @@
|
|
1
|
+
module Aws
|
2
|
+
|
3
|
+
|
4
|
+
# This is the interface for Amazon CloudWatch.
|
5
|
+
|
6
|
+
class Mon < Aws::AwsBase
|
7
|
+
include Aws::AwsBaseInterface
|
8
|
+
|
9
|
+
|
10
|
+
#Amazon EC2 API version being used
|
11
|
+
API_VERSION = "2009-05-15"
|
12
|
+
DEFAULT_HOST = "monitoring.amazonaws.com"
|
13
|
+
DEFAULT_PATH = '/'
|
14
|
+
DEFAULT_PROTOCOL = 'https'
|
15
|
+
DEFAULT_PORT = 443
|
16
|
+
|
17
|
+
# Available measures for EC2 instances:
|
18
|
+
# NetworkIn NetworkOut DiskReadOps DiskWriteOps DiskReadBytes DiskWriteBytes CPUUtilization
|
19
|
+
measures =%w(NetworkIn NetworkOut DiskReadOps DiskWriteOps DiskReadBytes DiskWriteBytes CPUUtilization)
|
20
|
+
|
21
|
+
|
22
|
+
def self.connection_name
|
23
|
+
:mon_connection
|
24
|
+
end
|
25
|
+
|
26
|
+
@@bench = Aws::AwsBenchmarkingBlock.new
|
27
|
+
def self.bench
|
28
|
+
@@bench
|
29
|
+
end
|
30
|
+
def self.bench_xml
|
31
|
+
@@bench.xml
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.bench_ec2
|
35
|
+
@@bench.service
|
36
|
+
end
|
37
|
+
|
38
|
+
# Current API version (sometimes we have to check it outside the GEM).
|
39
|
+
@@api = ENV['EC2_API_VERSION'] || API_VERSION
|
40
|
+
|
41
|
+
def self.api
|
42
|
+
@@api
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
47
|
+
init({:name => 'MON',
|
48
|
+
:default_host => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).host : DEFAULT_HOST,
|
49
|
+
:default_port => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).port : DEFAULT_PORT,
|
50
|
+
:default_service => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).path : DEFAULT_PATH,
|
51
|
+
:default_protocol => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).scheme : DEFAULT_PROTOCOL,
|
52
|
+
:api_version => API_VERSION},
|
53
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
54
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
55
|
+
params)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def generate_request(action, params={})
|
60
|
+
service_hash = {"Action" => action,
|
61
|
+
"AWSAccessKeyId" => @aws_access_key_id,
|
62
|
+
"Version" => @@api}
|
63
|
+
service_hash.update(params)
|
64
|
+
service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service])
|
65
|
+
|
66
|
+
# use POST method if the length of the query string is too large
|
67
|
+
if service_params.size > 2000
|
68
|
+
if signature_version == '2'
|
69
|
+
# resign the request because HTTP verb is included into signature
|
70
|
+
service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service])
|
71
|
+
end
|
72
|
+
request = Net::HTTP::Post.new(service)
|
73
|
+
request.body = service_params
|
74
|
+
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
75
|
+
else
|
76
|
+
request = Net::HTTP::Get.new("#{@params[:service]}?#{service_params}")
|
77
|
+
end
|
78
|
+
|
79
|
+
#puts "\n\n --------------- QUERY REQUEST TO AWS -------------- \n\n"
|
80
|
+
#puts "#{@params[:service]}?#{service_params}\n\n"
|
81
|
+
|
82
|
+
# prepare output hash
|
83
|
+
{:request => request,
|
84
|
+
:server => @params[:server],
|
85
|
+
:port => @params[:port],
|
86
|
+
:protocol => @params[:protocol]}
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Sends request to Amazon and parses the response
|
91
|
+
# Raises AwsError if any banana happened
|
92
|
+
# todo: remove this and switch to using request_info2
|
93
|
+
def request_info(request, parser, options={})
|
94
|
+
conn = get_conn(self.class.connection_name, @params, @logger)
|
95
|
+
request_info_impl(conn, @@bench, request, parser, options)
|
96
|
+
end
|
97
|
+
|
98
|
+
#-----------------------------------------------------------------
|
99
|
+
# REQUESTS
|
100
|
+
#-----------------------------------------------------------------
|
101
|
+
|
102
|
+
def list_metrics(options={})
|
103
|
+
|
104
|
+
next_token = options[:next_token] || nil
|
105
|
+
|
106
|
+
params = {}
|
107
|
+
params['NextToken'] = next_token unless next_token.nil?
|
108
|
+
|
109
|
+
@logger.info("list Metrics ")
|
110
|
+
|
111
|
+
link = generate_request("ListMetrics", params)
|
112
|
+
resp = request_info(link, QMonListMetrics.new(:logger => @logger))
|
113
|
+
|
114
|
+
rescue Exception
|
115
|
+
on_exception
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
# measureName: CPUUtilization (Units: Percent), NetworkIn (Units: Bytes), NetworkOut (Units: Bytes), DiskWriteOps (Units: Count)
|
120
|
+
# DiskReadBytes (Units: Bytes), DiskReadOps (Units: Count), DiskWriteBytes (Units: Bytes)
|
121
|
+
# stats: array containing one or more of Minimum, Maximum, Sum, Average, Samples
|
122
|
+
# start_time : Timestamp to start
|
123
|
+
# end_time: Timestamp to end
|
124
|
+
# unit: Either Seconds, Percent, Bytes, Bits, Count, Bytes, Bits/Second, Count/Second, and None
|
125
|
+
#
|
126
|
+
# Optional parameters:
|
127
|
+
# period: Integer 60 or multiple of 60
|
128
|
+
# dimensions: Hash containing keys ImageId, AutoScalingGroupName, InstanceId, InstanceType
|
129
|
+
# customUnit: nil. not supported currently.
|
130
|
+
# namespace: AWS/EC2
|
131
|
+
|
132
|
+
def get_metric_statistics (measure_name, stats, start_time, end_time, unit, options={})
|
133
|
+
|
134
|
+
period = options[:period] || 60
|
135
|
+
dimensions = options[:dimensions] || nil
|
136
|
+
custom_unit = options[:custom_unit] || nil
|
137
|
+
namespace = options[:namespace] || "AWS/EC2"
|
138
|
+
|
139
|
+
params = {}
|
140
|
+
params['MeasureName'] = measure_name
|
141
|
+
i =1
|
142
|
+
stats.each do |s|
|
143
|
+
params['Statistics.member.'+i.to_s] = s
|
144
|
+
i = i+1
|
145
|
+
end
|
146
|
+
params['Period'] = period
|
147
|
+
if (dimensions != nil)
|
148
|
+
i = 1
|
149
|
+
dimensions.each do |k, v|
|
150
|
+
params['Dimensions.member.'+i.to_s+".Name."+i.to_s] = k
|
151
|
+
params['Dimensions.member.'+i.to_s+".Value."+i.to_s] = v
|
152
|
+
i = i+1
|
153
|
+
end
|
154
|
+
end
|
155
|
+
params['StartTime'] = start_time
|
156
|
+
params['EndTime'] = end_time
|
157
|
+
params['Unit'] = unit
|
158
|
+
#params['CustomUnit'] = customUnit always nil
|
159
|
+
params['Namespace'] = namespace
|
160
|
+
|
161
|
+
link = generate_request("GetMetricStatistics", params)
|
162
|
+
resp = request_info(link, QMonGetMetricStatistics.new(:logger => @logger))
|
163
|
+
|
164
|
+
rescue Exception
|
165
|
+
on_exception
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
#-----------------------------------------------------------------
|
170
|
+
# PARSERS: Instances
|
171
|
+
#-----------------------------------------------------------------
|
172
|
+
|
173
|
+
|
174
|
+
class QMonGetMetricStatistics < Aws::AwsParser
|
175
|
+
|
176
|
+
def reset
|
177
|
+
@result = []
|
178
|
+
end
|
179
|
+
|
180
|
+
def tagstart(name, attributes)
|
181
|
+
@metric = {} if name == 'member'
|
182
|
+
end
|
183
|
+
|
184
|
+
def tagend(name)
|
185
|
+
case name
|
186
|
+
when 'Timestamp' then
|
187
|
+
@metric[:timestamp] = @text
|
188
|
+
when 'Samples' then
|
189
|
+
@metric[:samples] = @text
|
190
|
+
when 'Unit' then
|
191
|
+
@metric[:unit] = @text
|
192
|
+
when 'Average' then
|
193
|
+
@metric[:average] = @text
|
194
|
+
when 'Minimum' then
|
195
|
+
@metric[:minimum] = @text
|
196
|
+
when 'Maximum' then
|
197
|
+
@metric[:maximum] = @text
|
198
|
+
when 'Sum' then
|
199
|
+
@metric[:sum] = @text
|
200
|
+
when 'Value' then
|
201
|
+
@metric[:value] = @text
|
202
|
+
when 'member' then
|
203
|
+
@result << @metric
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
class QMonListMetrics < Aws::AwsParser
|
209
|
+
|
210
|
+
def reset
|
211
|
+
@result = []
|
212
|
+
@namespace = ""
|
213
|
+
@measure_name = ""
|
214
|
+
end
|
215
|
+
|
216
|
+
def tagstart(name, attributes)
|
217
|
+
@metric = {} if name == 'member'
|
218
|
+
end
|
219
|
+
|
220
|
+
def tagend(name)
|
221
|
+
case name
|
222
|
+
when 'MeasureName' then
|
223
|
+
@measure_name = @text
|
224
|
+
when 'Namespace' then
|
225
|
+
@namespace = @text
|
226
|
+
when 'Name' then
|
227
|
+
@metric[:name] = @text
|
228
|
+
when 'Value' then
|
229
|
+
@metric[:value] = @text
|
230
|
+
when 'member' then
|
231
|
+
@metric[:namespace] = @namespace
|
232
|
+
@metric[:measure_name] = @measure_name
|
233
|
+
@result << @metric
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
end
|
243
|
+
|
data/lib/elb/elb_interface.rb
CHANGED
@@ -1,359 +1,361 @@
|
|
1
1
|
module Aws
|
2
2
|
|
3
|
-
|
3
|
+
require 'xmlsimple'
|
4
4
|
|
5
|
-
|
5
|
+
class Elb < AwsBase
|
6
6
|
|
7
|
-
|
7
|
+
include AwsBaseInterface
|
8
8
|
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
#Amazon ELB API version being used
|
11
|
+
API_VERSION = "2009-05-15"
|
12
|
+
DEFAULT_HOST = "elasticloadbalancing.amazonaws.com"
|
13
|
+
DEFAULT_PATH = '/'
|
14
|
+
DEFAULT_PROTOCOL = 'https'
|
15
|
+
DEFAULT_PORT = 443
|
16
16
|
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@@bench.service
|
26
|
-
end
|
27
|
-
|
28
|
-
# Current API version (sometimes we have to check it outside the GEM).
|
29
|
-
@@api = ENV['ELB_API_VERSION'] || API_VERSION
|
30
|
-
|
31
|
-
def self.api
|
32
|
-
@@api
|
33
|
-
end
|
18
|
+
@@bench = AwsBenchmarkingBlock.new
|
19
|
+
def self.bench
|
20
|
+
@@bench
|
21
|
+
end
|
22
|
+
def self.bench_xml
|
23
|
+
@@bench.xml
|
24
|
+
end
|
34
25
|
|
26
|
+
def self.bench_ec2
|
27
|
+
@@bench.service
|
28
|
+
end
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
:default_host => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).host : DEFAULT_HOST,
|
39
|
-
:default_port => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).port : DEFAULT_PORT,
|
40
|
-
:default_service => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).path : DEFAULT_PATH,
|
41
|
-
:default_protocol => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).scheme : DEFAULT_PROTOCOL,
|
42
|
-
:api_version => API_VERSION },
|
43
|
-
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
44
|
-
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
45
|
-
params)
|
46
|
-
end
|
30
|
+
# Current API version (sometimes we have to check it outside the GEM).
|
31
|
+
@@api = ENV['ELB_API_VERSION'] || API_VERSION
|
47
32
|
|
33
|
+
def self.api
|
34
|
+
@@api
|
35
|
+
end
|
48
36
|
|
49
|
-
# Sends request to Amazon and parses the response
|
50
|
-
# Raises AwsError if any banana happened
|
51
|
-
def request_info(request, parser, options={})
|
52
|
-
request_info2(request, parser, @params, :elb_connection, @logger, @@bench, options)
|
53
|
-
end
|
54
37
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
"DBSecurityGroups",
|
67
|
-
"EC2SecurityGroups",
|
68
|
-
"IPRanges"],
|
69
|
-
:pull_out_array=>options[:pull_out_array],
|
70
|
-
:pull_out_single=>options[:pull_out_single],
|
71
|
-
:wrapper=>options[:wrapper])
|
72
|
-
end
|
38
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
39
|
+
init({:name => 'ELB',
|
40
|
+
:default_host => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).host : DEFAULT_HOST,
|
41
|
+
:default_port => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).port : DEFAULT_PORT,
|
42
|
+
:default_service => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).path : DEFAULT_PATH,
|
43
|
+
:default_protocol => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).scheme : DEFAULT_PROTOCOL,
|
44
|
+
:api_version => API_VERSION},
|
45
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
46
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
47
|
+
params)
|
48
|
+
end
|
73
49
|
|
74
50
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
# name: name of load balancer
|
81
|
-
# availability_zones: array of zones
|
82
|
-
# listeners: array of hashes containing :load_balancer_port, :instance_port, :protocol
|
83
|
-
# eg: {:load_balancer_port=>80, :instance_port=>8080, :protocol=>"HTTP"}
|
84
|
-
def create_load_balancer(name, availability_zones, listeners)
|
85
|
-
params = hash_params('AvailabilityZones.member', availability_zones)
|
86
|
-
i = 1
|
87
|
-
listeners.each do |l|
|
88
|
-
params["Listeners.member.#{i}.Protocol"] = "#{l[:protocol]}"
|
89
|
-
params["Listeners.member.#{i}.LoadBalancerPort"] = "#{l[:load_balancer_port]}"
|
90
|
-
params["Listeners.member.#{i}.InstancePort"] = "#{l[:instance_port]}"
|
91
|
-
i += 1
|
92
|
-
end
|
93
|
-
params['LoadBalancerName'] = name
|
51
|
+
# Sends request to Amazon and parses the response
|
52
|
+
# Raises AwsError if any banana happened
|
53
|
+
def request_info(request, parser, options={})
|
54
|
+
request_info2(request, parser, @params, :elb_connection, @logger, @@bench, options)
|
55
|
+
end
|
94
56
|
|
95
|
-
|
57
|
+
# todo: convert to xml-simple version and get rid of parser below
|
58
|
+
def do_request(action, params, options={})
|
59
|
+
link = generate_request(action, params)
|
60
|
+
resp = request_info_xml_simple(:rds_connection, @params, link, @logger,
|
61
|
+
:group_tags =>{"LoadBalancersDescriptions"=>"LoadBalancersDescription",
|
62
|
+
"DBParameterGroups" =>"DBParameterGroup",
|
63
|
+
"DBSecurityGroups" =>"DBSecurityGroup",
|
64
|
+
"EC2SecurityGroups" =>"EC2SecurityGroup",
|
65
|
+
"IPRanges" =>"IPRange"},
|
66
|
+
:force_array =>["DBInstances",
|
67
|
+
"DBParameterGroups",
|
68
|
+
"DBSecurityGroups",
|
69
|
+
"EC2SecurityGroups",
|
70
|
+
"IPRanges"],
|
71
|
+
:pull_out_array =>options[:pull_out_array],
|
72
|
+
:pull_out_single=>options[:pull_out_single],
|
73
|
+
:wrapper =>options[:wrapper])
|
74
|
+
end
|
96
75
|
|
97
|
-
link = generate_request("CreateLoadBalancer", params)
|
98
|
-
resp = request_info(link, QElbCreateParser.new(:logger => @logger))
|
99
76
|
|
100
|
-
|
101
|
-
|
102
|
-
|
77
|
+
#-----------------------------------------------------------------
|
78
|
+
# REQUESTS
|
79
|
+
#-----------------------------------------------------------------
|
80
|
+
|
81
|
+
#
|
82
|
+
# name: name of load balancer
|
83
|
+
# availability_zones: array of zones
|
84
|
+
# listeners: array of hashes containing :load_balancer_port, :instance_port, :protocol
|
85
|
+
# eg: {:load_balancer_port=>80, :instance_port=>8080, :protocol=>"HTTP"}
|
86
|
+
def create_load_balancer(name, availability_zones, listeners)
|
87
|
+
params = hash_params('AvailabilityZones.member', availability_zones)
|
88
|
+
i = 1
|
89
|
+
listeners.each do |l|
|
90
|
+
params["Listeners.member.#{i}.Protocol"] = "#{l[:protocol]}"
|
91
|
+
params["Listeners.member.#{i}.LoadBalancerPort"] = "#{l[:load_balancer_port]}"
|
92
|
+
params["Listeners.member.#{i}.InstancePort"] = "#{l[:instance_port]}"
|
93
|
+
i += 1
|
94
|
+
end
|
95
|
+
params['LoadBalancerName'] = name
|
96
|
+
|
97
|
+
@logger.info("Creating LoadBalancer called #{params['LoadBalancerName']}")
|
98
|
+
|
99
|
+
link = generate_request("CreateLoadBalancer", params)
|
100
|
+
resp = request_info(link, QElbCreateParser.new(:logger => @logger))
|
101
|
+
|
102
|
+
rescue Exception
|
103
|
+
on_exception
|
104
|
+
end
|
103
105
|
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
# name: name of load balancer
|
108
|
+
# instance_ids: array of instance_id's to add to load balancer
|
109
|
+
def register_instances_with_load_balancer(name, instance_ids)
|
110
|
+
params = {}
|
111
|
+
params['LoadBalancerName'] = name
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
i = 1
|
114
|
+
instance_ids.each do |l|
|
115
|
+
params["Instances.member.#{i}.InstanceId"] = "#{l}"
|
116
|
+
i += 1
|
117
|
+
end
|
116
118
|
|
117
|
-
|
119
|
+
@logger.info("Registering Instances #{instance_ids.join(',')} with Load Balancer '#{name}'")
|
118
120
|
|
119
|
-
|
120
|
-
|
121
|
+
link = generate_request("RegisterInstancesWithLoadBalancer", params)
|
122
|
+
resp = request_info(link, QElbRegisterInstancesParser.new(:logger => @logger))
|
121
123
|
|
122
|
-
|
123
|
-
|
124
|
-
|
124
|
+
rescue Exception
|
125
|
+
on_exception
|
126
|
+
end
|
125
127
|
|
126
|
-
|
127
|
-
|
128
|
-
|
128
|
+
def deregister_instances_from_load_balancer(name, instance_ids)
|
129
|
+
params = {}
|
130
|
+
params['LoadBalancerName'] = name
|
129
131
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
i = 1
|
133
|
+
instance_ids.each do |l|
|
134
|
+
params["Instances.member.#{i}.InstanceId"] = "#{l}"
|
135
|
+
i += 1
|
136
|
+
end
|
135
137
|
|
136
|
-
|
138
|
+
@logger.info("Deregistering Instances #{instance_ids.join(',')} from Load Balancer '#{name}'")
|
137
139
|
|
138
|
-
|
139
|
-
|
140
|
+
link = generate_request("DeregisterInstancesFromLoadBalancer", params) # Same response as register I believe
|
141
|
+
resp = request_info(link, QElbRegisterInstancesParser.new(:logger => @logger))
|
140
142
|
|
141
|
-
|
142
|
-
|
143
|
-
|
143
|
+
rescue Exception
|
144
|
+
on_exception
|
145
|
+
end
|
144
146
|
|
145
147
|
|
146
|
-
|
147
|
-
|
148
|
+
def describe_load_balancers(lparams={})
|
149
|
+
@logger.info("Describing Load Balancers")
|
148
150
|
|
149
|
-
|
150
|
-
|
151
|
+
params = {}
|
152
|
+
params.update(hash_params('LoadBalancerNames.member', lparams[:names])) if lparams[:names]
|
151
153
|
|
152
|
-
|
154
|
+
link = generate_request("DescribeLoadBalancers", params)
|
153
155
|
|
154
|
-
|
156
|
+
resp = request_info(link, QElbDescribeLoadBalancersParser.new(:logger => @logger))
|
155
157
|
|
156
|
-
|
157
|
-
|
158
|
-
|
158
|
+
rescue Exception
|
159
|
+
on_exception
|
160
|
+
end
|
159
161
|
|
160
162
|
|
161
|
-
|
162
|
-
|
163
|
+
def describe_instance_health(name, instance_ids=[])
|
164
|
+
instance_ids = [instance_ids] if instance_ids.is_a?(String)
|
163
165
|
# @logger.info("Describing Instance Health")
|
164
|
-
|
165
|
-
|
166
|
+
params = {}
|
167
|
+
params['LoadBalancerName'] = name
|
166
168
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
169
|
+
i = 1
|
170
|
+
instance_ids.each do |l|
|
171
|
+
params["Instances.member.#{i}.InstanceId"] = "#{l}"
|
172
|
+
i += 1
|
173
|
+
end
|
172
174
|
|
173
|
-
|
175
|
+
@logger.info("Describing Instances Health #{instance_ids.join(',')} with Load Balancer '#{name}'")
|
174
176
|
|
175
|
-
|
176
|
-
|
177
|
+
link = generate_request("DescribeInstanceHealth", params)
|
178
|
+
resp = request_info(link, QElbDescribeInstancesHealthParser.new(:logger => @logger))
|
177
179
|
|
178
180
|
|
179
|
-
|
180
|
-
|
181
|
-
|
181
|
+
rescue Exception
|
182
|
+
on_exception
|
183
|
+
end
|
182
184
|
|
183
185
|
|
184
|
-
|
185
|
-
|
186
|
+
def delete_load_balancer(name)
|
187
|
+
@logger.info("Deleting Load Balancer - " + name.to_s)
|
186
188
|
|
187
|
-
|
188
|
-
|
189
|
+
params = {}
|
190
|
+
params['LoadBalancerName'] = name
|
189
191
|
|
190
|
-
|
192
|
+
link = generate_request("DeleteLoadBalancer", params)
|
191
193
|
|
192
|
-
|
194
|
+
resp = request_info(link, QElbDeleteParser.new(:logger => @logger))
|
193
195
|
|
194
|
-
|
195
|
-
|
196
|
-
|
196
|
+
rescue Exception
|
197
|
+
on_exception
|
198
|
+
end
|
197
199
|
|
198
200
|
|
199
|
-
|
200
|
-
|
201
|
-
|
201
|
+
#-----------------------------------------------------------------
|
202
|
+
# PARSERS: Instances
|
203
|
+
#-----------------------------------------------------------------
|
202
204
|
|
203
205
|
|
204
|
-
|
206
|
+
class QElbCreateParser < AwsParser
|
205
207
|
|
206
|
-
|
207
|
-
|
208
|
-
|
208
|
+
def reset
|
209
|
+
@result = {}
|
210
|
+
end
|
209
211
|
|
210
212
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
end
|
216
|
-
end
|
213
|
+
def tagend(name)
|
214
|
+
case name
|
215
|
+
when 'DNSName' then
|
216
|
+
@result[:dns_name] = @text
|
217
217
|
end
|
218
|
+
end
|
219
|
+
end
|
218
220
|
|
219
|
-
|
221
|
+
class QElbDescribeLoadBalancersParser < AwsParser
|
220
222
|
|
221
|
-
|
222
|
-
|
223
|
-
|
223
|
+
def reset
|
224
|
+
@result = []
|
225
|
+
end
|
224
226
|
|
225
|
-
|
227
|
+
def tagstart(name, attributes)
|
226
228
|
# puts 'tagstart ' + name + ' -- ' + @xmlpath
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
229
|
+
if (name == 'member' && @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/member/Listeners')
|
230
|
+
@listener = {}
|
231
|
+
end
|
232
|
+
if (name == 'member' && @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/member/AvailabilityZones')
|
233
|
+
@availability_zone = {}
|
234
|
+
end
|
235
|
+
if (name == 'member' && @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/member/Instances')
|
236
|
+
@instance = {}
|
237
|
+
end
|
238
|
+
if (name == 'member' && @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions')
|
239
|
+
@member = {:listeners=>[], :availability_zones=>[], :health_check=>{}, :instances=>[]}
|
240
|
+
end
|
239
241
|
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
def tagend(name)
|
246
|
+
case name
|
247
|
+
when 'LoadBalancerName' then
|
248
|
+
@member[:load_balancer_name] = @text
|
249
|
+
@member[:name] = @text
|
250
|
+
when 'CreatedTime' then
|
251
|
+
@member[:created_time] = Time.parse(@text)
|
252
|
+
@member[:created] = @member[:created_time]
|
253
|
+
when 'DNSName' then
|
254
|
+
@member[:dns_name] = @text
|
255
|
+
# Instances
|
256
|
+
when 'InstanceId' then
|
257
|
+
@instance[:instance_id] = @text
|
258
|
+
# Listeners
|
259
|
+
when 'Protocol' then
|
260
|
+
@listener[:protocol] = @text
|
261
|
+
when 'LoadBalancerPort' then
|
262
|
+
@listener[:load_balancer_port] = @text.to_i
|
263
|
+
when 'InstancePort' then
|
264
|
+
@listener[:instance_port] = @text.to_i
|
265
|
+
# HEALTH CHECK STUFF
|
266
|
+
when 'Interval' then
|
267
|
+
@member[:health_check][:interval] = @text.to_i
|
268
|
+
when 'Target' then
|
269
|
+
@member[:health_check][:target] = @text
|
270
|
+
when 'HealthyThreshold' then
|
271
|
+
@member[:health_check][:healthy_threshold] = @text.to_i
|
272
|
+
when 'Timeout' then
|
273
|
+
@member[:health_check][:timeout] = @text.to_i
|
274
|
+
when 'UnhealthyThreshold' then
|
275
|
+
@member[:health_check][:unhealthy_threshold] = @text.to_i
|
276
|
+
# AvailabilityZones
|
277
|
+
when 'member' then
|
278
|
+
if @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/member/Listeners'
|
279
|
+
@member[:listeners] << @listener
|
280
|
+
elsif @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/member/AvailabilityZones'
|
281
|
+
@availability_zone = @text
|
282
|
+
@member[:availability_zones] << @availability_zone
|
283
|
+
elsif @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/member/Instances'
|
284
|
+
@member[:instances] << @instance
|
285
|
+
elsif @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions'
|
286
|
+
@result << @member
|
240
287
|
end
|
241
288
|
|
242
|
-
|
243
|
-
def tagend(name)
|
244
|
-
case name
|
245
|
-
when 'LoadBalancerName' then
|
246
|
-
@member[:load_balancer_name] = @text
|
247
|
-
@member[:name] = @text
|
248
|
-
when 'CreatedTime' then
|
249
|
-
@member[:created_time] = Time.parse(@text)
|
250
|
-
@member[:created] = @member[:created_time]
|
251
|
-
when 'DNSName' then
|
252
|
-
@member[:dns_name] = @text
|
253
|
-
# Instances
|
254
|
-
when 'InstanceId' then
|
255
|
-
@instance[:instance_id] = @text
|
256
|
-
# Listeners
|
257
|
-
when 'Protocol' then
|
258
|
-
@listener[:protocol] = @text
|
259
|
-
when 'LoadBalancerPort' then
|
260
|
-
@listener[:load_balancer_port] = @text.to_i
|
261
|
-
when 'InstancePort' then
|
262
|
-
@listener[:instance_port] = @text.to_i
|
263
|
-
# HEALTH CHECK STUFF
|
264
|
-
when 'Interval' then
|
265
|
-
@member[:health_check][:interval] = @text.to_i
|
266
|
-
when 'Target' then
|
267
|
-
@member[:health_check][:target] = @text
|
268
|
-
when 'HealthyThreshold' then
|
269
|
-
@member[:health_check][:healthy_threshold] = @text.to_i
|
270
|
-
when 'Timeout' then
|
271
|
-
@member[:health_check][:timeout] = @text.to_i
|
272
|
-
when 'UnhealthyThreshold' then
|
273
|
-
@member[:health_check][:unhealthy_threshold] = @text.to_i
|
274
|
-
# AvailabilityZones
|
275
|
-
when 'member' then
|
276
|
-
if @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/member/Listeners'
|
277
|
-
@member[:listeners] << @listener
|
278
|
-
elsif @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/member/AvailabilityZones'
|
279
|
-
@availability_zone = @text
|
280
|
-
@member[:availability_zones] << @availability_zone
|
281
|
-
elsif @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/member/Instances'
|
282
|
-
@member[:instances] << @instance
|
283
|
-
elsif @xmlpath == 'DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions'
|
284
|
-
@result << @member
|
285
|
-
end
|
286
|
-
|
287
|
-
end
|
288
|
-
end
|
289
289
|
end
|
290
|
+
end
|
291
|
+
end
|
290
292
|
|
291
|
-
|
293
|
+
class QElbRegisterInstancesParser < AwsParser
|
292
294
|
|
293
|
-
|
294
|
-
|
295
|
-
|
295
|
+
def reset
|
296
|
+
@result = []
|
297
|
+
end
|
296
298
|
|
297
|
-
|
299
|
+
def tagstart(name, attributes)
|
298
300
|
# puts 'tagstart ' + name + ' -- ' + @xmlpath
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
301
|
+
if (name == 'member' &&
|
302
|
+
(@xmlpath == 'RegisterInstancesWithLoadBalancerResponse/RegisterInstancesWithLoadBalancerResult/Instances' ||
|
303
|
+
@xmlpath == 'DeregisterInstancesFromLoadBalancerResponse/DeregisterInstancesFromLoadBalancerResult/Instances')
|
304
|
+
)
|
305
|
+
@member = {}
|
306
|
+
end
|
305
307
|
|
306
|
-
|
308
|
+
end
|
307
309
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
end
|
315
|
-
end
|
316
|
-
#
|
310
|
+
def tagend(name)
|
311
|
+
case name
|
312
|
+
when 'InstanceId' then
|
313
|
+
@member[:instance_id] = @text
|
314
|
+
when 'member' then
|
315
|
+
@result << @member
|
317
316
|
end
|
317
|
+
end
|
318
|
+
#
|
319
|
+
end
|
318
320
|
|
319
|
-
|
321
|
+
class QElbDescribeInstancesHealthParser < AwsParser
|
320
322
|
|
321
|
-
|
322
|
-
|
323
|
-
|
323
|
+
def reset
|
324
|
+
@result = []
|
325
|
+
end
|
324
326
|
|
325
|
-
|
327
|
+
def tagstart(name, attributes)
|
326
328
|
# puts 'tagstart ' + name + ' -- ' + @xmlpath
|
327
|
-
|
328
|
-
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
def tagend(name)
|
333
|
-
case name
|
334
|
-
when 'Description' then
|
335
|
-
@member[:description] = @text
|
336
|
-
when 'State' then
|
337
|
-
@member[:state] = @text
|
338
|
-
when 'InstanceId' then
|
339
|
-
@member[:instance_id] = @text
|
340
|
-
when 'ReasonCode' then
|
341
|
-
@member[:reason_code] = @text
|
342
|
-
when 'member' then
|
343
|
-
@result << @member
|
344
|
-
end
|
345
|
-
end
|
346
|
-
#
|
329
|
+
if (name == 'member' && @xmlpath == 'DescribeInstanceHealthResponse/DescribeInstanceHealthResult/InstanceStates')
|
330
|
+
@member = {}
|
347
331
|
end
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
332
|
+
end
|
333
|
+
|
334
|
+
def tagend(name)
|
335
|
+
case name
|
336
|
+
when 'Description' then
|
337
|
+
@member[:description] = @text
|
338
|
+
when 'State' then
|
339
|
+
@member[:state] = @text
|
340
|
+
when 'InstanceId' then
|
341
|
+
@member[:instance_id] = @text
|
342
|
+
when 'ReasonCode' then
|
343
|
+
@member[:reason_code] = @text
|
344
|
+
when 'member' then
|
345
|
+
@result << @member
|
353
346
|
end
|
347
|
+
end
|
348
|
+
#
|
349
|
+
end
|
354
350
|
|
355
|
-
|
351
|
+
class QElbDeleteParser < AwsParser
|
352
|
+
def reset
|
353
|
+
@result = true
|
354
|
+
end
|
356
355
|
end
|
357
356
|
|
358
357
|
|
358
|
+
end
|
359
|
+
|
360
|
+
|
359
361
|
end
|