talaris-right_aws 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/History.txt +305 -0
  2. data/Manifest.txt +60 -0
  3. data/README.txt +163 -0
  4. data/Rakefile +104 -0
  5. data/lib/acf/right_acf_interface.rb +549 -0
  6. data/lib/acf/right_acf_invalidations.rb +144 -0
  7. data/lib/acf/right_acf_origin_access_identities.rb +230 -0
  8. data/lib/acf/right_acf_streaming_interface.rb +229 -0
  9. data/lib/acw/right_acw_interface.rb +248 -0
  10. data/lib/as/right_as_interface.rb +698 -0
  11. data/lib/awsbase/benchmark_fix.rb +39 -0
  12. data/lib/awsbase/right_awsbase.rb +1174 -0
  13. data/lib/awsbase/support.rb +35 -0
  14. data/lib/awsbase/version.rb +9 -0
  15. data/lib/ec2/right_ec2.rb +458 -0
  16. data/lib/ec2/right_ec2_ebs.rb +465 -0
  17. data/lib/ec2/right_ec2_images.rb +413 -0
  18. data/lib/ec2/right_ec2_instances.rb +785 -0
  19. data/lib/ec2/right_ec2_monitoring.rb +70 -0
  20. data/lib/ec2/right_ec2_placement_groups.rb +108 -0
  21. data/lib/ec2/right_ec2_reserved_instances.rb +174 -0
  22. data/lib/ec2/right_ec2_security_groups.rb +396 -0
  23. data/lib/ec2/right_ec2_spot_instances.rb +425 -0
  24. data/lib/ec2/right_ec2_tags.rb +139 -0
  25. data/lib/ec2/right_ec2_vpc.rb +583 -0
  26. data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
  27. data/lib/elb/right_elb_interface.rb +571 -0
  28. data/lib/iam/right_iam_access_keys.rb +71 -0
  29. data/lib/iam/right_iam_groups.rb +195 -0
  30. data/lib/iam/right_iam_interface.rb +341 -0
  31. data/lib/iam/right_iam_mfa_devices.rb +67 -0
  32. data/lib/iam/right_iam_users.rb +251 -0
  33. data/lib/rds/right_rds_interface.rb +1309 -0
  34. data/lib/right_aws.rb +83 -0
  35. data/lib/route_53/right_route_53_interface.rb +630 -0
  36. data/lib/s3/right_s3.rb +1123 -0
  37. data/lib/s3/right_s3_interface.rb +1198 -0
  38. data/lib/sdb/active_sdb.rb +1107 -0
  39. data/lib/sdb/right_sdb_interface.rb +753 -0
  40. data/lib/sqs/right_sqs.rb +387 -0
  41. data/lib/sqs/right_sqs_gen2.rb +342 -0
  42. data/lib/sqs/right_sqs_gen2_interface.rb +523 -0
  43. data/lib/sqs/right_sqs_interface.rb +593 -0
  44. data/right_aws.gemspec +91 -0
  45. data/test/acf/test_helper.rb +2 -0
  46. data/test/acf/test_right_acf.rb +138 -0
  47. data/test/awsbase/test_helper.rb +2 -0
  48. data/test/awsbase/test_right_awsbase.rb +12 -0
  49. data/test/ec2/test_helper.rb +2 -0
  50. data/test/ec2/test_right_ec2.rb +108 -0
  51. data/test/http_connection.rb +87 -0
  52. data/test/rds/test_helper.rb +2 -0
  53. data/test/rds/test_right_rds.rb +120 -0
  54. data/test/s3/test_helper.rb +2 -0
  55. data/test/s3/test_right_s3.rb +421 -0
  56. data/test/s3/test_right_s3_stubbed.rb +97 -0
  57. data/test/sdb/test_active_sdb.rb +357 -0
  58. data/test/sdb/test_batch_put_attributes.rb +54 -0
  59. data/test/sdb/test_helper.rb +3 -0
  60. data/test/sdb/test_right_sdb.rb +253 -0
  61. data/test/sqs/test_helper.rb +2 -0
  62. data/test/sqs/test_right_sqs.rb +285 -0
  63. data/test/sqs/test_right_sqs_gen2.rb +264 -0
  64. data/test/test_credentials.rb +37 -0
  65. data/test/ts_right_aws.rb +14 -0
  66. metadata +214 -0
