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,67 @@
1
+ module RightAws
2
+
3
+ class IamInterface < RightAwsBase
4
+
5
+ #-----------------------------------------------------------------
6
+ # MFADevices
7
+ #-----------------------------------------------------------------
8
+
9
+ # Lists the MFA devices associated with the specified User name.
10
+ #
11
+ # Options: :user_name, :max_items, :marker
12
+ #
13
+ def list_mfa_devices(options={}, &block)
14
+ incrementally_list_iam_resources('ListMFADevices', options, &block)
15
+ end
16
+
17
+ # Enables the specified MFA device and associates it with the specified User name.
18
+ # Once enabled, the MFA device is required for every subsequent login by the User name associated with the device.
19
+ #
20
+ # iam.enable_mfa_device('kd1', 'x12345', '12345', '67890') #=> true
21
+ #
22
+ def enable_mfa_device(user_name, serial_number, auth_code1, auth_code2)
23
+ request_hash = { 'UserName' => user_name,
24
+ 'SerialNumber' => serial_number,
25
+ 'AuthenticationCode1' => auth_code1,
26
+ 'AuthenticationCode2' => auth_code2 }
27
+ link = generate_request("EnableMFADevice", request_hash)
28
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
29
+ end
30
+
31
+ # Synchronizes the specified MFA device with AWS servers.
32
+ #
33
+ # iam.resync_mfa_device('kd1', 'x12345', '12345', '67890') #=> true
34
+ #
35
+ def resync_mfa_device(user_name, serial_number, auth_code1, auth_code2)
36
+ request_hash = { 'UserName' => user_name,
37
+ 'SerialNumber' => serial_number,
38
+ 'AuthenticationCode1' => auth_code1,
39
+ 'AuthenticationCode2' => auth_code2 }
40
+ link = generate_request("ResyncMFADevice", request_hash)
41
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
42
+ end
43
+
44
+ # Deactivates the specified MFA device and removes it from association with the User name for which it was originally enabled.
45
+ #
46
+ # deactivate_mfa_device('kd1', 'dev1234567890') #=> true
47
+ #
48
+ def deactivate_mfa_device(user_name, serial_number)
49
+ request_hash = { 'UserName' => user_name,
50
+ 'SerialNumber' => serial_number }
51
+ link = generate_request("DeactivateMFADevice", request_hash)
52
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
53
+ end
54
+
55
+ #-----------------------------------------------------------------
56
+ # PARSERS
57
+ #-----------------------------------------------------------------
58
+
59
+ class ListMFADevicesParser < BasicIamListParser #:nodoc:
60
+ def reset
61
+ @expected_tags = %w{ SerialNumber UserName }
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,251 @@
1
+ module RightAws
2
+
3
+ class IamInterface < RightAwsBase
4
+
5
+ #-----------------------------------------------------------------
6
+ # Users
7
+ #-----------------------------------------------------------------
8
+
9
+ # Lists the Users that have the specified path prefix.
10
+ #
11
+ # Options: :path_prefix, :max_items, :marker
12
+ #
13
+ # iam.list_users #=>
14
+ # [{:user_name=>"kd",
15
+ # :user_id=>"AI000000000000000006A",
16
+ # :arn=>"arn:aws:iam::640000000037:user/kd",
17
+ # :path=>"/"}]
18
+ #
19
+ def list_users(options={}, &block)
20
+ incrementally_list_iam_resources('ListUsers', options, &block)
21
+ end
22
+
23
+ # Creates a new User for your AWS Account.
24
+ #
25
+ # Options: :path
26
+ #
27
+ # iam.create_user('kd') #=>
28
+ # {:user_name=>"kd",
29
+ # :user_id=>"AI000000000000000006A",
30
+ # :arn=>"arn:aws:iam::640000000037:user/kd",
31
+ # :path=>"/"}
32
+ #
33
+ def create_user(user_name, options={})
34
+ request_hash = { 'UserName' => user_name }
35
+ request_hash['Path'] = options[:path] unless options[:path]
36
+ link = generate_request("CreateUser", request_hash)
37
+ request_info(link, GetUserParser.new(:logger => @logger))
38
+ end
39
+
40
+ # Updates the name and/or the path of the specified User.
41
+ #
42
+ # iam.update_user('kd1', :new_user_name => 'kd1', :new_path => '/kd1/') #=> true
43
+ #
44
+ def update_user(user_name, options={})
45
+ request_hash = { 'UserName' => user_name}
46
+ request_hash['NewUserName'] = options[:new_user_name] unless options[:new_user_name].right_blank?
47
+ request_hash['NewPath'] = options[:new_path] unless options[:new_path].right_blank?
48
+ link = generate_request("UpdateUser", request_hash)
49
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
50
+ end
51
+
52
+ # Retrieves information about the specified User, including the User's path, GUID, and ARN.
53
+ #
54
+ # iam.get_user('kd') #=>
55
+ # {:user_name=>"kd",
56
+ # :user_id=>"AI000000000000000006A",
57
+ # :arn=>"arn:aws:iam::640000000037:user/kd",
58
+ # :path=>"/"}
59
+ #
60
+ def get_user(user_name)
61
+ request_hash = { 'UserName' => user_name }
62
+ link = generate_request("GetUser", request_hash)
63
+ request_info(link, GetUserParser.new(:logger => @logger))
64
+ end
65
+
66
+ # Deletes the specified User. The User must not belong to any groups, have any keys or signing certificates, or have any attached policies.
67
+ #
68
+ # iam.delete_user('kd') #=> true
69
+ #
70
+ def delete_user(user_name)
71
+ request_hash = { 'UserName' => user_name }
72
+ link = generate_request("DeleteUser", request_hash)
73
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
74
+ end
75
+
76
+ #-----------------------------------------------------------------
77
+ # User Policies
78
+ #-----------------------------------------------------------------
79
+
80
+ # Lists the names of the policies associated with the specified User.
81
+ #
82
+ # Options: :max_items, :marker
83
+ #
84
+ # iam.list_user_policies('kd') #=> ["kd_user_policy_1"]
85
+ #
86
+ def list_user_policies(user_name, options={}, &block)
87
+ options[:user_name] = user_name
88
+ incrementally_list_iam_resources('ListUserPolicies', options, :parser => BasicIamListParser, &block)
89
+ end
90
+
91
+ # Adds (or updates) a policy document associated with the specified User
92
+ #
93
+ # iam.put_user_policy('kd', 'kd_user_policy_1', %Q({"Statement":[{"Effect":"Allow","Action":"*","Resource":"*"}]})) #=> true
94
+ #
95
+ def put_user_policy(user_name, policy_name, policy_document)
96
+ request_hash = { 'UserName' => user_name,
97
+ 'PolicyDocument' => policy_document,
98
+ 'PolicyName' => policy_name }
99
+ link = generate_request_impl(:post, "PutUserPolicy", request_hash)
100
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
101
+ end
102
+
103
+ # Retrieves the specified policy document for the specified User.
104
+ #
105
+ # iam.get_user_policy('kd','kd_user_policy_1') #=>
106
+ # {:user_name=>"kd",
107
+ # :policy_name=>"kd_user_policy_1",
108
+ # :policy_document=>"{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}]}"}
109
+ #
110
+ def get_user_policy(user_name, policy_name)
111
+ request_hash = { 'UserName' => user_name,
112
+ 'PolicyName' => policy_name }
113
+ link = generate_request("GetUserPolicy", request_hash)
114
+ result = request_info(link, GetUserPolicyParser.new(:logger => @logger))
115
+ result[:policy_document] = URI::decode(result[:policy_document])
116
+ result
117
+ end
118
+
119
+ # Deletes the specified policy associated with the specified User.
120
+ #
121
+ # iam.delete_user_policy('kd','kd_user_policy_1') #=> true
122
+ #
123
+ def delete_user_policy(user_name, policy_name)
124
+ request_hash = { 'UserName' => user_name,
125
+ 'PolicyName' => policy_name }
126
+ link = generate_request("DeleteUserPolicy", request_hash)
127
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
128
+ end
129
+
130
+ #-----------------------------------------------------------------
131
+ # User Groups
132
+ #-----------------------------------------------------------------
133
+
134
+ # Lists the names of the policies associated with the specified group. If there are none,
135
+ # the action returns an empty list.
136
+ #
137
+ # Options: :max_items, :marker
138
+ #
139
+ # iam.list_groups_for_user('kd') #=>
140
+ # [{:group_name=>"kd_test_1",
141
+ # :group_id=>"AGP000000000000000UTY",
142
+ # :arn=>"arn:aws:iam::640000000037:group/kd1/kd_test_1",
143
+ # :path=>"/kd1/"}]
144
+ #
145
+ def list_groups_for_user(user_name, options={}, &block)
146
+ options[:user_name] = user_name
147
+ incrementally_list_iam_resources('ListGroupsForUser', options, :parser => ListGroupsParser, &block)
148
+ end
149
+
150
+ # Adds the specified User to the specified group.
151
+ #
152
+ # iam.add_user_to_group('kd', 'kd_test_1') #=> true
153
+ #
154
+ def add_user_to_group(user_name, group_name)
155
+ request_hash = { 'UserName' => user_name,
156
+ 'GroupName' => group_name }
157
+ link = generate_request("AddUserToGroup", request_hash)
158
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
159
+ end
160
+
161
+ # Removes the specified User from the specified group.
162
+ #
163
+ # iam.remove_user_from_group('kd', 'kd_test_1') #=> true
164
+ #
165
+ def remove_user_from_group(user_name, group_name)
166
+ request_hash = { 'UserName' => user_name,
167
+ 'GroupName' => group_name }
168
+ link = generate_request("RemoveUserFromGroup", request_hash)
169
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
170
+ end
171
+
172
+ #-----------------------------------------------------------------
173
+ # User Login Profiles
174
+ #-----------------------------------------------------------------
175
+
176
+ # Creates a login profile for the specified User, giving the User the ability to access
177
+ # AWS services such as the AWS Management Console.
178
+ #
179
+ # iam.create_login_profile('kd','q1w2e3r4t5') #=> { :user_name => 'kd' }
180
+ #
181
+ def create_login_profile(user_name, password)
182
+ request_hash = { 'UserName' => user_name,
183
+ 'Password' => password}
184
+ link = generate_request("CreateLoginProfile", request_hash)
185
+ request_info(link, GetLoginProfileParser.new(:logger => @logger))
186
+ end
187
+
188
+ # Updates the login profile for the specified User. Use this API to change the User's password.
189
+ #
190
+ # update_login_profile('kd', '00000000') #=> true
191
+ #
192
+ def update_login_profile(user_name, options={})
193
+ request_hash = { 'UserName' => user_name}
194
+ request_hash['Password'] = options[:password] unless options[:passwrod].right_blank?
195
+ link = generate_request("UpdateLoginProfile", request_hash)
196
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
197
+ end
198
+
199
+ # Retrieves the login profile for the specified User
200
+ #
201
+ # iam.create_login_profile('kd','q1w2e3r4t5') #=> { :user_name => 'kd' }
202
+ #
203
+ def get_login_profile(user_name)
204
+ request_hash = { 'UserName' => user_name }
205
+ link = generate_request("GetLoginProfile", request_hash)
206
+ request_info(link, GetLoginProfileParser.new(:logger => @logger))
207
+ end
208
+
209
+ # Deletes the login profile for the specified User, which terminates the User's ability to access
210
+ # AWS services through the IAM login page.
211
+ #
212
+ # iam.delete_login_profile('kd') #=> true
213
+ #
214
+ def delete_login_profile(user_name)
215
+ request_hash = { 'UserName' => user_name }
216
+ link = generate_request("DeleteLoginProfile", request_hash)
217
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
218
+ end
219
+
220
+ #-----------------------------------------------------------------
221
+ # PARSERS
222
+ #-----------------------------------------------------------------
223
+
224
+ class ListUsersParser < BasicIamListParser #:nodoc:
225
+ def reset
226
+ @expected_tags = %w{ Arn Path UserId UserName }
227
+ end
228
+ end
229
+
230
+ class GetUserParser < BasicIamParser #:nodoc:
231
+ def reset
232
+ @expected_tags = %w{ Arn Path UserId UserName }
233
+ end
234
+ end
235
+
236
+ class GetUserPolicyParser < BasicIamParser #:nodoc:
237
+ def reset
238
+ @expected_tags = %w{ PolicyDocument PolicyName UserName }
239
+ end
240
+ end
241
+
242
+ class GetLoginProfileParser < BasicIamParser #:nodoc:
243
+ def reset
244
+ @expected_tags = %w{ UserName }
245
+ end
246
+ end
247
+
248
+ end
249
+
250
+ end
251
+
@@ -0,0 +1,1309 @@
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 = "2010-07-28"
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.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>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
55
+ #
56
+ # rds = RightAws::RdsInterface.new('xxxxxxxxxxxxxxxxxxxxx','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
57
+ # {:logger => Logger.new('/tmp/x.log')}) #=> #<RightAws::RdsInterface::0xb7b3c30c>
58
+ #
59
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
60
+ init({ :name => 'RDS',
61
+ :default_host => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).host : DEFAULT_HOST,
62
+ :default_port => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).port : DEFAULT_PORT,
63
+ :default_service => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).path : DEFAULT_PATH,
64
+ :default_protocol => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).scheme : DEFAULT_PROTOCOL,
65
+ :default_api_version => ENV['RDS_API_VERSION'] || API_VERSION },
66
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
67
+ aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
68
+ params)
69
+ end
70
+
71
+ #-----------------------------------------------------------------
72
+ # Requests
73
+ #-----------------------------------------------------------------
74
+
75
+ # Generates request hash for REST API.
76
+ def generate_request(action, params={}) #:nodoc:
77
+ generate_request_impl(:get, action, params )
78
+ end
79
+
80
+ # Sends request to Amazon and parses the response.
81
+ # Raises AwsError if any banana happened.
82
+ def request_info(request, parser, &block) # :nodoc:
83
+ request_info_impl(:rds_connection, @@bench, request, parser, &block)
84
+ end
85
+
86
+ # Incrementally lists something.
87
+ def incrementally_list_items(action, parser_class, params={}, &block) # :nodoc:
88
+ params = params.dup
89
+ params['MaxRecords'] = params.delete(:max_records) if params[:max_records]
90
+ params['Marker'] = params.delete(:marker) if params[:marker]
91
+ last_response = nil
92
+ loop do
93
+ link = generate_request(action, params)
94
+ last_response = request_info( link, parser_class.new(:logger => @logger))
95
+ params['Marker'] = last_response[:marker]
96
+ break unless block && block.call(last_response) && !last_response[:marker].right_blank?
97
+ end
98
+ last_response
99
+ end
100
+
101
+ #-----------------------------------------------------------------
102
+ # API Calls:
103
+ #-----------------------------------------------------------------
104
+
105
+ # --------------------------------------------
106
+ # DB Instances
107
+ # --------------------------------------------
108
+
109
+ # List DB instances.
110
+ #
111
+ # Optional params: +:aws_id+, +:max_records+, +:marker+
112
+ #
113
+ # # Get a list of DB instances. The response is an +Array+ of instances.
114
+ # rds.describe_db_instances #=>
115
+ # [{:instance_class=>"db.m1.small",
116
+ # :status=>"creating",
117
+ # :backup_retention_period=>1,
118
+ # :read_replica_db_instance_identifiers=>["kd-delete-me-01-replica-01"],
119
+ # :master_username=>"username",
120
+ # :preferred_maintenance_window=>"sun:05:00-sun:09:00",
121
+ # :db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
122
+ # :multi_az=>true,
123
+ # :engine=>"mysql",
124
+ # :auto_minor_version_upgrade=>false,
125
+ # :allocated_storage=>25,
126
+ # :availability_zone=>"us-east-1d",
127
+ # :aws_id=>"kd-delete-me-01",
128
+ # :preferred_backup_window=>"03:00-05:00",
129
+ # :engine_version=>"5.1.50",
130
+ # :pending_modified_values=>{:master_user_password=>"****"},
131
+ # :db_security_groups=>[{:status=>"active", :name=>"default"}]}]
132
+ #
133
+ # # Retrieve a custom DB instance.
134
+ # # The response is an +Array+ with a single instance record.
135
+ # rds.describe_db_instances("kd-test-n3")
136
+ #
137
+ # # Incrementally a list DB instances. Every response part is a +Hash+.
138
+ # rds.describe_db_instances(:max_records => 30) do |x|
139
+ # puts x.inspect #=>
140
+ # {:db_instances=>
141
+ # [{:instance_class=>"db.m1.small",
142
+ # :status=>"creating",
143
+ # :backup_retention_period=>1,
144
+ # :read_replica_db_instance_identifiers=>["kd-delete-me-01-replica-01"],
145
+ # :master_username=>"username",
146
+ # :preferred_maintenance_window=>"sun:05:00-sun:09:00",
147
+ # :db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
148
+ # :multi_az=>true,
149
+ # :engine=>"mysql",
150
+ # :auto_minor_version_upgrade=>false,
151
+ # :allocated_storage=>25,
152
+ # :availability_zone=>"us-east-1d",
153
+ # :aws_id=>"kd-delete-me-01",
154
+ # :preferred_backup_window=>"03:00-05:00",
155
+ # :engine_version=>"5.1.50",
156
+ # :pending_modified_values=>{:master_user_password=>"****"},
157
+ # :db_security_groups=>[{:status=>"active", :name=>"default"}]}]}
158
+ # true
159
+ # end
160
+ #
161
+ def describe_db_instances(*params, &block)
162
+ item, params = AwsUtils::split_items_and_params(params)
163
+ params = params.dup
164
+ params['DBInstanceIdentifier'] = item if item
165
+ result = []
166
+ incrementally_list_items('DescribeDBInstances', DescribeDbInstancesParser, params) do |response|
167
+ result += response[:db_instances]
168
+ block ? block.call(response) : true
169
+ end
170
+ result
171
+ end
172
+
173
+ # Create a new RDS instance of the type and size specified by you. The default storage engine for RDS Instances is InnoDB.
174
+ #
175
+ # Mandatory arguments: +aws_id+, +master_username+, +master_user_password+
176
+ # Optional params: +:allocated_storage+ (25 by def), +:instance_class+, +:engine+ ('MySQL' by def),
177
+ # +:endpoint_port+, +:db_name+, +:db_security_groups+, +:db_parameter_group+, +:availability_zone+, +:preferred_maintenance_window+
178
+ # +:backup_retention_period+, +:preferred_backup_window+, +:multi_az+, +:engine_version+, +:auto_minor_version_upgrade+
179
+ #
180
+ # rds.create_db_instance('kd-delete-me-01', 'username', 'password',
181
+ # :db_instance_class => 'db.m1.small',
182
+ # :multi_az => true,
183
+ # :auto_minor_version_upgrade => false ) #=>
184
+ # {:instance_class=>"db.m1.small",
185
+ # :multi_az=>true,
186
+ # :status=>"creating",
187
+ # :backup_retention_period=>1,
188
+ # :read_replica_db_instance_identifiers=>[],
189
+ # :master_username=>"username",
190
+ # :preferred_maintenance_window=>"sun:05:00-sun:09:00",
191
+ # :auto_minor_version_upgrade=>false,
192
+ # :db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
193
+ # :engine=>"mysql",
194
+ # :allocated_storage=>25,
195
+ # :aws_id=>"kd-delete-me-01",
196
+ # :preferred_backup_window=>"03:00-05:00",
197
+ # :engine_version=>"5.1.50",
198
+ # :pending_modified_values=>{:master_user_password=>"****"},
199
+ # :db_security_groups=>[{:status=>"active", :name=>"default"}]}
200
+ #
201
+ def create_db_instance(aws_id, master_username, master_user_password, params={})
202
+ request_hash = {}
203
+ # Mandatory
204
+ request_hash['DBInstanceIdentifier'] = aws_id
205
+ request_hash['MasterUsername'] = master_username
206
+ request_hash['MasterUserPassword'] = master_user_password
207
+ # Mandatory with default values
208
+ request_hash['DBInstanceClass'] = params[:instance_class].right_blank? ? DEFAULT_INSTANCE_CLASS : params[:instance_class].to_s
209
+ request_hash['AllocatedStorage'] = params[:allocated_storage].right_blank? ? 25 : params[:allocated_storage]
210
+ request_hash['Engine'] = params[:engine].right_blank? ? 'mysql' : params[:engine]
211
+ # Optional
212
+ request_hash['Port'] = params[:endpoint_port] unless params[:endpoint_port].right_blank?
213
+ request_hash['DBName'] = params[:db_name] unless params[:db_name].right_blank?
214
+ request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].right_blank?
215
+ request_hash['MultiAZ'] = params[:multi_az].to_s unless params[:multi_az].nil?
216
+ request_hash['PreferredMaintenanceWindow'] = params[:preferred_maintenance_window] unless params[:preferred_maintenance_window].right_blank?
217
+ request_hash['BackupRetentionPeriod'] = params[:backup_retention_period] unless params[:backup_retention_period].right_blank?
218
+ request_hash['PreferredBackupWindow'] = params[:preferred_backup_window] unless params[:preferred_backup_window].right_blank?
219
+ request_hash['DBParameterGroupName'] = params[:db_parameter_group] unless params[:db_parameter_group].right_blank?
220
+ request_hash['EngineVersion'] = params[:engine_version] unless params[:engine_version].right_blank?
221
+ request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade].to_s unless params[:auto_minor_version_upgrade].nil?
222
+ request_hash.merge!(amazonize_list('DBSecurityGroups.member', params[:db_security_groups]))
223
+ link = generate_request('CreateDBInstance', request_hash)
224
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
225
+ end
226
+
227
+ # Modify a DB instance.
228
+ #
229
+ # Mandatory arguments: +aws_id+.
230
+ # Optional params: +:master_user_password+, +:instance_class+, +:db_security_groups+,
231
+ # +:db_parameter_group+, +:preferred_maintenance_window+, +:allocated_storage+, +:apply_immediately+,
232
+ # +:backup_retention_period+, +:preferred_backup_window+, +:multi_az+, +:engine_version+,
233
+ # +:auto_minor_version_upgrade+, +:allow_major_version_upgrade+
234
+ #
235
+ # rds.modify_db_instance('kd-delete-me-01',
236
+ # :master_user_password => 'newpassword',
237
+ # :instance_class => 'db.m1.large',
238
+ # :multi_az => false,
239
+ # :allocated_storage => 30,
240
+ # :allow_major_version_upgrade => true,
241
+ # :auto_minor_version_upgrade => true,
242
+ # :preferred_maintenance_window => 'sun:06:00-sun:10:00',
243
+ # :preferred_backup_window => '02:00-04:00',
244
+ # :apply_immediately => true,
245
+ # :backup_retention_period => 2) #=>
246
+ # {:engine_version=>"5.1.50",
247
+ # :aws_id=>"kd-delete-me-01",
248
+ # :multi_az=>true,
249
+ # :status=>"available",
250
+ # :read_replica_db_instance_identifiers=>[],
251
+ # :availability_zone=>"us-east-1d",
252
+ # :auto_minor_version_upgrade=>true,
253
+ # :master_username=>"username",
254
+ # :preferred_maintenance_window=>"sun:06:00-sun:10:00",
255
+ # :db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
256
+ # :create_time=>"2010-11-17T10:21:59.720Z",
257
+ # :preferred_backup_window=>"02:00-04:00",
258
+ # :engine=>"mysql",
259
+ # :db_security_groups=>[{:status=>"active", :name=>"default"}],
260
+ # :endpoint_address=>"kd-delete-me-01.chxspydgchoo.us-east-1.rds.amazonaws.com",
261
+ # :instance_class=>"db.m1.small",
262
+ # :latest_restorable_time=>"2010-11-17T10:27:17.089Z",
263
+ # :backup_retention_period=>2,
264
+ # :pending_modified_values=>
265
+ # {:multi_az=>false, :master_user_password=>"****", :allocated_storage=>30, :instance_class=>"db.m1.large"},
266
+ # :allocated_storage=>25}
267
+ #
268
+ def modify_db_instance(aws_id, params={})
269
+ request_hash = {}
270
+ # Mandatory
271
+ request_hash['DBInstanceIdentifier'] = aws_id
272
+ # Optional
273
+ request_hash['MasterUserPassword'] = params[:master_user_password] unless params[:master_user_password].right_blank?
274
+ request_hash['DBInstanceClass'] = params[:instance_class].to_s.capitalize unless params[:instance_class].right_blank?
275
+ request_hash['PreferredMaintenanceWindow'] = params[:preferred_maintenance_window] unless params[:preferred_maintenance_window].right_blank?
276
+ request_hash['BackupRetentionPeriod'] = params[:backup_retention_period] unless params[:backup_retention_period].right_blank?
277
+ request_hash['PreferredBackupWindow'] = params[:preferred_backup_window] unless params[:preferred_backup_window].right_blank?
278
+ request_hash['AllocatedStorage'] = params[:allocated_storage] unless params[:allocated_storage].right_blank?
279
+ request_hash['MultiAZ'] = params[:multi_az].to_s unless params[:multi_az].nil?
280
+ request_hash['EngineVersion'] = params[:engine_version] unless params[:engine_version].right_blank?
281
+ request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade].to_s unless params[:auto_minor_version_upgrade].nil?
282
+ request_hash['AllowMajorVersionUpgrade'] = params[:allow_major_version_upgrade].to_s unless params[:allow_major_version_upgrade].nil?
283
+ request_hash['ApplyImmediately'] = params[:apply_immediately].to_s unless params[:apply_immediately].right_blank?
284
+ request_hash.merge!(amazonize_list('DBSecurityGroups.member', params[:db_security_groups]))
285
+ request_hash['DBParameterGroupName'] = params[:db_parameter_group] unless params[:db_parameter_group].right_blank?
286
+ link = generate_request('ModifyDBInstance', request_hash)
287
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
288
+ end
289
+
290
+ # Reboot Db instance.
291
+ #
292
+ # rds.reboot_db_instance('kd-my-awesome-db') #=>
293
+ # {:status=>"rebooting",
294
+ # :pending_modified_values=>{},
295
+ # :allocated_storage=>42,
296
+ # :master_username=>"kd",
297
+ # :db_security_groups=>[],
298
+ # :instance_class=>"Medium",
299
+ # :availability_zone=>"us-east-1a",
300
+ # :aws_id=>"kd-my-awesome-db",
301
+ # :create_time=>"2009-08-28T08:34:21.858Z",
302
+ # :engine=>"MySQL5.1",
303
+ # :preferred_maintenance_window=>"Sun:05:00-Sun:09:00"}
304
+ #
305
+ def reboot_db_instance(aws_id, params={})
306
+ params = params.dup
307
+ params['DBInstanceIdentifier'] = aws_id
308
+ link = generate_request('RebootDBInstance', params)
309
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
310
+ end
311
+
312
+ # Delete a DB instance
313
+ #
314
+ # Mandatory arguments: aws_id
315
+ # Optional params: :skip_final_snapshot ('false' by def),
316
+ # :snapshot_aws_id ('{instance_aws_id}-final-snapshot-YYYYMMDDHHMMSS')
317
+ #
318
+ # rds.delete_db_instance('my-awesome-db-g2') #=> true
319
+ #
320
+ def delete_db_instance(aws_id, params={})
321
+ request_hash = {}
322
+ request_hash['DBInstanceIdentifier'] = aws_id
323
+ request_hash['SkipFinalSnapshot'] = params.has_key?(:skip_final_snapshot) ? params[:skip_final_snapshot].to_s : 'false'
324
+ if request_hash['SkipFinalSnapshot'] == 'false' && params[:snapshot_aws_id].right_blank?
325
+ params = params.dup
326
+ params[:snapshot_aws_id] = "#{aws_id}-final-snapshot-#{Time.now.utc.strftime('%Y%m%d%H%M%S')}"
327
+ end
328
+ request_hash['FinalDBSnapshotIdentifier'] = params[:snapshot_aws_id] unless params[:snapshot_aws_id].right_blank?
329
+ link = generate_request('DeleteDBInstance', request_hash)
330
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
331
+ end
332
+
333
+ # --------------------------------------------
334
+ # DB SecurityGroups
335
+ # --------------------------------------------
336
+ #
337
+ # rds.describe_db_security_groups #=>
338
+ # [{:owner_id=>"82...25",
339
+ # :description=>"Default",
340
+ # :ec2_security_groups=>[],
341
+ # :ip_ranges=>[],
342
+ # :name=>"Default"},
343
+ # {:owner_id=>"82...25",
344
+ # :description=>"kd",
345
+ # :ec2_security_groups=>[],
346
+ # :ip_ranges=>[],
347
+ # :name=>"kd2"},
348
+ # {:owner_id=>"82...25",
349
+ # :description=>"kd",
350
+ # :ec2_security_groups=>
351
+ # [{:status=>"Authorized", :owner_id=>"82...23", :name=>"default"},
352
+ # {:status=>"Authorized", :owner_id=>"82...24", :name=>"default1"},
353
+ # {:status=>"Authorized", :owner_id=>"82...25", :name=>"default"},
354
+ # {:status=>"Authorized", :owner_id=>"82...26", :name=>"default"},
355
+ # {:status=>"Authorized", :owner_id=>"82...26", :name=>"default1"},
356
+ # {:status=>"Authorized", :owner_id=>"82...29", :name=>"default22"}],
357
+ # :ip_ranges=>
358
+ # [{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
359
+ # {:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
360
+ # {:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
361
+ # {:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
362
+ # {:status=>"Authorized", :cidrip=>"131.0.0.1/8"}],
363
+ # :name=>"kd3"}]
364
+ #
365
+ # # get a custom group
366
+ # rds.describe_db_security_groups('kd3')
367
+ #
368
+ def describe_db_security_groups(*db_security_group_name, &block)
369
+ items, params = AwsUtils::split_items_and_params(db_security_group_name)
370
+ params['DBSecurityGroupName'] = items.first unless items.right_blank?
371
+ result = []
372
+ incrementally_list_items('DescribeDBSecurityGroups', DescribeDbSecurityGroupsParser, params) do |response|
373
+ result += response[:db_security_groups]
374
+ block ? block.call(response) : true
375
+ end
376
+ result
377
+ end
378
+
379
+ # Create a database security group so that ingress to an RDS Instance can be controlled.
380
+ # A new security group cannot have the same name as an existing group.
381
+ #
382
+ # ds.create_db_security_group('kd3', 'kd') #=>
383
+ # {:ec2_security_groups=>[],
384
+ # :description=>"kd",
385
+ # :ip_ranges=>[],
386
+ # :name=>"kd3",
387
+ # :owner_id=>"82...25"}
388
+ #
389
+ def create_db_security_group(db_security_group_name, db_security_group_description)
390
+ link = generate_request('CreateDBSecurityGroup', 'DBSecurityGroupName' => db_security_group_name,
391
+ 'DBSecurityGroupDescription' => db_security_group_description)
392
+ request_info(link, DescribeDbSecurityGroupsParser.new(:logger => @logger))[:db_security_groups].first
393
+ end
394
+
395
+ def modify_db_security_group_ingress(action, db_security_group_name, params={}) # :nodoc:
396
+ request_hash = { 'DBSecurityGroupName' => db_security_group_name}
397
+ request_hash['CIDRIP'] = params[:cidrip] unless params[:cidrip].right_blank?
398
+ request_hash['EC2SecurityGroupName'] = params[:ec2_security_group_name] unless params[:ec2_security_group_name].right_blank?
399
+ request_hash['EC2SecurityGroupOwnerId'] = params[:ec2_security_group_owner] unless params[:ec2_security_group_owner].right_blank?
400
+ link = generate_request(action, request_hash)
401
+ request_info(link, DescribeDbSecurityGroupsParser.new(:logger => @logger))[:db_security_groups].first
402
+ end
403
+
404
+ # Authorize an ingress. Params: +:cidrip+ or (+:ec2_security_group_name+ and +:ec2_security_group_owner+)
405
+ #
406
+ # rds.authorize_db_security_group_ingress('kd3', :cidrip => '131.0.0.1/8')
407
+ # {:owner_id=>"82...25",
408
+ # :ec2_security_groups=>[],
409
+ # :description=>"kd",
410
+ # :ip_ranges=>
411
+ # [{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
412
+ # {:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
413
+ # {:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
414
+ # {:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
415
+ # {:status=>"Authorizing", :cidrip=>"131.0.0.1/8"}],
416
+ # :name=>"kd3"}
417
+ #
418
+ # rds.authorize_db_security_group_ingress('kd3',:ec2_security_group_owner => '82...27',
419
+ # :ec2_security_group_name => 'default') #=>
420
+ # {:owner_id=>"82...25",
421
+ # :ec2_security_groups=>
422
+ # [{:status=>"Authorized", :owner_id=>"82...25", :name=>"g1"},
423
+ # {:status=>"Authorized", :owner_id=>"82...26", :name=>"g2"},
424
+ # {:status=>"Authorizing", :owner_id=>"82...27", :name=>"default"}],
425
+ # :ip_ranges=>
426
+ # [{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
427
+ # {:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
428
+ # {:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
429
+ # {:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
430
+ # {:status=>"Authorized", :cidrip=>"131.0.0.1/8"}],
431
+ # :name=>"kd3"}
432
+ #
433
+ def authorize_db_security_group_ingress(db_security_group_name, params={})
434
+ modify_db_security_group_ingress('AuthorizeDBSecurityGroupIngress', db_security_group_name, params)
435
+ end
436
+
437
+ # Revoke an ingress.
438
+ # Optional params: +:cidrip+ or (+:ec2_security_group_name+ and +:ec2_security_group_owner+)
439
+ #
440
+ # rds.revoke_db_security_group_ingress('kd3', :ec2_security_group_owner => '82...25',
441
+ # :ec2_security_group_name => 'default') #=>
442
+ # {:owner_id=>"82...25",
443
+ # :ec2_security_groups=>
444
+ # [{:status=>"Revoking", :owner_id=>"826693181925", :name=>"default"}],
445
+ # :name=>"kd3",
446
+ # :description=>"kd",
447
+ # :ip_ranges=>
448
+ # [{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
449
+ # {:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
450
+ # {:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
451
+ # {:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
452
+ # {:status=>"Authorized", :cidrip=>"131.0.0.1/8"}]}
453
+ #
454
+ def revoke_db_security_group_ingress(db_security_group_name, params={})
455
+ modify_db_security_group_ingress('RevokeDBSecurityGroupIngress', db_security_group_name, params)
456
+ end
457
+
458
+ # Delete a database security group. Database security group must not be associated with any
459
+ # RDS Instances.
460
+ #
461
+ # rds.delete_db_security_group('kd3') #=> true
462
+ #
463
+ def delete_db_security_group(db_security_group_name)
464
+ link = generate_request('DeleteDBSecurityGroup', 'DBSecurityGroupName' => db_security_group_name)
465
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
466
+ end
467
+
468
+ # --------------------------------------------
469
+ # DB ParameterGroups
470
+ # --------------------------------------------
471
+
472
+ # Describe DBParameterGroups.
473
+ #
474
+ # rds.describe_db_parameter_groups #=>
475
+ # [{:engine=>"MySQL5.1",
476
+ # :description=>"Default parameter group for MySQL5.1",
477
+ # :name=>"default.MySQL5.1"}]
478
+ #
479
+ # # List parameter groups by 20
480
+ # rds.describe_db_parameter_groups(:max_records=>20) do |response|
481
+ # puts response.inspect
482
+ # true
483
+ # end
484
+ #
485
+ def describe_db_parameter_groups(*db_parameter_group_name, &block)
486
+ items, params = AwsUtils::split_items_and_params(db_parameter_group_name)
487
+ params['DBParameterGroupName'] = items.first unless items.right_blank?
488
+ result = []
489
+ incrementally_list_items('DescribeDBParameterGroups', DescribeDbParameterGroupsParser, params) do |response|
490
+ result += response[:db_parameter_groups]
491
+ block ? block.call(response) : true
492
+ end
493
+ result
494
+ end
495
+
496
+ # Creates a database parameter group so that configuration of an RDS Instance can be controlled.
497
+ #
498
+ # rds.create_db_parameter_group('my-new-group-1','My new group') #=> {}
499
+ #
500
+ # TODO: this call returns an empty hash, but should be a parameter group data - ask Amazon guys.
501
+ #
502
+ def create_db_parameter_group(db_parameter_group_name, db_parameter_group_description, db_parameter_group_family='mysql5.1', params={})
503
+ params['DBParameterGroupName'] = db_parameter_group_name
504
+ params['Description'] = db_parameter_group_description
505
+ params['DBParameterGroupFamily'] = db_parameter_group_family
506
+ link = generate_request('CreateDBParameterGroup', params )
507
+ request_info(link, DescribeDbParameterGroupsParser.new(:logger => @logger))[:db_parameter_groups].first
508
+ end
509
+
510
+ # Modify DBParameterGroup paramaters. Up to 20 params can be midified at once.
511
+ #
512
+ # rds.modify_db_parameter_group('kd1', 'max_allowed_packet' => 2048) #=> true
513
+ #
514
+ # rds.modify_db_parameter_group('kd1', 'max_allowed_packet' => {:value => 2048, :method => 'immediate') #=> true
515
+ #
516
+ def modify_db_parameter_group(db_parameter_group_name, params={}) # :nodoc:
517
+ request_hash = { 'DBParameterGroupName' => db_parameter_group_name}
518
+ parameters = []
519
+ params.each do |key, value|
520
+ method = 'pending-reboot'
521
+ if value.is_a?(Hash)
522
+ method = value[:method] unless value[:method].right_blank?
523
+ value = value[:value]
524
+ end
525
+ parameters << [key, value, method]
526
+ end
527
+ request_hash.merge!( amazonize_list(['Parameters.member.?.ParameterName',
528
+ 'Parameters.member.?.ParameterValue',
529
+ 'Parameters.member.?.ApplyMethod'],
530
+ parameters ))
531
+ link = generate_request('ModifyDBParameterGroup', request_hash)
532
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
533
+ end
534
+
535
+ # Delete DBParameter Group.
536
+ #
537
+ # rds.delete_db_parameter_group('kd1') #=> true
538
+ #
539
+ def delete_db_parameter_group(db_parameter_group_name)
540
+ link = generate_request('DeleteDBParameterGroup', 'DBParameterGroupName' => db_parameter_group_name)
541
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
542
+ end
543
+
544
+ # Modify the parameters of a DBParameterGroup to the engine/system default value.
545
+ #
546
+ # # Reset all parameters
547
+ # rds.reset_db_parameter_group('kd2', :all ) #=> true
548
+ #
549
+ # # Reset custom parameters
550
+ # rds.reset_db_parameter_group('kd2', 'max_allowed_packet', 'auto_increment_increment' ) #=> true
551
+ # rds.reset_db_parameter_group('kd2', 'max_allowed_packet', 'auto_increment_increment' => 'immediate' ) #=> true
552
+ #
553
+ def reset_db_parameter_group(db_parameter_group_name, *params)
554
+ params = params.flatten
555
+ request_hash = { 'DBParameterGroupName' => db_parameter_group_name }
556
+ if params.first.to_s == 'all'
557
+ request_hash['ResetAllParameters'] = true
558
+ else
559
+ tmp = []
560
+ params.each{ |item| tmp |= item.to_a }
561
+ params = []
562
+ tmp.each do |key, method|
563
+ method = 'pending-reboot' unless method
564
+ params << [key, method]
565
+ end
566
+ request_hash.merge!( amazonize_list(['Parameters.member.?.ParameterName',
567
+ 'Parameters.member.?.ApplyMethod'],
568
+ params ))
569
+ end
570
+ link = generate_request('ResetDBParameterGroup', request_hash)
571
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
572
+ end
573
+
574
+ # Get the detailed parameters list for a particular DBParameterGroup.
575
+ #
576
+ # rds.describe_db_parameters('kd1') #=>
577
+ # [{:is_modifiable=>true,
578
+ # :apply_type=>"static",
579
+ # :source=>"engine-default",
580
+ # :allowed_values=>"ON,OFF",
581
+ # :description=>"Controls whether user-defined functions that have only an xxx symbol for the main function can be loaded",
582
+ # :name=>"allow-suspicious-udfs",
583
+ # :data_type=>"boolean"},
584
+ # {:is_modifiable=>true,
585
+ # :apply_type=>"dynamic",
586
+ # :source=>"engine-default",
587
+ # :allowed_values=>"1-65535",
588
+ # :description=>"Intended for use with master-to-master replication, and can be used to control the operation of AUTO_INCREMENT columns",
589
+ # :name=>"auto_increment_increment",
590
+ # :data_type=>"integer"}, ... ]
591
+ #
592
+ # # List parameters by 20
593
+ # rds.describe_db_parameters('kd1', :max_records=>20) do |response|
594
+ # puts response.inspect
595
+ # true
596
+ # end
597
+ #
598
+ def describe_db_parameters(*db_parameter_group_name, &block)
599
+ item, params = AwsUtils::split_items_and_params(db_parameter_group_name)
600
+ params['DBParameterGroupName'] = item
601
+ result = []
602
+ incrementally_list_items('DescribeDBParameters', DescribeDbParametersParser, params) do |response|
603
+ result += response[:parameters]
604
+ block ? block.call(response) : true
605
+ end
606
+ result
607
+ end
608
+
609
+ # Describe a default parameters for the parameter group family.
610
+ #
611
+ # rds.describe_engine_default_parameters('MySQL5.1') #=>
612
+ # [{:is_modifiable=>true,
613
+ # :apply_type=>"static",
614
+ # :source=>"engine-default",
615
+ # :allowed_values=>"ON,OFF",
616
+ # :description=>"Controls whether user-defined functions that have only an xxx symbol for the main function can be loaded",
617
+ # :name=>"allow-suspicious-udfs",
618
+ # :data_type=>"boolean"},
619
+ # {:is_modifiable=>true,
620
+ # :apply_type=>"dynamic",
621
+ # :source=>"engine-default",
622
+ # :allowed_values=>"1-65535",
623
+ # :description=>"Intended for use with master-to-master replication, and can be used to control the operation of AUTO_INCREMENT columns",
624
+ # :name=>"auto_increment_increment",
625
+ # :data_type=>"integer"}, ... ]
626
+ #
627
+ def describe_engine_default_parameters(*db_parameter_group_family, &block)
628
+ db_parameter_group_family = ['MySQL5.1'] if db_parameter_group_family.right_blank?
629
+ item, params = AwsUtils::split_items_and_params(db_parameter_group_family)
630
+ params['DBParameterGroupFamily'] = item if item
631
+ result = []
632
+ incrementally_list_items('DescribeEngineDefaultParameters', DescribeDbParametersParser, params) do |response|
633
+ result += response[:parameters]
634
+ block ? block.call(response) : true
635
+ end
636
+ result
637
+ end
638
+
639
+ # --------------------------------------------
640
+ # DB Snapshots
641
+ # --------------------------------------------
642
+
643
+ # Get DBSecurityGroup details for a particular customer or for a particular DBSecurityGroup if a name is specified.
644
+ # Optional params: +:instance_aws_id+
645
+ #
646
+ # # all snapshots
647
+ # rds.describe_db_snapshots #=>
648
+ # [{:status=>"Available",
649
+ # :instance_aws_id=>"kd-test-n1",
650
+ # :allocated_storage=>25,
651
+ # :availability_zone=>"us-east-1b",
652
+ # :aws_id=>"kd-test-n1-final-snapshot-at-20090630131215",
653
+ # :engine=>"MySQL5.1",
654
+ # :endpoint_port=>3306,
655
+ # :instance_create_time=>"2009-06-30T12:48:15.590Z",
656
+ # :master_username=>"payless",
657
+ # :snapshot_time=>"2009-06-30T13:16:48.496Z"}, ...]
658
+ #
659
+ # # all snapshots for a custom instance
660
+ # rds.describe_db_snapshots(:instance_aws_id => 'kd-test-n3') #=>
661
+ # [{:status=>"Available",
662
+ # :instance_aws_id=>"kd-test-n3",
663
+ # :allocated_storage=>25,
664
+ # :availability_zone=>"us-east-1a",
665
+ # :aws_id=>"kd-test-n3-final-snapshot-20090713074916",
666
+ # :engine=>"MySQL5.1",
667
+ # :endpoint_port=>3306,
668
+ # :instance_create_time=>"2009-06-30T12:51:32.540Z",
669
+ # :master_username=>"payless",
670
+ # :snapshot_time=>"2009-07-13T07:52:35.542Z"}]
671
+ #
672
+ # # a snapshot by id
673
+ # rds.describe_db_snapshots('my-awesome-db-final-snapshot-20090713075554') #=>
674
+ # [{:status=>"Available",
675
+ # :allocated_storage=>25,
676
+ # :engine=>"MySQL5.1",
677
+ # :instance_aws_id=>"my-awesome-db",
678
+ # :availability_zone=>"us-east-1a",
679
+ # :instance_create_time=>"2009-07-13T07:53:08.912Z",
680
+ # :endpoint_port=>3306,
681
+ # :master_username=>"medium",
682
+ # :aws_id=>"my-awesome-db-final-snapshot-20090713075554",
683
+ # :snapshot_time=>"2009-07-13T07:59:17.537Z"}]
684
+ #
685
+ def describe_db_snapshots(params={}, &block)
686
+ item, params = AwsUtils::split_items_and_params(params)
687
+ params['DBSnapshotIdentifier'] = item if item
688
+ params['DBInstanceIdentifier'] = params.delete(:instance_aws_id) unless params[:instance_aws_id].right_blank?
689
+ result = []
690
+ incrementally_list_items('DescribeDBSnapshots', DescribeDbSnapshotsParser, params) do |response|
691
+ result += response[:db_snapshots]
692
+ block ? block.call(response) : true
693
+ end
694
+ result
695
+ end
696
+
697
+ # Create a DBSnapshot. The source DBInstance must be in Available state
698
+ #
699
+ # rds.create_db_snapshot('remove-me-tomorrow-2', 'my-awesome-db-g7' ) #=>
700
+ # {:status=>"PendingCreation",
701
+ # :allocated_storage=>50,
702
+ # :availability_zone=>"us-east-1b",
703
+ # :engine=>"MySQL5.1",
704
+ # :aws_id=>"remove-me-tomorrow-2",
705
+ # :instance_create_time=>"2009-07-13T09:35:39.243Z",
706
+ # :endpoint_port=>3306,
707
+ # :instance_aws_id=>"my-awesome-db-g7",
708
+ # :db_master_username=>"username"}
709
+ #
710
+ def create_db_snapshot(aws_id, instance_aws_id)
711
+ link = generate_request('CreateDBSnapshot', 'DBSnapshotIdentifier' => aws_id,
712
+ 'DBInstanceIdentifier' => instance_aws_id)
713
+ request_info(link, DescribeDbSnapshotsParser.new(:logger => @logger))[:db_snapshots].first
714
+ end
715
+
716
+ # Create a new RDS instance from a DBSnapshot. The source DBSnapshot must be
717
+ # in the "Available" state. The new RDS instance is created with the Default security group.
718
+ #
719
+ # Optional params: +:instance_class+, +:endpoint_port+, +:availability_zone+, +:multi_az+,
720
+ # +:auto_minor_version_upgrade+
721
+ #
722
+ # rds.restore_db_instance_from_db_snapshot('ahahahaha-final-snapshot-20090828081159', 'q1') #=>
723
+ # {:status=>"creating",
724
+ # :pending_modified_values=>{},
725
+ # :allocated_storage=>42,
726
+ # :db_security_groups=>[],
727
+ # :master_username=>"kd",
728
+ # :availability_zone=>"us-east-1a",
729
+ # :aws_id=>"q1",
730
+ # :create_time=>"2009-08-29T18:07:01.510Z",
731
+ # :instance_class=>"Medium",
732
+ # :preferred_maintenance_window=>"Sun:05:00-Sun:09:00",
733
+ # :engine=>"MySQL",
734
+ # :engine_version=>"5.1.49"}
735
+ #
736
+ def restore_db_instance_from_db_snapshot(snapshot_aws_id, instance_aws_id, params={})
737
+ request_hash = { 'DBSnapshotIdentifier' => snapshot_aws_id,
738
+ 'DBInstanceIdentifier' => instance_aws_id }
739
+ request_hash['DBInstanceClass'] = params[:instance_class] unless params[:instance_class].right_blank?
740
+ request_hash['Port'] = params[:endpoint_port] unless params[:endpoint_port].right_blank?
741
+ request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].right_blank?
742
+ request_hash['MultiAZ'] = params[:multi_az] unless params[:multi_az].nil?
743
+ request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade] unless params[:auto_minor_version_upgrade].nil?
744
+ link = generate_request('RestoreDBInstanceFromDBSnapshot', request_hash)
745
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
746
+ end
747
+
748
+ # Create a new RDS instance from a point-in-time system snapshot. The target
749
+ # database is created from the source database restore point with the same configuration as
750
+ # the original source database, except that the new RDS instance is created with the default
751
+ # security group.
752
+ #
753
+ # Optional params: +:instance_class+, +:endpoint_port+, +:availability_zone+, +:multi_az+, +:restore_time+,
754
+ # +:auto_minor_version_upgrade+, +:use_latest_restorable_time+
755
+ #
756
+ def restore_db_instance_to_point_in_time(instance_aws_id, new_instance_aws_id, params={})
757
+ request_hash = { 'SourceDBInstanceIdentifier' => instance_aws_id,
758
+ 'TargetDBInstanceIdentifier' => new_instance_aws_id}
759
+ request_hash['UseLatestRestorableTime'] = params[:use_latest_restorable_time].to_s unless params[:use_latest_restorable_time].nil?
760
+ request_hash['RestoreTime'] = params[:restore_time] unless params[:restore_time].right_blank?
761
+ request_hash['DBInstanceClass'] = params[:instance_class] unless params[:instance_class].right_blank?
762
+ request_hash['MultiAZ'] = params[:multi_az] unless params[:multi_az].nil?
763
+ request_hash['Port'] = params[:endpoint_port] unless params[:endpoint_port].right_blank?
764
+ request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].right_blank?
765
+ request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade] unless params[:auto_minor_version_upgrade].nil?
766
+ link = generate_request('RestoreDBInstanceToPointInTime', request_hash)
767
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
768
+ end
769
+
770
+ # Delete a DBSnapshot. The DBSnapshot must be in the Available state to be deleted.
771
+ #
772
+ # rds.delete_db_snapshot('remove-me-tomorrow-1') #=>
773
+ # {:status=>"Deleted",
774
+ # :allocated_storage=>50,
775
+ # :instance_create_time=>"2009-07-13T09:27:01.053Z",
776
+ # :availability_zone=>"us-east-1a",
777
+ # :db_master_username=>"username",
778
+ # :aws_id=>"remove-me-tomorrow-1",
779
+ # :snapshot_time=>"2009-07-13T10:59:30.227Z",
780
+ # :endpoint_port=>3306,
781
+ # :instance_aws_id=>"my-awesome-db-g5",
782
+ # :engine=>"MySQL5.1"}
783
+ #
784
+ def delete_db_snapshot(aws_id)
785
+ link = generate_request('DeleteDBSnapshot', 'DBSnapshotIdentifier' => aws_id)
786
+ request_info(link, DescribeDbSnapshotsParser.new(:logger => @logger))[:db_snapshots].first
787
+ end
788
+
789
+ # --------------------------------------------
790
+ # DB Events
791
+ # --------------------------------------------
792
+
793
+ # Get events related to RDS instances and DBSecurityGroups for the past 14 days.
794
+ # Optional params: +:duration+, +:start_time+, +:end_time+, +:aws_id+,
795
+ # +:source_type+('db-instance', 'db-security-group', 'db-snapshot', 'db-parameter-group')
796
+ #
797
+ # # get all enevts
798
+ # rds.describe_events #=>
799
+ # [{:aws_id=>"my-awesome-db-g4",
800
+ # :source_type=>"DBInstance",
801
+ # :message=>"Started user snapshot for database instance:my-awesome-db-g4",
802
+ # :date=>"2009-07-13T10:54:13.661Z"},
803
+ # {:aws_id=>"my-awesome-db-g5",
804
+ # :source_type=>"DBInstance",
805
+ # :message=>"Started user snapshot for database instance:my-awesome-db-g5",
806
+ # :date=>"2009-07-13T10:55:13.674Z"},
807
+ # {:aws_id=>"my-awesome-db-g7",
808
+ # :source_type=>"DBInstance",
809
+ # :message=>"Started user snapshot for database instance:my-awesome-db-g7",
810
+ # :date=>"2009-07-13T10:56:34.226Z"}]
811
+ #
812
+ # # get all events since yesterday
813
+ # rds.describe_events(:start_date => 1.day.ago)
814
+ #
815
+ # # get last 60 min events
816
+ # rds.describe_events(:duration => 60)
817
+ #
818
+ def describe_events(params={}, &block)
819
+ params = params.dup
820
+ params['SourceIdentifier'] = params.delete(:aws_id) unless params[:aws_id].right_blank?
821
+ params['SourceType'] = params.delete(:source_type) unless params[:source_type].right_blank?
822
+ params['Duration'] = params.delete(:duration) unless params[:duration].right_blank?
823
+ params['StartDate'] = fix_date(params.delete(:start_date)) unless params[:start_date].right_blank?
824
+ params['EndDate'] = fix_date(params.delete(:end_date)) unless params[:end_date].right_blank?
825
+ result = []
826
+ incrementally_list_items('DescribeEvents', DescribeEventsParser, params) do |response|
827
+ result += response[:events]
828
+ block ? block.call(response) : true
829
+ end
830
+ result
831
+ end
832
+
833
+ def fix_date(date) # :nodoc:
834
+ date = Time.at(date) if date.is_a?(Fixnum)
835
+ date = date.utc.strftime('%Y-%m-%dT%H:%M:%SZ') if date.is_a?(Time)
836
+ date
837
+ end
838
+
839
+ # --------------------------------------------
840
+ # DB Engine Versions
841
+ # --------------------------------------------
842
+
843
+ # Get a list of the available DB engines.
844
+ # Optional params: +:db_parameter_group_family+, +:default_only+, +:engine+, +:engine_version+
845
+ #
846
+ # rds.describe_db_engine_versions #=>
847
+ # [{:engine=>"mysql",
848
+ # :db_parameter_group_family=>"mysql5.1",
849
+ # :engine_version=>"5.1.45"},
850
+ # {:engine=>"mysql",
851
+ # :db_parameter_group_family=>"mysql5.1",
852
+ # :engine_version=>"5.1.49"},
853
+ # {:engine=>"mysql",
854
+ # :db_parameter_group_family=>"mysql5.1",
855
+ # :engine_version=>"5.1.50"}]
856
+ #
857
+ def describe_db_engine_versions(params={}, &block)
858
+ params = params.dup
859
+ params['DBParameterGroupFamily'] = params.delete(:db_parameter_group_family) unless params[:db_parameter_group_family].right_blank?
860
+ params['DefaultOnly'] = params.delete(:default_only).to_s unless params[:default_only].nil?
861
+ params['Engine'] = params.delete(:engine) unless params[:engine].right_blank?
862
+ params['EngineVersion'] = params.delete(:engine_version) unless params[:engine_version].right_blank?
863
+ result = []
864
+ incrementally_list_items('DescribeDBEngineVersions', DescribeDBEngineVersionsParser, params) do |response|
865
+ result += response[:db_engine_versions]
866
+ block ? block.call(response) : true
867
+ end
868
+ result
869
+ end
870
+
871
+ # --------------------------------------------
872
+ # DB Replicas
873
+ # --------------------------------------------
874
+
875
+ # Create a DB Instance that acts as a Read Replica of a source DB Instance.
876
+ #
877
+ # Optional params: +:endpoint_port+, +:availability_zone+, +:db_instance_class+, +:auto_minor_version_upgrade+
878
+ #
879
+ # rds.create_db_instance_read_replica('kd-delete-me-01-replica-01', 'kd-delete-me-01',
880
+ # :db_instance_class => 'db.m1.small',
881
+ # :endpoint_port => '11000',
882
+ # :auto_minor_version_upgrade => false ) #=>
883
+ # {:auto_minor_version_upgrade=>false,
884
+ # :read_replica_source_db_instance_identifier=>"kd-delete-me-01",
885
+ # :status=>"creating",
886
+ # :backup_retention_period=>0,
887
+ # :allocated_storage=>30,
888
+ # :read_replica_db_instance_identifiers=>[],
889
+ # :engine_version=>"5.1.50",
890
+ # :aws_id=>"kd-delete-me-01-replica-01",
891
+ # :multi_az=>false,
892
+ # :preferred_maintenance_window=>"sun:06:00-sun:10:00",
893
+ # :master_username=>"username",
894
+ # :preferred_backup_window=>"02:00-04:00",
895
+ # :db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
896
+ # :engine=>"mysql",
897
+ # :db_security_groups=>[{:status=>"active", :name=>"default"}],
898
+ # :instance_class=>"db.m1.small",
899
+ # :pending_modified_values=>{}}
900
+ #
901
+ def create_db_instance_read_replica(aws_id, source_db_instance_identifier, params={})
902
+ request_hash = { 'DBInstanceIdentifier' => aws_id,
903
+ 'SourceDBInstanceIdentifier' => source_db_instance_identifier}
904
+ request_hash['Port'] = params[:endpoint_port] unless params[:endpoint_port].right_blank?
905
+ request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].right_blank?
906
+ request_hash['DBInstanceClass'] = params[:db_instance_class] unless params[:db_instance_class].right_blank?
907
+ request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade].to_s unless params[:auto_minor_version_upgrade].nil?
908
+ link = generate_request('CreateDBInstanceReadReplica', request_hash)
909
+ request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first
910
+ end
911
+
912
+
913
+ #---------------------------------------------
914
+ # Reserved Instances
915
+ #---------------------------------------------
916
+
917
+ # Lists available reserved DB Instance offerings.
918
+ # Options: :aws_id, :instance_class, :duration, :product_description, :multi_az
919
+ #
920
+ # rds.describe_reserved_db_instances_offerings #=>
921
+ # [{:multi_az=>false,
922
+ # :duration=>31536000,
923
+ # :fixed_price=>1325.0,
924
+ # :usage_price=>0.262,
925
+ # :aws_id=>"248e7b75-2451-4381-9025-b5553d421c7b",
926
+ # :instance_class=>"db.m2.xlarge",
927
+ # :product_description=>"mysql"},
928
+ # {:multi_az=>true,
929
+ # :duration=>94608000,
930
+ # :fixed_price=>700.0,
931
+ # :usage_price=>0.092,
932
+ # :aws_id=>"248e7b75-49a7-4cd7-9a9b-354f4906a9b1",
933
+ # :instance_class=>"db.m1.small",
934
+ # :product_description=>"mysql"}, ... ]
935
+ #
936
+ # rds.describe_reserved_db_instances_offerings(:aws_id => "248e7b75-49a7-4cd7-9a9b-354f4906a9b1") #=>
937
+ # [{:duration=>94608000,
938
+ # :multi_az=>true,
939
+ # :fixed_price=>700.0,
940
+ # :usage_price=>0.092,
941
+ # :aws_id=>"248e7b75-49a7-4cd7-9a9b-354f4906a9b1",
942
+ # :instance_class=>"db.m1.small",
943
+ # :product_description=>"mysql"}]
944
+ #
945
+ # rds.describe_reserved_db_instances_offerings(:instance_class => "db.m1.small")
946
+ # rds.describe_reserved_db_instances_offerings(:duration => 31536000)
947
+ # rds.describe_reserved_db_instances_offerings(:product_description => 'mysql')
948
+ # rds.describe_reserved_db_instances_offerings(:multi_az => true)
949
+ #
950
+ def describe_reserved_db_instances_offerings(params={}, &block)
951
+ params = params.dup
952
+ params['ReservedDBInstancesOfferingId'] = params.delete(:aws_id) unless params[:aws_id].right_blank?
953
+ params['DBInstanceClass'] = params.delete(:instance_class) unless params[:instance_class].right_blank?
954
+ params['Duration'] = params.delete(:duration) unless params[:duration].right_blank?
955
+ params['ProductDescription'] = params.delete(:product_description) unless params[:product_description].right_blank?
956
+ params['MultiAZ'] = params.delete(:multi_az).to_s unless params[:multi_az].nil?
957
+ result = []
958
+ incrementally_list_items('DescribeReservedDBInstancesOfferings', DescribeReservedDBInstancesOfferingsParser, params) do |response|
959
+ result += response[:reserved_db_instances_offerings]
960
+ block ? block.call(response) : true
961
+ end
962
+ result
963
+ end
964
+
965
+ # Returns information about reserved DB Instances for this account, or about
966
+ # a specified reserved DB Instance.
967
+ # Options: :aws_id, :offering_aws_id, :instance_class, :duration, :product_description, :multi_az
968
+ #
969
+ # rds.describe_reserved_db_instances
970
+ # rds.describe_reserved_db_instances(:aws_id => "myreservedinstance")
971
+ # rds.describe_reserved_db_instances(:offering_aws_id => "248e7b75-49a7-4cd7-9a9b-354f4906a9b1")
972
+ # rds.describe_reserved_db_instances(:instance_class => "db.m1.small")
973
+ # rds.describe_reserved_db_instances(:duration => 31536000)
974
+ # rds.describe_reserved_db_instances(:product_description => 'mysql')
975
+ # rds.describe_reserved_db_instances_offerings(:multi_az => true)
976
+ #
977
+ def describe_reserved_db_instances(params={}, &block)
978
+ params = params.dup
979
+ params['ReservedDBInstancesId'] = params.delete(:aws_id) unless params[:aws_id].right_blank?
980
+ params['ReservedDBInstancesOfferingId'] = params.delete(:offering_aws_id) unless params[:offering_aws_id].right_blank?
981
+ params['DBInstanceClass'] = params.delete(:instance_class) unless params[:instance_class].right_blank?
982
+ params['Duration'] = params.delete(:duration) unless params[:duration].right_blank?
983
+ params['ProductDescription'] = params.delete(:product_description) unless params[:product_description].right_blank?
984
+ params['MultiAZ'] = params.delete(:multi_az).to_s unless params[:multi_az].nil?
985
+ result = []
986
+ incrementally_list_items('DescribeReservedDBInstances', DescribeReservedDBInstancesParser, params) do |response|
987
+ result += response[:reserved_db_instances]
988
+ block ? block.call(response) : true
989
+ end
990
+ result
991
+ end
992
+
993
+ # Purchases a reserved DB Instance offering.
994
+ # Options: :aws_id, :count
995
+ def purchase_reserved_db_instances_offering(offering_aws_id, params={})
996
+ request_hash = { 'ReservedDBInstancesOfferingId' => offering_aws_id }
997
+ request_hash['ReservedDBInstanceId'] = params[:aws_id] unless params[:aws_id].right_blank?
998
+ request_hash['DBInstanceCount'] = params[:count] unless params[:count].right_blank?
999
+ link = generate_request('PurchaseReservedDBInstancesOffering', request_hash)
1000
+ request_info(link, DescribeReservedDBInstancesParser.new(:logger => @logger))[:reserved_db_instances].first
1001
+ end
1002
+
1003
+ # --------------------------------------------
1004
+ # Parsers
1005
+ # --------------------------------------------
1006
+
1007
+ # --------------------------------------------
1008
+ # DB Instances
1009
+ # --------------------------------------------
1010
+
1011
+ class DescribeDbInstancesParser < RightAWSParser # :nodoc:
1012
+ def reset
1013
+ @result = { :db_instances => [] }
1014
+ end
1015
+ def tagstart(name, attributes)
1016
+ case name
1017
+ when 'DBInstance' then @item = { :db_security_groups => [], :pending_modified_values => {}, :read_replica_db_instance_identifiers => [] }
1018
+ when 'DBSecurityGroup' then @db_security_group = {}
1019
+ when 'DBParameterGroup',
1020
+ 'DBParameterGroupStatus' then @db_parameter_group = {}
1021
+ end
1022
+ end
1023
+ def tagend(name)
1024
+ case name
1025
+ when 'Marker' then @result[:marker] = @text
1026
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
1027
+ when 'DBInstanceIdentifier' then @item[:aws_id] = @text
1028
+ when 'InstanceCreateTime' then @item[:create_time] = @text
1029
+ when 'Engine' then @item[:engine] = @text
1030
+ when 'DBInstanceStatus' then @item[:status] = @text
1031
+ when 'Address' then @item[:endpoint_address] = @text
1032
+ when 'Port' then @item[:endpoint_port] = @text.to_i
1033
+ when 'MasterUsername' then @item[:master_username] = @text
1034
+ when 'AvailabilityZone' then @item[:availability_zone] = @text
1035
+ when 'LatestRestorableTime' then @item[:latest_restorable_time] = @text
1036
+ when 'ReadReplicaSourceDBInstanceIdentifier' then @item[:read_replica_source_db_instance_identifier] = @text
1037
+ when 'ReadReplicaDBInstanceIdentifier' then @item[:read_replica_db_instance_identifiers] << @text
1038
+ when 'DBSecurityGroupName' then @db_security_group[:name] = @text
1039
+ when 'Status' then @db_security_group[:status] = @text
1040
+ when 'DBParameterGroupName' then @db_parameter_group[:name] = @text
1041
+ when 'ParameterApplyStatus' then @db_parameter_group[:status] = @text
1042
+ when 'DBSecurityGroup' then @item[:db_security_groups] << @db_security_group
1043
+ when 'DBParameterGroup',
1044
+ 'DBParameterGroupStatus' then @item[:db_parameter_group] = @db_parameter_group
1045
+ when 'DBInstance' then @result[:db_instances] << @item
1046
+ else
1047
+ case full_tag_name
1048
+ when %r{DBInstance/DBInstanceClass$} then @item[:instance_class] = @text
1049
+ when %r{DBInstance/AllocatedStorage$} then @item[:allocated_storage] = @text.to_i
1050
+ when %r{DBInstance/MultiAZ$} then @item[:multi_az] = (@text == 'true')
1051
+ when %r{DBInstance/BackupRetentionPeriod$} then @item[:backup_retention_period] = @text.to_i
1052
+ when %r{DBInstance/PreferredMaintenanceWindow$} then @item[:preferred_maintenance_window] = @text
1053
+ when %r{DBInstance/PreferredBackupWindow$} then @item[:preferred_backup_window] = @text
1054
+ when %r{DBInstance/EngineVersion$} then @item[:engine_version] = @text
1055
+ when %r{DBInstance/AutoMinorVersionUpgrade$} then @item[:auto_minor_version_upgrade] = (@text == 'true')
1056
+ when %r{DBInstance/AllowMajorVersionUpgrade$} then @item[:allow_major_version_upgrade] = (@text == 'true')
1057
+ when %r{PendingModifiedValues/DBInstanceClass$} then @item[:pending_modified_values][:instance_class] = @text
1058
+ when %r{PendingModifiedValues/AllocatedStorage$} then @item[:pending_modified_values][:allocated_storage] = @text.to_i
1059
+ when %r{PendingModifiedValues/MasterUserPassword$} then @item[:pending_modified_values][:master_user_password] = @text
1060
+ when %r{PendingModifiedValues/MultiAZ$} then @item[:pending_modified_values][:multi_az] = (@text == 'true')
1061
+ when %r{PendingModifiedValues/BackupRetentionPeriod$} then @item[:pending_modified_values][:backup_retention_period] = @text.to_i
1062
+ when %r{PendingModifiedValues/PreferredMaintenanceWindow$} then @item[:pending_modified_values][:preferred_maintenance_window] = @text
1063
+ when %r{PendingModifiedValues/PreferredBackupWindow$} then @item[:pending_modified_values][:preferred_backup_window] = @text
1064
+ when %r{PendingModifiedValues/EngineVersion$} then @item[:pending_modified_values][:engine_version] = @text
1065
+ when %r{PendingModifiedValues/AutoMinorVersionUpgrade$} then @item[:pending_modified_values][:auto_minor_version_upgrade] = (@text == 'true')
1066
+ when %r{PendingModifiedValues/AllowMajorVersionUpgrade$} then @item[:pending_modified_values][:allow_major_version_upgrade] = (@text == 'true')
1067
+ end
1068
+ end
1069
+ end
1070
+ end
1071
+
1072
+ # --------------------------------------------
1073
+ # DB Security Groups
1074
+ # --------------------------------------------
1075
+
1076
+ class DescribeDbSecurityGroupsParser < RightAWSParser # :nodoc:
1077
+ def reset
1078
+ @result = { :db_security_groups => [] }
1079
+ end
1080
+ def tagstart(name, attributes)
1081
+ case name
1082
+ when 'DBSecurityGroup' then @item = { :ec2_security_groups => [], :ip_ranges => [] }
1083
+ when 'IPRange' then @ip_range = {}
1084
+ when 'EC2SecurityGroup' then @ec2_security_group = {}
1085
+ end
1086
+ end
1087
+ def tagend(name)
1088
+ case name
1089
+ when 'Marker' then @result[:marker] = @text
1090
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
1091
+ when 'DBSecurityGroupDescription' then @item[:description ] = @text
1092
+ when 'OwnerId' then @item[:owner_id] = @text
1093
+ when 'DBSecurityGroupName' then @item[:name] = @text
1094
+ when 'EC2SecurityGroupName' then @ec2_security_group[:name] = @text
1095
+ when 'EC2SecurityGroupOwnerId' then @ec2_security_group[:owner_id] = @text
1096
+ when 'CIDRIP' then @ip_range[:cidrip] = @text
1097
+ when 'IPRange' then @item[:ip_ranges] << @ip_range
1098
+ when 'EC2SecurityGroup' then @item[:ec2_security_groups] << @ec2_security_group
1099
+ when 'DBSecurityGroup'
1100
+ # Sort the ip_ranges and ec2_security_groups
1101
+ @item[:ip_ranges].sort!{ |i1,i2| "#{i1[:cidrip]}" <=> "#{i2[:cidrip]}" }
1102
+ @item[:ec2_security_groups].sort!{ |i1,i2| "#{i1[:owner_id]}#{i1[:name]}" <=> "#{i2[:owner_id]}#{i2[:name]}" }
1103
+ @result[:db_security_groups] << @item
1104
+ else
1105
+ case full_tag_name
1106
+ when %r{IPRange/Status$} then @ip_range[:status] = @text
1107
+ when %r{EC2SecurityGroup/Status$} then @ec2_security_group[:status] = @text
1108
+ end
1109
+ end
1110
+ end
1111
+ end
1112
+
1113
+ # --------------------------------------------
1114
+ # DB Security Groups
1115
+ # --------------------------------------------
1116
+
1117
+ class DescribeDbParameterGroupsParser < RightAWSParser # :nodoc:
1118
+ def reset
1119
+ @result = { :db_parameter_groups => [] }
1120
+ end
1121
+ def tagstart(name, attributes)
1122
+ case name
1123
+ when 'DBParameterGroup',
1124
+ 'ModifyDBParameterGroupResult' then @item = { }
1125
+ end
1126
+ end
1127
+ def tagend(name)
1128
+ case name
1129
+ when 'Marker' then @result[:marker] = @text
1130
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
1131
+ when 'DBParameterGroupName' then @item[:name] = @text
1132
+ when 'Description' then @item[:description] = @text
1133
+ when 'DBParameterGroupFamily' then @item[:db_parameter_group_family] = @text
1134
+ when 'DBParameterGroup',
1135
+ 'ModifyDBParameterGroupResult' then @result[:db_parameter_groups] << @item
1136
+ end
1137
+ end
1138
+ end
1139
+
1140
+ class DescribeDbParametersParser < RightAWSParser # :nodoc:
1141
+ def reset
1142
+ @result = { :parameters => [] }
1143
+ end
1144
+ def tagstart(name, attributes)
1145
+ case name
1146
+ when 'Parameter' then @item = {}
1147
+ end
1148
+ end
1149
+ def tagend(name)
1150
+ case name
1151
+ when 'Marker' then @result[:marker] = @text
1152
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
1153
+ when 'DBParameterGroupName' then @result[:group_name] = @text # DescribeDbParametersResponse
1154
+ when 'DBParameterGroupFamily' then @result[:db_parameter_group_family] = @text # DescribeDBEngineDefaultParametersResponse
1155
+ when 'DataType' then @item[:data_type] = @text
1156
+ when 'Source' then @item[:source] = @text
1157
+ when 'Description' then @item[:description] = @text
1158
+ when 'IsModifiable' then @item[:is_modifiable] = (@text == 'true')
1159
+ when 'ApplyType' then @item[:apply_type] = @text
1160
+ when 'AllowedValues' then @item[:allowed_values] = @text
1161
+ when 'ParameterName' then @item[:name] = @text
1162
+ when 'ParameterValue' then @item[:value] = @text
1163
+ when 'Parameter' then @result[:parameters] << @item
1164
+ end
1165
+ end
1166
+ end
1167
+
1168
+ # --------------------------------------------
1169
+ # DB Snapshots
1170
+ # --------------------------------------------
1171
+
1172
+ class DescribeDbSnapshotsParser < RightAWSParser # :nodoc:
1173
+ def reset
1174
+ @result = { :db_snapshots => [] }
1175
+ end
1176
+ def tagstart(name, attributes)
1177
+ case name
1178
+ when 'DBSnapshot' then @item = {}
1179
+ end
1180
+ end
1181
+ def tagend(name)
1182
+ case name
1183
+ when 'Marker' then @result[:marker] = @text
1184
+ when 'MaxRecords' then @result[:max_records] = @text.to_i # ?
1185
+ when 'Engine' then @item[:engine] = @text
1186
+ when 'EngineVersion' then @item[:engine_version] = @text
1187
+ when 'InstanceCreateTime' then @item[:instance_create_time] = @text
1188
+ when 'Port' then @item[:endpoint_port] = @text.to_i
1189
+ when 'Status' then @item[:status] = @text
1190
+ when 'AvailabilityZone' then @item[:availability_zone] = @text
1191
+ when 'MasterUsername' then @item[:master_username] = @text
1192
+ when 'AllocatedStorage' then @item[:allocated_storage] = @text.to_i
1193
+ when 'SnapshotCreateTime' then @item[:create_time] = @text
1194
+ when 'DBInstanceIdentifier' then @item[:instance_aws_id] = @text
1195
+ when 'DBSnapshotIdentifier' then @item[:aws_id] = @text
1196
+ when 'DBSnapshot' then @result[:db_snapshots] << @item
1197
+ end
1198
+ end
1199
+ end
1200
+
1201
+ # --------------------------------------------
1202
+ # DB Events
1203
+ # --------------------------------------------
1204
+
1205
+ class DescribeEventsParser < RightAWSParser # :nodoc:
1206
+ def reset
1207
+ @result = { :events => [] }
1208
+ end
1209
+ def tagstart(name, attributes)
1210
+ case name
1211
+ when 'Event' then @item = {}
1212
+ end
1213
+ end
1214
+ def tagend(name)
1215
+ case name
1216
+ when 'Marker' then @result[:marker] = @text
1217
+ when 'MaxRecords' then @result[:max_records] = @text.to_i # ?
1218
+ when 'Date' then @item[:date] = @text
1219
+ when 'SourceIdentifier' then @item[:aws_id] = @text
1220
+ when 'SourceType' then @item[:source_type] = @text
1221
+ when 'Message' then @item[:message] = @text
1222
+ when 'Event' then @result[:events] << @item
1223
+ end
1224
+ end
1225
+ end
1226
+
1227
+ # --------------------------------------------
1228
+ # DB Events
1229
+ # --------------------------------------------
1230
+
1231
+ class DescribeDBEngineVersionsParser < RightAWSParser # :nodoc:
1232
+ def reset
1233
+ @result = { :db_engine_versions => [] }
1234
+ end
1235
+ def tagstart(name, attributes)
1236
+ case name
1237
+ when 'DBEngineVersion' then @item = {}
1238
+ end
1239
+ end
1240
+ def tagend(name)
1241
+ case name
1242
+ when 'Marker' then @result[:marker] = @text
1243
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
1244
+ when 'DBParameterGroupFamily' then @item[:db_parameter_group_family] = @text
1245
+ when 'Engine' then @item[:engine] = @text
1246
+ when 'EngineVersion' then @item[:engine_version] = @text
1247
+ when 'DBEngineVersion' then @result[:db_engine_versions] << @item
1248
+ end
1249
+ end
1250
+ end
1251
+
1252
+ # --------------------------------------------
1253
+ # DB Reserved Instances
1254
+ # --------------------------------------------
1255
+
1256
+ class DescribeReservedDBInstancesOfferingsParser < RightAWSParser # :nodoc:
1257
+ def reset
1258
+ @result = { :reserved_db_instances_offerings => [] }
1259
+ end
1260
+ def tagstart(name, attributes)
1261
+ case name
1262
+ when 'ReservedDBInstancesOffering' then @item = {}
1263
+ end
1264
+ end
1265
+ def tagend(name)
1266
+ case name
1267
+ when 'Marker' then @result[:marker] = @text
1268
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
1269
+ when 'DBInstanceClass' then @item[:instance_class] = @text
1270
+ when 'Duration' then @item[:duration] = @text.to_i
1271
+ when 'FixedPrice' then @item[:fixed_price] = @text.to_f
1272
+ when 'UsagePrice' then @item[:usage_price] = @text.to_f
1273
+ when 'MultiAZ' then @item[:multi_az] = (@text == 'true')
1274
+ when 'ProductDescription' then @item[:product_description] = @text
1275
+ when 'ReservedDBInstancesOfferingId' then @item[:aws_id] = @text
1276
+ when 'ReservedDBInstancesOffering' then @result[:reserved_db_instances_offerings] << @item
1277
+ end
1278
+ end
1279
+ end
1280
+
1281
+ class DescribeReservedDBInstancesParser < RightAWSParser # :nodoc:
1282
+ def reset
1283
+ @result = { :reserved_db_instances => [] }
1284
+ end
1285
+ def tagstart(name, attributes)
1286
+ case name
1287
+ when 'ReservedDBInstance' then @item = {}
1288
+ end
1289
+ end
1290
+ def tagend(name)
1291
+ case name
1292
+ when 'Marker' then @result[:marker] = @text
1293
+ when 'MaxRecords' then @result[:max_records] = @text.to_i
1294
+ when 'DBInstanceClass' then @item[:instance_class] = @text
1295
+ when 'Duration' then @item[:duration] = @text.to_i
1296
+ when 'FixedPrice' then @item[:fixed_price] = @text.to_f
1297
+ when 'UsagePrice' then @item[:usage_price] = @text.to_f
1298
+ when 'MultiAZ' then @item[:multi_az] = (@text == 'true')
1299
+ when 'ProductDescription' then @item[:product_description] = @text
1300
+ when 'ReservedDBInstancesOfferingId' then @item[:offering_aws_id] = @text
1301
+ when 'ReservedDBInstanceId' then @item[:aws_id] = @text
1302
+ when 'State' then @item[:state] = @text
1303
+ when 'ReservedDBInstance' then @result[:reserved_db_instances] << @item
1304
+ end
1305
+ end
1306
+ end
1307
+
1308
+ end
1309
+ end