aws 1.11.9 → 1.11.36

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,8 +71,8 @@ module RightAws
71
71
  API_VERSION = "2008-12-01"
72
72
  DEFAULT_HOST = "ec2.amazonaws.com"
73
73
  DEFAULT_PATH = '/'
74
- DEFAULT_PROTOCOL = 'https'
75
- DEFAULT_PORT = 443
74
+ DEFAULT_PROTOCOL = 'http'
75
+ DEFAULT_PORT = 80
76
76
 
77
77
  # Default addressing type (public=NAT, direct=no-NAT) used when launching instances.
78
78
  DEFAULT_ADDRESSING_TYPE = 'public'
@@ -0,0 +1,224 @@
1
+ module RightAws
2
+
3
+ class Mon < RightAws::RightAwsBase
4
+ include RightAws::RightAwsBaseInterface
5
+
6
+
7
+ #Amazon EC2 API version being used
8
+ API_VERSION = "2009-05-15"
9
+ DEFAULT_HOST = "monitoring.amazonaws.com"
10
+ DEFAULT_PATH = '/'
11
+ DEFAULT_PROTOCOL = 'https'
12
+ DEFAULT_PORT = 443
13
+
14
+ # Available measures for EC2 instances:
15
+ # NetworkIn NetworkOut DiskReadOps DiskWriteOps DiskReadBytes DiskWriteBytes CPUUtilization
16
+ measures=%w(NetworkIn NetworkOut DiskReadOps DiskWriteOps DiskReadBytes DiskWriteBytes CPUUtilization)
17
+
18
+ @@bench = RightAws::AwsBenchmarkingBlock.new
19
+
20
+ def self.bench_xml
21
+ @@bench.xml
22
+ end
23
+
24
+ def self.bench_ec2
25
+ @@bench.service
26
+ end
27
+
28
+ # Current API version (sometimes we have to check it outside the GEM).
29
+ @@api = ENV['EC2_API_VERSION'] || API_VERSION
30
+
31
+ def self.api
32
+ @@api
33
+ end
34
+
35
+
36
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
37
+ init({ :name => 'MON',
38
+ :default_host => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).host : DEFAULT_HOST,
39
+ :default_port => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).port : DEFAULT_PORT,
40
+ :default_service => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).path : DEFAULT_PATH,
41
+ :default_protocol => ENV['MON_URL'] ? URI.parse(ENV['MON_URL']).scheme : DEFAULT_PROTOCOL },
42
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
43
+ aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
44
+ params)
45
+ end
46
+
47
+
48
+ def generate_request(action, params={})
49
+ service_hash = {"Action" => action,
50
+ "AWSAccessKeyId" => @aws_access_key_id,
51
+ "Version" => @@api }
52
+ service_hash.update(params)
53
+ service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service])
54
+
55
+ # use POST method if the length of the query string is too large
56
+ if service_params.size > 2000
57
+ if signature_version == '2'
58
+ # resign the request because HTTP verb is included into signature
59
+ service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service])
60
+ end
61
+ request = Net::HTTP::Post.new(service)
62
+ request.body = service_params
63
+ request['Content-Type'] = 'application/x-www-form-urlencoded'
64
+ else
65
+ request = Net::HTTP::Get.new("#{@params[:service]}?#{service_params}")
66
+ end
67
+
68
+ #puts "\n\n --------------- QUERY REQUEST TO AWS -------------- \n\n"
69
+ #puts "#{@params[:service]}?#{service_params}\n\n"
70
+
71
+ # prepare output hash
72
+ { :request => request,
73
+ :server => @params[:server],
74
+ :port => @params[:port],
75
+ :protocol => @params[:protocol] }
76
+ end
77
+
78
+
79
+ # Sends request to Amazon and parses the response
80
+ # Raises AwsError if any banana happened
81
+ def request_info(request, parser)
82
+ thread = @params[:multi_thread] ? Thread.current : Thread.main
83
+ thread[:elb_connection] ||= Rightscale::HttpConnection.new(:exception => RightAws::AwsError, :logger => @logger)
84
+ request_info_impl(thread[:elb_connection], @@bench, request, parser)
85
+ end
86
+
87
+ #-----------------------------------------------------------------
88
+ # REQUESTS
89
+ #-----------------------------------------------------------------
90
+
91
+ def list_metrics
92
+
93
+ params = { }
94
+
95
+ @logger.info("list Metrics ")
96
+
97
+ link = generate_request("ListMetrics", params)
98
+ resp = request_info(link, QMonListMetrics.new(:logger => @logger))
99
+
100
+ rescue Exception
101
+ on_exception
102
+ end
103
+
104
+
105
+ # measureName: CPUUtilization (Units: Percent), NetworkIn (Units: Bytes), NetworkOut (Units: Bytes), DiskWriteOps (Units: Count)
106
+ # DiskReadBytes (Units: Bytes), DiskReadOps (Units: Count), DiskWriteBytes (Units: Bytes)
107
+ # stats: array containing one or more of Minimum, Maximum, Sum, Average, Samples
108
+ # startTime : Timestamp to start
109
+ # endtime: Timestamp to end
110
+ # unit: Either Seconds, Percent, Bytes, Bits, Count, Bytes, Bits/Second, Count/Second, and None
111
+ # period: Integer 60 or multiple of 60
112
+ # dimension: Hash containing keys ImageId, AutoScalingGroupName, InstanceId, InstanceType
113
+ # customUnit: nil. not supported currently.
114
+ # namespace: AWS/EC2
115
+
116
+ def get_metric_statistics ( measure_name, stats, start_time, end_time, unit, period=60, dimensions=nil, custom_unit=nil, namespace="AWS/EC2" )
117
+
118
+ params = {}
119
+ params['MeasureName'] = measure_name
120
+ i=1
121
+ stats.each do |s|
122
+ params['Statistics.member.'+i.to_s] = s
123
+ i = i+1
124
+ end
125
+ params['Period'] = period
126
+ if (dimensions != nil)
127
+ i = 1
128
+ dimensions.each do |k, v|
129
+ params['Dimensions.member.'+i.to_s+".Name."+i.to_s] = k
130
+ params['Dimensions.member.'+i.to_s+".Value."+i.to_s] = v
131
+ i = i+1
132
+ end
133
+ end
134
+ params['StartTime'] = start_time
135
+ params['EndTime'] = end_time
136
+ params['Unit'] = unit
137
+ #params['CustomUnit'] = customUnit always nil
138
+ params['Namespace'] = namespace
139
+
140
+ @logger.info("get Metric Statistics ")
141
+
142
+ link = generate_request("GetMetricStatistics", params)
143
+ resp = request_info(link, QMonGetMetricStatistics.new(:logger => @logger))
144
+
145
+ rescue Exception
146
+ on_exception
147
+ end
148
+
149
+
150
+ #-----------------------------------------------------------------
151
+ # PARSERS: Instances
152
+ #-----------------------------------------------------------------
153
+
154
+
155
+ class QMonGetMetricStatistics < RightAws::RightAWSParser
156
+
157
+ def reset
158
+ @result = []
159
+ end
160
+
161
+ def tagstart(name, attributes)
162
+ @metric = {} if name == 'member'
163
+ end
164
+
165
+ def tagend(name)
166
+ case name
167
+ when 'Timestamp' then
168
+ @metric[:timestamp] = @text
169
+ when 'Samples' then
170
+ @metric[:samples] = @text
171
+ when 'Unit' then
172
+ @metric[:unit] = @text
173
+ when 'Average' then
174
+ @metric[:average] = @text
175
+ when 'Minimum' then
176
+ @metric[:minimum] = @text
177
+ when 'Maximum' then
178
+ @metric[:maximum] = @text
179
+ when 'Sum' then
180
+ @metric[:sum] = @text
181
+ when 'Value' then
182
+ @metric[:value] = @text
183
+ when 'member' then
184
+ @result << @metric
185
+ end
186
+ end
187
+ end
188
+
189
+ class QMonListMetrics < RightAws::RightAWSParser
190
+
191
+ def reset
192
+ @result = []
193
+ @namespace = ""
194
+ @measure_name = ""
195
+ end
196
+
197
+ def tagstart(name, attributes)
198
+ @metric = {} if name == 'member'
199
+ end
200
+
201
+ def tagend(name)
202
+ case name
203
+ when 'MeasureName' then
204
+ @measure_name = @text
205
+ when 'Namespace' then
206
+ @namespace = @text
207
+ when 'Name' then
208
+ @metric[:name] = @text
209
+ when 'Value' then
210
+ @metric[:value] = @text
211
+ when 'member' then
212
+ @metric[:namespace] = @namespace
213
+ @metric[:measure_name] = @measure_name
214
+ @result << @metric
215
+ end
216
+ end
217
+ end
218
+
219
+
220
+ end
221
+
222
+
223
+ end
224
+
@@ -0,0 +1,189 @@
1
+ module RightAws
2
+
3
+
4
+
5
+ class Elb < RightAwsBase
6
+ include RightAwsBaseInterface
7
+
8
+
9
+ #Amazon EC2 API version being used
10
+ API_VERSION = "2008-12-01"
11
+ DEFAULT_HOST = "elasticloadbalancing.amazonaws.com"
12
+ DEFAULT_PATH = '/'
13
+ DEFAULT_PROTOCOL = 'http'
14
+ DEFAULT_PORT = 80
15
+
16
+
17
+ @@bench = AwsBenchmarkingBlock.new
18
+ def self.bench_xml
19
+ @@bench.xml
20
+ end
21
+ def self.bench_ec2
22
+ @@bench.service
23
+ end
24
+
25
+ # Current API version (sometimes we have to check it outside the GEM).
26
+ @@api = ENV['EC2_API_VERSION'] || API_VERSION
27
+ def self.api
28
+ @@api
29
+ end
30
+
31
+
32
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
33
+ init({ :name => 'ELB',
34
+ :default_host => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).host : DEFAULT_HOST,
35
+ :default_port => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).port : DEFAULT_PORT,
36
+ :default_service => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).path : DEFAULT_PATH,
37
+ :default_protocol => ENV['ELB_URL'] ? URI.parse(ENV['ELB_URL']).scheme : DEFAULT_PROTOCOL },
38
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
39
+ aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
40
+ params)
41
+ end
42
+
43
+
44
+ def generate_request(action, params={})
45
+ service_hash = {"Action" => action,
46
+ "AWSAccessKeyId" => @aws_access_key_id,
47
+ "Version" => @@api }
48
+ service_hash.update(params)
49
+ service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service])
50
+
51
+ # use POST method if the length of the query string is too large
52
+ if service_params.size > 2000
53
+ if signature_version == '2'
54
+ # resign the request because HTTP verb is included into signature
55
+ service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service])
56
+ end
57
+ request = Net::HTTP::Post.new(service)
58
+ request.body = service_params
59
+ request['Content-Type'] = 'application/x-www-form-urlencoded'
60
+ else
61
+ request = Net::HTTP::Get.new("#{@params[:service]}?#{service_params}")
62
+ end
63
+
64
+ #puts "\n\n --------------- QUERY REQUEST TO AWS -------------- \n\n"
65
+ #puts "#{@params[:service]}?#{service_params}\n\n"
66
+
67
+ # prepare output hash
68
+ { :request => request,
69
+ :server => @params[:server],
70
+ :port => @params[:port],
71
+ :protocol => @params[:protocol] }
72
+ end
73
+
74
+
75
+ # Sends request to Amazon and parses the response
76
+ # Raises AwsError if any banana happened
77
+ def request_info(request, parser)
78
+ thread = @params[:multi_thread] ? Thread.current : Thread.main
79
+ thread[:elb_connection] ||= Rightscale::HttpConnection.new(:exception => RightAws::AwsError, :logger => @logger)
80
+ request_info_impl(thread[:elb_connection], @@bench, request, parser)
81
+ end
82
+
83
+
84
+ #-----------------------------------------------------------------
85
+ # REQUESTS
86
+ #-----------------------------------------------------------------
87
+
88
+
89
+ def register_instance_with_elb(instance_id, lparams={})
90
+ params = {}
91
+
92
+ params['LoadBalancerName'] = lparams[:load_balancer_name]
93
+ params['Instances.member.1.InstanceId'] = instance_id
94
+
95
+ @logger.info("Registering Instance #{instance_id} with Load Balancer '#{params['LoadBalancerName']}'")
96
+
97
+ link = generate_request("RegisterInstancesWithLoadBalancer", params)
98
+ resp = request_info(link, QElbRegisterInstanceParser.new(:logger => @logger))
99
+
100
+ rescue Exception
101
+ on_exception
102
+ end
103
+
104
+
105
+
106
+
107
+
108
+
109
+ def describe_load_balancers
110
+ @logger.info("Describing Load Balancers")
111
+
112
+ params = {}
113
+
114
+ link = generate_request("DescribeLoadBalancers", params)
115
+
116
+ resp = request_info(link, QElbDescribeLoadBalancersParser.new(:logger => @logger))
117
+
118
+ rescue Exception
119
+ on_exception
120
+ end
121
+
122
+
123
+
124
+
125
+ #-----------------------------------------------------------------
126
+ # PARSERS: Instances
127
+ #-----------------------------------------------------------------
128
+
129
+ class QElbDescribeLoadBalancersParser < RightAWSParser
130
+
131
+ def reset
132
+ @result = []
133
+ end
134
+
135
+
136
+ def tagend(name)
137
+ #case name
138
+ # when 'LoadBalancerName' then
139
+ # @result[:load_balancer_name] = @text
140
+ # when 'AvailabilityZones' then
141
+ # @result[:availability_zones] = @text
142
+ # when 'CreatedTime' then
143
+ # @result[:created_time] = Time.parse(@text)
144
+ # when 'DNSName' then
145
+ # @result[:dns_name] = @text
146
+ # when 'Instances' then
147
+ # @result[:instances] = @text
148
+ # when 'HealthCheck' then
149
+ # @result[:health_check] = @text
150
+ # when 'Listeners' then
151
+ # @result[:listeners] = @text
152
+ #end
153
+ end
154
+ end
155
+
156
+ class QElbRegisterInstanceParser < RightAWSParser
157
+
158
+ def reset
159
+ @result = []
160
+ end
161
+
162
+
163
+ def tagend(name)
164
+ #case name
165
+ # when 'LoadBalancerName' then
166
+ # @result[:load_balancer_name] = @text
167
+ # when 'AvailabilityZones' then
168
+ # @result[:availability_zones] = @text
169
+ # when 'CreatedTime' then
170
+ # @result[:created_time] = Time.parse(@text)
171
+ # when 'DNSName' then
172
+ # @result[:dns_name] = @text
173
+ # when 'Instances' then
174
+ # @result[:instances] = @text
175
+ # when 'HealthCheck' then
176
+ # @result[:health_check] = @text
177
+ # when 'Listeners' then
178
+ # @result[:listeners] = @text
179
+ #end
180
+ end
181
+ end
182
+
183
+
184
+
185
+
186
+ end
187
+
188
+
189
+ end
@@ -43,17 +43,16 @@ require 's3/right_s3_interface'
43
43
  require 's3/right_s3'
44
44
  require 'sqs/right_sqs_interface'
45
45
  require 'sqs/right_sqs'
46
- require 'sqs/right_sqs_gen2_interface'
47
- require 'sqs/right_sqs_gen2'
48
46
  require 'sdb/right_sdb_interface'
49
47
  require 'acf/right_acf_interface'
48
+ require 'elb/right_elb_interface'
50
49
 
51
50
 
52
51
  module RightAws #:nodoc:
53
52
  module VERSION #:nodoc:
54
53
  MAJOR = 1
55
54
  MINOR = 11
56
- TINY = 9
55
+ TINY = 30
57
56
 
58
57
  STRING = [MAJOR, MINOR, TINY].join('.')
59
58
  end
@@ -464,8 +464,8 @@ module RightAws
464
464
  # Retrieve object data and attributes from Amazon.
465
465
  # Returns a +String+.
466
466
  #
467
- def get(headers={})
468
- response = @bucket.s3.interface.get(@bucket.name, @name, headers)
467
+ def get(headers={}, &block)
468
+ response = @bucket.s3.interface.get(@bucket.name, @name, headers, &block)
469
469
  @data = response[:object]
470
470
  @headers, @meta_headers = self.class.split_meta(response[:headers])
471
471
  refresh(false)