cmeiklejohn-aws 2.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rds/rds.rb ADDED
@@ -0,0 +1,216 @@
1
+ module Aws
2
+ require 'xmlsimple'
3
+
4
+ # API Reference: http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/
5
+ class Rds < AwsBase
6
+ include AwsBaseInterface
7
+
8
+
9
+ # Amazon API version being used
10
+ API_VERSION = nil
11
+ DEFAULT_HOST = "rds.amazonaws.com"
12
+ DEFAULT_PATH = '/'
13
+ DEFAULT_PROTOCOL = 'https'
14
+ DEFAULT_PORT = 443
15
+
16
+ @@api = ENV['RDS_API_VERSION'] || API_VERSION
17
+
18
+
19
+ def self.api
20
+ @@api
21
+ end
22
+
23
+
24
+ @@bench = AwsBenchmarkingBlock.new
25
+
26
+
27
+ def self.bench_xml
28
+ @@bench.xml
29
+ end
30
+
31
+
32
+ def self.bench_ec2
33
+ @@bench.service
34
+ end
35
+
36
+
37
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
38
+ uri = ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']) : nil
39
+ init({ :name => 'RDS',
40
+ :default_host => uri ? uri.host : DEFAULT_HOST,
41
+ :default_port => uri ? uri.port : DEFAULT_PORT,
42
+ :default_service => uri ? uri.path : DEFAULT_PATH,
43
+ :default_protocol => uri ? uri.scheme : DEFAULT_PROTOCOL,
44
+ :api_version => API_VERSION },
45
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
46
+ aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
47
+ params)
48
+ end
49
+
50
+
51
+ def do_request(action, params, options={})
52
+ link = generate_request(action, params)
53
+ resp = request_info_xml_simple(:rds_connection, @params, link, @logger,
54
+ :group_tags=>{"DBInstances"=>"DBInstance",
55
+ "DBParameterGroups"=>"DBParameterGroup",
56
+ "DBSecurityGroups"=>"DBSecurityGroup",
57
+ "EC2SecurityGroups"=>"EC2SecurityGroup",
58
+ "IPRanges"=>"IPRange"},
59
+ :force_array=>["DBInstances",
60
+ "DBParameterGroups",
61
+ "DBSecurityGroups",
62
+ "EC2SecurityGroups",
63
+ "IPRanges"],
64
+ :pull_out_array=>options[:pull_out_array],
65
+ :pull_out_single=>options[:pull_out_single],
66
+ :wrapper=>options[:wrapper])
67
+ end
68
+
69
+
70
+ #-----------------------------------------------------------------
71
+ # REQUESTS
72
+ #-----------------------------------------------------------------
73
+
74
+ #
75
+ # identifier: db instance identifier. Must be unique per account per zone.
76
+ # instance_class: db.m1.small | db.m1.large | db.m1.xlarge | db.m2.2xlarge | db.m2.4xlarge
77
+ # See this for other values: http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/
78
+ #
79
+ # options:
80
+ # db_name: if you want a database created at the same time as the instance, specify :db_name option.
81
+ # availability_zone: default is random zone.
82
+ def create_db_instance(identifier, instance_class, allocated_storage, master_username, master_password, options={})
83
+ params = {}
84
+ params['DBInstanceIdentifier'] = identifier
85
+ params['DBInstanceClass'] = instance_class
86
+ params['AllocatedStorage'] = allocated_storage
87
+ params['MasterUsername'] = master_username
88
+ params['MasterUserPassword'] = master_password
89
+
90
+ params['Engine'] = options[:engine] || "MySQL5.1"
91
+ params['DBName'] = options[:db_name] if options[:db_name]
92
+ params['AvailabilityZone'] = options[:availability_zone] if options[:availability_zone]
93
+ params['PreferredMaintenanceWindow'] = options[:preferred_maintenance_window] if options[:preferred_maintenance_window]
94
+ params['BackupRetentionPeriod'] = options[:preferred_retention_period] if options[:preferred_retention_period]
95
+ params['PreferredBackupWindow'] = options[:preferred_backup_window] if options[:preferred_backup_window]
96
+
97
+ @logger.info("Creating DB Instance called #{identifier}")
98
+
99
+ link = do_request("CreateDBInstance", params, :pull_out_single=>[:create_db_instance_result, :db_instance])
100
+
101
+ rescue Exception
102
+ on_exception
103
+ end
104
+
105
+
106
+ # options:
107
+ # DBInstanceIdentifier
108
+ # MaxRecords
109
+ # Marker
110
+ #
111
+ # Returns array of instances as hashes.
112
+ # Response metadata can be retreived by calling array.response_metadata on the returned array.
113
+ def describe_db_instances(options={})
114
+ params = {}
115
+ params['DBInstanceIdentifier'] = options[:db_instance_identifier] if options[:db_instance_identifier]
116
+ params['MaxRecords'] = options[:max_records] if options[:max_records]
117
+ params['Marker'] = options[:marker] if options[:marker]
118
+
119
+ resp = do_request("DescribeDBInstances", params, :pull_out_array=>[:describe_db_instances_result, :db_instances])
120
+
121
+ rescue Exception
122
+ on_exception
123
+ end
124
+
125
+
126
+ # identifier: identifier of db instance to delete.
127
+ # final_snapshot_identifier: if specified, RDS will crate a final snapshot before deleting so you can restore it later.
128
+ def delete_db_instance(identifier, final_snapshot_identifier=nil)
129
+ @logger.info("Deleting DB Instance - " + identifier.to_s)
130
+
131
+ params = {}
132
+ params['DBInstanceIdentifier'] = identifier
133
+ if final_snapshot_identifier
134
+ params['FinalDBSnapshotIdentifier'] = final_snapshot_identifier
135
+ else
136
+ params['SkipFinalSnapshot'] = true
137
+ end
138
+
139
+ link = do_request("DeleteDBInstance", params, :pull_out_single=>[:delete_db_instance_result, :db_instance])
140
+
141
+ rescue Exception
142
+ on_exception
143
+ end
144
+
145
+
146
+ def create_db_security_group(group_name, description, options={})
147
+ params = {}
148
+ params['DBSecurityGroupName'] = group_name
149
+ params['DBSecurityGroupDescription'] = description
150
+
151
+ link = do_request("CreateDBSecurityGroup", params, :pull_out_single => [:create_db_security_group_result, :db_security_group])
152
+
153
+ rescue Exception
154
+ on_exception
155
+ end
156
+
157
+
158
+ def delete_db_security_group(group_name, options={})
159
+ params = {}
160
+ params['DBSecurityGroupName'] = group_name
161
+
162
+ link = do_request("DeleteDBSecurityGroup", params)
163
+
164
+ rescue Exception
165
+ on_exception
166
+ end
167
+
168
+
169
+ def describe_db_security_groups(options={})
170
+ params = {}
171
+ params['DBSecurityGroupName'] = options[:DBSecurityGroupName] if options[:DBSecurityGroupName]
172
+ params['MaxRecords'] = options[:MaxRecords] if options[:MaxRecords]
173
+
174
+ link = do_request("DescribeDBSecurityGroups", params, :pull_out_array=>[:describe_db_security_groups_result, :db_security_groups], :wrapper=>:db_security_group)
175
+
176
+
177
+ rescue Exception
178
+ on_exception
179
+ end
180
+
181
+
182
+ def authorize_db_security_group_ingress_ec2group(group_name, ec2_group_name, ec2_group_owner_id, options={})
183
+ params = {}
184
+ params['DBSecurityGroupName'] = group_name
185
+ params['EC2SecurityGroupOwnerId'] = ec2_group_owner_id
186
+ params['EC2SecurityGroupName'] = ec2_group_name
187
+ link = do_request("AuthorizeDBSecurityGroupIngress", params)
188
+ rescue Exception
189
+ on_exception
190
+ end
191
+
192
+
193
+ def authorize_db_security_group_ingress_range(group_name, ip_range, options={})
194
+ params = {}
195
+ params['DBSecurityGroupName'] = group_name
196
+ params['CIDRIP'] = ip_range
197
+ link = do_request("AuthorizeDBSecurityGroupIngress", params)
198
+ rescue Exception
199
+ on_exception
200
+ end
201
+
202
+
203
+ def revoke_db_security_group_ingress(group_name, ip_range, options={})
204
+ params = {}
205
+ params['DBSecurityGroupName'] = group_name
206
+ params['CIDRIP'] = ip_range
207
+ link = do_request("RevokeDBSecurityGroupIngress", params)
208
+ rescue Exception
209
+ on_exception
210
+ end
211
+
212
+
213
+
214
+ end
215
+
216
+ end
data/lib/right_aws.rb ADDED
@@ -0,0 +1,57 @@
1
+ #
2
+ # Copyright (c) 2007-2008 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
+ require 'benchmark'
25
+ require 'net/https'
26
+ require 'uri'
27
+ require 'time'
28
+ require "cgi"
29
+ require "base64"
30
+ require "rexml/document"
31
+ require "openssl"
32
+ require "digest/sha1"
33
+
34
+ require 'rubygems'
35
+ require 'right_http_connection'
36
+
37
+ $:.unshift(File.dirname(__FILE__))
38
+ require 'awsbase/benchmark_fix'
39
+ require 'awsbase/support'
40
+ require 'awsbase/right_awsbase'
41
+ require 'ec2/right_ec2'
42
+ require 'ec2/right_mon_interface'
43
+ require 's3/right_s3_interface'
44
+ require 's3/right_s3'
45
+ require 'sqs/right_sqs_interface'
46
+ require 'sqs/right_sqs'
47
+ require 'sdb/right_sdb_interface'
48
+ require 'acf/right_acf_interface'
49
+ require 'elb/elb_interface'
50
+
51
+
52
+ # backwards compatible.
53
+ # @deprecated
54
+ module RightAws
55
+ include Aws
56
+ extend Aws
57
+ end