ktheory-right_aws 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/History.txt +284 -0
  2. data/Manifest.txt +50 -0
  3. data/README.txt +167 -0
  4. data/Rakefile +110 -0
  5. data/lib/acf/right_acf_interface.rb +485 -0
  6. data/lib/acf/right_acf_origin_access_identities.rb +230 -0
  7. data/lib/acf/right_acf_streaming_interface.rb +236 -0
  8. data/lib/acw/right_acw_interface.rb +249 -0
  9. data/lib/as/right_as_interface.rb +699 -0
  10. data/lib/awsbase/benchmark_fix.rb +39 -0
  11. data/lib/awsbase/right_awsbase.rb +978 -0
  12. data/lib/awsbase/support.rb +115 -0
  13. data/lib/ec2/right_ec2.rb +395 -0
  14. data/lib/ec2/right_ec2_ebs.rb +452 -0
  15. data/lib/ec2/right_ec2_images.rb +373 -0
  16. data/lib/ec2/right_ec2_instances.rb +755 -0
  17. data/lib/ec2/right_ec2_monitoring.rb +70 -0
  18. data/lib/ec2/right_ec2_reserved_instances.rb +170 -0
  19. data/lib/ec2/right_ec2_security_groups.rb +277 -0
  20. data/lib/ec2/right_ec2_spot_instances.rb +399 -0
  21. data/lib/ec2/right_ec2_vpc.rb +571 -0
  22. data/lib/elb/right_elb_interface.rb +496 -0
  23. data/lib/rds/right_rds_interface.rb +998 -0
  24. data/lib/right_aws.rb +83 -0
  25. data/lib/s3/right_s3.rb +1126 -0
  26. data/lib/s3/right_s3_interface.rb +1199 -0
  27. data/lib/sdb/active_sdb.rb +1122 -0
  28. data/lib/sdb/right_sdb_interface.rb +721 -0
  29. data/lib/sqs/right_sqs.rb +388 -0
  30. data/lib/sqs/right_sqs_gen2.rb +343 -0
  31. data/lib/sqs/right_sqs_gen2_interface.rb +524 -0
  32. data/lib/sqs/right_sqs_interface.rb +594 -0
  33. data/test/acf/test_helper.rb +2 -0
  34. data/test/acf/test_right_acf.rb +138 -0
  35. data/test/ec2/test_helper.rb +2 -0
  36. data/test/ec2/test_right_ec2.rb +108 -0
  37. data/test/http_connection.rb +87 -0
  38. data/test/rds/test_helper.rb +2 -0
  39. data/test/rds/test_right_rds.rb +120 -0
  40. data/test/s3/test_helper.rb +2 -0
  41. data/test/s3/test_right_s3.rb +421 -0
  42. data/test/s3/test_right_s3_stubbed.rb +97 -0
  43. data/test/sdb/test_active_sdb.rb +357 -0
  44. data/test/sdb/test_helper.rb +3 -0
  45. data/test/sdb/test_right_sdb.rb +253 -0
  46. data/test/sqs/test_helper.rb +2 -0
  47. data/test/sqs/test_right_sqs.rb +291 -0
  48. data/test/sqs/test_right_sqs_gen2.rb +264 -0
  49. data/test/test_credentials.rb +37 -0
  50. data/test/ts_right_aws.rb +14 -0
  51. metadata +184 -0
