Class: Aws::Rds

Inherits:
AwsBase show all
Includes:
AwsBaseInterface
Defined in:
lib/rds/rds.rb

Overview

Constant Summary collapse

API_VERSION =

Amazon API version being used

nil
DEFAULT_HOST =
"rds.amazonaws.com"
DEFAULT_PATH =
'/'
DEFAULT_PROTOCOL =
'https'
DEFAULT_PORT =
443
@@api =
ENV['RDS_API_VERSION'] || API_VERSION
@@bench =
AwsBenchmarkingBlock.new

Constants included from AwsBaseInterface

AwsBaseInterface::DEFAULT_SIGNATURE_VERSION

Constants inherited from AwsBase

AwsBase::AMAZON_PROBLEMS

Instance Attribute Summary

Attributes included from AwsBaseInterface

#aws_access_key_id, #cache, #connection, #last_errors, #last_request, #last_request_id, #last_response, #logger, #params, #signature_version

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AwsBaseInterface

#cache_hits?, caching, caching=, #caching?, #generate_request2, #get_conn, #hash_params, #init, #multi_thread, #on_exception, #request_cache_or_info, #request_info2, #request_info_impl, #request_info_xml_simple, #signed_service_params, #update_cache

Methods inherited from AwsBase

amazon_problems, amazon_problems=

Constructor Details

#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ Rds

Returns a new instance of Rds.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rds/rds.rb', line 37

def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
    uri = ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']) : nil
    init({ :name => 'RDS',
           :default_host => uri ? uri.host : DEFAULT_HOST,
           :default_port => uri ? uri.port : DEFAULT_PORT,
           :default_service => uri ? uri.path : DEFAULT_PATH,
           :default_protocol => uri ? uri.scheme : DEFAULT_PROTOCOL },
         aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
         aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
         params)
end

Class Method Details

.apiObject



19
20
21
# File 'lib/rds/rds.rb', line 19

def self.api
    @@api
end

.bench_ec2Object



32
33
34
# File 'lib/rds/rds.rb', line 32

def self.bench_ec2
    @@bench.service
end

.bench_xmlObject



27
28
29
# File 'lib/rds/rds.rb', line 27

def self.bench_xml
    @@bench.xml
end

Instance Method Details

#authorize_db_security_group_ingress_ec2group(group_name, ec2_group_name, ec2_group_owner_id, options = {}) ⇒ Object



167
168
169
170
171
172
173
174
175
176
# File 'lib/rds/rds.rb', line 167

def authorize_db_security_group_ingress_ec2group(group_name, ec2_group_name, ec2_group_owner_id, options={})
    params = {}
    params['DBSecurityGroupName'] = group_name
    params['EC2SecurityGroupOwnerId'] = ec2_group_owner_id
    params['EC2SecurityGroupName'] = ec2_group_name
    link = generate_request("AuthorizeDBSecurityGroupIngress", params)
    resp = request_info_xml_simple(:rds_connection, @params, link, @logger)
rescue Exception
    on_exception
end

#authorize_db_security_group_ingress_range(group_name, ip_range, options = {}) ⇒ Object



179
180
181
182
183
184
185
186
187
# File 'lib/rds/rds.rb', line 179

def authorize_db_security_group_ingress_range(group_name, ip_range, options={})
    params = {}
    params['DBSecurityGroupName'] = group_name
    params['CIDRIP'] = ip_range
    link = generate_request("AuthorizeDBSecurityGroupIngress", params)
    resp = request_info_xml_simple(:rds_connection, @params, link, @logger)
rescue Exception
    on_exception
end

#create_db_instance(identifier, instance_class, allocated_storage, master_username, master_password, options = {}) ⇒ Object

identifier: db instance identifier. Must be unique per account per zone. instance_class: db.m1.small | db.m1.large | db.m1.xlarge | db.m2.2xlarge | db.m2.4xlarge See this for other values: docs.amazonwebservices.com/AmazonRDS/latest/APIReference/

options:

db_name: if you want a database created at the same time as the instance, specify :db_name option.
availability_zone: default is random zone.


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rds/rds.rb', line 67

