Class: RightAws::RdsInterface
- Inherits:
-
RightAwsBase
- Object
- RightAwsBase
- RightAws::RdsInterface
- Includes:
- RightAwsBaseInterface
- Defined in:
- lib/rds/right_rds_interface.rb
Defined Under Namespace
Classes: DescribeDBEngineVersionsParser, DescribeDBSubnetGroupsParser, DescribeDbInstancesParser, DescribeDbParameterGroupsParser, DescribeDbParametersParser, DescribeDbSecurityGroupsParser, DescribeDbSnapshotsParser, DescribeEventsParser, DescribeOrderableDBInstanceOptionsParser, DescribeReservedDBInstancesOfferingsParser, DescribeReservedDBInstancesParser
Constant Summary collapse
- API_VERSION =
"2012-09-17"
- DEFAULT_HOST =
'rds.amazonaws.com'
- DEFAULT_PORT =
443
- DEFAULT_PROTOCOL =
'https'
- DEFAULT_PATH =
'/'
- DEFAULT_INSTANCE_CLASS =
'db.m1.small'
- INSTANCE_CLASSES =
[ 'db.t1.micro', 'db.m1.small', 'db.m1.medium', 'db.m1.large', 'db.m1.xlarge', 'db.m2.xlarge', 'db.m2.2xlarge', 'db.m2.4xlarge']
- LICENSE_MODELS =
['bring-your-own-license', 'license-included', 'general-public-license']
- @@bench =
AwsBenchmarkingBlock.new
Constants included from RightAwsBaseInterface
RightAws::RightAwsBaseInterface::BLOCK_DEVICE_KEY_MAPPING, RightAws::RightAwsBaseInterface::DEFAULT_SIGNATURE_VERSION
Constants inherited from RightAwsBase
RightAws::RightAwsBase::AMAZON_PROBLEMS, RightAws::RightAwsBase::RAISE_ON_TIMEOUT_ON_ACTIONS
Instance Attribute Summary
Attributes included from RightAwsBaseInterface
#aws_access_key_id, #aws_secret_access_key, #cache, #connection, #last_errors, #last_request, #last_request_id, #last_response, #logger, #params, #signature_version
Class Method Summary collapse
Instance Method Summary collapse
-
#authorize_db_security_group_ingress(db_security_group_name, params = {}) ⇒ Object
Authorize an ingress.
-
#create_db_instance(aws_id, master_username, master_user_password, params = {}) ⇒ Object
Create a new RDS instance of the type and size specified by you.
-
#create_db_instance_read_replica(aws_id, source_db_instance_identifier, params = {}) ⇒ Object
Create a DB Instance that acts as a Read Replica of a source DB Instance.
-
#create_db_parameter_group(db_parameter_group_name, db_parameter_group_description, db_parameter_group_family = 'mysql5.1', params = {}) ⇒ Object
Creates a database parameter group so that configuration of an RDS Instance can be controlled.
-
#create_db_security_group(db_security_group_name, db_security_group_description, params = {}) ⇒ Object
Create a database security group so that ingress to an RDS Instance can be controlled.
-
#create_db_snapshot(aws_id, instance_aws_id) ⇒ Object
Create a DBSnapshot.
-
#create_db_subnet_group(subnet_group_name, subnets, subnet_group_description = '-') ⇒ Object
Create a new DB Subnet Group.
-
#delete_db_instance(aws_id, params = {}) ⇒ Object
Delete a DB instance.
-
#delete_db_parameter_group(db_parameter_group_name) ⇒ Object
Delete DBParameter Group.
-
#delete_db_security_group(db_security_group_name) ⇒ Object
Delete a database security group.
-
#delete_db_snapshot(aws_id) ⇒ Object
Delete a DBSnapshot.
-
#delete_db_subnet_group(name) ⇒ Object
Delete a DB Subnet Group.
-
#describe_db_engine_versions(params = {}, &block) ⇒ Object
Get a list of the available DB engines.
-
#describe_db_instances(*params, &block) ⇒ Object
List DB instances.
-
#describe_db_parameter_groups(*db_parameter_group_name, &block) ⇒ Object
Describe DBParameterGroups.
-
#describe_db_parameters(*db_parameter_group_name, &block) ⇒ Object
Get the detailed parameters list for a particular DBParameterGroup.
-
#describe_db_security_groups(*db_security_group_name, &block) ⇒ Object
——————————————– DB SecurityGroups ——————————————–.
-
#describe_db_snapshots(params = {}, &block) ⇒ Object
Get DBSecurityGroup details for a particular customer or for a particular DBSecurityGroup if a name is specified.
-
#describe_db_subnet_groups(params = {}, &block) ⇒ Object
Lists available DB Subnet Groups.
-
#describe_engine_default_parameters(*db_parameter_group_family, &block) ⇒ Object
Describe a default parameters for the parameter group family.
-
#describe_events(params = {}, &block) ⇒ Object
Get events related to RDS instances and DBSecurityGroups for the past 14 days.
-
#describe_orderable_db_instance_options(engine, params = {}, &block) ⇒ Object
Describe a list of orderable DB Instance options for the specified engine.
-
#describe_reserved_db_instances(params = {}, &block) ⇒ Object
Returns information about reserved DB Instances for this account, or about a specified reserved DB Instance.
-
#describe_reserved_db_instances_offerings(params = {}, &block) ⇒ Object
Lists available reserved DB Instance offerings.
-
#fix_date(date) ⇒ Object
:nodoc:.
-
#generate_request(action, params = {}) ⇒ Object
Generates request hash for REST API.
- #get_db_subnet_group(group_name, &block) ⇒ Object
-
#incrementally_list_items(action, parser_class, params = {}, &block) ⇒ Object
Incrementally lists something.
-
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ RdsInterface
constructor
Create a new handle to a RDS account.
-
#modify_db_instance(aws_id, params = {}) ⇒ Object
Modify a DB instance.
-
#modify_db_parameter_group(db_parameter_group_name, params = {}) ⇒ Object
Modify DBParameterGroup paramaters.
-
#modify_db_security_group_ingress(action, db_security_group_name, params = {}) ⇒ Object
:nodoc:.
-
#modify_db_subnet_group(subnet_group_name, subnets, subnet_group_description = '') ⇒ Object
Modify an existing DB Subnet Group.
-
#purchase_reserved_db_instances_offering(offering_aws_id, params = {}) ⇒ Object
Purchases a reserved DB Instance offering.
-
#reboot_db_instance(aws_id, params = {}) ⇒ Object
Reboot Db instance.
-
#request_info(request, parser, &block) ⇒ Object
Sends request to Amazon and parses the response.
-
#reset_db_parameter_group(db_parameter_group_name, *params) ⇒ Object
Modify the parameters of a DBParameterGroup to the engine/system default value.
-
#restore_db_instance_from_db_snapshot(snapshot_aws_id, instance_aws_id, params = {}) ⇒ Object
Create a new RDS instance from a DBSnapshot.
-
#restore_db_instance_to_point_in_time(instance_aws_id, new_instance_aws_id, params = {}) ⇒ Object
Create a new RDS instance from a point-in-time system snapshot.
-
#revoke_db_security_group_ingress(db_security_group_name, params = {}) ⇒ Object
Revoke an ingress.
Methods included from RightAwsBaseInterface
#amazonize_block_device_mappings, #amazonize_hash_with_key_mapping, #amazonize_list, #amazonize_list_with_key_mapping, #cache_hits?, caching, caching=, #caching?, #destroy_connection, #generate_request_impl, #get_connection, #get_connections_storage, #get_server_url, #init, #map_api_keys_and_values, #on_exception, #request_cache_or_info, #request_info_impl, #signed_service_params, #update_cache, #with_connection_options
Methods inherited from RightAwsBase
amazon_problems, amazon_problems=, raise_on_timeout_on_actions, raise_on_timeout_on_actions=
Constructor Details
#initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {}) ⇒ RdsInterface
Create a new handle to a RDS account. All handles share the same per process or per thread HTTP connection to RDS. Each handle is for a specific account. The params have the following options:
-
:endpoint_url
a fully qualified url to Amazon API endpoint (this overwrites: :server, :port, :service, :protocol). Example: ‘rds.amazonaws.com’ -
:server
: RDS service host, default: DEFAULT_HOST -
:port
: RDS service port, default: DEFAULT_PORT -
:protocol
: ‘http’ or ‘https’, default: DEFAULT_PROTOCOL -
:logger
: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
rds = RightAws::RdsInterface.new('xxxxxxxxxxxxxxxxxxxxx','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
{:logger => Logger.new('/tmp/x.log')}) #=> #<RightAws::RdsInterface::0xb7b3c30c>
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rds/right_rds_interface.rb', line 67 def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={}) init({ :name => 'RDS', :default_host => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).host : DEFAULT_HOST, :default_port => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).port : DEFAULT_PORT, :default_service => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).path : DEFAULT_PATH, :default_protocol => ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']).scheme : DEFAULT_PROTOCOL, :default_api_version => ENV['RDS_API_VERSION'] || API_VERSION }, aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'], aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'], params) end |
Class Method Details
.bench_service ⇒ Object
51 52 53 |
# File 'lib/rds/right_rds_interface.rb', line 51 def self.bench_service @@bench.service end |
.bench_xml ⇒ Object
48 49 50 |
# File 'lib/rds/right_rds_interface.rb', line 48 def self.bench_xml @@bench.xml end |
Instance Method Details
#authorize_db_security_group_ingress(db_security_group_name, params = {}) ⇒ Object
Authorize an ingress. Params: :cidrip
or (:ec2_security_group_name
and :ec2_security_group_owner
)
rds.('kd3', :cidrip => '131.0.0.1/8')
{:owner_id=>"82...25",
:ec2_security_groups=>[],
:description=>"kd",
:ip_ranges=>
[{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
{:status=>"Authorizing", :cidrip=>"131.0.0.1/8"}],
:name=>"kd3"}
rds.('kd3',:ec2_security_group_owner => '82...27',
:ec2_security_group_name => 'default') #=>
{:owner_id=>"82...25",
:ec2_security_groups=>
[{:status=>"Authorized", :owner_id=>"82...25", :name=>"g1"},
{:status=>"Authorized", :owner_id=>"82...26", :name=>"g2"},
{:status=>"Authorizing", :owner_id=>"82...27", :name=>"default"}],
:ip_ranges=>
[{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"131.0.0.1/8"}],
:name=>"kd3"}
459 460 461 |
# File 'lib/rds/right_rds_interface.rb', line 459 def (db_security_group_name, params={}) modify_db_security_group_ingress('AuthorizeDBSecurityGroupIngress', db_security_group_name, params) end |
#create_db_instance(aws_id, master_username, master_user_password, params = {}) ⇒ Object
Create a new RDS instance of the type and size specified by you. The default storage engine for RDS Instances is InnoDB.
Mandatory arguments: aws_id
, master_username
, master_user_password
Optional params: :allocated_storage
(25 by def), :instance_class
, :engine
(‘MySQL’ by def), :endpoint_port
, :db_name
, :db_security_groups
, :db_parameter_group
, :availability_zone
, :preferred_maintenance_window
:backup_retention_period
, :preferred_backup_window
, :multi_az
, :engine_version
, :auto_minor_version_upgrade
, :license_model
, :iops
, :db_subnet_group_name
, :character_set_name
, :option_group_name
rds.create_db_instance('kd-delete-me-01', 'username', 'password',
:instance_class => 'db.m1.small',
:multi_az => true,
:auto_minor_version_upgrade => false ) #=>
{:instance_class=>"db.m1.small",
:multi_az=>true,
:status=>"creating",
:backup_retention_period=>1,
:read_replica_db_instance_identifiers=>[],
:master_username=>"username",
:preferred_maintenance_window=>"sun:05:00-sun:09:00",
:auto_minor_version_upgrade=>false,
:db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
:engine=>"mysql",
:allocated_storage=>25,
:aws_id=>"kd-delete-me-01",
:preferred_backup_window=>"03:00-05:00",
:engine_version=>"5.1.50",
:pending_modified_values=>{:master_user_password=>"****"},
:db_security_groups=>[{:status=>"active", :name=>"default"}]}
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/rds/right_rds_interface.rb', line 210 def create_db_instance(aws_id, master_username, master_user_password, params={}) request_hash = {} # Mandatory request_hash['DBInstanceIdentifier'] = aws_id request_hash['MasterUsername'] = master_username request_hash['MasterUserPassword'] = master_user_password # Mandatory with default values request_hash['DBInstanceClass'] = params[:instance_class].right_blank? ? DEFAULT_INSTANCE_CLASS : params[:instance_class].to_s request_hash['AllocatedStorage'] = params[:allocated_storage].right_blank? ? 25 : params[:allocated_storage] request_hash['Engine'] = params[:engine].right_blank? ? 'mysql' : params[:engine] # Optional request_hash['Port'] = params[:endpoint_port] unless params[:endpoint_port].right_blank? request_hash['DBName'] = params[:db_name] unless params[:db_name].right_blank? request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].right_blank? request_hash['MultiAZ'] = params[:multi_az].to_s unless params[:multi_az].nil? request_hash['PreferredMaintenanceWindow'] = params[:preferred_maintenance_window] unless params[:preferred_maintenance_window].right_blank? request_hash['BackupRetentionPeriod'] = params[:backup_retention_period] unless params[:backup_retention_period].right_blank? request_hash['PreferredBackupWindow'] = params[:preferred_backup_window] unless params[:preferred_backup_window].right_blank? request_hash['DBParameterGroupName'] = params[:db_parameter_group] unless params[:db_parameter_group].right_blank? request_hash['EngineVersion'] = params[:engine_version] unless params[:engine_version].right_blank? request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade].to_s unless params[:auto_minor_version_upgrade].nil? request_hash['LicenseModel'] = params[:license_model] unless params[:license_model].right_blank? request_hash['CharacterSetName'] = params[:character_set_name] unless params[:character_set_name].right_blank? request_hash['DBSubnetGroupName'] = params[:db_subnet_group_name] unless params[:db_subnet_group_name].right_blank? request_hash['Iops'] = params[:iops] unless params[:iops].right_blank? request_hash['OptionGroupName'] = params[:option_group_name] unless params[:option_group_name].right_blank? request_hash.merge!(amazonize_list('DBSecurityGroups.member', params[:db_security_groups])) link = generate_request('CreateDBInstance', request_hash) request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first end |
#create_db_instance_read_replica(aws_id, source_db_instance_identifier, params = {}) ⇒ Object
Create a DB Instance that acts as a Read Replica of a source DB Instance.
Optional params: :endpoint_port
, :availability_zone
, :instance_class
, :auto_minor_version_upgrade
, :iops
, :option_group_name
rds.create_db_instance_read_replica('kd-delete-me-01-replica-01', 'kd-delete-me-01',
:instance_class => 'db.m1.small',
:endpoint_port => '11000',
:auto_minor_version_upgrade => false ) #=>
{:auto_minor_version_upgrade=>false,
:read_replica_source_db_instance_identifier=>"kd-delete-me-01",
:status=>"creating",
:backup_retention_period=>0,
:allocated_storage=>30,
:read_replica_db_instance_identifiers=>[],
:engine_version=>"5.1.50",
:aws_id=>"kd-delete-me-01-replica-01",
:multi_az=>false,
:preferred_maintenance_window=>"sun:06:00-sun:10:00",
:master_username=>"username",
:preferred_backup_window=>"02:00-04:00",
:db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
:engine=>"mysql",
:db_security_groups=>[{:status=>"active", :name=>"default"}],
:instance_class=>"db.m1.small",
:pending_modified_values=>{}}
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 |
# File 'lib/rds/right_rds_interface.rb', line 999 def create_db_instance_read_replica(aws_id, source_db_instance_identifier, params={}) request_hash = { 'DBInstanceIdentifier' => aws_id, 'SourceDBInstanceIdentifier' => source_db_instance_identifier} request_hash['Port'] = params[:endpoint_port] unless params[:endpoint_port].right_blank? request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].right_blank? request_hash['DBInstanceClass'] = params[:instance_class] unless params[:instance_class].right_blank? request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade].to_s unless params[:auto_minor_version_upgrade].nil? request_hash['Iops'] = params[:iops] unless params[:iops].right_blank? request_hash['OptionGroupName'] = params[:option_group_name] unless params[:option_group_name].right_blank? link = generate_request('CreateDBInstanceReadReplica', request_hash) request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first end |
#create_db_parameter_group(db_parameter_group_name, db_parameter_group_description, db_parameter_group_family = 'mysql5.1', params = {}) ⇒ Object
Creates a database parameter group so that configuration of an RDS Instance can be controlled.
rds.create_db_parameter_group('my-new-group-1','My new group') #=> {}
TODO: this call returns an empty hash, but should be a parameter group data - ask Amazon guys.
528 529 530 531 532 533 534 |
# File 'lib/rds/right_rds_interface.rb', line 528 def create_db_parameter_group(db_parameter_group_name, db_parameter_group_description, db_parameter_group_family='mysql5.1', params={}) params['DBParameterGroupName'] = db_parameter_group_name params['Description'] = db_parameter_group_description params['DBParameterGroupFamily'] = db_parameter_group_family link = generate_request('CreateDBParameterGroup', params ) request_info(link, DescribeDbParameterGroupsParser.new(:logger => @logger))[:db_parameter_groups].first end |
#create_db_security_group(db_security_group_name, db_security_group_description, params = {}) ⇒ Object
Create a database security group so that ingress to an RDS Instance can be controlled. A new security group cannot have the same name as an existing group.
Options: :vpc_id
ds.create_db_security_group('kd3', 'kd') #=>
{:ec2_security_groups=>[],
:description=>"kd",
:ip_ranges=>[],
:name=>"kd3",
:owner_id=>"82...25"}
412 413 414 415 416 417 418 |
# File 'lib/rds/right_rds_interface.rb', line 412 def create_db_security_group(db_security_group_name, db_security_group_description, params={}) request_hash = { 'DBSecurityGroupName' => db_security_group_name, 'DBSecurityGroupDescription' => db_security_group_description } request_hash['EC2VpcId'] = params[:vpc_id] unless params[:vpc_id].right_blank? link = generate_request('CreateDBSecurityGroup', request_hash) request_info(link, DescribeDbSecurityGroupsParser.new(:logger => @logger))[:db_security_groups].first end |
#create_db_snapshot(aws_id, instance_aws_id) ⇒ Object
Create a DBSnapshot. The source DBInstance must be in Available state
rds.create_db_snapshot('remove-me-tomorrow-2', 'my-awesome-db-g7' ) #=>
{:status=>"PendingCreation",
:allocated_storage=>50,
:availability_zone=>"us-east-1b",
:engine=>"MySQL5.1",
:aws_id=>"remove-me-tomorrow-2",
:instance_create_time=>"2009-07-13T09:35:39.243Z",
:endpoint_port=>3306,
:instance_aws_id=>"my-awesome-db-g7",
:db_master_username=>"username"}
762 763 764 765 766 |
# File 'lib/rds/right_rds_interface.rb', line 762 def create_db_snapshot(aws_id, instance_aws_id) link = generate_request('CreateDBSnapshot', 'DBSnapshotIdentifier' => aws_id, 'DBInstanceIdentifier' => instance_aws_id) request_info(link, DescribeDbSnapshotsParser.new(:logger => @logger))[:db_snapshots].first end |
#create_db_subnet_group(subnet_group_name, subnets, subnet_group_description = '-') ⇒ Object
Create a new DB Subnet Group.
rds.create_db_subnet_group('kd-subnet-group-1', ['subnet-5259d03a', 'subnet-eb518f83'], 'delete me please') #=>
{:subnets=>
[{:availability_zone=>
{:name=>"us-east-1a", :provisioned_iops_capable=>false},
:status=>"Active",
:subnet_id=>"subnet-eb518f83"},
{:availability_zone=>
{:name=>"us-east-1d", :provisioned_iops_capable=>false},
:status=>"Active",
:subnet_id=>"subnet-5259d03a"}],
:vpc_id=>"vpc-10518f78",
:status=>"Complete",
:description=>"delete me please",
:name=>"kd-subnet-group-1"}
P.S. docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_CreateDBSubnetGroup.html
1181 1182 1183 1184 1185 1186 1187 |
# File 'lib/rds/right_rds_interface.rb', line 1181 def create_db_subnet_group(subnet_group_name, subnets, subnet_group_description = '-') request_hash = { 'DBSubnetGroupName' => subnet_group_name, 'DBSubnetGroupDescription' => subnet_group_description } request_hash.merge!(amazonize_list('SubnetIds.member', subnets)) link = generate_request('CreateDBSubnetGroup', request_hash) request_info(link, DescribeDBSubnetGroupsParser.new(:logger => @logger))[:subnet_groups].first end |
#delete_db_instance(aws_id, params = {}) ⇒ Object
Delete a DB instance
Mandatory arguments: aws_id Optional params: :skip_final_snapshot (‘false’ by def),
:snapshot_aws_id ('{instance_aws_id}-final-snapshot-YYYYMMDDHHMMSS')
rds.delete_db_instance('my-awesome-db-g2') #=> true
341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/rds/right_rds_interface.rb', line 341 def delete_db_instance(aws_id, params={}) request_hash = {} request_hash['DBInstanceIdentifier'] = aws_id request_hash['SkipFinalSnapshot'] = params.has_key?(:skip_final_snapshot) ? params[:skip_final_snapshot].to_s : 'false' if request_hash['SkipFinalSnapshot'] == 'false' && params[:snapshot_aws_id].right_blank? params = params.dup params[:snapshot_aws_id] = "#{aws_id}-final-snapshot-#{Time.now.utc.strftime('%Y%m%d%H%M%S')}" end request_hash['FinalDBSnapshotIdentifier'] = params[:snapshot_aws_id] unless params[:snapshot_aws_id].right_blank? link = generate_request('DeleteDBInstance', request_hash) request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first end |
#delete_db_parameter_group(db_parameter_group_name) ⇒ Object
Delete DBParameter Group.
rds.delete_db_parameter_group(‘kd1’) #=> true
565 566 567 568 |
# File 'lib/rds/right_rds_interface.rb', line 565 def delete_db_parameter_group(db_parameter_group_name) link = generate_request('DeleteDBParameterGroup', 'DBParameterGroupName' => db_parameter_group_name) request_info(link, RightHttp2xxParser.new(:logger => @logger)) end |
#delete_db_security_group(db_security_group_name) ⇒ Object
Delete a database security group. Database security group must not be associated with any RDS Instances.
rds.delete_db_security_group('kd3') #=> true
489 490 491 492 |
# File 'lib/rds/right_rds_interface.rb', line 489 def delete_db_security_group(db_security_group_name) link = generate_request('DeleteDBSecurityGroup', 'DBSecurityGroupName' => db_security_group_name) request_info(link, RightHttp2xxParser.new(:logger => @logger)) end |
#delete_db_snapshot(aws_id) ⇒ Object
Delete a DBSnapshot. The DBSnapshot must be in the Available state to be deleted.
rds.delete_db_snapshot('remove-me-tomorrow-1') #=>
{:status=>"Deleted",
:allocated_storage=>50,
:instance_create_time=>"2009-07-13T09:27:01.053Z",
:availability_zone=>"us-east-1a",
:db_master_username=>"username",
:aws_id=>"remove-me-tomorrow-1",
:snapshot_time=>"2009-07-13T10:59:30.227Z",
:endpoint_port=>3306,
:instance_aws_id=>"my-awesome-db-g5",
:engine=>"MySQL5.1"}
850 851 852 853 |
# File 'lib/rds/right_rds_interface.rb', line 850 def delete_db_snapshot(aws_id) link = generate_request('DeleteDBSnapshot', 'DBSnapshotIdentifier' => aws_id) request_info(link, DescribeDbSnapshotsParser.new(:logger => @logger))[:db_snapshots].first end |
#delete_db_subnet_group(name) ⇒ Object
Delete a DB Subnet Group.
rds.delete_db_subnet_group("kd-subnet-group-1") #=> true
P.S. docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DeleteDBSubnetGroup.html
1222 1223 1224 1225 |
# File 'lib/rds/right_rds_interface.rb', line 1222 def delete_db_subnet_group(name) link = generate_request('DeleteDBSubnetGroup', 'DBSubnetGroupName' => name) request_info(link, RightHttp2xxParser.new(:logger => @logger)) end |
#describe_db_engine_versions(params = {}, &block) ⇒ Object
Get a list of the available DB engines. Optional params: :db_parameter_group_family
, :default_only
, :engine
, :engine_version
. :engine_version
rds.describe_db_engine_versions #=>
[{:db_parameter_group_family=>"mysql5.1",
:engine=>"mysql",
:db_engine_description=>"MySQL Community Edition",
:db_engine_version_description=>"Mysql 5.1.45",
:engine_version=>"5.1.45"},
{:db_parameter_group_family=>"oracle-se1-11.2",
:engine=>"oracle-se1",
:db_engine_description=>"Oracle Database Standard Edition One",
:db_engine_version_description=>
"Oracle Standard Edition One - DB Engine Version 11.2.0.2.v2",
:engine_version=>"11.2.0.2.v2"}]
rds.describe_db_engine_versions(:list_supported_character_sets => true) #=>
[{:db_parameter_group_family=>"mysql5.1",
:engine=>"mysql",
:db_engine_description=>"MySQL Community Edition",
:engine_version=>"5.1.45",
:db_engine_version_description=>"MySQL 5.1.45"},
{:db_parameter_group_family=>"oracle-ee-11.2",
:engine=>"oracle-ee",
:supported_character_sets=>
[{:name=>"AL32UTF8",
:description=>"Unicode 5.0 UTF-8 Universal character set"},
{:name=>"JA16EUC", :description=>"EUC 24-bit Japanese"},
{:name=>"JA16EUCTILDE",
:description=>
"The same as JA16EUC except for the way that the wave dash and the tilde are mapped to and from Unicode."},
{:name=>"JA16SJIS", :description=>"Shift-JIS 16-bit Japanese"},
{:name=>"WE8ISO8859P9",
:description=>"ISO 8859-9 West European and Turkish"},
{:name=>"US7ASCII", :description=>"ASCII 7-bit American"}],
:db_engine_description=>"Oracle Database Enterprise Edition",
:default_character_set=>
{:name=>"AL32UTF8",
:description=>"Unicode 5.0 UTF-8 Universal character set"},
:engine_version=>"11.2.0.2.v3",
:db_engine_version_description=>"Oracle 11.2.0.2.v3"}, ... ]
P.S. docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DescribeDBEngineVersions.html
953 954 955 956 957 958 959 960 961 962 963 964 965 966 |
# File 'lib/rds/right_rds_interface.rb', line 953 def describe_db_engine_versions(params={}, &block) params = params.dup params['DBParameterGroupFamily'] = params.delete(:db_parameter_group_family) unless params[:db_parameter_group_family].right_blank? params['DefaultOnly'] = params.delete(:default_only).to_s unless params[:default_only].nil? params['Engine'] = params.delete(:engine) unless params[:engine].right_blank? params['EngineVersion'] = params.delete(:engine_version) unless params[:engine_version].right_blank? params['ListSupportedCharacterSets'] = !!params.delete(:list_supported_character_sets) if params.has_key?(:list_supported_character_sets) result = [] incrementally_list_items('DescribeDBEngineVersions', DescribeDBEngineVersionsParser, params) do |response| result += response[:db_engine_versions] block ? block.call(response) : true end result end |
#describe_db_instances(*params, &block) ⇒ Object
List DB instances.
Optional params: :aws_id
, :max_records
, :marker
# Get a list of DB instances. The response is an +Array+ of instances.
rds.describe_db_instances #=>
[{:instance_class=>"db.m1.small",
:status=>"creating",
:backup_retention_period=>1,
:read_replica_db_instance_identifiers=>["kd-delete-me-01-replica-01"],
:master_username=>"username",
:preferred_maintenance_window=>"sun:05:00-sun:09:00",
:db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
:multi_az=>true,
:engine=>"mysql",
:auto_minor_version_upgrade=>false,
:allocated_storage=>25,
:availability_zone=>"us-east-1d",
:aws_id=>"kd-delete-me-01",
:preferred_backup_window=>"03:00-05:00",
:engine_version=>"5.1.50",
:pending_modified_values=>{:master_user_password=>"****"},
:db_security_groups=>[{:status=>"active", :name=>"default"}]}]
# Retrieve a custom DB instance.
# The response is an +Array+ with a single instance record.
rds.describe_db_instances("kd-test-n3")
# Incrementally a list DB instances. Every response part is a +Hash+.
rds.describe_db_instances(:max_records => 30) do |x|
puts x.inspect #=>
{:db_instances=>
[{:instance_class=>"db.m1.small",
:status=>"creating",
:backup_retention_period=>1,
:read_replica_db_instance_identifiers=>["kd-delete-me-01-replica-01"],
:master_username=>"username",
:preferred_maintenance_window=>"sun:05:00-sun:09:00",
:db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
:multi_az=>true,
:engine=>"mysql",
:auto_minor_version_upgrade=>false,
:allocated_storage=>25,
:availability_zone=>"us-east-1d",
:aws_id=>"kd-delete-me-01",
:preferred_backup_window=>"03:00-05:00",
:engine_version=>"5.1.50",
:pending_modified_values=>{:master_user_password=>"****"},
:db_security_groups=>[{:status=>"active", :name=>"default"}]}]}
true
end
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/rds/right_rds_interface.rb', line 169 def describe_db_instances(*params, &block) item, params = AwsUtils::split_items_and_params(params) params = params.dup params['DBInstanceIdentifier'] = item.first unless item.right_blank? result = [] incrementally_list_items('DescribeDBInstances', DescribeDbInstancesParser, params) do |response| result += response[:db_instances] block ? block.call(response) : true end result end |
#describe_db_parameter_groups(*db_parameter_group_name, &block) ⇒ Object
Describe DBParameterGroups.
rds.describe_db_parameter_groups #=>
[{:engine=>"MySQL5.1",
:description=>"Default parameter group for MySQL5.1",
:name=>"default.MySQL5.1"}]
# List parameter groups by 20
rds.describe_db_parameter_groups(:max_records=>20) do |response|
puts response.inspect
true
end
511 512 513 514 515 516 517 518 519 520 |
# File 'lib/rds/right_rds_interface.rb', line 511 def describe_db_parameter_groups(*db_parameter_group_name, &block) items, params = AwsUtils::split_items_and_params(db_parameter_group_name) params['DBParameterGroupName'] = items.first unless items.right_blank? result = [] incrementally_list_items('DescribeDBParameterGroups', DescribeDbParameterGroupsParser, params) do |response| result += response[:db_parameter_groups] block ? block.call(response) : true end result end |
#describe_db_parameters(*db_parameter_group_name, &block) ⇒ Object
Get the detailed parameters list for a particular DBParameterGroup.
rds.describe_db_parameters('kd1') #=>
[{:is_modifiable=>true,
:apply_type=>"static",
:source=>"engine-default",
:allowed_values=>"ON,OFF",
:description=>"Controls whether user-defined functions that have only an xxx symbol for the main function can be loaded",
:name=>"allow-suspicious-udfs",
:data_type=>"boolean"},
{:is_modifiable=>true,
:apply_type=>"dynamic",
:source=>"engine-default",
:allowed_values=>"1-65535",
:description=>"Intended for use with master-to-master replication, and can be used to control the operation of AUTO_INCREMENT columns",
:name=>"auto_increment_increment",
:data_type=>"integer"}, ... ]
# List parameters by 20
rds.describe_db_parameters('kd1', :max_records=>20) do |response|
puts response.inspect
true
end
624 625 626 627 628 629 630 631 632 633 |
# File 'lib/rds/right_rds_interface.rb', line 624 def describe_db_parameters(*db_parameter_group_name, &block) item, params = AwsUtils::split_items_and_params(db_parameter_group_name) params['DBParameterGroupName'] = item result = [] incrementally_list_items('DescribeDBParameters', DescribeDbParametersParser, params) do |response| result += response[:parameters] block ? block.call(response) : true end result end |
#describe_db_security_groups(*db_security_group_name, &block) ⇒ Object
DB SecurityGroups
rds.describe_db_security_groups #=>
[{:owner_id=>"82...25",
:description=>"Default",
:ec2_security_groups=>[],
:ip_ranges=>[],
:name=>"Default"},
{:owner_id=>"82...25",
:description=>"kd",
:ec2_security_groups=>[],
:ip_ranges=>[],
:name=>"kd2"},
{:owner_id=>"82...25",
:description=>"kd",
:ec2_security_groups=>
[{:status=>"Authorized", :owner_id=>"82...23", :name=>"default"},
{:status=>"Authorized", :owner_id=>"82...24", :name=>"default1"},
{:status=>"Authorized", :owner_id=>"82...25", :name=>"default"},
{:status=>"Authorized", :owner_id=>"82...26", :name=>"default"},
{:status=>"Authorized", :owner_id=>"82...26", :name=>"default1"},
{:status=>"Authorized", :owner_id=>"82...29", :name=>"default22"}],
:ip_ranges=>
[{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"131.0.0.1/8"}],
:name=>"kd3"}]
# get a custom group
rds.describe_db_security_groups('kd3')
389 390 391 392 393 394 395 396 397 398 |
# File 'lib/rds/right_rds_interface.rb', line 389 def describe_db_security_groups(*db_security_group_name, &block) items, params = AwsUtils::split_items_and_params(db_security_group_name) params['DBSecurityGroupName'] = items.first unless items.right_blank? result = [] incrementally_list_items('DescribeDBSecurityGroups', DescribeDbSecurityGroupsParser, params) do |response| result += response[:db_security_groups] block ? block.call(response) : true end result end |
#describe_db_snapshots(params = {}, &block) ⇒ Object
Get DBSecurityGroup details for a particular customer or for a particular DBSecurityGroup if a name is specified. Optional params: :instance_aws_id
# all snapshots
rds.describe_db_snapshots #=>
[{:status=>"Available",
:instance_aws_id=>"kd-test-n1",
:allocated_storage=>25,
:availability_zone=>"us-east-1b",
:aws_id=>"kd-test-n1-final-snapshot-at-20090630131215",
:engine=>"MySQL5.1",
:endpoint_port=>3306,
:instance_create_time=>"2009-06-30T12:48:15.590Z",
:master_username=>"payless",
:snapshot_time=>"2009-06-30T13:16:48.496Z"}, ...]
# all snapshots for a custom instance
rds.describe_db_snapshots(:instance_aws_id => 'kd-test-n3') #=>
[{:status=>"Available",
:instance_aws_id=>"kd-test-n3",
:allocated_storage=>25,
:availability_zone=>"us-east-1a",
:aws_id=>"kd-test-n3-final-snapshot-20090713074916",
:engine=>"MySQL5.1",
:endpoint_port=>3306,
:instance_create_time=>"2009-06-30T12:51:32.540Z",
:master_username=>"payless",
:snapshot_time=>"2009-07-13T07:52:35.542Z"}]
# a snapshot by id
rds.describe_db_snapshots('my-awesome-db-final-snapshot-20090713075554') #=>
[{:status=>"Available",
:allocated_storage=>25,
:engine=>"MySQL5.1",
:instance_aws_id=>"my-awesome-db",
:availability_zone=>"us-east-1a",
:instance_create_time=>"2009-07-13T07:53:08.912Z",
:endpoint_port=>3306,
:master_username=>"medium",
:aws_id=>"my-awesome-db-final-snapshot-20090713075554",
:snapshot_time=>"2009-07-13T07:59:17.537Z"}]
737 738 739 740 741 742 743 744 745 746 747 |
# File 'lib/rds/right_rds_interface.rb', line 737 def describe_db_snapshots(params={}, &block) item, params = AwsUtils::split_items_and_params(params) params['DBSnapshotIdentifier'] = item if item params['DBInstanceIdentifier'] = params.delete(:instance_aws_id) unless params[:instance_aws_id].right_blank? result = [] incrementally_list_items('DescribeDBSnapshots', DescribeDbSnapshotsParser, params) do |response| result += response[:db_snapshots] block ? block.call(response) : true end result end |
#describe_db_subnet_groups(params = {}, &block) ⇒ Object
Lists available DB Subnet Groups. Options: :name, :max_records, :marker
rds.describe_db_subnet_groups #=>
[{:subnets=>
[{:availability_zone=>
{:name=>"us-east-1d", :provisioned_iops_capable=>false},
:status=>"Active",
:subnet_id=>"subnet-5259d03a"},
{:availability_zone=>
{:name=>"us-east-1a", :provisioned_iops_capable=>false},
:status=>"Active",
:subnet_id=>"subnet-eb518f83"}],
:vpc_id=>"vpc-10518f78",
:status=>"Complete",
:description=>"delete me please",
:name=>"kd-subnet-group"},
{:subnets=>
[{:availability_zone=>
{:name=>"us-east-1a", :provisioned_iops_capable=>false},
:status=>"Active",
:subnet_id=>"subnet-eb518f83"},
{:availability_zone=>
{:name=>"us-east-1d", :provisioned_iops_capable=>false},
:status=>"Active",
:subnet_id=>"subnet-5259d03a"}],
:vpc_id=>"vpc-10518f78",
:status=>"Complete",
:description=>"delete me please",
:name=>"kd-subnet-group-1"}]
P.S. docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DescribeDBSubnetGroups.html
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 |
# File 'lib/rds/right_rds_interface.rb', line 1147 def describe_db_subnet_groups(params={}, &block) params = params.dup params['DBSubnetGroupName'] = params.delete(:name) unless params[:name].right_blank? result = [] incrementally_list_items('DescribeDBSubnetGroups', DescribeDBSubnetGroupsParser, params) do |response| result += response[:subnet_groups] block ? block.call(response) : true end result end |
#describe_engine_default_parameters(*db_parameter_group_family, &block) ⇒ Object
Describe a default parameters for the parameter group family.
rds.describe_engine_default_parameters('MySQL5.1') #=>
[{:is_modifiable=>true,
:apply_type=>"static",
:source=>"engine-default",
:allowed_values=>"ON,OFF",
:description=>"Controls whether user-defined functions that have only an xxx symbol for the main function can be loaded",
:name=>"allow-suspicious-udfs",
:data_type=>"boolean"},
{:is_modifiable=>true,
:apply_type=>"dynamic",
:source=>"engine-default",
:allowed_values=>"1-65535",
:description=>"Intended for use with master-to-master replication, and can be used to control the operation of AUTO_INCREMENT columns",
:name=>"auto_increment_increment",
:data_type=>"integer"}, ... ]
653 654 655 656 657 658 659 660 661 662 663 |
# File 'lib/rds/right_rds_interface.rb', line 653 def describe_engine_default_parameters(*db_parameter_group_family, &block) db_parameter_group_family = ['MySQL5.1'] if db_parameter_group_family.right_blank? item, params = AwsUtils::split_items_and_params(db_parameter_group_family) params['DBParameterGroupFamily'] = item if item result = [] incrementally_list_items('DescribeEngineDefaultParameters', DescribeDbParametersParser, params) do |response| result += response[:parameters] block ? block.call(response) : true end result end |
#describe_events(params = {}, &block) ⇒ Object
Get events related to RDS instances and DBSecurityGroups for the past 14 days. Optional params: :duration
, :start_time
, :end_time
, :aws_id
,
+:source_type+('db-instance', 'db-security-group', 'db-snapshot', 'db-parameter-group')
# get all enevts
rds.describe_events #=>
[{:aws_id=>"my-awesome-db-g4",
:source_type=>"DBInstance",
:message=>"Started user snapshot for database instance:my-awesome-db-g4",
:date=>"2009-07-13T10:54:13.661Z"},
{:aws_id=>"my-awesome-db-g5",
:source_type=>"DBInstance",
:message=>"Started user snapshot for database instance:my-awesome-db-g5",
:date=>"2009-07-13T10:55:13.674Z"},
{:aws_id=>"my-awesome-db-g7",
:source_type=>"DBInstance",
:message=>"Started user snapshot for database instance:my-awesome-db-g7",
:date=>"2009-07-13T10:56:34.226Z"}]
# get all events since yesterday
rds.describe_events(:start_date => 1.day.ago)
# get last 60 min events
rds.describe_events(:duration => 60)
884 885 886 887 888 889 890 891 892 893 894 895 896 897 |
# File 'lib/rds/right_rds_interface.rb', line 884 def describe_events(params={}, &block) params = params.dup params['SourceIdentifier'] = params.delete(:aws_id) unless params[:aws_id].right_blank? params['SourceType'] = params.delete(:source_type) unless params[:source_type].right_blank? params['Duration'] = params.delete(:duration) unless params[:duration].right_blank? params['StartDate'] = fix_date(params.delete(:start_date)) unless params[:start_date].right_blank? params['EndDate'] = fix_date(params.delete(:end_date)) unless params[:end_date].right_blank? result = [] incrementally_list_items('DescribeEvents', DescribeEventsParser, params) do |response| result += response[:events] block ? block.call(response) : true end result end |
#describe_orderable_db_instance_options(engine, params = {}, &block) ⇒ Object
Describe a list of orderable DB Instance options for the specified engine. Optionals: :instance_class
, :engine_version
, :license_model
, :vpc
rds.describe_orderable_db_instance_options('oracle-ee', :engine_version => '11.2.0.2.v2') #=>
[{:read_replica_capable=>false,
:instance_class=>"db.m1.large",
:availability_zones=>["us-east-1a", "us-east-1b", "us-east-1d"],
:engine=>"oracle-ee",
:license_model=>"bring-your-own-license",
:engine_version=>"11.2.0.2.v2",
:multi_az_capable=>"false"}, ... ]
677 678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'lib/rds/right_rds_interface.rb', line 677 def (engine, params={}, &block) request_hash = { 'Engine' => engine } request_hash['DBInstanceClass'] = params[:instance_class] unless params[:instance_class].right_blank? request_hash['EngineVersion'] = params[:engine_version] unless params[:engine_version].right_blank? request_hash['LicenseModel'] = params[:license_model] unless params[:license_model].right_blank? request_hash['Vpc'] = !!params[:vpc] if params.has_key?(:vpc) result = [] incrementally_list_items('DescribeOrderableDBInstanceOptions', DescribeOrderableDBInstanceOptionsParser, request_hash) do |response| result += response[:items] block ? block.call(response) : true end result end |
#describe_reserved_db_instances(params = {}, &block) ⇒ Object
Returns information about reserved DB Instances for this account, or about a specified reserved DB Instance. Options: :aws_id, :offering_aws_id, :instance_class, :duration, :product_description, :multi_az
rds.describe_reserved_db_instances
rds.describe_reserved_db_instances(:aws_id => "myreservedinstance")
rds.describe_reserved_db_instances(:offering_aws_id => "248e7b75-49a7-4cd7-9a9b-354f4906a9b1")
rds.describe_reserved_db_instances(:instance_class => "db.m1.small")
rds.describe_reserved_db_instances(:duration => 31536000)
rds.describe_reserved_db_instances(:product_description => 'mysql')
rds.describe_reserved_db_instances_offerings(:multi_az => true)
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 |
# File 'lib/rds/right_rds_interface.rb', line 1084 def describe_reserved_db_instances(params={}, &block) params = params.dup params['ReservedDBInstancesId'] = params.delete(:aws_id) unless params[:aws_id].right_blank? params['ReservedDBInstancesOfferingId'] = params.delete(:offering_aws_id) unless params[:offering_aws_id].right_blank? params['DBInstanceClass'] = params.delete(:instance_class) unless params[:instance_class].right_blank? params['Duration'] = params.delete(:duration) unless params[:duration].right_blank? params['ProductDescription'] = params.delete(:product_description) unless params[:product_description].right_blank? params['MultiAZ'] = params.delete(:multi_az).to_s unless params[:multi_az].nil? result = [] incrementally_list_items('DescribeReservedDBInstances', DescribeReservedDBInstancesParser, params) do |response| result += response[:reserved_db_instances] block ? block.call(response) : true end result end |
#describe_reserved_db_instances_offerings(params = {}, &block) ⇒ Object
Lists available reserved DB Instance offerings. Options: :aws_id, :instance_class, :duration, :product_description, :multi_az
rds.describe_reserved_db_instances_offerings #=>
[{:recurring_charges=>[],
:offering_type=>"Medium Utilization",
:duration=>94608000,
:currency_code=>"USD",
:fixed_price=>82.0,
:product_description=>"oracle-se(byol)",
:usage_price=>0.01,
:aws_id=>"248e7b75-01ff-4f1d-8fad-918b76337c13",
:multi_az=>false,
:instance_class=>"db.t1.micro"},
{:recurring_charges=>[{:frequency=>"Hourly", :amount=>"0.24"}],
:offering_type=>"Heavy Utilization",
:duration=>31536000,
:currency_code=>"USD",
:fixed_price=>1040.0,
:product_description=>"sqlserver-web(li)",
:usage_price=>0.0,
:aws_id=>"248e7b75-05eb-46df-a7b8-4117b5001667",
:multi_az=>false,
:instance_class=>"db.m2.xlarge"}, ... ]
rds.describe_reserved_db_instances_offerings(:aws_id => "248e7b75-49a7-4cd7-9a9b-354f4906a9b1") #=>
[{:duration=>94608000,
:multi_az=>true,
:fixed_price=>700.0,
:usage_price=>0.092,
:currency_code=>"USD",
:aws_id=>"248e7b75-49a7-4cd7-9a9b-354f4906a9b1",
:instance_class=>"db.m1.small",
:product_description=>"mysql"}]
rds.describe_reserved_db_instances_offerings(:instance_class => "db.m1.small")
rds.describe_reserved_db_instances_offerings(:duration => 31536000)
rds.describe_reserved_db_instances_offerings(:product_description => 'mysql')
rds.describe_reserved_db_instances_offerings(:multi_az => true)
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'lib/rds/right_rds_interface.rb', line 1057 def describe_reserved_db_instances_offerings(params={}, &block) params = params.dup params['ReservedDBInstancesOfferingId'] = params.delete(:aws_id) unless params[:aws_id].right_blank? params['DBInstanceClass'] = params.delete(:instance_class) unless params[:instance_class].right_blank? params['Duration'] = params.delete(:duration) unless params[:duration].right_blank? params['ProductDescription'] = params.delete(:product_description) unless params[:product_description].right_blank? params['MultiAZ'] = params.delete(:multi_az).to_s unless params[:multi_az].nil? result = [] incrementally_list_items('DescribeReservedDBInstancesOfferings', DescribeReservedDBInstancesOfferingsParser, params) do |response| result += response[:reserved_db_instances_offerings] block ? block.call(response) : true end result end |
#fix_date(date) ⇒ Object
:nodoc:
899 900 901 902 903 |
# File 'lib/rds/right_rds_interface.rb', line 899 def fix_date(date) # :nodoc: date = Time.at(date) if date.is_a?(Fixnum) date = date.utc.strftime('%Y-%m-%dT%H:%M:%SZ') if date.is_a?(Time) date end |
#generate_request(action, params = {}) ⇒ Object
Generates request hash for REST API.
84 85 86 |
# File 'lib/rds/right_rds_interface.rb', line 84 def generate_request(action, params={}) #:nodoc: generate_request_impl(:get, action, params ) end |
#get_db_subnet_group(group_name, &block) ⇒ Object
1158 1159 1160 |
# File 'lib/rds/right_rds_interface.rb', line 1158 def get_db_subnet_group(group_name, &block) describe_db_subnet_groups(:name => group_name, &block) end |
#incrementally_list_items(action, parser_class, params = {}, &block) ⇒ Object
Incrementally lists something.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rds/right_rds_interface.rb', line 95 def incrementally_list_items(action, parser_class, params={}, &block) # :nodoc: params = params.dup params['MaxRecords'] = params.delete(:max_records) if params[:max_records] params['Marker'] = params.delete(:marker) if params[:marker] last_response = nil loop do link = generate_request(action, params) last_response = request_info( link, parser_class.new(:logger => @logger)) params['Marker'] = last_response[:marker] break unless block && block.call(last_response) && !last_response[:marker].right_blank? end last_response end |
#modify_db_instance(aws_id, params = {}) ⇒ Object
Modify a DB instance.
Mandatory arguments: aws_id
. Optional params: :master_user_password
, :instance_class
, :db_security_groups
, :db_parameter_group
, :preferred_maintenance_window
, :allocated_storage
, :apply_immediately
, :backup_retention_period
, :preferred_backup_window
, :multi_az
, :engine_version
, :auto_minor_version_upgrade
, :allow_major_version_upgrade
, :iops
, ::option_group_name
rds.modify_db_instance('kd-delete-me-01',
:master_user_password => 'newpassword',
:instance_class => 'db.m1.large',
:multi_az => false,
:allocated_storage => 30,
:allow_major_version_upgrade => true,
:auto_minor_version_upgrade => true,
:preferred_maintenance_window => 'sun:06:00-sun:10:00',
:preferred_backup_window => '02:00-04:00',
:apply_immediately => true,
:backup_retention_period => 2) #=>
{:engine_version=>"5.1.50",
:aws_id=>"kd-delete-me-01",
:multi_az=>true,
:status=>"available",
:read_replica_db_instance_identifiers=>[],
:availability_zone=>"us-east-1d",
:auto_minor_version_upgrade=>true,
:master_username=>"username",
:preferred_maintenance_window=>"sun:06:00-sun:10:00",
:db_parameter_group=>{:status=>"in-sync", :name=>"default.mysql5.1"},
:create_time=>"2010-11-17T10:21:59.720Z",
:preferred_backup_window=>"02:00-04:00",
:engine=>"mysql",
:db_security_groups=>[{:status=>"active", :name=>"default"}],
:endpoint_address=>"kd-delete-me-01.chxspydgchoo.us-east-1.rds.amazonaws.com",
:instance_class=>"db.m1.small",
:latest_restorable_time=>"2010-11-17T10:27:17.089Z",
:backup_retention_period=>2,
:pending_modified_values=>
{:multi_az=>false, :master_user_password=>"****", :allocated_storage=>30, :instance_class=>"db.m1.large"},
:allocated_storage=>25}
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/rds/right_rds_interface.rb', line 282 def modify_db_instance(aws_id, params={}) request_hash = {} # Mandatory request_hash['DBInstanceIdentifier'] = aws_id # Optional request_hash['MasterUserPassword'] = params[:master_user_password] unless params[:master_user_password].right_blank? request_hash['DBInstanceClass'] = params[:instance_class].to_s.capitalize unless params[:instance_class].right_blank? request_hash['PreferredMaintenanceWindow'] = params[:preferred_maintenance_window] unless params[:preferred_maintenance_window].right_blank? request_hash['BackupRetentionPeriod'] = params[:backup_retention_period] unless params[:backup_retention_period].right_blank? request_hash['PreferredBackupWindow'] = params[:preferred_backup_window] unless params[:preferred_backup_window].right_blank? request_hash['AllocatedStorage'] = params[:allocated_storage] unless params[:allocated_storage].right_blank? request_hash['MultiAZ'] = params[:multi_az].to_s unless params[:multi_az].nil? request_hash['EngineVersion'] = params[:engine_version] unless params[:engine_version].right_blank? request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade].to_s unless params[:auto_minor_version_upgrade].nil? request_hash['AllowMajorVersionUpgrade'] = params[:allow_major_version_upgrade].to_s unless params[:allow_major_version_upgrade].nil? request_hash['ApplyImmediately'] = params[:apply_immediately].to_s unless params[:apply_immediately].right_blank? request_hash.merge!(amazonize_list('DBSecurityGroups.member', params[:db_security_groups])) request_hash['DBParameterGroupName'] = params[:db_parameter_group] unless params[:db_parameter_group].right_blank? request_hash['Iops'] = params[:iops] unless params[:iops].right_blank? request_hash['OptionGroupName'] = params[:option_group_name] unless params[:option_group_name].right_blank? link = generate_request('ModifyDBInstance', request_hash) request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first end |
#modify_db_parameter_group(db_parameter_group_name, params = {}) ⇒ Object
Modify DBParameterGroup paramaters. Up to 20 params can be midified at once.
rds.modify_db_parameter_group('kd1', 'max_allowed_packet' => 2048) #=> true
rds.modify_db_parameter_group('kd1', 'max_allowed_packet' => {:value => 2048, :method => 'immediate') #=> true
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/rds/right_rds_interface.rb', line 542 def modify_db_parameter_group(db_parameter_group_name, params={}) # :nodoc: request_hash = { 'DBParameterGroupName' => db_parameter_group_name} parameters = [] params.each do |key, value| method = 'pending-reboot' if value.is_a?(Hash) method = value[:method] unless value[:method].right_blank? value = value[:value] end parameters << [key, value, method] end request_hash.merge!( amazonize_list(['Parameters.member.?.ParameterName', 'Parameters.member.?.ParameterValue', 'Parameters.member.?.ApplyMethod'], parameters )) link = generate_request('ModifyDBParameterGroup', request_hash) request_info(link, RightHttp2xxParser.new(:logger => @logger)) end |
#modify_db_security_group_ingress(action, db_security_group_name, params = {}) ⇒ Object
:nodoc:
420 421 422 423 424 425 426 427 428 |
# File 'lib/rds/right_rds_interface.rb', line 420 def modify_db_security_group_ingress(action, db_security_group_name, params={}) # :nodoc: request_hash = { 'DBSecurityGroupName' => db_security_group_name} request_hash['CIDRIP'] = params[:cidrip] unless params[:cidrip].right_blank? request_hash['EC2SecurityGroupName'] = params[:ec2_security_group_name] unless params[:ec2_security_group_name].right_blank? request_hash['EC2SecurityGroupOwnerId'] = params[:ec2_security_group_owner] unless params[:ec2_security_group_owner].right_blank? request_hash['EC2SecurityGroupId'] = params[:ec2_security_group_id] unless params[:ec2_security_group_id].right_blank? link = generate_request(action, request_hash) request_info(link, DescribeDbSecurityGroupsParser.new(:logger => @logger))[:db_security_groups].first end |
#modify_db_subnet_group(subnet_group_name, subnets, subnet_group_description = '') ⇒ Object
Modify an existing DB Subnet Group.
rds.modify_db_subnet_group('kd-subnet-group', ['subnet-5259d03a', 'subnet-eb518f83'], 'hahaha!') #=>
{:subnets=>
[{:availability_zone=>
{:name=>"us-east-1d", :provisioned_iops_capable=>false},
:status=>"Active",
:subnet_id=>"subnet-5259d03a"},
{:availability_zone=>
{:name=>"us-east-1a", :provisioned_iops_capable=>false},
:status=>"Active",
:subnet_id=>"subnet-eb518f83"}],
:vpc_id=>"vpc-10518f78",
:status=>"Complete",
:description=>"hahaha!",
:name=>"kd-subnet-group"}
P.S. docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_ModifyDBSubnetGroup.html
1208 1209 1210 1211 1212 1213 1214 |
# File 'lib/rds/right_rds_interface.rb', line 1208 def modify_db_subnet_group(subnet_group_name, subnets, subnet_group_description = '') request_hash = { 'DBSubnetGroupName' => subnet_group_name} request_hash['DBSubnetGroupDescription'] = subnet_group_description unless subnet_group_description.right_blank? request_hash.merge!(amazonize_list('SubnetIds.member', subnets)) link = generate_request('ModifyDBSubnetGroup', request_hash) request_info(link, DescribeDBSubnetGroupsParser.new(:logger => @logger))[:subnet_groups].first end |
#purchase_reserved_db_instances_offering(offering_aws_id, params = {}) ⇒ Object
Purchases a reserved DB Instance offering. Options: :aws_id, :count
1102 1103 1104 1105 1106 1107 1108 |
# File 'lib/rds/right_rds_interface.rb', line 1102 def purchase_reserved_db_instances_offering(offering_aws_id, params={}) request_hash = { 'ReservedDBInstancesOfferingId' => offering_aws_id } request_hash['ReservedDBInstanceId'] = params[:aws_id] unless params[:aws_id].right_blank? request_hash['DBInstanceCount'] = params[:count] unless params[:count].right_blank? link = generate_request('PurchaseReservedDBInstancesOffering', request_hash) request_info(link, DescribeReservedDBInstancesParser.new(:logger => @logger))[:reserved_db_instances].first end |
#reboot_db_instance(aws_id, params = {}) ⇒ Object
Reboot Db instance.
Options: :force_failover
rds.reboot_db_instance('kd-my-awesome-db') #=>
{:status=>"rebooting",
:pending_modified_values=>{},
:allocated_storage=>42,
:master_username=>"kd",
:db_security_groups=>[],
:instance_class=>"Medium",
:availability_zone=>"us-east-1a",
:aws_id=>"kd-my-awesome-db",
:create_time=>"2009-08-28T08:34:21.858Z",
:engine=>"MySQL5.1",
:preferred_maintenance_window=>"Sun:05:00-Sun:09:00"}
P.S. docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_RebootDBInstance.html
325 326 327 328 329 330 331 |
# File 'lib/rds/right_rds_interface.rb', line 325 def reboot_db_instance(aws_id, params={}) params = params.dup params['DBInstanceIdentifier'] = aws_id params['ForceFailover'] = !!params[:force_failover] if params.has_key?(:force_failover) link = generate_request('RebootDBInstance', params) request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first end |
#request_info(request, parser, &block) ⇒ Object
Sends request to Amazon and parses the response. Raises AwsError if any banana happened.
90 91 92 |
# File 'lib/rds/right_rds_interface.rb', line 90 def request_info(request, parser, &block) # :nodoc: request_info_impl(:rds_connection, @@bench, request, parser, &block) end |
#reset_db_parameter_group(db_parameter_group_name, *params) ⇒ Object
Modify the parameters of a DBParameterGroup to the engine/system default value.
# Reset all parameters
rds.reset_db_parameter_group('kd2', :all ) #=> true
# Reset custom parameters
rds.reset_db_parameter_group('kd2', 'max_allowed_packet', 'auto_increment_increment' ) #=> true
rds.reset_db_parameter_group('kd2', 'max_allowed_packet', 'auto_increment_increment' => 'immediate' ) #=> true
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/rds/right_rds_interface.rb', line 579 def reset_db_parameter_group(db_parameter_group_name, *params) params = params.flatten request_hash = { 'DBParameterGroupName' => db_parameter_group_name } if params.first.to_s == 'all' request_hash['ResetAllParameters'] = true else tmp = [] params.each{ |item| tmp |= item.to_a } params = [] tmp.each do |key, method| method = 'pending-reboot' unless method params << [key, method] end request_hash.merge!( amazonize_list(['Parameters.member.?.ParameterName', 'Parameters.member.?.ApplyMethod'], params )) end link = generate_request('ResetDBParameterGroup', request_hash) request_info(link, RightHttp2xxParser.new(:logger => @logger)) end |
#restore_db_instance_from_db_snapshot(snapshot_aws_id, instance_aws_id, params = {}) ⇒ Object
Create a new RDS instance from a DBSnapshot. The source DBSnapshot must be in the “Available” state. The new RDS instance is created with the Default security group.
Optional params: :instance_class
, :endpoint_port
, :availability_zone
, :multi_az
, :auto_minor_version_upgrade
, :license_model
, :db_name
, :engine
, :db_subnet_group_name
, :iops
, :option_group_name
rds.restore_db_instance_from_db_snapshot('ahahahaha-final-snapshot-20090828081159', 'q1') #=>
{:status=>"creating",
:pending_modified_values=>{},
:allocated_storage=>42,
:db_security_groups=>[],
:master_username=>"kd",
:availability_zone=>"us-east-1a",
:aws_id=>"q1",
:create_time=>"2009-08-29T18:07:01.510Z",
:instance_class=>"Medium",
:preferred_maintenance_window=>"Sun:05:00-Sun:09:00",
:engine=>"MySQL",
:engine_version=>"5.1.49"}
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
# File 'lib/rds/right_rds_interface.rb', line 789 def restore_db_instance_from_db_snapshot(snapshot_aws_id, instance_aws_id, params={}) request_hash = { 'DBSnapshotIdentifier' => snapshot_aws_id, 'DBInstanceIdentifier' => instance_aws_id } request_hash['DBInstanceClass'] = params[:instance_class] unless params[:instance_class].right_blank? request_hash['Port'] = params[:endpoint_port] unless params[:endpoint_port].right_blank? request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].right_blank? request_hash['MultiAZ'] = params[:multi_az] unless params[:multi_az].nil? request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade] unless params[:auto_minor_version_upgrade].nil? request_hash['LicenseModel'] = params[:license_model] unless params[:license_model].right_blank? request_hash['DBName'] = params[:db_name] unless params[:db_name].right_blank? request_hash['Engine'] = params[:engine] unless params[:enginel].right_blank? request_hash['DBSubnetGroupName'] = params[:db_subnet_group_name] unless params[:db_subnet_group_name].right_blank? request_hash['Iops'] = params[:iops] unless params[:iops].right_blank? request_hash['OptionGroupName'] = params[:option_group_name] unless params[:option_group_name].right_blank? link = generate_request('RestoreDBInstanceFromDBSnapshot', request_hash) request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first end |
#restore_db_instance_to_point_in_time(instance_aws_id, new_instance_aws_id, params = {}) ⇒ Object
Create a new RDS instance from a point-in-time system snapshot. The target database is created from the source database restore point with the same configuration as the original source database, except that the new RDS instance is created with the default security group.
Optional params: :instance_class
, :endpoint_port
, :availability_zone
, :multi_az
, :restore_time
, :auto_minor_version_upgrade
, :use_latest_restorable_time
, :license_model
, :db_name
, :engine
:db_subnet_group_name
, :iops
, :option_group_name
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
# File 'lib/rds/right_rds_interface.rb', line 816 def restore_db_instance_to_point_in_time(instance_aws_id, new_instance_aws_id, params={}) request_hash = { 'SourceDBInstanceIdentifier' => instance_aws_id, 'TargetDBInstanceIdentifier' => new_instance_aws_id} request_hash['UseLatestRestorableTime'] = params[:use_latest_restorable_time].to_s unless params[:use_latest_restorable_time].nil? request_hash['RestoreTime'] = params[:restore_time] unless params[:restore_time].right_blank? request_hash['DBInstanceClass'] = params[:instance_class] unless params[:instance_class].right_blank? request_hash['MultiAZ'] = params[:multi_az] unless params[:multi_az].nil? request_hash['Port'] = params[:endpoint_port] unless params[:endpoint_port].right_blank? request_hash['AvailabilityZone'] = params[:availability_zone] unless params[:availability_zone].right_blank? request_hash['AutoMinorVersionUpgrade'] = params[:auto_minor_version_upgrade] unless params[:auto_minor_version_upgrade].nil? request_hash['LicenseModel'] = params[:license_model] unless params[:license_model].right_blank? request_hash['DBName'] = params[:db_name] unless params[:db_name].right_blank? request_hash['Engine'] = params[:engine] unless params[:enginel].right_blank? request_hash['DBSubnetGroupName'] = params[:db_subnet_group_name] unless params[:db_subnet_group_name].right_blank? request_hash['Iops'] = params[:iops] unless params[:iops].right_blank? request_hash['OptionGroupName'] = params[:option_group_name] unless params[:option_group_name].right_blank? link = generate_request('RestoreDBInstanceToPointInTime', request_hash) request_info(link, DescribeDbInstancesParser.new(:logger => @logger))[:db_instances].first end |
#revoke_db_security_group_ingress(db_security_group_name, params = {}) ⇒ Object
Revoke an ingress. Optional params: :cidrip
or (:ec2_security_group_name
and :ec2_security_group_owner
)
rds.revoke_db_security_group_ingress('kd3', :ec2_security_group_owner => '82...25',
:ec2_security_group_name => 'default') #=>
{:owner_id=>"82...25",
:ec2_security_groups=>
[{:status=>"Revoking", :owner_id=>"826693181925", :name=>"default"}],
:name=>"kd3",
:description=>"kd",
:ip_ranges=>
[{:status=>"Authorized", :cidrip=>"127.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"128.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"129.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"130.0.0.1/8"},
{:status=>"Authorized", :cidrip=>"131.0.0.1/8"}]}
480 481 482 |
# File 'lib/rds/right_rds_interface.rb', line 480 def revoke_db_security_group_ingress(db_security_group_name, params={}) modify_db_security_group_ingress('RevokeDBSecurityGroupIngress', db_security_group_name, params) end |