@@ -0,0 +1,248 @@
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>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
58
+ # * <tt>:signature_version</tt>: The signature version : '0','1' or '2'(default)
59
+ # * <tt>:cache</tt>: true/false(default): list_metrics
60
+ #
61
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
62
+ init({ :name => 'ACW',
63
+ :default_host => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).host : DEFAULT_HOST,
64
+ :default_port => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).port : DEFAULT_PORT,
65
+ :default_service => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).path : DEFAULT_PATH,
66
+ :default_protocol => ENV['ACW_URL'] ? URI.parse(ENV['ACW_URL']).scheme : DEFAULT_PROTOCOL,
67
+ :default_api_version => ENV['ACW_API_VERSION'] || API_VERSION },
68
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'] ,
69
+ aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
70
+ params)
71
+ end
72
+
73
+ def generate_request(action, params={}) #:nodoc:
74
+ generate_request_impl(:get, action, params )
75
+ end
76
+
77
+ # Sends request to Amazon and parses the response
78
+ # Raises AwsError if any banana happened
79
+ def request_info(request, parser) #:nodoc:
80
+ request_info_impl(:ams_connection, @@bench, request, parser)
81
+ end
82
+
83
+ #-----------------------------------------------------------------
84
+ # MetricStatistics
85
+ #-----------------------------------------------------------------
86
+
87
+ # Get time-series data for one or more statistics of given a Metric
88
+ # Returns a hash of stat data.
89
+ #
90
+ # Options are:
91
+ #
92
+ # :period - x*60 seconds interval (where x > 0)
93
+ # :statistics - Average, Minimum. Maximum, Sum, Samples
94
+ # :start_time - The timestamp of the first datapoint to return, inclusive.
95
+ # :end_time - The timestamp to use for determining the last datapoint to return. This is the last datapoint to fetch, exclusive.
96
+ # :namespace - The namespace corresponding to the service of interest. For example, AWS/EC2 represents Amazon EC2.
97
+ # :unit - Seconds, Percent, Bytes, Bits, Count, Bytes/Second, Bits/Second, Count/Second, and None
98
+ # :custom_unit - The user-defined CustomUnit applied to a Measure. Please see the key term Unit.
99
+ #
100
+ # :dimentions
101
+ # Dimensions for EC2 Metrics:
102
+ # * ImageId - shows the requested metric for all instances running this EC2 Amazon Machine Image(AMI)
103
+ # * AvailabilityZone - shows the requested metric for all instances running in that EC2 Availability Zone
104
+ # * CapacityGroupName - shows the requested metric for all instances in the specified capacity group - this dimension is
105
+ # only available for EC2 metrics when the instances are in an Amazon Automatic Scaling Service
106
+ # Capacity Group
107
+ # * InstanceId - shows the requested metric for only the identified instance
108
+ # * InstanceType - shows the requested metric for all instances running with that instance type
109
+ # * Service (required) - the name of the service that reported the monitoring data - for EC2 metrics, use "EC2"
110
+ # * Namespace (required) - in private beta, the available metrics are all reported by AWS services, so set this to "AWS"
111
+ # Dimensions for Load Balancing Metrics:
112
+ # * AccessPointName - shows the requested metric for the specified AccessPoint name
113
+ # * AvailabilityZone - shows the requested metric for all instances running in that EC2 Availability Zone
114
+ # * Service (required) - the name of the service that reported the monitoring data - for LoadBalancing metrics, use "LBS"
115
+ # * Namespace (required) - in private beta, the available metrics are all reported by AWS services, so set this to "AWS"
116
+ #
117
+ # :measure_name
118
+ # EC2 Metrics:
119
+ # * CPUUtilization the percentage of allocated EC2 Compute Units that are currently in use on the instance. Units are Percent.
120
+ # * NetworkIn - the number of bytes received on all network interfaces by the instance. Units are Bytes.
121
+ # * NetworkOut - the number of bytes sent out on all network interfaces by the instance. Units are Bytes.
122
+ # * DiskReadOps - completed read operations from all disks available to the instance in one minute. Units are Count/Second.
123
+ # * DiskWriteOps - completed writes operations to all disks available to the instance in one minute. Units are Count/Second.
124
+ # * DiskReadBytes - bytes read from all disks available to the instance in one minute. Units are Bytes/Second.
125
+ # * DiskWriteBytes - bytes written to all disks available to the instance in one minute. Units are Bytes/Second.
126
+ # Load Balancing Metrics:
127
+ # * Latency - time taken between a request and the corresponding response as seen by the load balancer. Units are in
128
+ # seconds, and the available statistics include minimum, maximum, average and count.
129
+ # * RequestCount - number of requests processed by the AccessPoint over the valid period. Units are count per second, and
130
+ # the available statistics include minimum, maximum and sum. A valid period can be anything equal to or
131
+ # multiple of sixty (60) seconds.
132
+ # * HealthyHostCount - number of healthy EndPoints for the valid Period. A valid period can be anything equal to or a multiple
133
+ # of sixty (60) seconds. Units are the count of EndPoints. The meaningful statistic for HealthyHostCount
134
+ # is the average for an AccessPoint within an Availability Zone. Both Load Balancing dimensions,
135
+ # AccessPointName and AvailabilityZone, should be specified when retreiving HealthyHostCount.
136
+ # * UnHealthyHostCount - number of unhealthy EndPoints for the valid Period. A valid period can be anything equal to or a multiple
137
+ # of sixty (60) seconds. Units are the count of EndPoints. The meaningful statistic for UnHealthyHostCount
138
+ # is the average for an AccessPoint within Availability Amazon Monitoring Service Developer Guide Load
139
+ # Balancing Metrics Version PRIVATE BETA 2009-01-22 19 Zone. Both Load Balancing dimensions, AccessPointName
140
+ # and AvailabilityZone, should be specified when retreiving UnHealthyHostCount.
141
+ #
142
+ def get_metric_statistics(options={})
143
+ # Period (60 sec by default)
144
+ period = (options[:period] && options[:period].to_i) || 60
145
+ # Statistics ('Average' by default)
146
+ statistics = Array(options[:statistics]).flatten
147
+ statistics = statistics.right_blank? ? ['Average'] : statistics.map{|statistic| statistic.to_s.capitalize }
148
+ # Times (5.min.ago up to now by default)
149
+ start_time = options[:start_time] || (Time.now.utc - 5*60)
150
+ start_time = start_time.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00") if start_time.is_a?(Time)
151
+ end_time = options[:end_time] || Time.now.utc
152
+ end_time = end_time.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00") if end_time.is_a?(Time)
153
+ # Measure name
154
+ measure_name = options[:measure_name] || 'CPUUtilization'
155
+ # Dimentions (a hash, empty by default)
156
+ dimentions = options[:dimentions] || {}
157
+ #
158
+ request_hash = { 'Period' => period,
159
+ 'StartTime' => start_time,
160
+ 'EndTime' => end_time,
161
+ 'MeasureName' => measure_name }
162
+ request_hash['Unit'] = options[:unit] if options[:unit]
163
+ request_hash['CustomUnit'] = options[:custom_unit] if options[:custom_unit]
164
+ request_hash['Namespace'] = options[:namespace] if options[:namespace]
165
+ request_hash.merge!(amazonize_list('Statistics.member', statistics))
166
+ # dimentions
167
+ dim = []
168
+ dimentions.each do |key, values|
169
+ Array(values).each { |value| dim << [key, value] }
170
+ end
171
+ request_hash.merge!(amazonize_list(['Dimensions.member.?.Name', 'Dimensions.member.?.Value'], dim))
172
+ #
173
+ link = generate_request("GetMetricStatistics", request_hash)
174
+ request_info(link, GetMetricStatisticsParser.new(:logger => @logger))
175
+ end
176
+
177
+ # This call returns a list of the valid metrics for which there is recorded data available to a you.
178
+ #
179
+ # acw.list_metrics #=>
180
+ # [ { :namespace => "AWS/ELB",
181
+ # :measure_name => "HealthyHostCount",
182
+ # :dimentions => { "LoadBalancerName"=>"test-kd1" } },
183
+ # { :namespace => "AWS/ELB",
184
+ # :measure_name => "UnHealthyHostCount",
185
+ # :dimentions => { "LoadBalancerName"=>"test-kd1" } } ]
186
+ def list_metrics
187
+ link = generate_request("ListMetrics")
188
+ request_cache_or_info :list_metrics, link, ListMetricsParser, @@bench, true
189
+ end
190
+
191
+ #-----------------------------------------------------------------
192
+ # PARSERS: MetricStatistics
193
+ #-----------------------------------------------------------------
194
+
195
+ class GetMetricStatisticsParser < RightAWSParser #:nodoc:
196
+ def tagstart(name, attributes)
197
+ @item = {} if name == 'member'
198
+ end
199
+ def tagend(name)
200
+ case name
201
+ when 'Timestamp' then @item[:timestamp] = @text
202
+ when 'Unit' then @item[:unit] = @text
203
+ when 'CustomUnit' then @item[:custom_unit] = @text
204
+ when 'Samples' then @item[:samples] = @text.to_f
205
+ when 'Average' then @item[:average] = @text.to_f
206
+ when 'Minimum' then @item[:minimum] = @text.to_f
207
+ when 'Maximum' then @item[:maximum] = @text.to_f
208
+ when 'Sum' then @item[:sum] = @text.to_f
209
+ when 'member' then @result[:datapoints] << @item
210
+ when 'Label' then @result[:label] = @text
211
+ end
212
+ end
213
+ def reset
214
+ @result = { :datapoints => [] }
215
+ end
216
+ end
217
+
218
+ class ListMetricsParser < RightAWSParser #:nodoc:
219
+ def tagstart(name, attributes)
220
+ case name
221
+ when 'member'
222
+ case @xmlpath
223
+ when @p then @item = { :dimentions => {} }
224
+ end
225
+ end
226
+ end
227
+ def tagend(name)
228
+ case name
229
+ when 'MeasureName' then @item[:measure_name] = @text
230
+ when 'Namespace' then @item[:namespace] = @text
231
+ when 'Name' then @dname = @text
232
+ when 'Value' then @dvalue = @text
233
+ when 'member'
234
+ case @xmlpath
235
+ when "#@p/member/Dimensions" then @item[:dimentions][@dname] = @dvalue
236
+ when @p then @result << @item
237
+ end
238
+ end
239
+ end
240
+ def reset
241
+ @p = 'ListMetricsResponse/ListMetricsResult/Metrics'
242
+ @result = []
243
+ end
244
+ end
245
+
246
+ end
247
+
248
+ end
@@ -0,0 +1,698 @@
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::AsInterface -- RightScale Amazon Auto Scaling interface
27
+ # The RightAws::AsInterface class provides a complete interface to Amazon Auto Scaling service.
28
+ #
29
+ # For explanations of the semantics of each call, please refer to Amazon's documentation at
30
+ # http://docs.amazonwebservices.com/AutoScaling/latest/DeveloperGuide/
31
+ #
32
+ # Create an interface handle:
33
+ #
34
+ # as = RightAws::AsInterface.new(aws_access_key_id, aws_security_access_key)
35
+ #
36
+ # Create a launch configuration:
37
+ #
38
+ # as.create_launch_configuration('CentOS.5.1-c', 'ami-08f41161', 'm1.small',
39
+ # :key_name => 'kd-moo-test',
40
+ # :security_groups => ['default'],
41
+ # :user_data => "Woohoo: CentOS.5.1-c" )
42
+ #
43
+ # Create an AutoScaling group:
44
+ #
45
+ # as.create_auto_scaling_group('CentOS.5.1-c-array', 'CentOS.5.1-c', 'us-east-1c',
46
+ # :min_size => 2,
47
+ # :max_size => 5)
48
+ #
49
+ # Create a new trigger:
50
+ #
51
+ # as.create_or_update_scaling_trigger('kd.tr.1', 'CentOS.5.1-c-array',
52
+ # :measure_name => 'CPUUtilization',
53
+ # :statistic => :average,
54
+ # :dimensions => {
55
+ # 'AutoScalingGroupName' => 'CentOS.5.1-c-array',
56
+ # 'Namespace' => 'AWS',
57
+ # 'Service' => 'EC2' },
58
+ # :period => 60,
59
+ # :lower_threshold => 5,
60
+ # :lower_breach_scale_increment => -1,
61
+ # :upper_threshold => 60,
62
+ # :upper_breach_scale_increment => 1,
63
+ # :breach_duration => 300 )
64
+ #
65
+ # Describe scaling activity:
66
+ #
67
+ # as.incrementally_describe_scaling_activities('CentOS.5.1-c-array') #=> List of activities
68
+ #
69
+ # Describe the Auto Scaling group status:
70
+ #
71
+ # as.describe_auto_scaling_groups('CentOS.5.1-c-array') #=> Current group status
72
+ #
73
+ class AsInterface < RightAwsBase
74
+ include RightAwsBaseInterface
75
+
76
+ # Amazon AS API version being used
77
+ API_VERSION = '2009-05-15'
78
+ DEFAULT_HOST = 'autoscaling.amazonaws.com'
79
+ DEFAULT_PATH = '/'
80
+ DEFAULT_PROTOCOL = 'https'
81
+ DEFAULT_PORT = 443
82
+
83
+ @@bench = AwsBenchmarkingBlock.new
84
+ def self.bench_xml
85
+ @@bench.xml
86
+ end
87
+ def self.bench_service
88
+ @@bench.service
89
+ end
90
+
91
+ # Create a new handle to an CSLS account. All handles share the same per process or per thread
92
+ # HTTP connection to Amazon CSLS. Each handle is for a specific account. The params have the
93
+ # following options:
94
+ # * <tt>:endpoint_url</tt> a fully qualified url to Amazon API endpoint (this overwrites: :server, :port, :service, :protocol). Example: 'https://autoscaling.amazonaws.com/'
95
+ # * <tt>:server</tt>: AS service host, default: DEFAULT_HOST
96
+ # * <tt>:port</tt>: AS service port, default: DEFAULT_PORT
97
+ # * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
98
+ # * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
99
+ # * <tt>:signature_version</tt>: The signature version : '0','1' or '2'(default)
100
+ # * <tt>:cache</tt>: true/false(default): describe_auto_scaling_groups
101
+ #
102
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
103
+ init({ :name => 'AS',
104
+ :default_host => ENV['AS_URL'] ? URI.parse(ENV['AS_URL']).host : DEFAULT_HOST,
105
+ :default_port => ENV['AS_URL'] ? URI.parse(ENV['AS_URL']).port : DEFAULT_PORT,
106
+ :default_service => ENV['AS_URL'] ? URI.parse(ENV['AS_URL']).path : DEFAULT_PATH,
107
+ :default_protocol => ENV['AS_URL'] ? URI.parse(ENV['AS_URL']).scheme : DEFAULT_PROTOCOL,
108
+ :default_api_version => ENV['AS_API_VERSION'] || API_VERSION },
109
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'] ,
110
+ aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
111
+ params)
112
+ end
113
+
114
+ def generate_request(action, params={}) #:nodoc:
115
+ generate_request_impl(:get, action, params )
116
+ end
117
+
118
+ # Sends request to Amazon and parses the response
119
+ # Raises AwsError if any banana happened
120
+ def request_info(request, parser) #:nodoc:
121
+ request_info_impl(:aass_connection, @@bench, request, parser)
122
+ end
123
+
124
+ #-----------------------------------------------------------------
125
+ # Auto Scaling Groups
126
+ #-----------------------------------------------------------------
127
+
128
+ # Describe auto scaling groups.
129
+ # Returns a full description of the AutoScalingGroups from the given list.
130
+ # This includes all EC2 instances that are members of the group. If a list
131
+ # of names is not provided, then the full details of all AutoScalingGroups
132
+ # is returned. This style conforms to the EC2 DescribeInstances API behavior.
133
+ #
134
+ def describe_auto_scaling_groups(*auto_scaling_group_names)
135
+ auto_scaling_group_names = auto_scaling_group_names.flatten.compact
136
+ request_hash = amazonize_list('AutoScalingGroupNames.member', auto_scaling_group_names)
137
+ link = generate_request("DescribeAutoScalingGroups", request_hash)
138
+ request_cache_or_info(:describe_auto_scaling_groups, link, DescribeAutoScalingGroupsParser, @@bench, auto_scaling_group_names.right_blank?)
139
+ end
140
+
141
+ # Creates a new auto scaling group with the specified name.
142
+ # Returns +true+ or raises an exception.
143
+ #
144
+ # Options: +:min_size+, +:max_size+, +:cooldown+, +:load_balancer_names+
145
+ #
146
+ # as.create_auto_scaling_group('CentOS.5.1-c-array', 'CentOS.5.1-c', 'us-east-1c',
147
+ # :min_size => 2,
148
+ # :max_size => 5) #=> true
149
+ #
150
+ # Amazon's notice: Constraints: Restricted to one Availability Zone
151
+ def create_auto_scaling_group(auto_scaling_group_name, launch_configuration_name, availability_zones, options={})
152
+ options[:min_size] ||= 1
153
+ options[:max_size] ||= 20
154
+ options[:cooldown] ||= 0
155
+ request_hash = amazonize_list('AvailabilityZones.member', availability_zones)
156
+ request_hash.merge!( amazonize_list('LoadBalancerNames.member', options[:load_balancer_names]) )
157
+ request_hash.merge!( 'AutoScalingGroupName' => auto_scaling_group_name,
158
+ 'LaunchConfigurationName' => launch_configuration_name,
159
+ 'MinSize' => options[:min_size],
160
+ 'MaxSize' => options[:max_size],
161
+ 'Cooldown' => options[:cooldown] )
162
+ link = generate_request("CreateAutoScalingGroup", request_hash)
163
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
164
+ end
165
+
166
+ # Deletes all configuration for this auto scaling group and also deletes the group.
167
+ # Returns +true+ or raises an exception.
168
+ #
169
+ def delete_auto_scaling_group(auto_scaling_group_name)
170
+ link = generate_request('DeleteAutoScalingGroup', 'AutoScalingGroupName' => auto_scaling_group_name)
171
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
172
+ end
173
+
174
+ # Adjusts the desired size of the Capacity Group by using scaling actions, as necessary. When
175
+ # adjusting the size of the group downward, it is not possible to define which EC2 instances will be
176
+ # terminated. This also applies to any auto-scaling decisions that might result in the termination of
177
+ # instances.
178
+ #
179
+ # Returns +true+ or raises an exception.
180
+ #
181
+ # as.set_desired_capacity('CentOS.5.1-c',3) #=> 3
182
+ #
183
+ def set_desired_capacity(auto_scaling_group_name, desired_capacity)
184
+ link = generate_request('SetDesiredCapacity', 'AutoScalingGroupName' => auto_scaling_group_name,
185
+ 'DesiredCapacity' => desired_capacity )
186
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
187
+ end
188
+
189
+ # Updates the configuration for the given AutoScalingGroup. If MaxSize is lower than the current size,
190
+ # then there will be an implicit call to SetDesiredCapacity to set the group to the new MaxSize. The
191
+ # same is true for MinSize there will also be an implicit call to SetDesiredCapacity. All optional
192
+ # parameters are left unchanged if not passed in the request.
193
+ #
194
+ # The new settings are registered upon the completion of this call. Any launch configuration settings
195
+ # will take effect on any triggers after this call returns. However, triggers that are currently in
196
+ # progress can not be affected. See key term Trigger.
197
+ #
198
+ # Returns +true+ or raises an exception.
199
+ #
200
+ # Options: +:launch_configuration_name+, +:min_size+, +:max_size+, +:cooldown+, +:availability_zones+.
201
+ # (Amazon's notice: +:availability_zones+ is reserved for future use.)
202
+ #
203
+ # as.update_auto_scaling_group('CentOS.5.1-c', :min_size => 1, :max_size => 4) #=> true
204
+ #
205
+ def update_auto_scaling_group(auto_scaling_group_name, options={})
206
+ request_hash = amazonize_list('AvailabilityZones.member', options[:availability_zones])
207
+ request_hash['AutoScalingGroupName'] = auto_scaling_group_name
208
+ request_hash['LaunchConfigurationName'] = options[:launch_configuration_name] if options[:launch_configuration_name]
209
+ request_hash['MinSize'] = options[:min_size] if options[:min_size]
210
+ request_hash['MaxSize'] = options[:max_size] if options[:max_size]
211
+ request_hash['Cooldown'] = options[:cooldown] if options[:cooldown]
212
+ link = generate_request("UpdateAutoScalingGroup", request_hash)
213
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
214
+ end
215
+
216
+ #-----------------------------------------------------------------
217
+ # Scaling Activities
218
+ #-----------------------------------------------------------------
219
+
220
+ # Describe all Scaling Activities.
221
+ #
222
+ # describe_scaling_activities('CentOS.5.1-c-array') #=>
223
+ # [{:cause=>
224
+ # "At 2009-05-28 10:11:35Z trigger kd.tr.1 breached high threshold value for
225
+ # CPUUtilization, 10.0, adjusting the desired capacity from 1 to 2. At 2009-05-28 10:11:35Z
226
+ # a breaching trigger explicitly set group desired capacity changing the desired capacity
227
+ # from 1 to 2. At 2009-05-28 10:11:40Z an instance was started in response to a difference
228
+ # between desired and actual capacity, increasing the capacity from 1 to 2.",
229
+ # :activity_id=>"067c9abb-f8a7-4cf8-8f3c-dc6f280457c4",
230
+ # :progress=>0,
231
+ # :description=>"Launching a new EC2 instance",
232
+ # :status_code=>"InProgress",
233
+ # :start_time=>Thu May 28 10:11:40 UTC 2009},
234
+ # {:end_time=>Thu May 28 09:35:23 UTC 2009,
235
+ # :cause=>
236
+ # "At 2009-05-28 09:31:21Z a user request created an AutoScalingGroup changing the desired
237
+ # capacity from 0 to 1. At 2009-05-28 09:32:35Z an instance was started in response to a
238
+ # difference between desired and actual capacity, increasing the capacity from 0 to 1.",
239
+ # :activity_id=>"90d506ba-1b75-4d29-8739-0a75b1ba8030",
240
+ # :progress=>100,
241
+ # :description=>"Launching a new EC2 instance",
242
+ # :status_code=>"Successful",
243
+ # :start_time=>Thu May 28 09:32:35 UTC 2009}]}
244
+ #
245
+ def describe_scaling_activities(auto_scaling_group_name, *activity_ids)
246
+ result = []
247
+ incrementally_describe_scaling_activities(auto_scaling_group_name, *activity_ids) do |response|
248
+ result += response[:scaling_activities]
249
+ true
250
+ end
251
+ result
252
+ end
253
+
254
+ # Incrementally describe Scaling Activities.
255
+ # Returns the scaling activities specified for the given group. If the input list is empty, all the
256
+ # activities from the past six weeks will be returned. Activities will be sorted by completion time.
257
+ # Activities that have no completion time will be considered as using the most recent possible time.
258
+ #
259
+ # Optional params: +:max_records+, +:next_token+.
260
+ #
261
+ # # get max 100 first activities
262
+ # as.incrementally_describe_scaling_activities('CentOS.5.1-c-array') #=>
263
+ # {:scaling_activities=>
264
+ # [{:cause=>
265
+ # "At 2009-05-28 10:11:35Z trigger kd.tr.1 breached high threshold value for
266
+ # CPUUtilization, 10.0, adjusting the desired capacity from 1 to 2. At 2009-05-28 10:11:35Z
267
+ # a breaching trigger explicitly set group desired capacity changing the desired capacity
268
+ # from 1 to 2. At 2009-05-28 10:11:40Z an instance was started in response to a difference
269
+ # between desired and actual capacity, increasing the capacity from 1 to 2.",
270
+ # :activity_id=>"067c9abb-f8a7-4cf8-8f3c-dc6f280457c4",
271
+ # :progress=>0,
272
+ # :description=>"Launching a new EC2 instance",
273
+ # :status_code=>"InProgress",
274
+ # :start_time=>Thu May 28 10:11:40 UTC 2009},
275
+ # {:end_time=>Thu May 28 09:35:23 UTC 2009,
276
+ # :cause=>
277
+ # "At 2009-05-28 09:31:21Z a user request created an AutoScalingGroup changing the desired
278
+ # capacity from 0 to 1. At 2009-05-28 09:32:35Z an instance was started in response to a
279
+ # difference between desired and actual capacity, increasing the capacity from 0 to 1.",
280
+ # :activity_id=>"90d506ba-1b75-4d29-8739-0a75b1ba8030",
281
+ # :progress=>100,
282
+ # :description=>"Launching a new EC2 instance",
283
+ # :status_code=>"Successful",
284
+ # :start_time=>Thu May 28 09:32:35 UTC 2009}]}
285
+ #
286
+ # # list by 5 records
287
+ # incrementally_describe_scaling_activities('CentOS.5.1-c-array', :max_records => 5) do |response|
288
+ # puts response.inspect
289
+ # true
290
+ # end
291
+ #
292
+ def incrementally_describe_scaling_activities(auto_scaling_group_name, *activity_ids, &block)
293
+ activity_ids = activity_ids.flatten.compact
294
+ params = activity_ids.last.kind_of?(Hash) ? activity_ids.pop : {}
295
+ request_hash = amazonize_list('ActivityIds.member', activity_ids)
296
+ request_hash['AutoScalingGroupName'] = auto_scaling_group_name
297
+ request_hash['MaxRecords'] = params[:max_records] if params[:max_records]
298
+ request_hash['NextToken'] = params[:next_token] if params[:next_token]
299
+ last_response = nil
300
+ loop do
301
+ link = generate_request("DescribeScalingActivities", request_hash)
302
+ last_response = request_info( link, DescribeScalingActivitiesParser.new(:logger => @logger))
303
+ request_hash['NextToken'] = last_response[:next_token]
304
+ break unless block && block.call(last_response) && !last_response[:next_token].right_blank?
305
+ end
306
+ last_response
307
+ end
308
+
309
+ #-----------------------------------------------------------------
310
+ # Instance and Instance Workflow Operations
311
+ #-----------------------------------------------------------------
312
+
313
+ # This call will terminate the specified Instance. Optionally, the desired group size can be adjusted.
314
+ # If set to true, the default, the AutoScalingGroup size will decrease by one. If the AutoScalingGroup
315
+ # is associated with a LoadBalancer, the system will deregister the instance before terminating it.
316
+ # This call simply registers a termination request. The termination of the instance can not happen
317
+ # immediately.
318
+ #
319
+ # Returns the activity to terminate the instance.
320
+ #
321
+ def terminate_instance_in_auto_scaling_group(instance_id, should_decrement_desired_capacity=true)
322
+ request_hash = { 'InstanceId' => instance_id }
323
+ request_hash['ShouldDecrementDesiredCapacity'] = should_decrement_desired_capacity
324
+ link = generate_request('TerminateInstanceInAutoScalingGroup', request_hash )
325
+ request_info(link, DescribeScalingActivitiesParser.new(:logger => @logger))[:scaling_activities].first
326
+ end
327
+
328
+ #-----------------------------------------------------------------
329
+ # Launch Configuration Operations
330
+ #-----------------------------------------------------------------
331
+
332
+ # Creates a new Launch Configuration. Please note that the launch configuration name used must
333
+ # be unique, within the scope of your Amazon Web Services AWS account, and the maximum limit of
334
+ # launch configurations must not yet have been met, or else the call will fail.
335
+ #
336
+ # Once created, the new launch configuration is available for immediate use.
337
+ #
338
+ # Options: +:security_groups+, +:block_device_mappings+, +:key_name+,
339
+ # +:user_data+, +:kernel_id+, +:ramdisk_id+
340
+ #
341
+ # as.create_launch_configuration('kd: CentOS.5.1-c.1', 'ami-08f41161', 'c1.medium',
342
+ # :key_name => 'tim',
343
+ # :security_groups => ['default'],
344
+ # :user_data => "Woohoo: CentOS.5.1-c",
345
+ # :block_device_mappings => [ { :device_name => '/dev/sdk',
346
+ # :ebs_snapshot_id => 'snap-145cbc7d',
347
+ # :ebs_delete_on_termination => true,
348
+ # :ebs_volume_size => 3,
349
+ # :virtual_name => 'ephemeral2'
350
+ # } ]
351
+ # ) #=> true
352
+ #
353
+ def create_launch_configuration(launch_configuration_name, image_id, instance_type, options={})
354
+ request_hash = { 'LaunchConfigurationName' => launch_configuration_name,
355
+ 'ImageId' => image_id,
356
+ 'InstanceType' => instance_type }
357
+ request_hash.merge!(amazonize_list('SecurityGroups.member', options[:security_groups])) unless options[:security_groups].right_blank?
358
+ request_hash.merge!(amazonize_block_device_mappings(options[:block_device_mappings], 'BlockDeviceMappings.member'))
359
+ request_hash['KeyName'] = options[:key_name] if options[:key_name]
360
+ request_hash['UserData'] = Base64.encode64(options[:user_data]).delete("\n") unless options[:user_data].right_blank? if options[:user_data]
361
+ request_hash['KernelId'] = options[:kernel_id] if options[:kernel_id]
362
+ request_hash['RamdiskId'] = options[:ramdisk_id] if options[:ramdisk_id]
363
+ link = generate_request("CreateLaunchConfiguration", request_hash)
364
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
365
+ end
366
+
367
+
368
+ # Describe all Launch Configurations.
369
+ # Returns an array of configurations.
370
+ #
371
+ # as.describe_launch_configurations #=>
372
+ # [{:security_groups=>["default"],
373
+ # :ramdisk_id=>"",
374
+ # :user_data=>"V29vaG9vOiBDZW50T1MuNS4xLWM=",
375
+ # :instance_type=>"c1.medium",
376
+ # :block_device_mappings=>
377
+ # [{:virtual_name=>"ephemeral2", :device_name=>"/dev/sdk"}],
378
+ # :launch_configuration_name=>"kd: CentOS.5.1-c.1",
379
+ # :created_time=>"2010-03-29T10:00:32.742Z",
380
+ # :image_id=>"ami-08f41161",
381
+ # :key_name=>"tim",
382
+ # :kernel_id=>""}, ...]
383
+ #
384
+ def describe_launch_configurations(*launch_configuration_names)
385
+ result = []
386
+ incrementally_describe_launch_configurations(*launch_configuration_names) do |response|
387
+ result += response[:launch_configurations]
388
+ true
389
+ end
390
+ result
391
+ end
392
+
393
+ # Incrementally describe Launch Configurations.
394
+ # Returns a full description of the launch configurations given the specified names. If no names
395
+ # are specified, then the full details of all launch configurations are returned.
396
+ #
397
+ # Optional params: +:max_records+, +:next_token+.
398
+ #
399
+ # # get max 100 first configurations
400
+ # as.incrementally_describe_launch_configurations #=>
401
+ # {:launch_configurations=>
402
+ # [{:created_time=>Thu May 28 09:31:20 UTC 2009,
403
+ # :kernel_id=>"",
404
+ # :launch_configuration_name=>"CentOS.5.1-c",
405
+ # :ramdisk_id=>"",
406
+ # :security_groups=>["default"],
407
+ # :key_name=>"kd-moo-test",
408
+ # :user_data=>"Woohoo: CentOS.5.1-c-array",
409
+ # :image_id=>"ami-08f41161",
410
+ # :block_device_mappings=>[],
411
+ # :instance_type=>"m1.small"}, ... ]}
412
+ #
413
+ # # list by 5 records
414
+ # incrementally_describe_launch_configurations(:max_records => 5) do |response|
415
+ # puts response.inspect
416
+ # true
417
+ # end
418
+ #
419
+ def incrementally_describe_launch_configurations(*launch_configuration_names, &block)
420
+ launch_configuration_names = launch_configuration_names.flatten.compact
421
+ params = launch_configuration_names.last.kind_of?(Hash) ? launch_configuration_names.pop : {}
422
+ request_hash = amazonize_list('LaunchConfigurationNames.member', launch_configuration_names)
423
+ request_hash['MaxRecords'] = params[:max_records] if params[:max_records]
424
+ request_hash['NextToken'] = params[:next_token] if params[:next_token]
425
+ last_response = nil
426
+ loop do
427
+ link = generate_request("DescribeLaunchConfigurations", request_hash)
428
+ last_response = request_info( link, DescribeLaunchConfigurationsParser.new(:logger => @logger) )
429
+ request_hash['NextToken'] = last_response[:next_token]
430
+ break unless block && block.call(last_response) && !last_response[:next_token].right_blank?
431
+ end
432
+ last_response
433
+ end
434
+
435
+ # Delete launch configuration.
436
+ # Returns +true+ or an exception.
437
+ #
438
+ # as.delete_launch_configuration('CentOS.5.1') #=> true
439
+ #
440
+ def delete_launch_configuration(launch_configuration_name)
441
+ link = generate_request('DeleteLaunchConfiguration', 'LaunchConfigurationName' => launch_configuration_name)
442
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
443
+ end
444
+
445
+ #-----------------------------------------------------------------
446
+ # Trigger Operations
447
+ #-----------------------------------------------------------------
448
+
449
+ # Create or update specified trigger.
450
+ # This call sets the parameters that governs when and how to scale an AutoScalingGroup.
451
+ # If the Trigger, within the scope of the caller's AWS account, specified already exists,
452
+ # it will be updated. If a trigger with a different name already exists, this call will fail.
453
+ #
454
+ # Returns +true+ or an exception.
455
+ #
456
+ # Options: +:measure_name+, +:statistic+, +:period+, +:lower_threshold+, +:lower_breach_scale_increment+,
457
+ # +:upper_threshold+, +:upper_breach_scale_increment+, +:dimensions+, +:breach_duration+, +:unit+, +:custom_unit+
458
+ #
459
+ # as.create_or_update_scaling_trigger('kd.tr.1', 'CentOS.5.1-c-array',
460
+ # :measure_name => 'CPUUtilization',
461
+ # :statistic => :average,
462
+ # :dimensions => {
463
+ # 'AutoScalingGroupName' => 'CentOS.5.1-c-array',
464
+ # 'Namespace' => 'AWS',
465
+ # 'Service' => 'EC2' },
466
+ # :period => 60,
467
+ # :lower_threshold => 5,
468
+ # :lower_breach_scale_increment => -1,
469
+ # :upper_threshold => 60,
470
+ # :upper_breach_scale_increment => 1,
471
+ # :breach_duration => 300 ) #=> true
472
+ #
473
+ def create_or_update_scaling_trigger(trigger_name, auto_scaling_group_name, options={})
474
+ request_hash = { 'TriggerName' => trigger_name,
475
+ 'AutoScalingGroupName' => auto_scaling_group_name,
476
+ 'MeasureName' => options[:measure_name],
477
+ 'Statistic' => options[:statistic].to_s.capitalize,
478
+ 'Period' => options[:period],
479
+ 'LowerThreshold' => options[:lower_threshold],
480
+ 'LowerBreachScaleIncrement' => options[:lower_breach_scale_increment],
481
+ 'UpperThreshold' => options[:upper_threshold],
482
+ 'UpperBreachScaleIncrement' => options[:upper_breach_scale_increment],
483
+ 'BreachDuration' => options[:breach_duration] }
484
+ request_hash['Unit'] = options[:unit] if options[:unit]
485
+ request_hash['CustomUnit'] = options[:custom_unit] if options[:custom_unit]
486
+ dimensions = []
487
+ (options[:dimensions] || {}).each do |key, values|
488
+ Array(values).each { |value| dimensions << [key, value] }
489
+ end
490
+ request_hash.merge!(amazonize_list(['Dimensions.member.?.Name', 'Dimensions.member.?.Value'], dimensions))
491
+ link = generate_request("CreateOrUpdateScalingTrigger", request_hash)
492
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
493
+ end
494
+
495
+ # Describe triggers.
496
+ # Returns a full description of the trigger in the specified Auto Scaling Group.
497
+ #
498
+ # as.describe_triggers('CentOS.5.1-c-array') #=>
499
+ # [{:status=>"HighBreaching",
500
+ # :breach_duration=>300,
501
+ # :measure_name=>"CPUUtilization",
502
+ # :trigger_name=>"kd.tr.1",
503
+ # :period=>60,
504
+ # :lower_threshold=>0.0,
505
+ # :lower_breach_scale_increment=>-1,
506
+ # :dimensions=>
507
+ # {"Namespace"=>"AWS",
508
+ # "AutoScalingGroupName"=>"CentOS.5.1-c-array",
509
+ # "Service"=>"EC2"},
510
+ # :statistic=>"Average",
511
+ # :upper_threshold=>10.0,
512
+ # :created_time=>Thu May 28 09:48:46 UTC 2009,
513
+ # :auto_scaling_group_name=>"CentOS.5.1-c-array",
514
+ # :upper_breach_scale_increment=>1}]
515
+ #
516
+ def describe_triggers(auto_scaling_group_name)
517
+ link = generate_request("DescribeTriggers", 'AutoScalingGroupName' => auto_scaling_group_name)
518
+ request_info(link, DescribeTriggersParser.new(:logger => @logger))
519
+ end
520
+
521
+ # Delete specified trigger.
522
+ # Returns +true+ or an exception.
523
+ #
524
+ # as.delete_trigger('kd.tr.1', 'CentOS.5.1-c-array') #=> true
525
+ #
526
+ def delete_trigger(trigger_name, auto_scaling_group_name)
527
+ link = generate_request('DeleteTrigger', 'TriggerName' => trigger_name,
528
+ 'AutoScalingGroupName' => auto_scaling_group_name)
529
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
530
+ end
531
+
532
+ #-----------------------------------------------------------------
533
+ # PARSERS: Scaling Activity
534
+ #-----------------------------------------------------------------
535
+
536
+ class DescribeScalingActivitiesParser < RightAWSParser #:nodoc:
537
+ def tagstart(name, attributes)
538
+ case name
539
+ when 'member', 'Activity' then @item = {}
540
+ end
541
+ end
542
+ def tagend(name)
543
+ case name
544
+ when 'ActivityId' then @item[:activity_id] = @text
545
+ when 'StartTime' then @item[:start_time] = @text
546
+ when 'EndTime' then @item[:end_time] = @text
547
+ when 'Progress' then @item[:progress] = @text.to_i
548
+ when 'StatusCode' then @item[:status_code] = @text
549
+ when 'Cause' then @item[:cause] = @text
550
+ when 'Description' then @item[:description] = @text
551
+ when 'member', 'Activity' then @result[:scaling_activities] << @item
552
+ when 'NextToken' then @result[:next_token] = @text
553
+ end
554
+ end
555
+ def reset
556
+ @result = { :scaling_activities => []}
557
+ end
558
+ end
559
+
560
+ #-----------------------------------------------------------------
561
+ # PARSERS: Auto Scaling Groups
562
+ #-----------------------------------------------------------------
563
+
564
+ class DescribeAutoScalingGroupsParser < RightAWSParser #:nodoc:
565
+ def tagstart(name, attributes)
566
+ case name
567
+ when 'member'
568
+ case @xmlpath
569
+ when @p then @item = { :instances => [ ],
570
+ :availability_zones => [],
571
+ :load_balancer_names => [] }
572
+ when "#@p/member/Instances" then @instance = { }
573
+ end
574
+ end
575
+ end
576
+ def tagend(name)
577
+ case name
578
+ when 'CreatedTime' then @item[:created_time] = @text
579
+ when 'MinSize' then @item[:min_size] = @text.to_i
580
+ when 'MaxSize' then @item[:max_size] = @text.to_i
581
+ when 'DesiredCapacity' then @item[:desired_capacity] = @text.to_i
582
+ when 'Cooldown' then @item[:cooldown] = @text.to_i
583
+ when 'LaunchConfigurationName' then @item[:launch_configuration_name] = @text
584
+ when 'AutoScalingGroupName' then @item[:auto_scaling_group_name] = @text
585
+ when 'InstanceId' then @instance[:instance_id] = @text
586
+ when 'LifecycleState' then @instance[:lifecycle_state] = @text
587
+ when 'AvailabilityZone' then @instance[:availability_zone] = @text
588
+ when 'member'
589
+ case @xmlpath
590
+ when @p then
591
+ @item[:availability_zones].sort!
592
+ @result << @item
593
+ when "#@p/member/AvailabilityZones" then @item[:availability_zones] << @text
594
+ when "#@p/member/LoadBalancerNames" then @item[:load_balancer_names] << @text
595
+ when "#@p/member/Instances" then @item[:instances] << @instance
596
+ end
597
+ end
598
+ end
599
+ def reset
600
+ @p = 'DescribeAutoScalingGroupsResponse/DescribeAutoScalingGroupsResult/AutoScalingGroups'
601
+ @result = []
602
+ end
603
+ end
604
+
605
+ #-----------------------------------------------------------------
606
+ # PARSERS: Launch Configurations
607
+ #-----------------------------------------------------------------
608
+
609
+ class DescribeLaunchConfigurationsParser < RightAWSParser #:nodoc:
610
+ def tagstart(name, attributes)
611
+ case full_tag_name
612
+ when %r{/LaunchConfigurations/member$}
613
+ @item = { :block_device_mappings => [],
614
+ :security_groups => [] }
615
+ when %r{/BlockDeviceMappings/member$}
616
+ @block_device_mapping = {}
617
+ end
618
+ end
619
+ def tagend(name)
620
+ case name
621
+ when 'CreatedTime' then @item[:created_time] = @text
622
+ when 'InstanceType' then @item[:instance_type] = @text
623
+ when 'KeyName' then @item[:key_name] = @text
624
+ when 'ImageId' then @item[:image_id] = @text
625
+ when 'KernelId' then @item[:kernel_id] = @text
626
+ when 'RamdiskId' then @item[:ramdisk_id] = @text
627
+ when 'LaunchConfigurationName' then @item[:launch_configuration_name] = @text
628
+ when 'UserData' then @item[:user_data] = @text
629
+ when 'NextToken' then @result[:next_token] = @text
630
+ else
631
+ case full_tag_name
632
+ when %r{/BlockDeviceMappings/member} # no trailing $
633
+ case name
634
+ when 'DeviceName' then @block_device_mapping[:device_name] = @text
635
+ when 'VirtualName' then @block_device_mapping[:virtual_name] = @text
636
+ when 'member' then @item[:block_device_mappings] << @block_device_mapping
637
+ end
638
+ when %r{member/SecurityGroups/member$}
639
+ @item[:security_groups] << @text
640
+ when %r{/LaunchConfigurations/member$}
641
+ @item[:security_groups].sort!
642
+ @result[:launch_configurations] << @item
643
+ end
644
+ end
645
+ end
646
+ def reset
647
+ @result = { :launch_configurations => []}
648
+ end
649
+ end
650
+
651
+ #-----------------------------------------------------------------
652
+ # PARSERS: Triggers
653
+ #-----------------------------------------------------------------
654
+
655
+ class DescribeTriggersParser < RightAWSParser #:nodoc:
656
+ def tagstart(name, attributes)
657
+ case name
658
+ when 'member'
659
+ case @xmlpath
660
+ when 'DescribeTriggersResponse/DescribeTriggersResult/Triggers'
661
+ @item = { :dimensions => {} }
662
+ when 'DescribeTriggersResponse/DescribeTriggersResult/Triggers/member/Dimensions'
663
+ @dimension = {}
664
+ end
665
+ end
666
+ end
667
+ def tagend(name)
668
+ case name
669
+ when 'AutoScalingGroupName' then @item[:auto_scaling_group_name] = @text
670
+ when 'MeasureName' then @item[:measure_name] = @text
671
+ when 'CreatedTime' then @item[:created_time] = @text
672
+ when 'BreachDuration' then @item[:breach_duration] = @text.to_i
673
+ when 'UpperBreachScaleIncrement' then @item[:upper_breach_scale_increment] = @text.to_i
674
+ when 'UpperThreshold' then @item[:upper_threshold] = @text.to_f
675
+ when 'LowerThreshold' then @item[:lower_threshold] = @text.to_f
676
+ when 'LowerBreachScaleIncrement' then @item[:lower_breach_scale_increment] = @text.to_i
677
+ when 'Period' then @item[:period] = @text.to_i
678
+ when 'Status' then @item[:status] = @text
679
+ when 'TriggerName' then @item[:trigger_name] = @text
680
+ when 'Statistic' then @item[:statistic] = @text
681
+ when 'Unit' then @item[:unit] = @text
682
+ when 'Name' then @dimension[:name] = @text
683
+ when 'Value' then @dimension[:value] = @text
684
+ when 'member'
685
+ case @xmlpath
686
+ when "#@p/member/Dimensions" then @item[:dimensions][@dimension[:name]] = @dimension[:value]
687
+ when @p then @result << @item
688
+ end
689
+ end
690
+ end
691
+ def reset
692
+ @p = 'DescribeTriggersResponse/DescribeTriggersResult/Triggers'
693
+ @result = []
694
+ end
695
+ end
696
+ end
697
+
698
+ end