@@ -0,0 +1,249 @@
1
+ #
2
+ # Copyright (c) 2007-2009 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #
23
+
24
+ module RightAws
25
+
26
+ # = RightAWS::AcwInterface -- RightScale Amazon Cloud Watch interface
27
+ # The RightAws::AcwInterface class provides a complete interface to Amazon Cloud Watch service.
28
+ #
29
+ # For explanations of the semantics of each call, please refer to Amazon's documentation at
30
+ # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/
31
+ #
32
+ class AcwInterface < RightAwsBase
33
+ include RightAwsBaseInterface
34
+
35
+ # Amazon ACW API version being used
36
+ API_VERSION = "2009-05-15"
37
+ DEFAULT_HOST = "monitoring.amazonaws.com"
38
+ DEFAULT_PATH = '/'
39
+ DEFAULT_PROTOCOL = 'https'
40
+ DEFAULT_PORT = 443
41
+
42
+ @@bench = AwsBenchmarkingBlock.new
43
+ def self.bench_xml
44
+ @@bench.xml
45
+ end
46
+ def self.bench_service
47
+ @@bench.service
48
+ end
49
+
50
+ # Create a new handle to an ACW account. All handles share the same per process or per thread
51
+ # HTTP connection to Amazon ACW. Each handle is for a specific account. The params have the
52
+ # following options:
53
+ # * <tt>:endpoint_url</tt> a fully qualified url to Amazon API endpoint (this overwrites: :server, :port, :service, :protocol). Example: 'https://monitoring.amazonaws.com/'
54
+ # * <tt>:server</tt>: ACW service host, default: DEFAULT_HOST
55
+ # * <tt>:port</tt>: ACW service port, default: DEFAULT_PORT
56
+ # * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
57
+ # * <tt>:multi_thread</tt>: true=HTTP connection per thread, false=per process
58
+ # * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
59
+ # * <tt>:signature_version</tt>: The signature version : '0','1' or '2'(default)
60
+ # * <tt>:cache</tt>: true/false(default): list_metrics
61
+ #
62
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
63
+ init({ :name => 'ACW',
64
+ :default_host => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).host : DEFAULT_HOST,
65
+ :default_port => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).port : DEFAULT_PORT,
66
+ :default_service => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).path : DEFAULT_PATH,
67
+ :default_protocol => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).scheme : DEFAULT_PROTOCOL,
68
+ :default_api_version => ENV['ACW_API_VERSION'] || API_VERSION },
69
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'] ,
70
+ aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
71
+ params)
72
+ end
73
+
74
+ def generate_request(action, params={}) #:nodoc:
75
+ generate_request_impl(:get, action, params )
76
+ end
77
+
78
+ # Sends request to Amazon and parses the response
79
+ # Raises AwsError if any banana happened
80
+ def request_info(request, parser) #:nodoc:
81
+ request_info_impl(:ams_connection, @@bench, request, parser)
82
+ end
83
+
84
+ #-----------------------------------------------------------------
85
+ # MetricStatistics
86
+ #-----------------------------------------------------------------
87
+
88
+ # Get time-series data for one or more statistics of given a Metric
89
+ # Returns a hash of stat data.
90
+ #
91
+ # Options are:
92
+ #
93
+ # :period - x*60 seconds interval (where x > 0)
94
+ # :statistics - Average, Minimum. Maximum, Sum, Samples
95
+ # :start_time - The timestamp of the first datapoint to return, inclusive.
96
+ # :end_time - The timestamp to use for determining the last datapoint to return. This is the last datapoint to fetch, exclusive.
97
+ # :namespace - The namespace corresponding to the service of interest. For example, AWS/EC2 represents Amazon EC2.
98
+ # :unit - Seconds, Percent, Bytes, Bits, Count, Bytes/Second, Bits/Second, Count/Second, and None
99
+ # :custom_unit - The user-defined CustomUnit applied to a Measure. Please see the key term Unit.
100
+ #
101
+ # :dimentions
102
+ # Dimensions for EC2 Metrics:
103
+ # * ImageId - shows the requested metric for all instances running this EC2 Amazon Machine Image(AMI)
104
+ # * AvailabilityZone - shows the requested metric for all instances running in that EC2 Availability Zone
105
+ # * CapacityGroupName - shows the requested metric for all instances in the specified capacity group - this dimension is
106
+ # only available for EC2 metrics when the instances are in an Amazon Automatic Scaling Service
107
+ # Capacity Group
108
+ # * InstanceId - shows the requested metric for only the identified instance
109
+ # * InstanceType - shows the requested metric for all instances running with that instance type
110
+ # * Service (required) - the name of the service that reported the monitoring data - for EC2 metrics, use "EC2"
111
+ # * Namespace (required) - in private beta, the available metrics are all reported by AWS services, so set this to "AWS"
112
+ # Dimensions for Load Balancing Metrics:
113
+ # * AccessPointName - shows the requested metric for the specified AccessPoint name
114
+ # * AvailabilityZone - shows the requested metric for all instances running in that EC2 Availability Zone
115
+ # * Service (required) - the name of the service that reported the monitoring data - for LoadBalancing metrics, use "LBS"
116
+ # * Namespace (required) - in private beta, the available metrics are all reported by AWS services, so set this to "AWS"
117
+ #
118
+ # :measure_name
119
+ # EC2 Metrics:
120
+ # * CPUUtilization the percentage of allocated EC2 Compute Units that are currently in use on the instance. Units are Percent.
121
+ # * NetworkIn - the number of bytes received on all network interfaces by the instance. Units are Bytes.
122
+ # * NetworkOut - the number of bytes sent out on all network interfaces by the instance. Units are Bytes.
123
+ # * DiskReadOps - completed read operations from all disks available to the instance in one minute. Units are Count/Second.
124
+ # * DiskWriteOps - completed writes operations to all disks available to the instance in one minute. Units are Count/Second.
125
+ # * DiskReadBytes - bytes read from all disks available to the instance in one minute. Units are Bytes/Second.
126
+ # * DiskWriteBytes - bytes written to all disks available to the instance in one minute. Units are Bytes/Second.
127
+ # Load Balancing Metrics:
128
+ # * Latency - time taken between a request and the corresponding response as seen by the load balancer. Units are in
129
+ # seconds, and the available statistics include minimum, maximum, average and count.
130
+ # * RequestCount - number of requests processed by the AccessPoint over the valid period. Units are count per second, and
131
+ # the available statistics include minimum, maximum and sum. A valid period can be anything equal to or
132
+ # multiple of sixty (60) seconds.
133
+ # * HealthyHostCount - number of healthy EndPoints for the valid Period. A valid period can be anything equal to or a multiple
134
+ # of sixty (60) seconds. Units are the count of EndPoints. The meaningful statistic for HealthyHostCount
135
+ # is the average for an AccessPoint within an Availability Zone. Both Load Balancing dimensions,
136
+ # AccessPointName and AvailabilityZone, should be specified when retreiving HealthyHostCount.
137
+ # * UnHealthyHostCount - number of unhealthy EndPoints for the valid Period. A valid period can be anything equal to or a multiple
138
+ # of sixty (60) seconds. Units are the count of EndPoints. The meaningful statistic for UnHealthyHostCount
139
+ # is the average for an AccessPoint within Availability Amazon Monitoring Service Developer Guide Load
140
+ # Balancing Metrics Version PRIVATE BETA 2009-01-22 19 Zone. Both Load Balancing dimensions, AccessPointName
141
+ # and AvailabilityZone, should be specified when retreiving UnHealthyHostCount.
142
+ #
143
+ def get_metric_statistics(options={})
144
+ # Period (60 sec by default)
145
+ period = (options[:period] && options[:period].to_i) || 60
146
+ # Statistics ('Average' by default)
147
+ statistics = Array(options[:statistics]).flatten
148
+ statistics = statistics.blank? ? ['Average'] : statistics.map{|statistic| statistic.to_s.capitalize }
149
+ # Times (5.min.ago up to now by default)
150
+ start_time = options[:start_time] || (Time.now.utc - 5*60)
151
+ start_time = start_time.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00") if start_time.is_a?(Time)
152
+ end_time = options[:end_time] || Time.now.utc
153
+ end_time = end_time.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00") if end_time.is_a?(Time)
154
+ # Measure name
155
+ measure_name = options[:measure_name] || 'CPUUtilization'
156
+ # Dimentions (a hash, empty by default)
157
+ dimentions = options[:dimentions] || {}
158
+ #
159
+ request_hash = { 'Period' => period,
160
+ 'StartTime' => start_time,
161
+ 'EndTime' => end_time,
162
+ 'MeasureName' => measure_name }
163
+ request_hash['Unit'] = options[:unit] if options[:unit]
164
+ request_hash['CustomUnit'] = options[:custom_unit] if options[:custom_unit]
165
+ request_hash['Namespace'] = options[:namespace] if options[:namespace]
166
+ request_hash.merge!(amazonize_list('Statistics.member', statistics))
167
+ # dimentions
168
+ dim = []
169
+ dimentions.each do |key, values|
170
+ Array(values).each { |value| dim << [key, value] }
171
+ end
172
+ request_hash.merge!(amazonize_list(['Dimensions.member.?.Name', 'Dimensions.member.?.Value'], dim))
173
+ #
174
+ link = generate_request("GetMetricStatistics", request_hash)
175
+ request_info(link, GetMetricStatisticsParser.new(:logger => @logger))
176
+ end
177
+
178
+ # This call returns a list of the valid metrics for which there is recorded data available to a you.
179
+ #
180
+ # acw.list_metrics #=>
181
+ # [ { :namespace => "AWS/ELB",
182
+ # :measure_name => "HealthyHostCount",
183
+ # :dimentions => { "LoadBalancerName"=>"test-kd1" } },
184
+ # { :namespace => "AWS/ELB",
185
+ # :measure_name => "UnHealthyHostCount",
186
+ # :dimentions => { "LoadBalancerName"=>"test-kd1" } } ]
187
+ def list_metrics
188
+ link = generate_request("ListMetrics")
189
+ request_cache_or_info :list_metrics, link, ListMetricsParser, @@bench, true
190
+ end
191
+
192
+ #-----------------------------------------------------------------
193
+ # PARSERS: MetricStatistics
194
+ #-----------------------------------------------------------------
195
+
196
+ class GetMetricStatisticsParser < RightAWSParser #:nodoc:
197
+ def tagstart(name, attributes)
198
+ @item = {} if name == 'member'
199
+ end
200
+ def tagend(name)
201
+ case name
202
+ when 'Timestamp' then @item[:timestamp] = @text
203
+ when 'Unit' then @item[:unit] = @text
204
+ when 'CustomUnit' then @item[:custom_unit] = @text
205
+ when 'Samples' then @item[:samples] = @text.to_f
206
+ when 'Average' then @item[:average] = @text.to_f
207
+ when 'Minimum' then @item[:minimum] = @text.to_f
208
+ when 'Maximum' then @item[:maximum] = @text.to_f
209
+ when 'Sum' then @item[:sum] = @text.to_f
210
+ when 'member' then @result[:datapoints] << @item
211
+ when 'Label' then @result[:label] = @text
212
+ end
213
+ end
214
+ def reset
215
+ @result = { :datapoints => [] }
216
+ end
217
+ end
218
+
219
+ class ListMetricsParser < RightAWSParser #:nodoc:
220
+ def tagstart(name, attributes)
221
+ case name
222
+ when 'member'
223
+ case @xmlpath
224
+ when @p then @item = { :dimentions => {} }
225
+ end
226
+ end
227
+ end
228
+ def tagend(name)
229
+ case name
230
+ when 'MeasureName' then @item[:measure_name] = @text
231
+ when 'Namespace' then @item[:namespace] = @text
232
+ when 'Name' then @dname = @text
233
+ when 'Value' then @dvalue = @text
234
+ when 'member'
235
+ case @xmlpath
236
+ when "#@p/member/Dimensions" then @item[:dimentions][@dname] = @dvalue
237
+ when @p then @result << @item
238
+ end
239
+ end
240
+ end
241
+ def reset
242
+ @p = 'ListMetricsResponse/ListMetricsResult/Metrics'
243
+ @result = []
244
+ end
245
+ end
246
+
247
+ end
248
+
249
+ end