def create_db_instance(identifier, instance_class, allocated_storage, master_username, master_password, options={})
    params = {}
    params['DBInstanceIdentifier'] = identifier
    params['DBInstanceClass'] = instance_class
    params['AllocatedStorage'] = allocated_storage
    params['MasterUsername'] = master_username
    params['MasterUserPassword'] = master_password

    params['Engine'] = options[:engine] || "MySQL5.1"
    params['DBName'] = options[:db_name] if options[:db_name]
    params['AvailabilityZone'] = options[:availability_zone] if options[:availability_zone]
    params['PreferredMaintenanceWindow'] = options[:preferred_maintenance_window] if options[:preferred_maintenance_window]
    params['BackupRetentionPeriod'] = options[:preferred_retention_period] if options[:preferred_retention_period]
    params['PreferredBackupWindow'] = options[:preferred_backup_window] if options[:preferred_backup_window]

    @logger.info("Creating DB Instance called #{identifier}")

    link = generate_request("CreateDBInstance", params)
    resp = request_info_xml_simple(:rds_connection, @params, link, @logger)

rescue Exception
    on_exception
end

#create_db_security_groups(group_name, description, options = {}) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# File 'lib/rds/rds.rb', line 131

def create_db_security_groups(group_name, description, options={})
    params = {}
    params['DBSecurityGroupName'] = group_name
    params['DBSecurityGroupDescription'] = description
    params['Engine'] = options[:engine] || "MySQL5.1"
    link = generate_request("CreateDBSecurityGroup", params)
    resp = request_info_xml_simple(:rds_connection, @params, link, @logger)
rescue Exception
    on_exception
end

#delete_db_instance(identifier, final_snapshot_identifier = nil) ⇒ Object

identifier: identifier of db instance to delete. final_snapshot_identifier: if specified, RDS will crate a final snapshot before deleting so you can restore it later.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rds/rds.rb', line 112

def delete_db_instance(identifier, final_snapshot_identifier=nil)
    @logger.info("Deleting DB Instance - " + identifier.to_s)

    params = {}
    params['DBInstanceIdentifier'] = identifier
    if final_snapshot_identifier
        params['FinalDBSnapshotIdentifier'] = final_snapshot_identifier
    else
        params['SkipFinalSnapshot'] = true
    end

    link = generate_request("DeleteDBInstance", params)
    resp = request_info_xml_simple(:rds_connection, @params, link, @logger)

rescue Exception
    on_exception
end

#delete_db_security_group(group_name, options = {}) ⇒ Object



143
144
145
146
147
148
149
150
# File 'lib/rds/rds.rb', line 143

def delete_db_security_group(group_name, options={})
    params = {}
    params['DBSecurityGroupName'] = group_name
    link = generate_request("DeleteDBSecurityGroup", params)
    resp = request_info_xml_simple(:rds_connection, @params, link, @logger)
rescue Exception
    on_exception
end

#describe_db_instances(options = {}) ⇒ Object

options:

DBInstanceIdentifier
MaxRecords
Marker


96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rds/rds.rb', line 96

def describe_db_instances(options={})
    params = {}
    params['DBInstanceIdentifier'] = options[:DBInstanceIdentifier] if options[:DBInstanceIdentifier]
    params['MaxRecords'] = options[:MaxRecords] if options[:MaxRecords]
    params['Marker'] = options[:Marker] if options[:Marker]

    link = generate_request("DescribeDBInstances", params)
    resp = request_info_xml_simple(:rds_connection, @params, link, @logger)

rescue Exception
    on_exception
end

#describe_db_security_groups(options = {}) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/rds/rds.rb', line 153

def describe_db_security_groups(options={})
    params = {}
    params['DBSecurityGroupName'] = options[:DBSecurityGroupName] if options[:DBSecurityGroupName]
    params['MaxRecords'] = options[:MaxRecords] if options[:MaxRecords]

    force_array = options[:force_array].nil? ? false : options[:force_array]

    link = generate_request("DescribeDBSecurityGroups", params)
    resp = request_info_xml_simple(:rds_connection, @params, link, @logger, :force_array => force_array)
rescue Exception
    on_exception
end

#generate_request(action, params = {}) ⇒ Object



50
51
52
# File 'lib/rds/rds.rb', line 50

def generate_request(action, params={})
    generate_request2(@aws_access_key_id, @aws_secret_access_key, action, @@api, @params, params)
end

#revoke_db_security_group_ingress(group_name, ip_range, options = {}) ⇒ Object



190
191
192
193
194
195
196
197
198
# File 'lib/rds/rds.rb', line 190

def revoke_db_security_group_ingress(group_name, ip_range, options={})
    params = {}
    params['DBSecurityGroupName'] = group_name
    params['CIDRIP'] = ip_range
    link = generate_request("RevokeDBSecurityGroupIngress", params)
    resp = request_info_xml_simple(:rds_connection, @params, link, @logger)
rescue Exception
    on_exception
end