redaranj-right_aws 1.11.1 → 1.11.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,998 @@
1
+ #
2
+ # Copyright (c) 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
+ class RdsInterface < RightAwsBase
27
+
28
+ include RightAwsBaseInterface
29
+
30
+ API_VERSION = "2009-10-16"
31
+ DEFAULT_HOST = 'rds.amazonaws.com'
32
+ DEFAULT_PORT = 443
33
+ DEFAULT_PROTOCOL = 'https'
34
+ DEFAULT_PATH = '/'
35
+
36
+ DEFAULT_INSTANCE_CLASS = 'db.m1.small'
37
+ INSTANCE_CLASSES = ['db.m1.small', 'db.m1.large', 'db.m1.xlarge', 'db.m2.2xlarge', 'db.m2.4xlarge']
38
+
39
+ @@bench = AwsBenchmarkingBlock.new
40
+ def self.bench_xml
41
+ @@bench.xml
42
+ end
43
+ def self.bench_service
44
+ @@bench.service
45
+ end
46
+
47
+ # Create a new handle to a RDS account. All handles share the same per process or per thread
48
+ # HTTP connection to RDS. Each handle is for a specific account. The params have the
49
+ # following options:
50
+ # * <tt>:endpoint_url</tt> a fully qualified url to Amazon API endpoint (this overwrites: :server, :port, :service, :protocol). Example: 'https://rds.amazonaws.com'
51
+ # * <tt>:server</tt>: RDS service host, default: DEFAULT_HOST
52
+ # * <tt>:port</tt>: RDS service port, default: DEFAULT_PORT
53
+ # * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
54
+ # * <tt>:multi_thread</tt>: true=HTTP connection per thread, false=per process
55
+ # * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
56
+ #
57
+ # rds = RightAws::RdsInterface.new('xxxxxxxxxxxxxxxxxxxxx','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
58
+ # {:logger => Logger.new('/tmp/x.log')}) #=> #<RightAws::RdsInterface::0xb7b3c30c>
59
+ #
60
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
61
+ init({ :name => 'RDS',
62
+ :default_host => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).host : DEFAULT_HOST,
63
+ :default_port => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).port : DEFAULT_PORT,
64
+ :default_service => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).path : DEFAULT_PATH,
65
+ :default_protocol => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).scheme : DEFAULT_PROTOCOL,
66
+ :default_api_version => ENV['RDS_API_VERSION'] || API_VERSION },
67
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
68
+ aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
69
+ params)
70
+ end
71
+
72
+ #-----------------------------------------------------------------
73
+ # Requests
74
+ #-----------------------------------------------------------------
75
+
76
+ # Generates request hash for REST API.
77
+ def generate_request(action, params={}) #:nodoc:
78
+ generate_request_impl(:get, action, params )
79
+ end
80
+
81
+ # Sends request to Amazon and parses the response.
82
+ # Raises AwsError if any banana happened.
83
+ def request_info(request, parser, &block) # :nodoc:
84
+ request_info_impl(:rds_connection, @@bench, request, parser, &block)
85
+ end
86
+
87
+ # Incrementally lists something.
88
+ def incrementally_list_items(action, parser_class, params={}, &block) # :nodoc:
89
+ params = params.dup
90
+ params['MaxRecords'] = params.delete(:max_records) if params[:max_records]
91
+ params['Marker'] = params.delete(:marker) if params[:marker]
92
+ last_response = nil
93
+ loop do
94
+ link = generate_request(action, params)
95
+ last_response = request_info( link, parser_class.new(:logger => @logger))
96
+ params['Marker'] = last_response[:marker]
97
+ break unless block && block.call(last_response) && !last_response[:marker].blank?
98
+ end
99
+ last_response
100
+ end
101
+
102
+ #-----------------------------------------------------------------
103
+ # API Calls:
104
+ #-----------------------------------------------------------------
105
+
106
+ # --------------------------------------------
107
+ # DB Instances
108
+ # --------------------------------------------
109
+
110
+ # List DB instances.
111
+ #
112
+ # Optional params: +:aws_id+, +:max_records+, +:marker+
113
+ #
114
+ # # Get a list of DB instances. The response is an +Array+ of instances.
115
+ # rds.describe_db_instances #=>
116
+ # [{:instance_class=>"Medium",
117
+ # :status=>"creating",
118
+ # :engine=>"MySQL5.1",
119
+ # :allocated_storage=>50,
120
+ # :pending_modified_values=>{},
121
+ # :db_parameter_group=>{:status=>"in-sync", :name=>"default.MySQL5.1"},
122
+ # :db_security_groups=>
123
+ # [{:status=>"active", :name=>"kd-2-test"},
124
+ # {:status=>"active", :name=>"default"},
125
+ # {:status=>"active", :name=>"kd-1-test"}],
126
+ # :availability_zone=>"us-east-1b",
127
+ # :master_username=>"username",
128
+ # :aws_id=>"kd-my-awesome-db-2",
129
+ # :preferred_maintenance_window=>"Sun:05:00-Sun:09:00"}]
130
+ #
131
+ # # Retrieve a custom DB instance.
132
+ # # The response is an +Array+ with a single instance record.
133
+ # rds.describe_db_instances("kd-test-n3")
134
+ #
135
+ # # Incrementally a list DB instances. Every response part is a +Hash+.
136
+ # rds.describe_db_instances(:max_records => 30) do |x|
137
+ # puts x.inspect #=>
138
+ # {:db_instances=>
139
+ # [{:instance_class=>"Medium",
140
+ # :status=>"creating",
141
+ # :engine=>"MySQL5.1",
142
+ # :allocated_storage=>50,
143
+ # :pending_modified_values=>{},
144
+ # :db_parameter_group=>{:status=>"in-sync", :name=>"default.MySQL5.1"},
145
+ # :db_security_groups=>
146
+ # [{:status=>"active", :name=>"kd-2-test"},
147
+ # {:status=>"active", :name=>"default"},
148
+ # {:status=>"active", :name=>"kd-1-test"}],
149
+ # :availability_zone=>"us-east-1b",
150
+ # :master_username=>"username",
151
+ # :aws_id=>"kd-my-awesome-db-2",
152
+ # :preferred_maintenance_window=>"Sun:05:00-Sun:09:00"}]}
153
+ # true
154
+ # end
155
+ #
156
+ def describe_db_instances(params={}, &block)
157
+ item, params = AwsUtils::split_items_and_params(params)
158
+ params = params.dup
159
+ params['DBInstanceIdentifier'] = item if item
160
+ result = []
161
+ incrementally_list_items('DescribeDBInstances', DescribeDbInstancesParser, params) do |response|
162
+ result += response[:db_instances]
163
+ block ? block.call(response) : true
164
+ end
165
+ result
166
+ end
167
+
168
+ # Create a new RDS instance of the type and size specified by you. The default storage engine for RDS Instances is InnoDB.
169
+ #
170
+ # Mandatory arguments: +aws_id+, +master_username+, +master_user_password+
171
+ # Optional params: +:allocated_storage+ (25 by def), +:instance_class+, +:engine+ ('MySQL5.1' by def),
172
+ # +:endpoint_port+, +:db_name+, +:db_security_groups+, +:db_parameter_group+, +:availability_zone+, +:preferred_maintenance_window+
173
+ # +:backup_retention_period+, +:preferred_backup_window+
174
+ #
175
+ # ds.create_db_instance('my-awesome-db', 'username', 'password') #=>
176
+ # {:instance_class=>"Medium",
177
+ # :status=>"creating",
178
+ # :engine=>"MySQL5.1",
179
+ # :allocated_storage=>50,
180
+ # :pending_modified_values=>{},
181
+ # :db_security_groups=>
182
+ # [{:status=>"active", :name=>"kd-2-test"},
183
+ # {:status=>"active", :name=>"default"},
184
+ # {:status=>"active", :name=>"kd-1-test"}],
185
+ # :availability_zone=>"us-east-1b",
186
+ # :master_username=>"username",
187
+ # :aws_id=>"kd-my-awesome-db-2",
188
+ # :preferred_maintenance_window=>"Sun:05:00-Sun:09:00"}
189
+ #
190
+ def create_db_instance(aws_id, master_username, master_user_password, params={})
191
+ request_hash = {}
192
+ # Mandatory
193
+ request_hash['DBInstanceIdentifier'] = aws_id
194
+ request_hash['MasterUsername'] = master_username
195
+ request_hash['MasterUserPassword'] = master_user_password
196
+ # Mandatory with default values
197
+ request_hash['DBInstanceClass'] = params[:instance_class].blank? ? DEFAULT_INSTANCE_CLASS : params[:instance_class].to_s
198
+ request_hash['AllocatedStorage'] = params[:allocated_storage].blank? ? 25 : params[:allocated_storage]
199
+ request_hash['Engine'] = params[:engine].blank? ? 'MySQL5.1' : params[:engine]
200
+ # Optional
201
+ request_hash['EndpointPort'] = params[:endpoint_port] unless params[:endpoint_port].blank?
202
+ request_hash['DBName'] = params[:db_name] unless params[:db_name].blank?
203
+ request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].blank?
204
+ request_hash['PreferredMaintenanceWindow'] = params[:preferred_maintenance_window] unless params[:preferred_maintenance_window].blank?
205
+ request_hash['BackupRetentionPeriod'] = params[:backup_retention_period] unless params[:backup_retention_period].blank?
206
+ request_hash['PreferredBackupWindow'] = params[:preferred_backup_window] unless params[:preferred_backup_window].blank?
207
+ request_hash.merge!(amazonize_list('DBSecurityGroups.member', params[:db_security_groups]))
208
+ # request_hash.merge!(amazonize_list('DBParameterGroups.member', params[:db_parameter_groups]))
209
+ request_hash['DBParameterGroup'] = params[:db_parameter_group] unless params[:db_parameter_group].blank?
210
+ link = generate_request('CreateDBInstance', request_hash)
211
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
212
+ end
213
+
214
+ # Modify a DB instance.
215
+ #
216
+ # Mandatory arguments: +aws_id+.
217
+ # Optional params: +:master_user_password+, +:instance_class+, +:db_security_groups+,
218
+ # +:db_parameter_group+, +:preferred_maintenance_window+, +:allocated_storage+, +:apply_immediately+,
219
+ # +:backup_retention_period+, +:preferred_backup_window+
220
+ #
221
+ def modify_db_instance(aws_id, params={})
222
+ request_hash = {}
223
+ # Mandatory
224
+ request_hash['DBInstanceIdentifier'] = aws_id
225
+ # Optional
226
+ request_hash['MasterUserPassword'] = params[:master_user_password] unless params[:master_user_password].blank?
227
+ request_hash['DBInstanceClass'] = params[:instance_class].to_s.capitalize unless params[:instance_class].blank?
228
+ request_hash['PreferredMaintenanceWindow'] = params[:preferred_maintenance_window] unless params[:preferred_maintenance_window].blank?
229
+ request_hash['BackupRetentionPeriod'] = params[:backup_retention_period] unless params[:backup_retention_period].blank?
230
+ request_hash['PreferredBackupWindow'] = params[:preferred_backup_window] unless params[:preferred_backup_window].blank?
231
+ request_hash['AllocatedStorage'] = params[:allocated_storage] unless params[:allocated_storage].blank?
232
+ request_hash['ApplyImmediately'] = params[:apply_immediately].to_s unless params[:apply_immediately].blank?
233
+ request_hash.merge!(amazonize_list('DBSecurityGroups.member', params[:db_security_groups]))
234
+ # request_hash.merge!(amazonize_list('DBParameterGroups.member', params[:db_parameter_groups]))
235
+ request_hash['DBParameterGroupName'] = params[:db_parameter_group] unless params[:db_parameter_group].blank?
236
+ link = generate_request('ModifyDBInstance', request_hash)
237
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
238
+ end
239
+
240
+ # Reboot Db instance.
241
+ #
242
+ # rds.reboot_db_instance('kd-my-awesome-db') #=>
243
+ # {:status=>"rebooting",
244
+ # :pending_modified_values=>{},
245
+ # :allocated_storage=>42,
246
+ # :master_username=>"kd",
247
+ # :db_security_groups=>[],
248
+ # :instance_class=>"Medium",
249
+ # :availability_zone=>"us-east-1a",
250
+ # :aws_id=>"kd-my-awesome-db",
251
+ # :create_time=>"2009-08-28T08:34:21.858Z",
252
+ # :engine=>"MySQL5.1",
253
+ # :preferred_maintenance_window=>"Sun:05:00-Sun:09:00"}
254
+ #
255
+ def reboot_db_instance(aws_id, params={})
256
+ params = params.dup
257
+ params['DBInstanceIdentifier'] = aws_id
258
+ link = generate_request('RebootDBInstance', params)
259
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
260
+ end
261
+
262
+ # Delete a DB instance
263
+ #
264
+ # Mandatory arguments: aws_id
265
+ # Optional params: :skip_final_snapshot ('false' by def),
266
+ # :snapshot_aws_id ('{instance_aws_id}-final-snapshot-YYYYMMDDHHMMSS')
267
+ #
268
+ # rds.delete_db_instance('my-awesome-db-g2') #=> true
269
+ #
270
+ def delete_db_instance(aws_id, params={})
271
+ request_hash = {}
272
+ request_hash['DBInstanceIdentifier'] = aws_id
273
+ request_hash['SkipFinalSnapshot'] = params.has_key?(:skip_final_snapshot) ? params[:skip_final_snapshot].to_s : 'false'
274
+ if request_hash['SkipFinalSnapshot'] == 'false' && params[:snapshot_aws_id].blank?
275
+ params = params.dup
276
+ params[:snapshot_aws_id] = "#{aws_id}-final-snapshot-#{Time.now.utc.strftime('%Y%m%d%H%M%S')}"
277
+ end
278
+ request_hash['FinalDBSnapshotIdentifier'] = params[:snapshot_aws_id] unless params[:snapshot_aws_id].blank?
279
+ link = generate_request('DeleteDBInstance', request_hash)
280
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
281
+ end
282
+
283
+ # --------------------------------------------
284
+ # DB SecurityGroups
285
+ # --------------------------------------------
286
+ #
287
+ # rds.describe_db_security_groups #=>
288
+ # [{:owner_id=>"82...25",
289
+ # :description=>"Default",
290
+ # :ec2_security_groups=>[],
291
+ # :ip_ranges=>[],
292
+ # :name=>"Default"},
293
+ # {:owner_id=>"82...25",
294
+ # :description=>"kd",
295
+ # :ec2_security_groups=>[],
296
+ # :ip_ranges=>[],
297
+ # :name=>"kd2"},
298
+ # {:owner_id=>"82...25",
299
+ # :description=>"kd",
300
+ # :ec2_security_groups=>
301
+ # [{:status=>"Authorized", :owner_id=>"82...23", :name=>"default"},
302
+ # {:status=>"Authorized", :owner_id=>"82...24", :name=>"default1"},
303
+ # {:status=>"Authorized", :owner_id=>"82...25", :name=>"default"},
304
+ # {:status=>"Authorized", :owner_id=>"82...26", :name=>"default"},
305
+ # {:status=>"Authorized", :owner_id=>"82...26", :name=>"default1"},
306
+ # {:status=>"Authorized", :owner_id=>"82...29", :name=>"default22"}],
307
+ # :ip_ranges=>
308
+ # [{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
309
+ # {:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
310
+ # {:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
311
+ # {:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
312
+ # {:status=>"Authorized", :cidrip=>"131.0.0.1/8"}],
313
+ # :name=>"kd3"}]
314
+ #
315
+ # # get a custom group
316
+ # rds.describe_db_security_groups('kd3')
317
+ #
318
+ def describe_db_security_groups(*db_security_group_name, &block)
319
+ item, params = AwsUtils::split_items_and_params(db_security_group_name)
320
+ params['DBSecurityGroupName'] = item if item
321
+ result = []
322
+ incrementally_list_items('DescribeDBSecurityGroups', DescribeDbSecurityGroupsParser, params) do |response|
323
+ result += response[:db_security_groups]
324
+ block ? block.call(response) : true
325
+ end
326
+ result
327
+ end
328
+
329
+ # Create a database security group so that ingress to an RDS Instance can be controlled.
330
+ # A new security group cannot have the same name as an existing group.
331
+ #
332
+ # ds.create_db_security_group('kd3', 'kd') #=>
333
+ # {:ec2_security_groups=>[],
334
+ # :description=>"kd",
335
+ # :ip_ranges=>[],
336
+ # :name=>"kd3",
337
+ # :owner_id=>"82...25"}
338
+ #
339
+ def create_db_security_group(db_security_group_name, db_security_group_description)
340
+ link = generate_request('CreateDBSecurityGroup', 'DBSecurityGroupName' => db_security_group_name,
341
+ 'DBSecurityGroupDescription' => db_security_group_description)
342
+ request_info(link, DescribeDbSecurityGroupsParser.new(:logger => @logger))[:db_security_groups].first
343
+ end
344
+
345
+ def modify_db_security_group_ingress(action, db_security_group_name, params={}) # :nodoc:
346
+ request_hash = { 'DBSecurityGroupName' => db_security_group_name}
347
+ request_hash['CIDRIP'] = params[:cidrip] unless params[:cidrip].blank?
348
+ request_hash['EC2SecurityGroupName'] = params[:ec2_security_group_name] unless params[:ec2_security_group_name].blank?
349
+ request_hash['EC2SecurityGroupOwnerId'] = params[:ec2_security_group_owner] unless params[:ec2_security_group_owner].blank?
350
+ link = generate_request(action, request_hash)
351
+ request_info(link, DescribeDbSecurityGroupsParser.new(:logger => @logger))[:db_security_groups].first
352
+ end
353
+
354
+ # Authorize an ingress. Params: +:cidrip+ or (+:ec2_security_group_name+ and +:ec2_security_group_owner+)
355
+ #
356
+ # rds.authorize_db_security_group_ingress('kd3', :cidrip => '131.0.0.1/8')
357
+ # {:owner_id=>"82...25",
358
+ # :ec2_security_groups=>[],
359
+ # :description=>"kd",
360
+ # :ip_ranges=>
361
+ # [{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
362
+ # {:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
363
+ # {:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
364
+ # {:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
365
+ # {:status=>"Authorizing", :cidrip=>"131.0.0.1/8"}],
366
+ # :name=>"kd3"}
367
+ #
368
+ # rds.authorize_db_security_group_ingress('kd3',:ec2_security_group_owner => '82...27',
369
+ # :ec2_security_group_name => 'default') #=>
370
+ # {:owner_id=>"82...25",
371
+ # :ec2_security_groups=>
372
+ # [{:status=>"Authorized", :owner_id=>"82...25", :name=>"g1"},
373
+ # {:status=>"Authorized", :owner_id=>"82...26", :name=>"g2"},
374
+ # {:status=>"Authorizing", :owner_id=>"82...27", :name=>"default"}],
375
+ # :ip_ranges=>
376
+ # [{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
377
+ # {:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
378
+ # {:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
379
+ # {:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
380
+ # {:status=>"Authorized", :cidrip=>"131.0.0.1/8"}],
381
+ # :name=>"kd3"}
382
+ #
383
+ def authorize_db_security_group_ingress(db_security_group_name, params={})
384
+ modify_db_security_group_ingress('AuthorizeDBSecurityGroupIngress', db_security_group_name, params)
385
+ end
386
+
387
+ # Revoke an ingress.
388
+ # Optional params: +:cidrip+ or (+:ec2_security_group_name+ and +:ec2_security_group_owner+)
389
+ #
390
+ # rds.revoke_db_security_group_ingress('kd3', :ec2_security_group_owner => '82...25',
391
+ # :ec2_security_group_name => 'default') #=>
392
+ # {:owner_id=>"82...25",
393
+ # :ec2_security_groups=>
394
+ # [{:status=>"Revoking", :owner_id=>"826693181925", :name=>"default"}],
395
+ # :name=>"kd3",
396
+ # :description=>"kd",
397
+ # :ip_ranges=>
398
+ # [{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
399
+ # {:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
400
+ # {:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
401
+ # {:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
402
+ # {:status=>"Authorized", :cidrip=>"131.0.0.1/8"}]}
403
+ #
404
+ def revoke_db_security_group_ingress(db_security_group_name, params={})
405
+ modify_db_security_group_ingress('RevokeDBSecurityGroupIngress', db_security_group_name, params)
406
+ end
407
+
408
+ # Delete a database security group. Database security group must not be associated with any
409
+ # RDS Instances.
410
+ #
411
+ # rds.delete_db_security_group('kd3') #=> true
412
+ #
413
+ def delete_db_security_group(db_security_group_name)
414
+ link = generate_request('DeleteDBSecurityGroup', 'DBSecurityGroupName' => db_security_group_name)
415
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
416
+ end
417
+
418
+ # --------------------------------------------
419
+ # DB ParameterGroups
420
+ # --------------------------------------------
421
+
422
+ # Describe DBParameterGroups.
423
+ #
424
+ # rds.describe_db_parameter_groups #=>
425
+ # [{:engine=>"MySQL5.1",
426
+ # :description=>"Default parameter group for MySQL5.1",
427
+ # :name=>"default.MySQL5.1"}]
428
+ #
429
+ # # List parameter groups by 20
430
+ # rds.describe_db_parameter_groups(:max_records=>20) do |response|
431
+ # puts response.inspect
432
+ # true
433
+ # end
434
+ #
435
+ def describe_db_parameter_groups(*db_parameter_group_name, &block)
436
+ item, params = AwsUtils::split_items_and_params(db_parameter_group_name)
437
+ params['DBParameterGroupName'] = item if item
438
+ result = []
439
+ incrementally_list_items('DescribeDBParameterGroups', DescribeDbParameterGroupsParser, params) do |response|
440
+ result += response[:db_parameter_groups]
441
+ block ? block.call(response) : true
442
+ end
443
+ result
444
+ end
445
+
446
+ # Creates a database parameter group so that configuration of an RDS Instance can be controlled.
447
+ #
448
+ # rds.create_db_parameter_group('my-new-group-1','My new group') #=> {}
449
+ #
450
+ # TODO: this call returns an empty hash, but should be a parameter group data - ask Amazon guys.
451
+ #
452
+ def create_db_parameter_group(db_parameter_group_name, db_parameter_group_description, engine='MySQL5.1', params={})
453
+ params['DBParameterGroupName'] = db_parameter_group_name
454
+ params['Description'] = db_parameter_group_description
455
+ params['Engine'] = engine
456
+ link = generate_request('CreateDBParameterGroup', params )
457
+ request_info(link, DescribeDbParameterGroupsParser.new(:logger => @logger))[:db_parameter_groups].first
458
+ end
459
+
460
+
461
+ # Modify DBParameterGroup paramaters. Up to 20 params can be midified at once.
462
+ #
463
+ # rds.modify_db_parameter_group('kd1', 'max_allowed_packet' => 2048) #=> true
464
+ #
465
+ # rds.modify_db_parameter_group('kd1', 'max_allowed_packet' => {:value => 2048, :method => 'immediate') #=> true
466
+ #
467
+ def modify_db_parameter_group(db_parameter_group_name, params={}) # :nodoc:
468
+ request_hash = { 'DBParameterGroupName' => db_parameter_group_name}
469
+ parameters = []
470
+ params.each do |key, value|
471
+ method = 'pending-reboot'
472
+ if value.is_a?(Hash)
473
+ method = value[:method] unless value[:method].blank?
474
+ value = value[:value]
475
+ end
476
+ parameters << [key, value, method]
477
+ end
478
+ request_hash.merge!( amazonize_list(['Parameters.member.?.ParameterName',
479
+ 'Parameters.member.?.ParameterValue',
480
+ 'Parameters.member.?.ApplyMethod'],
481
+ parameters ))
482
+ link = generate_request('ModifyDBParameterGroup', request_hash)
483
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
484
+ end
485
+
486
+ # Delete DBParameter Group.
487
+ #
488
+ # rds.delete_db_parameter_group('kd1') #=> true
489
+ #
490
+ def delete_db_parameter_group(db_parameter_group_name)
491
+ link = generate_request('DeleteDBParameterGroup', 'DBParameterGroupName' => db_parameter_group_name)
492
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
493
+ end
494
+
495
+ # Modify the parameters of a DBParameterGroup to the engine/system default value.
496
+ #
497
+ # # Reset all parameters
498
+ # rds.reset_db_parameter_group('kd2', :all ) #=> true
499
+ #
500
+ # # Reset custom parameters
501
+ # rds.reset_db_parameter_group('kd2', 'max_allowed_packet', 'auto_increment_increment' ) #=> true
502
+ # rds.reset_db_parameter_group('kd2', 'max_allowed_packet', 'auto_increment_increment' => 'immediate' ) #=> true
503
+ #
504
+ def reset_db_parameter_group(db_parameter_group_name, *params)
505
+ params = params.flatten
506
+ request_hash = { 'DBParameterGroupName' => db_parameter_group_name }
507
+ if params.first.to_s == 'all'
508
+ request_hash['ResetAllParameters'] = true
509
+ else
510
+ tmp = []
511
+ params.each{ |item| tmp |= item.to_a }
512
+ params = []
513
+ tmp.each do |key, method|
514
+ method = 'pending-reboot' unless method
515
+ params << [key, method]
516
+ end
517
+ request_hash.merge!( amazonize_list(['Parameters.member.?.ParameterName',
518
+ 'Parameters.member.?.ApplyMethod'],
519
+ params ))
520
+ end
521
+ link = generate_request('ResetDBParameterGroup', request_hash)
522
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
523
+ end
524
+
525
+ # Get the detailed parameters list for a particular DBParameterGroup.
526
+ #
527
+ # rds.describe_db_parameters('kd1') #=>
528
+ # [{:is_modifiable=>true,
529
+ # :apply_type=>"static",
530
+ # :source=>"engine-default",
531
+ # :allowed_values=>"ON,OFF",
532
+ # :description=>"Controls whether user-defined functions that have only an xxx symbol for the main function can be loaded",
533
+ # :name=>"allow-suspicious-udfs",
534
+ # :data_type=>"boolean"},
535
+ # {:is_modifiable=>true,
536
+ # :apply_type=>"dynamic",
537
+ # :source=>"engine-default",
538
+ # :allowed_values=>"1-65535",
539
+ # :description=>"Intended for use with master-to-master replication, and can be used to control the operation of AUTO_INCREMENT columns",
540
+ # :name=>"auto_increment_increment",
541
+ # :data_type=>"integer"}, ... ]
542
+ #
543
+ # # List parameters by 20
544
+ # rds.describe_db_parameters('kd1', :max_records=>20) do |response|
545
+ # puts response.inspect
546
+ # true
547
+ # end
548
+ #
549
+ def describe_db_parameters(*db_parameter_group_name, &block)
550
+ item, params = AwsUtils::split_items_and_params(db_parameter_group_name)
551
+ params['DBParameterGroupName'] = item
552
+ result = []
553
+ incrementally_list_items('DescribeDBParameters', DescribeDbParametersParser, params) do |response|
554
+ result += response[:parameters]
555
+ block ? block.call(response) : true
556
+ end
557
+ result
558
+ end
559
+
560
+ # Describe a default parameters for the engine.
561
+ #
562
+ # rds.describe_engine_default_parameters('MySQL5.1') #=>
563
+ # [{:is_modifiable=>true,
564
+ # :apply_type=>"static",
565
+ # :source=>"engine-default",
566
+ # :allowed_values=>"ON,OFF",
567
+ # :description=>"Controls whether user-defined functions that have only an xxx symbol for the main function can be loaded",
568
+ # :name=>"allow-suspicious-udfs",
569
+ # :data_type=>"boolean"},
570
+ # {:is_modifiable=>true,
571
+ # :apply_type=>"dynamic",
572
+ # :source=>"engine-default",
573
+ # :allowed_values=>"1-65535",
574
+ # :description=>"Intended for use with master-to-master replication, and can be used to control the operation of AUTO_INCREMENT columns",
575
+ # :name=>"auto_increment_increment",
576
+ # :data_type=>"integer"}, ... ]
577
+ #
578
+ def describe_engine_default_parameters(*engine, &block)
579
+ engine = ['MySQL5.1'] if engine.blank?
580
+ item, params = AwsUtils::split_items_and_params(engine)
581
+ params['Engine'] = item if item
582
+ result = []
583
+ incrementally_list_items('DescribeEngineDefaultParameters', DescribeDbParametersParser, params) do |response|
584
+ result += response[:parameters]
585
+ block ? block.call(response) : true
586
+ end
587
+ result
588
+ end
589
+
590
+ # --------------------------------------------
591
+ # DB Snapshots
592
+ # --------------------------------------------
593
+
594
+ # Get DBSecurityGroup details for a particular customer or for a particular DBSecurityGroup if a name is specified.
595
+ # Optional params: +:instance_aws_id+
596
+ #
597
+ # # all snapshots
598
+ # rds.describe_db_snapshots #=>
599
+ # [{:status=>"Available",
600
+ # :instance_aws_id=>"kd-test-n1",
601
+ # :allocated_storage=>25,
602
+ # :availability_zone=>"us-east-1b",
603
+ # :aws_id=>"kd-test-n1-final-snapshot-at-20090630131215",
604
+ # :engine=>"MySQL5.1",
605
+ # :endpoint_port=>3306,
606
+ # :instance_create_time=>"2009-06-30T12:48:15.590Z",
607
+ # :master_username=>"payless",
608
+ # :snapshot_time=>"2009-06-30T13:16:48.496Z"}, ...]
609
+ #
610
+ # # all snapshots for a custom instance
611
+ # rds.describe_db_snapshots(:instance_aws_id => 'kd-test-n3') #=>
612
+ # [{:status=>"Available",
613
+ # :instance_aws_id=>"kd-test-n3",
614
+ # :allocated_storage=>25,
615
+ # :availability_zone=>"us-east-1a",
616
+ # :aws_id=>"kd-test-n3-final-snapshot-20090713074916",
617
+ # :engine=>"MySQL5.1",
618
+ # :endpoint_port=>3306,
619
+ # :instance_create_time=>"2009-06-30T12:51:32.540Z",
620
+ # :master_username=>"payless",
621
+ # :snapshot_time=>"2009-07-13T07:52:35.542Z"}]
622
+ #
623
+ # # a snapshot by id
624
+ # rds.describe_db_snapshots('my-awesome-db-final-snapshot-20090713075554') #=>
625
+ # [{:status=>"Available",
626
+ # :allocated_storage=>25,
627
+ # :engine=>"MySQL5.1",
628
+ # :instance_aws_id=>"my-awesome-db",
629
+ # :availability_zone=>"us-east-1a",
630
+ # :instance_create_time=>"2009-07-13T07:53:08.912Z",
631
+ # :endpoint_port=>3306,
632
+ # :master_username=>"medium",
633
+ # :aws_id=>"my-awesome-db-final-snapshot-20090713075554",
634
+ # :snapshot_time=>"2009-07-13T07:59:17.537Z"}]
635
+ #
636
+ def describe_db_snapshots(params={}, &block)
637
+ item, params = AwsUtils::split_items_and_params(params)
638
+ params['DBSnapshotIdentifier'] = item if item
639
+ params['DBInstanceIdentifier'] = params.delete(:instance_aws_id) unless params[:instance_aws_id].blank?
640
+ result = []
641
+ incrementally_list_items('DescribeDBSnapshots', DescribeDbSnapshotsParser, params) do |response|
642
+ result += response[:db_snapshots]
643
+ block ? block.call(response) : true
644
+ end
645
+ result
646
+ end
647
+
648
+ # Create a DBSnapshot. The source DBInstance must be in Available state
649
+ #
650
+ # rds.create_db_snapshot('remove-me-tomorrow-2', 'my-awesome-db-g7' ) #=>
651
+ # {:status=>"PendingCreation",
652
+ # :allocated_storage=>50,
653
+ # :availability_zone=>"us-east-1b",
654
+ # :engine=>"MySQL5.1",
655
+ # :aws_id=>"remove-me-tomorrow-2",
656
+ # :instance_create_time=>"2009-07-13T09:35:39.243Z",
657
+ # :endpoint_port=>3306,
658
+ # :instance_aws_id=>"my-awesome-db-g7",
659
+ # :db_master_username=>"username"}
660
+ #
661
+ def create_db_snapshot(aws_id, instance_aws_id)
662
+ link = generate_request('CreateDBSnapshot', 'DBSnapshotIdentifier' => aws_id,
663
+ 'DBInstanceIdentifier' => instance_aws_id)
664
+ request_info(link, DescribeDbSnapshotsParser.new(:logger => @logger))[:db_snapshots].first
665
+ end
666
+
667
+ # Create a new RDS instance from a DBSnapshot. The source DBSnapshot must be
668
+ # in the "Available" state. The new RDS instance is created with the Default security group.
669
+ #
670
+ # Optional params: +:instance_class+, +:endpoint_port+, +:availability_zone+
671
+ #
672
+ # rds.restore_db_instance_from_db_snapshot('ahahahaha-final-snapshot-20090828081159', 'q1') #=>
673
+ # {:status=>"creating",
674
+ # :pending_modified_values=>{},
675
+ # :allocated_storage=>42,
676
+ # :db_security_groups=>[],
677
+ # :master_username=>"kd",
678
+ # :availability_zone=>"us-east-1a",
679
+ # :aws_id=>"q1",
680
+ # :create_time=>"2009-08-29T18:07:01.510Z",
681
+ # :instance_class=>"Medium",
682
+ # :preferred_maintenance_window=>"Sun:05:00-Sun:09:00",
683
+ # :engine=>"MySQL5.1"}
684
+ #
685
+ def restore_db_instance_from_db_snapshot(snapshot_aws_id, instance_aws_id, params={})
686
+ request_hash = { 'DBSnapshotIdentifier' => snapshot_aws_id,
687
+ 'DBInstanceIdentifier' => instance_aws_id }
688
+ request_hash['DBInstanceClass'] = params[:instance_class] unless params[:instance_class].blank?
689
+ request_hash['EndpointPort'] = params[:endpoint_port] unless params[:endpoint_port].blank?
690
+ request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].blank?
691
+ link = generate_request('RestoreDBInstanceFromDBSnapshot', request_hash)
692
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
693
+ end
694
+
695
+ # Create a new RDS instance from a point-in-time system snapshot. The target
696
+ # database is created from the source database restore point with the same configuration as
697
+ # the original source database, except that the new RDS instance is created with the default
698
+ # security group.
699
+ def restore_db_instance_to_point_in_time(instance_aws_id, new_instance_aws_id, restore_time)
700
+ request_hash = { 'SourceDBInstanceIdentifier' => instance_aws_id,
701
+ 'TargetDBInstanceIdentifier' => new_instance_aws_id,
702
+ 'RestoreTime' => restore_time}
703
+ link = generate_request('RestoreDBInstanceToPointInTime', request_hash)
704
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
705
+ end
706
+
707
+ # Delete a DBSnapshot. The DBSnapshot must be in the Available state to be deleted.
708
+ #
709
+ # rds.delete_db_snapshot('remove-me-tomorrow-1') #=>
710
+ # {:status=>"Deleted",
711
+ # :allocated_storage=>50,
712
+ # :instance_create_time=>"2009-07-13T09:27:01.053Z",
713
+ # :availability_zone=>"us-east-1a",
714
+ # :db_master_username=>"username",
715
+ # :aws_id=>"remove-me-tomorrow-1",
716
+ # :snapshot_time=>"2009-07-13T10:59:30.227Z",
717
+ # :endpoint_port=>3306,
718
+ # :instance_aws_id=>"my-awesome-db-g5",
719
+ # :engine=>"MySQL5.1"}
720
+ #
721
+ def delete_db_snapshot(aws_id)
722
+ link = generate_request('DeleteDBSnapshot', 'DBSnapshotIdentifier' => aws_id)
723
+ request_info(link, DescribeDbSnapshotsParser.new(:logger => @logger))[:db_snapshots].first
724
+ end
725
+
726
+ # --------------------------------------------
727
+ # DB Events
728
+ # --------------------------------------------
729
+
730
+ # Get events related to RDS instances and DBSecurityGroups for the past 14 days.
731
+ # Optional params: +:duration+, +:start_time+, +:end_time+, +:aws_id+,
732
+ # +:source_type+('db-instance', 'db-security-group', 'db-snapshot', 'db-parameter-group')
733
+ #
734
+ # # get all enevts
735
+ # rds.describe_events #=>
736
+ # [{:aws_id=>"my-awesome-db-g4",
737
+ # :source_type=>"DBInstance",
738
+ # :message=>"Started user snapshot for database instance:my-awesome-db-g4",
739
+ # :date=>"2009-07-13T10:54:13.661Z"},
740
+ # {:aws_id=>"my-awesome-db-g5",
741
+ # :source_type=>"DBInstance",
742
+ # :message=>"Started user snapshot for database instance:my-awesome-db-g5",
743
+ # :date=>"2009-07-13T10:55:13.674Z"},
744
+ # {:aws_id=>"my-awesome-db-g7",
745
+ # :source_type=>"DBInstance",
746
+ # :message=>"Started user snapshot for database instance:my-awesome-db-g7",
747
+ # :date=>"2009-07-13T10:56:34.226Z"}]
748
+ #
749
+ # # get all events since yesterday
750
+ # rds.describe_events(:start_date => 1.day.ago)
751
+ #
752
+ # # get last 60 min events
753
+ # rds.describe_events(:duration => 60)
754
+ #
755
+ def describe_events(params={}, &block)
756
+ params = params.dup
757
+ params['SourceIdentifier'] = params.delete(:aws_id) unless params[:aws_id].blank?
758
+ params['SourceType'] = params.delete(:source_type) unless params[:source_type].blank?
759
+ params['Duration'] = params.delete(:duration) unless params[:duration].blank?
760
+ params['StartDate'] = fix_date(params.delete(:start_date)) unless params[:start_date].blank?
761
+ params['EndDate'] = fix_date(params.delete(:end_date)) unless params[:end_date].blank?
762
+ result = []
763
+ incrementally_list_items('DescribeEvents', DescribeEventsParser, params) do |response|
764
+ result += response[:events]
765
+ block ? block.call(response) : true
766
+ end
767
+ result
768
+ end
769
+
770
+ def fix_date(date) # :nodoc:
771
+ date = Time.at(date) if date.is_a?(Fixnum)
772
+ date = date.utc.strftime('%Y-%m-%dT%H:%M:%SZ') if date.is_a?(Time)
773
+ date
774
+ end
775
+
776
+ # --------------------------------------------
777
+ # Parsers
778
+ # --------------------------------------------
779
+
780
+ # --------------------------------------------
781
+ # DB Instances
782
+ # --------------------------------------------
783
+
784
+ class DescribeDbInstancesParser < RightAWSParser # :nodoc:
785
+ def reset
786
+ @m = [ 'DBInstance',
787
+ 'CreateDBInstanceResult',
788
+ 'DeleteDBInstanceResult',
789
+ 'ModifyDBInstanceResult',
790
+ 'RebootDBInstanceResult',
791
+ 'RestoreDBInstanceToPointInTimeResponse',
792
+ 'RestoreDBInstanceFromDBSnapshotResult' ]
793
+ @result = { :db_instances => [] }
794
+ end
795
+ def tagstart(name, attributes)
796
+ case name
797
+ when *@m then @db_instance = { :db_security_groups => [],
798
+ :pending_modified_values => {} }
799
+ when 'DBSecurityGroup' then @db_security_group = {}
800
+ when 'DBParameterGroup', 'DBParameterGroupStatus' then @db_parameter_group = {}
801
+ end
802
+ end
803
+ def tagend(name)
804
+ case name
805
+ when 'Marker' then @result[:marker] = @text
806
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
807
+ when 'DBInstanceIdentifier' then @db_instance[:aws_id] = @text
808
+ when 'DBName' then @db_instance[:name] = @text # ? is this one used?
809
+ when 'InstanceCreateTime' then @db_instance[:create_time] = @text
810
+ when 'Engine' then @db_instance[:engine] = @text
811
+ when 'DBInstanceStatus' then @db_instance[:status] = @text
812
+ when 'AllocatedStorage' then @db_instance[:allocated_storage] = @text.to_i
813
+ when 'Port' then @db_instance[:endpoint_port] = @text.to_i
814
+ when 'Address' then @db_instance[:endpoint_address] = @text
815
+ when 'MasterUsername' then @db_instance[:master_username] = @text
816
+ when 'AvailabilityZone' then @db_instance[:availability_zone] = @text
817
+ when 'PreferredMaintenanceWindow' then @db_instance[:preferred_maintenance_window] = @text
818
+ when 'BackupRetentionPeriod' then @db_instance[:backup_retention_period] = @text
819
+ when 'PreferredBackupWindow' then @db_instance[:preferred_backup_window] = @text
820
+ when 'DBInstanceClass'
821
+ case @xmlpath
822
+ when /PendingModifiedValues$/ then @db_instance[:pending_modified_values][:instance_class] = @text
823
+ else @db_instance[:instance_class] = @text
824
+ end
825
+ when 'MasterUserPassword' then @db_instance[:pending_modified_values][:master_user_password] = @text
826
+ when 'DBSecurityGroupName' then @db_security_group[:name] = @text
827
+ when 'Status' then @db_security_group[:status] = @text
828
+ when 'DBParameterGroupName' then @db_parameter_group[:name] = @text
829
+ when 'ParameterApplyStatus' then @db_parameter_group[:status] = @text
830
+ when 'DBSecurityGroup' then @db_instance[:db_security_groups] << @db_security_group
831
+ when 'DBParameterGroup','DBParameterGroupStatus'
832
+ @db_instance[:db_parameter_group] = @db_parameter_group
833
+ when *@m then @result[:db_instances] << @db_instance
834
+ end
835
+ end
836
+ end
837
+
838
+ # --------------------------------------------
839
+ # DB Security Groups
840
+ # --------------------------------------------
841
+
842
+ class DescribeDbSecurityGroupsParser < RightAWSParser # :nodoc:
843
+ def reset
844
+ @m = [ 'DBSecurityGroup',
845
+ 'CreateDBSecurityGroupResult',
846
+ 'AuthorizeDBSecurityGroupIngressResult',
847
+ 'RevokeDBSecurityGroupIngressResult' ]
848
+ @result = { :db_security_groups => [] }
849
+ end
850
+ def tagstart(name, attributes)
851
+ case name
852
+ when *@m then @item = { :ec2_security_groups => [], :ip_ranges => [] }
853
+ when 'IPRange' then @ip_range = {}
854
+ when 'EC2SecurityGroup' then @ec2_security_group = {}
855
+ end
856
+ end
857
+ def tagend(name)
858
+ case name
859
+ when 'Marker' then @result[:marker] = @text
860
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
861
+ when 'DBSecurityGroupDescription' then @item[:description] = @text
862
+ when 'OwnerId' then @item[:owner_id] = @text
863
+ when 'DBSecurityGroupName' then @item[:name] = @text
864
+ when 'Status'
865
+ case @xmlpath
866
+ when /IPRange$/ then @ip_range[:status] = @text
867
+ when /EC2SecurityGroup$/ then @ec2_security_group[:status] = @text
868
+ end
869
+ when 'EC2SecurityGroupName' then @ec2_security_group[:name] = @text
870
+ when 'EC2SecurityGroupOwnerId' then @ec2_security_group[:owner_id] = @text
871
+ when 'CIDRIP' then @ip_range[:cidrip] = @text
872
+ when 'IPRange' then @item[:ip_ranges] << @ip_range
873
+ when 'EC2SecurityGroup' then @item[:ec2_security_groups] << @ec2_security_group
874
+ when *@m
875
+ # Sort the ip_ranges and ec2_security_groups
876
+ @item[:ip_ranges].sort!{ |i1,i2| "#{i1[:cidrip]}" <=> "#{i2[:cidrip]}" }
877
+ @item[:ec2_security_groups].sort!{ |i1,i2| "#{i1[:owner_id]}#{i1[:name]}" <=> "#{i2[:owner_id]}#{i2[:name]}" }
878
+ @result[:db_security_groups] << @item
879
+ end
880
+ end
881
+ end
882
+
883
+ # --------------------------------------------
884
+ # DB Security Groups
885
+ # --------------------------------------------
886
+
887
+ class DescribeDbParameterGroupsParser < RightAWSParser # :nodoc:
888
+ def reset
889
+ @m = [ 'DBParameterGroup', 'CreateDBParameterGroupResult', 'ModifyDBParameterGroupResult' ]
890
+ @result = { :db_parameter_groups => [] }
891
+ end
892
+ def tagstart(name, attributes)
893
+ case name
894
+ when *@m then @item = { }
895
+ end
896
+ end
897
+ def tagend(name)
898
+ case name
899
+ when 'Marker' then @result[:marker] = @text
900
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
901
+ when 'DBParameterGroupName' then @item[:name] = @text
902
+ when 'Description' then @item[:description] = @text
903
+ when 'Engine' then @item[:engine] = @text
904
+ when *@m then @result[:db_parameter_groups] << @item
905
+ end
906
+ end
907
+ end
908
+
909
+ class DescribeDbParametersParser < RightAWSParser # :nodoc:
910
+ def reset
911
+ @result = { :parameters => [] }
912
+ end
913
+ def tagstart(name, attributes)
914
+ case name
915
+ when 'Parameter' then @item = {}
916
+ end
917
+ end
918
+ def tagend(name)
919
+ case name
920
+ when 'Marker' then @result[:marker] = @text
921
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
922
+ when 'DBParameterGroupName' then @result[:group_name] = @text # DescribeDbParametersResponse
923
+ when 'Engine' then @result[:engine] = @text # DescribeDBEngineDefaultParametersResponse
924
+ when 'DataType' then @item[:data_type] = @text
925
+ when 'Source' then @item[:source] = @text
926
+ when 'Description' then @item[:description] = @text
927
+ when 'IsModifiable' then @item[:is_modifiable] = @text[/true/] ? true : false
928
+ when 'ApplyType' then @item[:apply_type] = @text
929
+ when 'AllowedValues' then @item[:allowed_values] = @text
930
+ when 'ParameterName' then @item[:name] = @text
931
+ when 'ParameterValue' then @item[:value] = @text
932
+ when 'Parameter' then @result[:parameters] << @item
933
+ end
934
+ end
935
+ end
936
+
937
+ # --------------------------------------------
938
+ # DB Snapshots
939
+ # --------------------------------------------
940
+
941
+ class DescribeDbSnapshotsParser < RightAWSParser # :nodoc:
942
+ def reset
943
+ @m = ['DBSnapshot', 'CreateDBSnapshotResult', 'DeleteDBSnapshotResult']
944
+ @result = { :db_snapshots => [] }
945
+ end
946
+ def tagstart(name, attributes)
947
+ case name
948
+ when *@m
949
+ @db_snapshot = {}
950
+ end
951
+ end
952
+ def tagend(name)
953
+ case name
954
+ when 'Marker' then @result[:marker] = @text
955
+ when 'MaxRecords' then @result[:max_records] = @text.to_i # ?
956
+ when 'Engine' then @db_snapshot[:engine] = @text
957
+ when 'InstanceCreateTime' then @db_snapshot[:instance_create_time] = @text
958
+ when 'EndpointPort' then @db_snapshot[:endpoint_port] = @text.to_i
959
+ when 'Status' then @db_snapshot[:status] = @text
960
+ when 'AvailabilityZone' then @db_snapshot[:availability_zone] = @text
961
+ when 'MasterUsername' then @db_snapshot[:master_username] = @text
962
+ when 'AllocatedStorage' then @db_snapshot[:allocated_storage] = @text.to_i
963
+ when 'SnapshotCreateTime' then @db_snapshot[:create_time] = @text
964
+ when 'DBInstanceIdentifier' then @db_snapshot[:instance_aws_id] = @text
965
+ when 'DBSnapshotIdentifier' then @db_snapshot[:aws_id] = @text
966
+ when *@m then @result[:db_snapshots] << @db_snapshot
967
+ end
968
+ end
969
+ end
970
+
971
+ # --------------------------------------------
972
+ # DB Events
973
+ # --------------------------------------------
974
+
975
+ class DescribeEventsParser < RightAWSParser # :nodoc:
976
+ def reset
977
+ @result = { :events => [] }
978
+ end
979
+ def tagstart(name, attributes)
980
+ case name
981
+ when 'Event' then @event = {}
982
+ end
983
+ end
984
+ def tagend(name)
985
+ case name
986
+ when 'Marker' then @result[:marker] = @text
987
+ when 'MaxRecords' then @result[:max_records] = @text.to_i # ?
988
+ when 'Date' then @event[:date] = @text
989
+ when 'SourceIdentifier' then @event[:aws_id] = @text
990
+ when 'SourceType' then @event[:source_type] = @text
991
+ when 'Message' then @event[:message] = @text
992
+ when 'Event' then @result[:events] << @event
993
+ end
994
+ end
995
+ end
996
+
997
+ end
998
+ end