From f3bdc7f074ec14c1521af83cbad4469e30f63f54 Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Mon, 28 Feb 2011 05:09:12 +0800 Subject: [PATCH] [rds] support basic rds operations --- lib/fog/aws/parsers/rds/create_db_instance.rb | 34 ++++ .../rds/create_db_instance_read_replica.rb | 34 ++++ .../parsers/rds/create_db_parameter_group.rb | 35 ++++ lib/fog/aws/parsers/rds/create_db_snapshot.rb | 35 ++++ lib/fog/aws/parsers/rds/db_parser.rb | 123 +++++++++++++ lib/fog/aws/parsers/rds/delete_db_instance.rb | 35 ++++ .../parsers/rds/delete_db_parameter_group.rb | 27 +++ lib/fog/aws/parsers/rds/delete_db_snapshot.rb | 34 ++++ .../aws/parsers/rds/describe_db_instances.rb | 36 ++++ .../rds/describe_db_parameter_groups.rb | 38 ++++ .../aws/parsers/rds/describe_db_parameters.rb | 44 +++++ .../aws/parsers/rds/describe_db_snapshots.rb | 39 ++++ lib/fog/aws/parsers/rds/modify_db_instance.rb | 34 ++++ .../parsers/rds/modify_db_parameter_group.rb | 28 +++ lib/fog/aws/parsers/rds/reboot_db_instance.rb | 35 ++++ lib/fog/aws/parsers/rds/snapshot_parser.rb | 40 +++++ lib/fog/aws/rds.rb | 146 +++++++++++++++ lib/fog/aws/rds/models/parameter.rb | 21 +++ lib/fog/aws/rds/models/parameter_group.rb | 36 ++++ lib/fog/aws/rds/models/parameter_groups.rb | 27 +++ lib/fog/aws/rds/models/parameters.rb | 37 ++++ lib/fog/aws/rds/models/server.rb | 105 +++++++++++ lib/fog/aws/rds/models/servers.rb | 27 +++ lib/fog/aws/rds/models/snapshot.rb | 49 +++++ lib/fog/aws/rds/models/snapshots.rb | 45 +++++ .../aws/requests/rds/create_db_instance.rb | 56 ++++++ .../rds/create_db_instance_read_replica.rb | 42 +++++ .../requests/rds/create_db_parameter_group.rb | 41 +++++ .../aws/requests/rds/create_db_snapshot.rb | 36 ++++ .../aws/requests/rds/delete_db_instance.rb | 40 +++++ .../requests/rds/delete_db_parameter_group.rb | 36 ++++ .../aws/requests/rds/delete_db_snapshot.rb | 36 ++++ .../aws/requests/rds/describe_db_instances.rb | 42 +++++ .../rds/describe_db_parameter_groups.rb | 45 +++++ .../requests/rds/describe_db_parameters.rb | 46 +++++ .../aws/requests/rds/describe_db_snapshots.rb | 42 +++++ .../aws/requests/rds/modify_db_instance.rb | 54 ++++++ .../requests/rds/modify_db_parameter_group.rb | 55 ++++++ .../aws/requests/rds/reboot_db_instance.rb | 34 ++++ lib/fog/bin/aws.rb | 4 + lib/fog/providers/aws.rb | 1 + tests/aws/requests/rds/helper.rb | 169 ++++++++++++++++++ tests/aws/requests/rds/instance_tests.rb | 129 +++++++++++++ tests/aws/requests/rds/model_tests.rb | 98 ++++++++++ .../aws/requests/rds/parameter_group_tests.rb | 67 +++++++ .../requests/rds/parameter_request_tests.rb | 35 ++++ 46 files changed, 2252 insertions(+) create mode 100644 lib/fog/aws/parsers/rds/create_db_instance.rb create mode 100644 lib/fog/aws/parsers/rds/create_db_instance_read_replica.rb create mode 100644 lib/fog/aws/parsers/rds/create_db_parameter_group.rb create mode 100644 lib/fog/aws/parsers/rds/create_db_snapshot.rb create mode 100644 lib/fog/aws/parsers/rds/db_parser.rb create mode 100644 lib/fog/aws/parsers/rds/delete_db_instance.rb create mode 100644 lib/fog/aws/parsers/rds/delete_db_parameter_group.rb create mode 100644 lib/fog/aws/parsers/rds/delete_db_snapshot.rb create mode 100644 lib/fog/aws/parsers/rds/describe_db_instances.rb create mode 100644 lib/fog/aws/parsers/rds/describe_db_parameter_groups.rb create mode 100644 lib/fog/aws/parsers/rds/describe_db_parameters.rb create mode 100644 lib/fog/aws/parsers/rds/describe_db_snapshots.rb create mode 100644 lib/fog/aws/parsers/rds/modify_db_instance.rb create mode 100644 lib/fog/aws/parsers/rds/modify_db_parameter_group.rb create mode 100644 lib/fog/aws/parsers/rds/reboot_db_instance.rb create mode 100644 lib/fog/aws/parsers/rds/snapshot_parser.rb create mode 100644 lib/fog/aws/rds.rb create mode 100644 lib/fog/aws/rds/models/parameter.rb create mode 100644 lib/fog/aws/rds/models/parameter_group.rb create mode 100644 lib/fog/aws/rds/models/parameter_groups.rb create mode 100644 lib/fog/aws/rds/models/parameters.rb create mode 100644 lib/fog/aws/rds/models/server.rb create mode 100644 lib/fog/aws/rds/models/servers.rb create mode 100644 lib/fog/aws/rds/models/snapshot.rb create mode 100644 lib/fog/aws/rds/models/snapshots.rb create mode 100644 lib/fog/aws/requests/rds/create_db_instance.rb create mode 100644 lib/fog/aws/requests/rds/create_db_instance_read_replica.rb create mode 100644 lib/fog/aws/requests/rds/create_db_parameter_group.rb create mode 100644 lib/fog/aws/requests/rds/create_db_snapshot.rb create mode 100644 lib/fog/aws/requests/rds/delete_db_instance.rb create mode 100644 lib/fog/aws/requests/rds/delete_db_parameter_group.rb create mode 100644 lib/fog/aws/requests/rds/delete_db_snapshot.rb create mode 100644 lib/fog/aws/requests/rds/describe_db_instances.rb create mode 100644 lib/fog/aws/requests/rds/describe_db_parameter_groups.rb create mode 100644 lib/fog/aws/requests/rds/describe_db_parameters.rb create mode 100644 lib/fog/aws/requests/rds/describe_db_snapshots.rb create mode 100644 lib/fog/aws/requests/rds/modify_db_instance.rb create mode 100644 lib/fog/aws/requests/rds/modify_db_parameter_group.rb create mode 100644 lib/fog/aws/requests/rds/reboot_db_instance.rb create mode 100644 tests/aws/requests/rds/helper.rb create mode 100644 tests/aws/requests/rds/instance_tests.rb create mode 100644 tests/aws/requests/rds/model_tests.rb create mode 100644 tests/aws/requests/rds/parameter_group_tests.rb create mode 100644 tests/aws/requests/rds/parameter_request_tests.rb diff --git a/lib/fog/aws/parsers/rds/create_db_instance.rb b/lib/fog/aws/parsers/rds/create_db_instance.rb new file mode 100644 index 000000000..889a33db5 --- /dev/null +++ b/lib/fog/aws/parsers/rds/create_db_instance.rb @@ -0,0 +1,34 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/db_parser' + + class CreateDBInstance < Fog::Parsers::AWS::RDS::DbParser + + def reset + @response = { 'CreateDBInstanceResult' => {}, 'ResponseMetadata' => {} } + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'DBInstance' + @response['CreateDBInstanceResult']['DBInstance'] = @db_instance + @db_instance = fresh_instance + when 'RequestId' + @response['ResponseMetadata'][name] = @value + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/create_db_instance_read_replica.rb b/lib/fog/aws/parsers/rds/create_db_instance_read_replica.rb new file mode 100644 index 000000000..bb6345251 --- /dev/null +++ b/lib/fog/aws/parsers/rds/create_db_instance_read_replica.rb @@ -0,0 +1,34 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/db_parser' + + class CreateDBInstanceReadReplica < Fog::Parsers::AWS::RDS::DbParser + + def reset + @response = { 'CreateDBInstanceReadReplicaResult' => {}, 'ResponseMetadata' => {} } + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'DBInstance' + @response['CreateDBInstanceReadReplicaResult']['DBInstance'] = @db_instance + @db_instance = fresh_instance + when 'RequestId' + @response['ResponseMetadata'][name] = @value + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/create_db_parameter_group.rb b/lib/fog/aws/parsers/rds/create_db_parameter_group.rb new file mode 100644 index 000000000..c0ca6c48d --- /dev/null +++ b/lib/fog/aws/parsers/rds/create_db_parameter_group.rb @@ -0,0 +1,35 @@ +module Fog + module Parsers + module AWS + module RDS + + class CreateDbParameterGroup < Fog::Parsers::Base + + def reset + @response = { 'CreateDBParameterGroupResult' => {}, 'ResponseMetadata' => {} } + @db_parameter_group = {} + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'DBParameterGroupFamily' + @db_parameter_group['DBParameterGroupFamily'] = @value + when 'Description' + @db_parameter_group['Description'] = @value + when 'DBParameterGroupName' + @db_parameter_group['DBParameterGroupName'] = @value + when 'DBParameterGroup' + @response['CreateDBParameterGroupResult']['DBParameterGroup']= @db_parameter_group + when 'RequestId' + @response['ResponseMetadata'][name] = @value + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/create_db_snapshot.rb b/lib/fog/aws/parsers/rds/create_db_snapshot.rb new file mode 100644 index 000000000..e9a25ff01 --- /dev/null +++ b/lib/fog/aws/parsers/rds/create_db_snapshot.rb @@ -0,0 +1,35 @@ +module Fog + module Parsers + module AWS + module RDS + require 'fog/aws/parsers/rds/snapshot_parser' + + class CreateDBSnapshot < Fog::Parsers::AWS::RDS::SnapshotParser + + def reset + @response = { 'CreateDBSnapshotResult' => {}, 'ResponseMetadata' => {} } + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'DBSnapshot' then + @response['CreateDBSnapshotResult']['DBSnapshot'] = @db_snapshot + @db_snapshot = fresh_snapshot + when 'RequestId' + @response['ResponseMetadata'][name] = @value + else + super + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/db_parser.rb b/lib/fog/aws/parsers/rds/db_parser.rb new file mode 100644 index 000000000..350b4f9ef --- /dev/null +++ b/lib/fog/aws/parsers/rds/db_parser.rb @@ -0,0 +1,123 @@ +module Fog + module Parsers + module AWS + module RDS + + class DbParser < Fog::Parsers::Base + + def reset + @db_instance = fresh_instance + + end + + def fresh_instance + {'PendingModifiedValues' => [], 'DBSecurityGroups' => [], 'ReadReplicaDBInstanceIdentifiers' => [], 'Endpoint' => {}} + end + + def start_element(name, attrs = []) + super + case name + when 'PendingModifiedValues' + @in_pending_modified_values = true + @pending_modified_values = {} + when 'DBSecurityGroups' + @in_db_security_groups = true + @db_security_groups = [] + when 'DBSecurityGroup' + @db_security_group = {} + when 'Endpoint' + @in_endpoint = true + @endpoint = {} + when 'DBParameterGroup' + @db_parameter_group = {} + when 'DBParameterGroups' + @in_db_parameter_groups = true + @db_parameter_groups = [] + end + + end + + def end_element(name) + case name + + when 'LatestRestorableTime', 'InstanceCreateTime' + @db_instance[name] = Time.parse @value + when 'Engine', + 'DBInstanceStatus', 'DBInstanceIdentifier', 'EngineVersion', + 'PreferredBackupWindow', 'PreferredMaintenanceWindow', + 'AvailabilityZone', 'MasterUsername' + @db_instance[name] = @value + when 'MultiAZ', 'AutoMinorVersionUpgrade' + if @value == 'false' + @db_instance[name] = false + else + @db_instance[name] = true + end + when 'DBParameterGroups' + @in_db_parameter_groups = false + @db_instance['DBParameterGroups'] = @db_parameter_groups + when 'DBParameterGroup' + @db_parameter_groups << @db_parameter_group + @db_parameter_group = {} + when 'ParameterApplyStatus', 'DBParameterGroupName' + if @in_db_parameter_groups + @db_parameter_group[name] = @value + end + + when 'BackupRetentionPeriod' + if @in_pending_modified_values + @pending_modified_values[name] = @value.to_i + else + @db_instance[name] = @value.to_i + end + when 'DBInstanceClass', 'EngineVersion', 'MasterUserPassword', 'MultiAZ' + if @in_pending_modified_values + @pending_modified_values[name] = @value + else + @db_instance[name] = @value + end + when 'DBSecurityGroups' + @in_db_security_groups = false + @db_instance['DBSecurityGroups'] = @db_security_groups + when 'Status', 'DBSecurityGroupName' + if @in_db_security_groups + @db_security_group[name]=@value + end + when 'DBSecurityGroup' + @db_security_groups << @db_security_group + @db_security_group = {} + + when 'AllocatedStorage' + if @in_pending_modified_values + @pending_modified_values[name] = @value.to_i + else + @db_instance[name] = @value.to_i + end + when 'Address' + @endpoint[name] = @value + when 'Port' + if @in_pending_modified_values + @pending_modified_values[name] = @value.to_i + elsif @in_endpoint + @endpoint[name] = @value.to_i + end + + when 'PendingModifiedValues' + @in_pending_modified_values = false + @db_instance['PendingModifiedValues'] = @pending_modified_values + when 'Endpoint' + @in_endpoint = false + @db_instance['Endpoint'] = @endpoint + when 'ReadReplicaDBInstanceIdentifier' + @db_instance['ReadReplicaDBInstanceIdentifiers'] << @value + when 'ReadReplicaSourceDBInstanceIdentifier' + @db_instance['ReadReplicaSourceDBInstanceIdentifier'] = @value + when 'DBInstance' + @db_instance = fresh_instance + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/delete_db_instance.rb b/lib/fog/aws/parsers/rds/delete_db_instance.rb new file mode 100644 index 000000000..0e02cacbc --- /dev/null +++ b/lib/fog/aws/parsers/rds/delete_db_instance.rb @@ -0,0 +1,35 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/db_parser' + + class DeleteDBInstance < Fog::Parsers::AWS::RDS::DbParser + + def reset + @response = { 'DeleteDBInstanceResult' => {}, 'ResponseMetadata' => {} } + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + + when 'DBInstance' + @response['DeleteDBInstanceResult']['DBInstance'] = @db_instance + @db_instance = fresh_instance + when 'RequestId' + @response['ResponseMetadata'][name] = @value + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/delete_db_parameter_group.rb b/lib/fog/aws/parsers/rds/delete_db_parameter_group.rb new file mode 100644 index 000000000..d2570fb9f --- /dev/null +++ b/lib/fog/aws/parsers/rds/delete_db_parameter_group.rb @@ -0,0 +1,27 @@ +module Fog + module Parsers + module AWS + module RDS + + class DeleteDbParameterGroup < Fog::Parsers::Base + + def reset + @response = { 'ResponseMetadata' => {} } + @db_parameter_group = {} + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = @value + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/delete_db_snapshot.rb b/lib/fog/aws/parsers/rds/delete_db_snapshot.rb new file mode 100644 index 000000000..37f5fc6bd --- /dev/null +++ b/lib/fog/aws/parsers/rds/delete_db_snapshot.rb @@ -0,0 +1,34 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/snapshot_parser' + + class DeleteDBSnapshot < Fog::Parsers::AWS::RDS::SnapshotParser + + def reset + @response = { 'DeleteDBSnapshotResult' => {}, 'ResponseMetadata' => {} } + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = @value + when 'DBSnapshot' + @response['DeleteDBSnapshotResult']['DBSnapshot'] = @db_snapshot + @db_snapshot = fresh_snapshot + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/describe_db_instances.rb b/lib/fog/aws/parsers/rds/describe_db_instances.rb new file mode 100644 index 000000000..cebcfe93b --- /dev/null +++ b/lib/fog/aws/parsers/rds/describe_db_instances.rb @@ -0,0 +1,36 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/db_parser' + + class DescribeDBInstances < Fog::Parsers::AWS::RDS::DbParser + + def reset + @response = { 'DescribeDBInstancesResult' => {'DBInstances' => []}, 'ResponseMetadata' => {} } + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'DBInstance' + @response['DescribeDBInstancesResult']['DBInstances'] << @db_instance + @db_instance = fresh_instance + when 'Marker' + @response['DescribeDBInstancesResult']['Marker'] = @value + when 'RequestId' + @response['ResponseMetadata'][name] = @value + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/describe_db_parameter_groups.rb b/lib/fog/aws/parsers/rds/describe_db_parameter_groups.rb new file mode 100644 index 000000000..5dc2fef34 --- /dev/null +++ b/lib/fog/aws/parsers/rds/describe_db_parameter_groups.rb @@ -0,0 +1,38 @@ +module Fog + module Parsers + module AWS + module RDS + + class DescribeDBParameterGroups < Fog::Parsers::Base + + def reset + @response = { 'DescribeDBParameterGroupsResult' => {'DBParameterGroups' => []}, 'ResponseMetadata' => {} } + @db_parameter_group = {} + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'DBParameterGroupFamily' then @db_parameter_group['DBParameterGroupFamily'] = @value + when 'Description' then @db_parameter_group['Description'] = @value + when 'DBParameterGroupName' then @db_parameter_group['DBParameterGroupName'] = @value + when 'DBParameterGroup' then + @response['DescribeDBParameterGroupsResult']['DBParameterGroups'] << @db_parameter_group + @db_parameter_group = {} + when 'Marker' + @response['DescribeDBParameterGroupsResult']['Marker'] = @value + when 'RequestId' + @response['ResponseMetadata'][name] = @value + end + + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/describe_db_parameters.rb b/lib/fog/aws/parsers/rds/describe_db_parameters.rb new file mode 100644 index 000000000..8aadb122f --- /dev/null +++ b/lib/fog/aws/parsers/rds/describe_db_parameters.rb @@ -0,0 +1,44 @@ +module Fog + module Parsers + module AWS + module RDS + + class DescribeDBParameters < Fog::Parsers::Base + + def reset + @response = { 'DescribeDBParametersResult' =>{}, 'ResponseMetadata' => {} } + @parameter = {} + @parameters = [] + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'ParameterValue' then @parameter['ParameterValue'] = @value + when 'DataType' then @parameter['DataType'] = @value + when 'AllowedValues' then @parameter['AllowedValues'] = @value + when 'Source' then @parameter['Source'] = @value + when 'IsModifiable' then + @parameter['IsModifiable'] = @value == 'true' ? true : false + when 'Description' then @parameter['Description'] = @value + when 'ApplyType' then @parameter['ApplyType'] = @value + when 'ParameterName' then @parameter['ParameterName'] = @value + when 'Parameter' + @parameters << @parameter + @parameter = {} + when 'Marker' + @response['DescribeDBParametersResult']['Marker'] = @value + when 'Parameters' + @response['DescribeDBParametersResult']['Parameters'] = @parameters + when 'RequestId' + @response['ResponseMetadata'][name] = @value + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/describe_db_snapshots.rb b/lib/fog/aws/parsers/rds/describe_db_snapshots.rb new file mode 100644 index 000000000..66f52b010 --- /dev/null +++ b/lib/fog/aws/parsers/rds/describe_db_snapshots.rb @@ -0,0 +1,39 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/snapshot_parser' + + class DescribeDBSnapshots < Fog::Parsers::AWS::RDS::SnapshotParser + + def reset + @response = { 'DescribeDBSnapshotsResult' => {'DBSnapshots' => []}, 'ResponseMetadata' => {} } + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'DBSnapshot' then + @response['DescribeDBSnapshotsResult']['DBSnapshots'] << @db_snapshot + @db_snapshot = fresh_snapshot + when 'Marker' + @response['DescribeDBSnapshotsResult']['Marker'] = @value + when 'RequestId' + @response['ResponseMetadata'][name] = @value + else + super + end + + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/modify_db_instance.rb b/lib/fog/aws/parsers/rds/modify_db_instance.rb new file mode 100644 index 000000000..114e3ca93 --- /dev/null +++ b/lib/fog/aws/parsers/rds/modify_db_instance.rb @@ -0,0 +1,34 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/db_parser' + + class ModifyDBInstance < Fog::Parsers::AWS::RDS::DbParser + + def reset + @response = { 'ModifyDBInstanceResult' => {}, 'ResponseMetadata' => {} } + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'DBInstance' + @response['ModifyDBInstanceResult']['DBInstance'] = @db_instance + @db_instance = fresh_instance + when 'RequestId' + @response['ResponseMetadata'][name] = @value + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/modify_db_parameter_group.rb b/lib/fog/aws/parsers/rds/modify_db_parameter_group.rb new file mode 100644 index 000000000..6d10cca3d --- /dev/null +++ b/lib/fog/aws/parsers/rds/modify_db_parameter_group.rb @@ -0,0 +1,28 @@ +module Fog + module Parsers + module AWS + module RDS + + class ModifyDbParameterGroup < Fog::Parsers::Base + + def reset + @response = { 'ModifyDBParameterGroupResult' => {}, 'ResponseMetadata' => {} } + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'DBParameterGroupName' + @response['ModifyDBParameterGroupResult']['DBParameterGroupName'] = @value + when 'RequestId' + @response['ResponseMetadata'][name] = @value + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/reboot_db_instance.rb b/lib/fog/aws/parsers/rds/reboot_db_instance.rb new file mode 100644 index 000000000..e41550c99 --- /dev/null +++ b/lib/fog/aws/parsers/rds/reboot_db_instance.rb @@ -0,0 +1,35 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/db_parser' + + class RebootDBInstance < Fog::Parsers::AWS::RDS::DbParser + + def reset + @response = { 'RebootDBInstanceResult' => {}, 'ResponseMetadata' => {} } + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + + when 'DBInstance' + @response['RebootDBInstanceResult']['DBInstance'] = @db_instance + @db_instance = fresh_instance + when 'RequestId' + @response['ResponseMetadata'][name] = @value + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/snapshot_parser.rb b/lib/fog/aws/parsers/rds/snapshot_parser.rb new file mode 100644 index 000000000..602cd765f --- /dev/null +++ b/lib/fog/aws/parsers/rds/snapshot_parser.rb @@ -0,0 +1,40 @@ +module Fog + module Parsers + module AWS + module RDS + + class SnapshotParser < Fog::Parsers::Base + + def reset + @db_snapshot = fresh_snapshot + end + + def fresh_snapshot + {} + end + + def start_element(name, attrs = []) + super + + end + + def end_element(name) + case name + when 'AllocatedStorage' then @db_snapshot['AllocatedStorage'] = @value.to_i + when 'AvailabilityZone' then @db_snapshot['AvailabilityZone'] = @value + when 'DBInstanceIdentifier' then @db_snapshot['DBInstanceIdentifier'] = @value + when 'DBSnapshotIdentifier' then @db_snapshot['DBSnapshotIdentifier'] = @value + when 'Engine' then @db_snapshot['Engine'] = @value + when 'EngineVersion' then @db_snapshot['EngineVersion'] = @value + when 'InstanceCreateTime' then @db_snapshot['InstanceCreateTime'] = Time.parse @value + when 'MasterUsername' then @db_snapshot['MasterUsername'] = @value + when 'Port' then @db_snapshot['Port'] = @value.to_i + when 'SnapshotCreateTime' then @db_snapshot['SnapshotCreateTime'] = Time.parse @value + when 'Status' then @db_snapshot['Status'] = @value + end + end + end + end + end + end +end diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb new file mode 100644 index 000000000..63f6425b1 --- /dev/null +++ b/lib/fog/aws/rds.rb @@ -0,0 +1,146 @@ +module Fog + module AWS + class RDS < Fog::Service + + class NotFound < Fog::Errors::Error; end + class IdentifierTaken < Fog::Errors::Error; end + + requires :aws_access_key_id, :aws_secret_access_key + recognizes :region, :host, :path, :port, :scheme, :persistent + + request_path 'fog/aws/requests/rds' + + request :create_db_instance + request :modify_db_instance + request :describe_db_instances + request :delete_db_instance + request :reboot_db_instance + request :create_db_instance_read_replica + + request :describe_db_snapshots + request :create_db_snapshot + request :delete_db_snapshot + + + request :create_db_parameter_group + request :delete_db_parameter_group + request :modify_db_parameter_group + request :describe_db_parameter_groups + + request :describe_db_parameters + + model_path 'fog/aws/rds/models' + model :server + collection :servers + model :snapshot + collection :snapshots + model :parameter_group + collection :parameter_groups + + model :parameter + collection :parameters + + class Mock + + def initialize(options={}) + end + + end + + class Real + + # Initialize connection to ELB + # + # ==== Notes + # options parameter must include values for :aws_access_key_id and + # :aws_secret_access_key in order to create a connection + # + # ==== Examples + # elb = ELB.new( + # :aws_access_key_id => your_aws_access_key_id, + # :aws_secret_access_key => your_aws_secret_access_key + # ) + # + # ==== Parameters + # * options<~Hash> - config arguments for connection. Defaults to {}. + # * region<~String> - optional region to use, in ['eu-west-1', 'us-east-1', 'us-west-1'i, 'ap-southeast-1'] + # + # ==== Returns + # * ELB object with connection to AWS. + def initialize(options={}) + @aws_access_key_id = options[:aws_access_key_id] + @aws_secret_access_key = options[:aws_secret_access_key] + @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) + options[:region] ||= 'us-east-1' + @host = options[:host] || case options[:region] + when 'ap-southeast-1' + 'rds.ap-southeast-1.amazonaws.com' + when 'eu-west-1' + 'rds.eu-west-1.amazonaws.com' + when 'us-east-1' + 'rds.us-east-1.amazonaws.com' + when 'us-west-1' + 'rds.us-west-1.amazonaws.com' + else + raise ArgumentError, "Unknown region: #{options[:region].inspect}" + end + @path = options[:path] || '/' + @port = options[:port] || 443 + @scheme = options[:scheme] || 'https' + @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent]) + end + + def reload + @connection.reset + end + + private + + def request(params) + idempotent = params.delete(:idempotent) + parser = params.delete(:parser) + + body = AWS.signed_params( + params, + { + :aws_access_key_id => @aws_access_key_id, + :hmac => @hmac, + :host => @host, + :path => @path, + :port => @port, + :version => '2010-07-28' + } + ) + + begin + response = @connection.request({ + :body => body, + :expects => 200, + :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, + :idempotent => idempotent, + :host => @host, + :method => 'POST', + :parser => parser + }) + rescue Excon::Errors::HTTPStatusError => error + if match = error.message.match(/(.*)<\/Code>[\s\\\w]+(.*)<\/Message>/m) + case match[1].split('.').last + when 'DBInstanceNotFound', 'DBParameterGroupNotFound', 'DBSnapshotNotFound' + raise Fog::AWS::RDS::NotFound.slurp(error, match[2]) + when 'DBParameterGroupAlreadyExists' + raise Fog::AWS::RDS::IdentifierTaken.slurp(error, match[2]) + else + raise + end + else + raise + end + end + + response + end + + end + end + end +end diff --git a/lib/fog/aws/rds/models/parameter.rb b/lib/fog/aws/rds/models/parameter.rb new file mode 100644 index 000000000..3e31492ce --- /dev/null +++ b/lib/fog/aws/rds/models/parameter.rb @@ -0,0 +1,21 @@ +require 'fog/core/model' + +module Fog + module AWS + class RDS + + class Parameter < Fog::Model + + attribute :name, :aliases => ['ParameterName'] + attribute :data_type, :aliases => 'DataType' + attribute :description, :aliases => 'Description' + attribute :allowed_values, :aliases => 'AllowedValues' + attribute :source, :aliases => 'Source' + attribute :modifiable, :aliases => 'IsModifiable' + attribute :apply_type, :aliases => 'ApplyType' + attribute :value, :aliases => 'ParameterValue' + + end + end + end +end diff --git a/lib/fog/aws/rds/models/parameter_group.rb b/lib/fog/aws/rds/models/parameter_group.rb new file mode 100644 index 000000000..d584535f0 --- /dev/null +++ b/lib/fog/aws/rds/models/parameter_group.rb @@ -0,0 +1,36 @@ +require 'fog/core/model' + +module Fog + module AWS + class RDS + + class ParameterGroup < Fog::Model + + identity :id, :aliases => ['DBParameterGroupName', :name] + attribute :family, :aliases => 'DBParameterGroupFamily' + attribute :description, :aliases => 'Description' + + def save + requires :family + requires :description + requires :id + connection.create_db_parameter_group(id, family, description) + end + + def modify(changes) + connection.modify_db_parameter_group id, changes.collect {|c| {'ParameterName' => c[:name], 'ParameterValue' => c[:value], 'ApplyMethod' => c[:apply_method]}} + end + + def destroy + requires :id + connection.delete_db_parameter_group(id) + true + end + + def parameters(filters={}) + connection.parameters({:group => self}.merge(filters)) + end + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/rds/models/parameter_groups.rb b/lib/fog/aws/rds/models/parameter_groups.rb new file mode 100644 index 000000000..c18d6edcc --- /dev/null +++ b/lib/fog/aws/rds/models/parameter_groups.rb @@ -0,0 +1,27 @@ +require 'fog/core/collection' +require 'fog/aws/rds/models/parameter_group' + +module Fog + module AWS + class RDS + + class ParameterGroups < Fog::Collection + + model Fog::AWS::RDS::ParameterGroup + + def all + data = connection.describe_db_parameter_groups.body['DescribeDBParameterGroupsResult']['DBParameterGroups'] + load(data) # data is an array of attribute hashes + end + + def get(identity) + data = connection.describe_db_parameter_groups(identity).body['DescribeDBParameterGroupsResult']['DBParameterGroups'].first + new(data) # data is an attribute hash + rescue Fog::AWS::RDS::NotFound + nil + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/rds/models/parameters.rb b/lib/fog/aws/rds/models/parameters.rb new file mode 100644 index 000000000..e8d79764d --- /dev/null +++ b/lib/fog/aws/rds/models/parameters.rb @@ -0,0 +1,37 @@ +require 'fog/core/collection' +require 'fog/aws/rds/models/parameter' + +module Fog + module AWS + class RDS + + class Parameters < Fog::Collection + attribute :group + attribute :filters + model Fog::AWS::RDS::Parameter + + def initialize(attributes) + self.filters ||= {} + if attributes[:source] + filters[:source] = attributes[:source] + end + super + end + + def all(filters = filters) + self.filters = filters + result = [] + marker = nil + finished = false + while !finished + data = connection.describe_db_parameters(group.id, filters.merge(:marker => marker)).body + result.concat(data['DescribeDBParametersResult']['Parameters']) + marker = data['DescribeDBParametersResult']['Marker'] + finished = marker.nil? + end + load(result) # data is an array of attribute hashes + end + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/rds/models/server.rb b/lib/fog/aws/rds/models/server.rb new file mode 100644 index 000000000..f51464328 --- /dev/null +++ b/lib/fog/aws/rds/models/server.rb @@ -0,0 +1,105 @@ +require 'fog/core/model' + +module Fog + module AWS + class RDS + + class Server < Fog::Model + + identity :id, :aliases => 'DBInstanceIdentifier' + attribute :engine, :aliases => 'Engine' + attribute :engine_version, :aliases => 'EngineVersion' + attribute :state, :aliases => 'DBInstanceStatus' + attribute :allocated_storage, :aliases => 'AllocatedStorage', :type => :integer + attribute :availability_zone , :aliases => 'AvailabilityZone' + attribute :flavor_id, :aliases => 'DBInstanceClass' + attribute :endpoint, :aliases => 'Endpoint' + attribute :read_replica_source, :aliases => 'ReadReplicaSourceDBInstanceIdentifier' + attribute :read_replica_identifiers, :aliases => 'ReadReplicaDBInstanceIdentifiers', :type => :array + attribute :master_username, :aliases => 'MasterUsername' + attribute :multi_az, :aliases => 'MultiAZ' + attribute :created_at, :aliases => 'InstanceCreateTime', :type => :time + attribute :last_restorable_time, :aliases => 'LatestRestorableTime', :type => :time + attribute :auto_minor_version_upgrade, :aliases => 'AutoMinorVersionUpgrade' + attribute :pending_modified_values, :aliases => 'PendingModifiedValues' + attribute :preferred_backup_window, :aliases => 'PreferredBackupWindow' + attribute :preferred_maintenance_window, :aliases => 'PreferredMaintenanceWindow' + attribute :db_name, :aliases => 'DBName' + attribute :db_security_groups, :aliases => 'DBSecurityGroups' + attribute :db_parameter_groups, :aliases => 'DBParameterGroups' + attribute :backup_retention_period, :aliases => 'BackupRetentionPeriod', :type => :integer + + attr_accessor :password, :parameter_group_name, :security_group_names, :port + + def initialize(attributes={}) + self.flavor_id ||= 'db.m1.small' + super + end + + def create_read_replica(replica_id, options={}) + connection.create_db_instance_read_replica(replica_id, id, options) + connection.servers.get(replica_id) + end + + def ready? + state == 'available' + end + + def destroy(snapshot_identifier) + requires :id + connection.delete_db_instance(id, snapshot_identifier, snapshot_identifier.nil?) + true + end + + def reboot + connection.reboot_db_instance(id) + true + end + + def snapshots + requires :id + connection.snapshots(:server => self) + end + + def modify(immediately, options) + data = connection.modify_db_instance(id, immediately, options) + merge_attributes(data.body['ModifyDBInstanceResult']['DBInstance']) + true + end + + def save + requires :engine + requires :allocated_storage + requires :master_username + requires :password + options = { + 'AllocatedStorage' => allocated_storage, + 'AutoMinorVersionUpgrade' => auto_minor_version_upgrade, + 'BackupRetentionPeriod' => backup_retention_period, + 'DBName' => db_name, + 'DBParameterGroupName' => parameter_group_name, + 'DBSecurityGroups' => security_group_names, + 'DBInstanceIdentifier' => id, + 'AvailabilityZone' => availability_zone, + 'DBInstanceClass' => flavor_id, + 'Port' => port, + 'Engine' => engine, + 'EngineVersion' => engine_version, + 'MasterUsername' => master_username, + 'MasterUserPassword' => password, + 'PreferredMaintenanceWindow' => preferred_maintenance_window, + 'PreferredBackupWindow' => preferred_backup_window, + 'MultiAZ' => multi_az + } + options.delete_if {|key, value| value.nil?} + + + data = connection.create_db_instance(id, options) + merge_attributes(data.body['CreateDBInstanceResult']['DBInstance']) + true + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/rds/models/servers.rb b/lib/fog/aws/rds/models/servers.rb new file mode 100644 index 000000000..6267e0f96 --- /dev/null +++ b/lib/fog/aws/rds/models/servers.rb @@ -0,0 +1,27 @@ +require 'fog/core/collection' +require 'fog/aws/rds/models/server' + +module Fog + module AWS + class RDS + + class Servers < Fog::Collection + + model Fog::AWS::RDS::Server + + def all + data = connection.describe_db_instances.body['DescribeDBInstancesResult']['DBInstances'] + load(data) # data is an array of attribute hashes + end + + def get(identity) + data = connection.describe_db_instances(identity).body['DescribeDBInstancesResult']['DBInstances'].first + new(data) # data is an attribute hash + rescue Fog::AWS::RDS::NotFound + nil + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/rds/models/snapshot.rb b/lib/fog/aws/rds/models/snapshot.rb new file mode 100644 index 000000000..c91df09cb --- /dev/null +++ b/lib/fog/aws/rds/models/snapshot.rb @@ -0,0 +1,49 @@ +require 'fog/core/model' + +module Fog + module AWS + class RDS + + class Snapshot < Fog::Model + + identity :id, :aliases => ['DBSnapshotIdentifier', :name] + attribute :instance_id, :aliases => 'DBInstanceIdentifier' + attribute :created_at, :aliases => 'SnapshotCreateTime', :type => :time + attribute :instance_created_at, :aliases => 'InstanceCreateTime', :type => :time + attribute :engine, :aliases => 'Engine' + attribute :engine_version, :aliases => 'EngineVersion' + attribute :master_username, :aliases => 'MasterUsername' + attribute :state, :aliases => 'Status' + attribute :port, :aliases => 'Port', :type => :integer + attribute :allocated_storage, :aliases => 'AllocatedStorage', :type => :integer + attribute :availability_zone, :aliases => 'AvailabilityZone' + + def ready? + state == 'available' + end + + def destroy + requires :id + + connection.delete_db_snapshot(id) + true + end + + def save + requires :instance_id + requires :id + + data = connection.create_db_snapshot(instance_id, id).body['CreateDBSnapshotResult']['DBSnapshot'] + merge_attributes(data) + true + end + + def server + requires :instance_id + connection.servers.get(instance_id) + end + + end + end + end +end diff --git a/lib/fog/aws/rds/models/snapshots.rb b/lib/fog/aws/rds/models/snapshots.rb new file mode 100644 index 000000000..7f2af171f --- /dev/null +++ b/lib/fog/aws/rds/models/snapshots.rb @@ -0,0 +1,45 @@ +require 'fog/core/collection' +require 'fog/aws/rds/models/snapshot' + +module Fog + module AWS + class RDS + + class Snapshots < Fog::Collection + attribute :server + attribute :filters + model Fog::AWS::RDS::Snapshot + + def initialize(attributes) + self.filters ||= {} + if attributes[:server] + filters[:identifier] = attributes[:server].id + end + super + end + + def all(filters = filters) + self.filters = filters + data = connection.describe_db_snapshots(filters).body['DescribeDBSnapshotsResult']['DBSnapshots'] + load(data) # data is an array of attribute hashes + end + + def get(identity) + data = connection.describe_db_snapshots(identity).body['DescribeDBSnapshotsResult']['DBSnapshots'].first + new(data) # data is an attribute hash + rescue Fog::AWS::RDS::NotFound + nil + end + + def new(attributes = {}) + if server + super({ :instance_id => server.id }.merge!(attributes)) + else + super + end + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/requests/rds/create_db_instance.rb b/lib/fog/aws/requests/rds/create_db_instance.rb new file mode 100644 index 000000000..91efb2db4 --- /dev/null +++ b/lib/fog/aws/requests/rds/create_db_instance.rb @@ -0,0 +1,56 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/create_db_instance' + + # create a db instance + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html + # ==== Parameters + # * DBInstanceIdentifier <~String> - name of the db instance to modify + # + # * AllocatedStorage <~Integer> Storage space, in GB + # * AutoMinorVersionUpgrade <~Boolean> Indicates that minor version upgrades will be applied automatically to the DB Instance during the maintenance window + # * AvailabilityZone <~String> The availability zone to create the instance in + # * BackupRetentionPeriod <~Integer> 0-8 The number of days to retain automated backups. + # * DBInstanceClass <~String> The new compute and memory capacity of the DB Instance + # * DBName <~String> The name of the database to create when the DB Instance is created + # * DBParameterGroupName <~String> The name of the DB Parameter Group to apply to this DB Instance + # * DBSecurityGroups <~Array> A list of DB Security Groups to authorize on this DB Instance + # * Engine <~String> The name of the database engine to be used for this instance. + # * EngineVersion <~String> The version number of the database engine to use. + # * MasterUsername <~String> The db master user + # * MasterUserPassword <~String> The new password for the DB Instance master user + # * MultiAZ <~Boolean> Specifies if the DB Instance is a Multi-AZ deployment + # * Port <~Integer> The port number on which the database accepts connections. + # * PreferredBackupWindow <~String> The daily time range during which automated backups are created if automated backups are enabled + # * PreferredMaintenanceWindow <~String> The weekly time range (in UTC) during which system maintenance can occur, which may result in an outage + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def create_db_instance(db_name, options={}) + + if security_groups = options.delete('DBSecurityGroups') + options.merge!(AWS.indexed_param('DBSecurityGroups.member.%d', [*security_groups])) + end + + request({ + 'Action' => 'CreateDBInstance', + 'DBInstanceIdentifier' => db_name, + :parser => Fog::Parsers::AWS::RDS::CreateDBInstance.new, + }.merge(options)) + end + + end + + class Mock + + def create_db_instance(db_name, options={}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/create_db_instance_read_replica.rb b/lib/fog/aws/requests/rds/create_db_instance_read_replica.rb new file mode 100644 index 000000000..e613530af --- /dev/null +++ b/lib/fog/aws/requests/rds/create_db_instance_read_replica.rb @@ -0,0 +1,42 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/create_db_instance_read_replica' + + # create a read replica db instance + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_CreateDBInstanceReadReplica.html + # ==== Parameters + # * DBInstanceIdentifier <~String> - name of the db instance to create + # * SourceDBInstanceIdentifier <~String> - name of the db instance that will be the source. Must have backup retention on + # * AutoMinorVersionUpgrade <~Boolean> Indicates that minor version upgrades will be applied automatically to the DB Instance during the maintenance window + # * AvailabilityZone <~String> The availability zone to create the instance in + # * DBInstanceClass <~String> The new compute and memory capacity of the DB Instance + # * Port <~Integer> The port number on which the database accepts connections. + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def create_db_instance_read_replica(instance_identifier, source_identifier, options={}) + + + request({ + 'Action' => 'CreateDBInstanceReadReplica', + 'DBInstanceIdentifier' => instance_identifier, + 'SourceDBInstanceIdentifier' => source_identifier, + :parser => Fog::Parsers::AWS::RDS::CreateDBInstanceReadReplica.new, + }.merge(options)) + end + + end + + class Mock + + def create_db_instance_read_replica(instance_identifier, source_identifier, options={}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/create_db_parameter_group.rb b/lib/fog/aws/requests/rds/create_db_parameter_group.rb new file mode 100644 index 000000000..9fdcf680f --- /dev/null +++ b/lib/fog/aws/requests/rds/create_db_parameter_group.rb @@ -0,0 +1,41 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/create_db_parameter_group' + + # create a database parameter group + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_CreateDBParameterGroup.html + # ==== Parameters + # * DBParameterGroupName <~String> - name of the parameter group + # * DBParameterGroupFamily <~String> - The DB parameter group family name. Current valid values: MySQL5.1 | MySQL5.5 + # * Description <~String> - The description for the DB Parameter Grou + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def create_db_parameter_group(group_name, group_family, description) + + request({ + 'Action' => 'CreateDBParameterGroup', + 'DBParameterGroupName' => group_name, + 'DBParameterGroupFamily' => group_family, + 'Description' => description, + + :parser => Fog::Parsers::AWS::RDS::CreateDbParameterGroup.new + }) + end + + end + + class Mock + + def create_db_parameter_group(group_name, group_family, description) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/create_db_snapshot.rb b/lib/fog/aws/requests/rds/create_db_snapshot.rb new file mode 100644 index 000000000..24a2574db --- /dev/null +++ b/lib/fog/aws/requests/rds/create_db_snapshot.rb @@ -0,0 +1,36 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/create_db_snapshot' + + # creates a db snapshot + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_CreateDBSnapshot.html + # ==== Parameters + # * DBInstanceIdentifier <~String> - ID of instance to create snapshot for + # * DBSnapshotIdentifier <~String> - The identifier for the DB Snapshot. 1-255 alphanumeric or hyphen characters. Must start with a letter + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def create_db_snapshot(identifier, name) + request({ + 'Action' => 'CreateDBSnapshot', + 'DBInstanceIdentifier' => identifier, + 'DBSnapshotIdentifier' => name, + :parser => Fog::Parsers::AWS::RDS::CreateDBSnapshot.new + }) + end + + end + + class Mock + + def create_db_snapshot(identifier, name) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/delete_db_instance.rb b/lib/fog/aws/requests/rds/delete_db_instance.rb new file mode 100644 index 000000000..0c5979b21 --- /dev/null +++ b/lib/fog/aws/requests/rds/delete_db_instance.rb @@ -0,0 +1,40 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/delete_db_instance' + + # delete a database instance + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DeleteDBInstance.html + # ==== Parameters + # * DBInstanceIdentifier <~String> - The DB Instance identifier for the DB Instance to be deleted. + # * FinalDBSnapshotIdentifier <~String> - The DBSnapshotIdentifier of the new DBSnapshot created when SkipFinalSnapshot is set to false + # * SkipFinalSnapshot <~Boolean> - Determines whether a final DB Snapshot is created before the DB Instance is deleted + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def delete_db_instance(identifier, snapshot_identifier, skip_snapshot = false) + params = {} + params['FinalDBSnapshotIdentifier'] = snapshot_identifier if snapshot_identifier + request({ + 'Action' => 'DeleteDBInstance', + 'DBInstanceIdentifier' => identifier, + 'SkipFinalSnapshot' => skip_snapshot, + :parser => Fog::Parsers::AWS::RDS::DeleteDBInstance.new + }.merge(params)) + end + + end + + class Mock + + def delete_db_snapshot(identifier, snapshot_identifier, skip_snapshot = false) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/delete_db_parameter_group.rb b/lib/fog/aws/requests/rds/delete_db_parameter_group.rb new file mode 100644 index 000000000..d7f294b3e --- /dev/null +++ b/lib/fog/aws/requests/rds/delete_db_parameter_group.rb @@ -0,0 +1,36 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/delete_db_parameter_group' + + # delete a database parameter group + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DeleteDBParameterGroup.html + # ==== Parameters + # * DBParameterGroupName <~String> - name of the parameter group. Must not be associated with any instances + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def delete_db_parameter_group(group_name) + + request({ + 'Action' => 'DeleteDBParameterGroup', + 'DBParameterGroupName' => group_name, + + :parser => Fog::Parsers::AWS::RDS::DeleteDbParameterGroup.new + }) + end + + end + + class Mock + + def delete_db_parameter_group(group_name) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/delete_db_snapshot.rb b/lib/fog/aws/requests/rds/delete_db_snapshot.rb new file mode 100644 index 000000000..ea42c35ce --- /dev/null +++ b/lib/fog/aws/requests/rds/delete_db_snapshot.rb @@ -0,0 +1,36 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/delete_db_snapshot' + + # delete a database snapshot + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DeleteDBSnapshot.html + # ==== Parameters + # * DBSnapshotIdentifier <~String> - name of the snapshot + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def delete_db_snapshot(group_name) + + request({ + 'Action' => 'DeleteDBSnapshot', + 'DBSnapshotIdentifier' => group_name, + + :parser => Fog::Parsers::AWS::RDS::DeleteDBSnapshot.new + }) + end + + end + + class Mock + + def delete_db_snapshot(group_name) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/describe_db_instances.rb b/lib/fog/aws/requests/rds/describe_db_instances.rb new file mode 100644 index 000000000..ea7bd34a1 --- /dev/null +++ b/lib/fog/aws/requests/rds/describe_db_instances.rb @@ -0,0 +1,42 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/describe_db_instances' + + # Describe all or specified load db instances + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DescribeDBInstances.html + # ==== Parameters + # * DBInstanceIdentifier <~String> - ID of instance to retrieve information for. if absent information for all instances is returned + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def describe_db_instances(identifier=nil, opts={}) + params = {} + params['DBInstanceIdentifier'] = identifier if identifier + if opts[:marker] + params['Marker'] = opts[:marker] + end + if opts[:max_records] + params['MaxRecords'] = opts[:max_records] + end + + request({ + 'Action' => 'DescribeDBInstances', + :parser => Fog::Parsers::AWS::RDS::DescribeDBInstances.new + }.merge(params)) + end + + end + + class Mock + + def describe_db_instances(identifier=nil, opts={}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/describe_db_parameter_groups.rb b/lib/fog/aws/requests/rds/describe_db_parameter_groups.rb new file mode 100644 index 000000000..26244a255 --- /dev/null +++ b/lib/fog/aws/requests/rds/describe_db_parameter_groups.rb @@ -0,0 +1,45 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/describe_db_parameter_groups' + + # This API returns a list of DBParameterGroup descriptions. If a DBParameterGroupName is specified, the list will contain only the descriptions of the specified DBParameterGroup + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DescribeDBParameterGroups.html + # ==== Parameters + # * DBParameterGroupName <~String> - The name of a specific database parameter group to return details for. + # * Source <~String> - The parameter types to return. user | system | engine-default + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def describe_db_parameter_groups(name=nil, opts={}) + params={} + if opts[:marker] + params['Marker'] = opts[:marker] + end + if name + params['DBParameterGroupName'] = name + end + if opts[:max_records] + params['MaxRecords'] = opts[:max_records] + end + + request({ + 'Action' => 'DescribeDBParameterGroups', + :parser => Fog::Parsers::AWS::RDS::DescribeDBParameterGroups.new + }.merge(params)) + end + + end + + class Mock + + def describe_db_parameter_groups(name=nil, opts={}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/describe_db_parameters.rb b/lib/fog/aws/requests/rds/describe_db_parameters.rb new file mode 100644 index 000000000..d76036b01 --- /dev/null +++ b/lib/fog/aws/requests/rds/describe_db_parameters.rb @@ -0,0 +1,46 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/describe_db_parameters' + + # Describe parameters from a parameter group + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DescribeDBParameters.html + # ==== Parameters + # * DBParameterGroupName <~String> - name of parameter group to retrieve parameters for + # * Source <~String> - The parameter types to return. user | system | engine-default + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def describe_db_parameters(name, opts={}) + params={} + if opts[:marker] + params['Marker'] = opts[:marker] + end + if opts[:source] + params['Source'] = opts[:source] + end + if opts[:max_records] + params['MaxRecords'] = opts[:max_records] + end + + request({ + 'Action' => 'DescribeDBParameters', + 'DBParameterGroupName' => name, + :parser => Fog::Parsers::AWS::RDS::DescribeDBParameters.new + }.merge(params)) + end + + end + + class Mock + + def describe_db_parameters(name, opts={}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/describe_db_snapshots.rb b/lib/fog/aws/requests/rds/describe_db_snapshots.rb new file mode 100644 index 000000000..473e076a1 --- /dev/null +++ b/lib/fog/aws/requests/rds/describe_db_snapshots.rb @@ -0,0 +1,42 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/describe_db_snapshots' + + # Describe all or specified db snapshots + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DescribeDBSnapshots.html + # ==== Parameters + # * DBInstanceIdentifier <~String> - ID of instance to retrieve information for. if absent information for all instances is returned + # * DBSnapshotIdentifier <~String> - ID of snapshot to retrieve information for. if absent information for all snapshots is returned + # * Marker <~String> - An optional marker provided in the previous DescribeDBInstances request + # * MaxRecords <~Integer> - Max number of records to return (between 20 and 100) + # Only one of DBInstanceIdentifier or DBSnapshotIdentifier can be specified + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def describe_db_snapshots(opts={}) + params = {} + params['DBInstanceIdentifier'] = opts[:identifier] if opts[:identifier] + params['DBSnapshotIdentifier'] = opts[:snapshot_id] if opts[:snapshot_id] + params['Marker'] = opts[:marker] if opts[:marker] + params['MaxRecords'] = opts[:max_records] if opts[:max_records] + request({ + 'Action' => 'DescribeDBSnapshots', + :parser => Fog::Parsers::AWS::RDS::DescribeDBSnapshots.new + }.merge(params)) + end + + end + + class Mock + + def describe_db_snapshots(opts={}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/modify_db_instance.rb b/lib/fog/aws/requests/rds/modify_db_instance.rb new file mode 100644 index 000000000..084e64831 --- /dev/null +++ b/lib/fog/aws/requests/rds/modify_db_instance.rb @@ -0,0 +1,54 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/modify_db_instance' + + # modifies a database instance + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_ModifyDBInstance.html + # ==== Parameters + # * DBInstanceIdentifier <~String> - name of the db instance to modify + # * ApplyImmediately <~Boolean> - whether to apply the changes immediately or wait for the next maintenance window + # + # * AllocatedStorage <~Integer> Storage space, in GB + # * AllowMajorVersionUpgrade <~Boolean> Must be set to true if EngineVersion specifies a different major version + # * AutoMinorVersionUpgrade <~Boolean> Indicates that minor version upgrades will be applied automatically to the DB Instance during the maintenance window + # * BackupRetentionPeriod <~Integer> 0-8 The number of days to retain automated backups. + # * DBInstanceClass <~String> The new compute and memory capacity of the DB Instanc + # * DBParameterGroupName <~String> The name of the DB Parameter Group to apply to this DB Instance + # * DBSecurityGroups <~Array> A list of DB Security Groups to authorize on this DB Instance + # * EngineVersion <~String> The version number of the database engine to upgrade to. + # * MasterUserPassword <~String> The new password for the DB Instance master user + # * MultiAZ <~Boolean> Specifies if the DB Instance is a Multi-AZ deployment + # * PreferredBackupWindow <~String> The daily time range during which automated backups are created if automated backups are enabled + # * PreferredMaintenanceWindow <~String> The weekly time range (in UTC) during which system maintenance can occur, which may result in an outage + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def modify_db_instance(db_name, apply_immediately, options={}) + + if security_groups = options.delete('DBSecurityGroups') + options.merge!(AWS.indexed_param('DBSecurityGroups.member.%d', [*security_groups])) + end + + request({ + 'Action' => 'ModifyDBInstance', + 'DBInstanceIdentifier' => db_name, + 'ApplyImmediately' => apply_immediately, + :parser => Fog::Parsers::AWS::RDS::ModifyDBInstance.new, + }.merge(options)) + end + + end + + class Mock + + def modify_db_instance(db_name, apply_immediately, options={}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/modify_db_parameter_group.rb b/lib/fog/aws/requests/rds/modify_db_parameter_group.rb new file mode 100644 index 000000000..7cb001584 --- /dev/null +++ b/lib/fog/aws/requests/rds/modify_db_parameter_group.rb @@ -0,0 +1,55 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/modify_db_parameter_group' + + # modifies a database parameter group + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_ModifyDBParameterGroup.html + # ==== Parameters + # * DBParameterGroupName <~String> - name of the parameter group + # * Parameters<~Array> - Array of up to 20 Hashes describing parameters to set + # * 'ParameterName'<~String> - parameter name. + # * 'ParameterValue'<~String> - new paremeter value + # * 'ApplyMethod'<~String> - immediate | pending-reboot whether to set the parameter immediately or not (may require an instance restart) + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def modify_db_parameter_group(group_name, parameters) + + parameter_names = [] + parameter_values = [] + parameter_apply_methods = [] + + parameters.each do |parameter| + parameter_names.push(parameter['ParameterName']) + parameter_values.push(parameter['ParameterValue']) + parameter_apply_methods.push(parameter['ApplyMethod']) + end + params = {} + params.merge!(AWS.indexed_param('Parameters.member.%d.ParameterName', parameter_names)) + params.merge!(AWS.indexed_param('Parameters.member.%d.ParameterValue', parameter_values)) + params.merge!(AWS.indexed_param('Parameters.member.%d.ApplyMethod', parameter_apply_methods)) + + request({ + 'Action' => 'ModifyDBParameterGroup', + 'DBParameterGroupName' => group_name, + + :parser => Fog::Parsers::AWS::RDS::ModifyDbParameterGroup.new + }.merge(params)) + end + + end + + class Mock + + def modify_db_parameter_group(group_name, parameters) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/rds/reboot_db_instance.rb b/lib/fog/aws/requests/rds/reboot_db_instance.rb new file mode 100644 index 000000000..7d54b70a8 --- /dev/null +++ b/lib/fog/aws/requests/rds/reboot_db_instance.rb @@ -0,0 +1,34 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/reboot_db_instance' + + # reboots a database instance + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_RebootDBInstance.html + # ==== Parameters + # * DBInstanceIdentifier <~String> - name of the db instance to reboot + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def reboot_db_instance(instance_identifier) + request({ + 'Action' => 'RebootDBInstance', + 'DBInstanceIdentifier' => instance_identifier, + :parser => Fog::Parsers::AWS::RDS::RebootDBInstance.new, + }) + end + + end + + class Mock + + def reboot_db_instance(instance_identifier) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/bin/aws.rb b/lib/fog/bin/aws.rb index aca92ce0e..cd837db79 100644 --- a/lib/fog/bin/aws.rb +++ b/lib/fog/bin/aws.rb @@ -19,6 +19,8 @@ class AWS < Fog::Bin Fog::AWS::SES when :eu_storage, :storage Fog::AWS::Storage + when :rds + Fog::AWS::RDS else # @todo Replace most instances of ArgumentError with NotImplementedError # @todo For a list of widely supported Exceptions, see: @@ -40,6 +42,8 @@ class AWS < Fog::Bin Fog::AWS::ELB.new when :iam Fog::AWS::IAM.new + when :rds + Fog::AWS::RDS.new when :eu_storage Fog::Storage.new(:provider => 'AWS', :region => 'eu-west-1') when :sdb, :simpledb diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index a290c02ed..848ce6f7c 100644 --- a/lib/fog/providers/aws.rb +++ b/lib/fog/providers/aws.rb @@ -14,6 +14,7 @@ module Fog service(:ses, 'aws/ses') service(:simpledb, 'aws/simpledb') service(:storage, 'storage/aws') + service(:rds, 'aws/rds') def self.indexed_param(key, values) params = {} diff --git a/tests/aws/requests/rds/helper.rb b/tests/aws/requests/rds/helper.rb new file mode 100644 index 000000000..2cdd7ca31 --- /dev/null +++ b/tests/aws/requests/rds/helper.rb @@ -0,0 +1,169 @@ +class AWS + + module RDS + + module Formats + + BASIC = { + 'ResponseMetadata' => {'RequestId' => String} + } + + DB_PARAMETER_GROUP = { + 'DBParameterGroupFamily' => String, + 'DBParameterGroupName'=> String, + 'Description'=> String + } + CREATE_DB_PARAMETER_GROUP = { + 'ResponseMetadata' => {'RequestId' => String}, + 'CreateDBParameterGroupResult' => { + 'DBParameterGroup' => DB_PARAMETER_GROUP + } + } + + DESCRIBE_DB_PARAMETER_GROUP = { + 'ResponseMetadata' => {'RequestId' => String}, + 'DescribeDBParameterGroupsResult' =>{ + 'DBParameterGroups' => [DB_PARAMETER_GROUP] + } + } + + MODIFY_PARAMETER_GROUP = BASIC.merge({ + 'ModifyDBParameterGroupResult' => { + 'DBParameterGroupName' => String + } + }) + + DB_PARAMETER = { + 'ParameterValue' => Fog::Nullable::String, + 'DataType' => String, + 'AllowedValues' => Fog::Nullable::String, + 'Source' => String, + 'IsModifiable' => Fog::Boolean, + 'Description' => String, + 'ParameterName' => String, + 'ApplyType' => String, + } + DESCRIBE_DB_PARAMETERS = BASIC.merge({ + 'DescribeDBParametersResult' => { + 'Marker' => Fog::Nullable::String, + 'Parameters' => [DB_PARAMETER] + } + + }) + + + SNAPSHOT={ + 'AllocatedStorage' => Integer, + 'AvailabilityZone' => String, + 'DBInstanceIdentifier' => String, + 'DBSnapshotIdentifier' => String, + 'EngineVersion' => String, + 'Engine' => String, + 'InstanceCreateTime' => Time, + 'MasterUsername' => String, + 'Port' => Integer, + 'SnapshotCreateTime' => Fog::Nullable::Time, + 'Status' => String + } + INSTANCE = { + 'AllocatedStorage' => Integer, + 'AutoMinorVersionUpgrade' => Fog::Boolean, + 'AvailabilityZone' => Fog::Nullable::String, + 'BackupRetentionPeriod' => Integer, + 'DBInstanceClass' => String, + 'DBInstanceIdentifier' => String, + 'DBInstanceStatus' => String, + 'DBName' => Fog::Nullable::String, + 'DBParameterGroups' => [{ + 'ParameterApplyStatus' => String, + 'DBParameterGroupName' => String + }], + 'DBSecurityGroups' => [{ + 'Status' => String, + 'DBSecurityGroupName' => String + }], + 'Endpoint' => { + 'Address' => Fog::Nullable::String, + 'Port' => Fog::Nullable::Integer + }, + 'Engine' => String, + 'EngineVersion' => String, + 'InstanceCreateTime' => Fog::Nullable::Time, + 'LatestRestorableTime' => Fog::Nullable::Time, + 'MasterUsername' => String, + 'MultiAZ' => Fog::Boolean, + 'PendingModifiedValues' => { + 'BackupRetentionPeriod' => Fog::Nullable::Integer, + 'DBInstanceClass' => Fog::Nullable::String, + 'EngineVersion' => Fog::Nullable::String, + 'MasterUserPassword' => Fog::Nullable::String, + 'MultiAZ' => Fog::Nullable::String, + 'AllocatedStorage' => Fog::Nullable::Integer, + 'Port' => Fog::Nullable::Integer + }, + 'PreferredBackupWindow'=> String, + 'PreferredMaintenanceWindow'=> String, + 'ReadReplicaDBInstanceIdentifiers'=> [String], + 'ReadReplicaSourceDBInstanceIdentifier'=> Fog::Nullable::String + } + + CREATE_DB_INSTANCE = BASIC.merge({ + 'CreateDBInstanceResult' => { + 'DBInstance' => INSTANCE + } + }) + + DESCRIBE_DB_INSTANCES = BASIC.merge({ + 'DescribeDBInstancesResult' => { + 'Marker' => Fog::Nullable::String, + 'DBInstances' => [INSTANCE] + } + }) + + MODIFY_DB_INSTANCE = BASIC.merge({ + 'ModifyDBInstanceResult' => { + 'DBInstance' => INSTANCE + } + }) + + DELETE_DB_INSTANCE = BASIC.merge({ + 'DeleteDBInstanceResult' => { + 'DBInstance' => INSTANCE + } + }) + + REBOOT_DB_INSTANCE = BASIC.merge({ + 'RebootDBInstanceResult' => { + 'DBInstance' => INSTANCE + } + }) + + CREATE_READ_REPLICA = BASIC.merge({ + 'CreateDBInstanceReadReplicaResult' => { + 'DBInstance' => INSTANCE + } + }) + + CREATE_DB_SNAPSHOT = BASIC.merge({ + 'CreateDBSnapshotResult' => { + 'DBSnapshot' => SNAPSHOT + } + }) + + DESCRIBE_DB_SNAPSHOTS = BASIC.merge({ + 'DescribeDBSnapshotsResult' => { + 'Marker' => Fog::Nullable::String, + 'DBSnapshots' => [SNAPSHOT] + } + }) + DELETE_DB_SNAPSHOT = BASIC.merge({ + 'DeleteDBSnapshotResult' => { + 'DBSnapshot' => SNAPSHOT + } + }) + + end + + end + +end diff --git a/tests/aws/requests/rds/instance_tests.rb b/tests/aws/requests/rds/instance_tests.rb new file mode 100644 index 000000000..7770b439e --- /dev/null +++ b/tests/aws/requests/rds/instance_tests.rb @@ -0,0 +1,129 @@ +Shindo.tests('AWS::RDS | instance requests', ['aws', 'rds']) do + @db_instance_id='fog-test' + @db_replica_id='fog-replica' + + tests('success') do + pending if Fog.mocking? + + tests("#create_db_instance").formats(AWS::RDS::Formats::CREATE_DB_INSTANCE) do + result = AWS[:rds].create_db_instance(@db_instance_id, 'AllocatedStorage' => 5, + 'DBInstanceClass' => 'db.m1.small', + 'Engine' => 'mysql', + 'EngineVersion' => '5.1.50', + 'MasterUsername' => 'foguser', + 'BackupRetentionPeriod' => 1, + 'MasterUserPassword' => 'fogpassword').body + + instance = result['CreateDBInstanceResult']['DBInstance'] + returns('creating'){ instance['DBInstanceStatus']} + result + end + + tests("#describe_db_instances").formats(AWS::RDS::Formats::DESCRIBE_DB_INSTANCES) do + AWS[:rds].describe_db_instances.body + end + + server = AWS[:rds].servers.get(@db_instance_id) + server.wait_for {ready?} + + + tests("#modify_db_instance with immediate apply").formats(AWS::RDS::Formats::MODIFY_DB_INSTANCE) do + body = AWS[:rds].modify_db_instance( @db_instance_id, true, 'AllocatedStorage'=> 10).body + tests 'pending storage' do + instance = body['ModifyDBInstanceResult']['DBInstance'] + returns(10){instance['PendingModifiedValues']['AllocatedStorage']} + end + body + end + server.wait_for { state == 'modifying'} + server.wait_for { state == 'available'} + + server.reload + tests 'new storage' do + returns(10){ server.allocated_storage} + end + + tests("reboot db instance") do + tests("#reboot").formats(AWS::RDS::Formats::REBOOT_DB_INSTANCE) do + AWS[:rds].reboot_db_instance( @db_instance_id).body + end + + server.wait_for { state == 'rebooting'} + server.wait_for { state == 'available'} + server.reload + end + + + tests("#create_db_snapshot").formats(AWS::RDS::Formats::CREATE_DB_SNAPSHOT) do + body = AWS[:rds].create_db_snapshot(@db_instance_id, 'fog-snapshot').body + returns('creating'){ body['CreateDBSnapshotResult']['DBSnapshot']['Status']} + body + end + + tests("#describe_db_snapshots").formats(AWS::RDS::Formats::DESCRIBE_DB_SNAPSHOTS) do + body = AWS[:rds].describe_db_snapshots().body + end + + Fog.wait_for do + data = AWS[:rds].describe_db_snapshots(:snapshot_id => 'fog-snapshot') + status = data.body['DescribeDBSnapshotsResult']['DBSnapshots'].first['Status'] + status =='available' + end + + tests( "#create read replica").formats(AWS::RDS::Formats::CREATE_READ_REPLICA) do + AWS[:rds].create_db_instance_read_replica(@db_replica_id, @db_instance_id).body + end + + replica = AWS[:rds].servers.get(@db_replica_id) + replica.wait_for {ready?} + + tests("replica source") do + returns(@db_instance_id){replica.read_replica_source} + end + server.reload + + tests("replica identifiers") do + returns([@db_replica_id]){server.read_replica_identifiers} + end + + tests("#delete_db_instance").formats(AWS::RDS::Formats::DELETE_DB_INSTANCE) do + AWS[:rds].delete_db_instance(@db_replica_id, nil, true) + body = AWS[:rds].delete_db_instance(@db_instance_id, 'fog-final-snapshot').body + Fog.wait_for do + AWS[:rds].servers.length == 0 + end + + tests "final snapshot" do + returns('available'){AWS[:rds].describe_db_snapshots(:snapshot_id => 'fog-final-snapshot').body['DescribeDBSnapshotsResult']['DBSnapshots'].first['Status']} + end + body + end + + + + tests("#delete_db_snapshot").formats(AWS::RDS::Formats::DELETE_DB_SNAPSHOT) do + AWS[:rds].delete_db_snapshot('fog-snapshot').body + end + + AWS[:rds].delete_db_snapshot('fog-final-snapshot') + + returns([]){ AWS[:rds].describe_db_snapshots.body['DescribeDBSnapshotsResult']['DBSnapshots']} + + end + + tests('failure') do + pending if Fog.mocking? + + tests "deleting nonexisting instance" do + raises(Fog::AWS::RDS::NotFound) {AWS[:rds].delete_db_instance('doesnexist', 'irrelevant')} + end + tests "deleting non existing snapshot" do + raises(Fog::AWS::RDS::NotFound) {AWS[:rds].delete_db_snapshot('doesntexist')} + end + tests "modifying non existing instance" do + raises(Fog::AWS::RDS::NotFound) { AWS[:rds].modify_db_instance 'doesntexit', true, 'AllocatedStorage'=> 10} + end + end +end + + \ No newline at end of file diff --git a/tests/aws/requests/rds/model_tests.rb b/tests/aws/requests/rds/model_tests.rb new file mode 100644 index 000000000..918104534 --- /dev/null +++ b/tests/aws/requests/rds/model_tests.rb @@ -0,0 +1,98 @@ +Shindo.tests('AWS::RDS | models', ['aws', 'rds']) do + @db_instance_id='fog-test' + @db_replica_id='fog-replica' + + tests('success') do + pending if Fog.mocking? + + tests('parametergroups') do + group = nil + + tests('create') do + group = AWS[:rds].parameter_groups.create :id => 'testgroup', :family => 'mysql5.1', :description => 'test' + end + + tests('#parameters') do + parameters = group.parameters + #search for a sample parameter + tests 'contains parameter' do + returns(true){ !!parameters.detect {|p| p.name == 'query_cache_size'}} + end + end + + tests('modify') do + group.modify([{:name => 'query_cache_size', :value => '6553600', :apply_method => 'immediate'}]) + + tests 'parameter has changed' do + returns('6553600'){group.parameters.detect {|p| p.name == 'query_cache_size'}.value} + end + end + + tests('destroy').succeeds do + group.destroy + end + + returns(nil){AWS[:rds].parameter_groups.detect {|g| g.id == 'testgroup'}} + end + + tests('servers') do + server = nil + tests('create').succeeds do + server = AWS[:rds].servers.create( :id => @db_instance_id, :allocated_storage => 5, :engine => 'mysql', + :master_username => 'foguser', :password => 'fogpassword', + :backup_retention_period => 0) + end + + server.wait_for {ready?} + + tests('snapshots') do + snapshot = nil + + tests('create').succeeds do + snapshot = server.snapshots.create(:id => 'testsnapshot') + end + + returns(@db_instance_id){snapshot.instance_id} + server.reload + server.wait_for {ready?} + snapshot.wait_for {ready?} + tests('all') do + returns(['testsnapshot']){server.snapshots.collect {|s| s.id}} + end + + tests('destroy').succeeds do + snapshot.destroy + end + + returns([]) {server.snapshots} + end + + group = AWS[:rds].parameter_groups.create :id => 'some-group', :family => 'mysql5.1', :description => 'test' + tests('modify') do + server.modify(true, 'DBParameterGroupName' => 'some-group') + server.reload + returns('some-group'){server.db_parameter_groups.first['DBParameterGroupName']} + end + + tests('reboot').succeeds do + server.reboot + end + server.wait_for {state == 'rebooting'} + server.wait_for {state == 'available'} + + tests('destroy').succeeds do + server.destroy('finalsnapshot') + end + + Fog.wait_for do + AWS[:rds].servers.length == 0 + end + + group.destroy + + tests("final snapshot was created") do + AWS[:rds].snapshots.get('finalsnapshot').destroy + end + end + end +end \ No newline at end of file diff --git a/tests/aws/requests/rds/parameter_group_tests.rb b/tests/aws/requests/rds/parameter_group_tests.rb new file mode 100644 index 000000000..04d60f09f --- /dev/null +++ b/tests/aws/requests/rds/parameter_group_tests.rb @@ -0,0 +1,67 @@ +Shindo.tests('AWS::RDS | parameter group requests', ['aws', 'rds']) do + tests('success') do + + tests("#create_db_parameter_groups").formats(AWS::RDS::Formats::CREATE_DB_PARAMETER_GROUP) do + pending if Fog.mocking? + body = AWS[:rds].create_db_parameter_group('fog-group', 'MySQL5.1', 'Some description').body + + returns( 'mysql5.1') { body['CreateDBParameterGroupResult']['DBParameterGroup']['DBParameterGroupFamily']} + returns( 'fog-group') { body['CreateDBParameterGroupResult']['DBParameterGroup']['DBParameterGroupName']} + returns( 'Some description') { body['CreateDBParameterGroupResult']['DBParameterGroup']['Description']} + + body + end + + AWS[:rds].create_db_parameter_group('other-fog-group', 'MySQL5.1', 'Some description') + + tests("#describe_db_parameter_groups").formats(AWS::RDS::Formats::DESCRIBE_DB_PARAMETER_GROUP) do + pending if Fog.mocking? + + body = AWS[:rds].describe_db_parameter_groups().body + + returns(3) {body['DescribeDBParameterGroupsResult']['DBParameterGroups'].length} + body + end + + tests("#describe_db_parameter_groups('fog-group)").formats(AWS::RDS::Formats::DESCRIBE_DB_PARAMETER_GROUP) do + pending if Fog.mocking? + + body = AWS[:rds].describe_db_parameter_groups('fog-group').body + + returns(1) {body['DescribeDBParameterGroupsResult']['DBParameterGroups'].length} + + group = body['DescribeDBParameterGroupsResult']['DBParameterGroups'].first + returns( 'mysql5.1') { group['DBParameterGroupFamily']} + returns( 'fog-group') { group['DBParameterGroupName']} + returns( 'Some description') { group['Description']} + + body + end + + tests("delete_db_parameter_group").formats(AWS::RDS::Formats::BASIC) do + pending if Fog.mocking? + body = AWS[:rds].delete_db_parameter_group('fog-group').body + + raises(Fog::AWS::RDS::NotFound) {AWS[:rds].describe_db_parameter_groups('fog-group')} + + body + end + + AWS[:rds].delete_db_parameter_group('other-fog-group') + end + + tests("failures") do + pending if Fog.mocking? + raises(Fog::AWS::RDS::NotFound) {AWS[:rds].describe_db_parameter_groups('doesntexist')} + raises(Fog::AWS::RDS::NotFound) {AWS[:rds].delete_db_parameter_group('doesntexist')} + + tests "creating second group with same id" do + AWS[:rds].create_db_parameter_group('fog-group', 'MySQL5.1', 'Some description') + raises(Fog::AWS::RDS::IdentifierTaken) {AWS[:rds].create_db_parameter_group('fog-group', 'MySQL5.1', 'Some description')} + end + + AWS[:rds].delete_db_parameter_group('fog-group') + + end + +end \ No newline at end of file diff --git a/tests/aws/requests/rds/parameter_request_tests.rb b/tests/aws/requests/rds/parameter_request_tests.rb new file mode 100644 index 000000000..720ef535d --- /dev/null +++ b/tests/aws/requests/rds/parameter_request_tests.rb @@ -0,0 +1,35 @@ +Shindo.tests('AWS::RDS | parameter requests', ['aws', 'rds']) do + tests('success') do + pending if Fog.mocking? + + AWS[:rds].create_db_parameter_group('fog-group', 'MySQL5.1', 'Some description') + + tests('#modify_db_parameter_group').formats(AWS::RDS::Formats::MODIFY_PARAMETER_GROUP) do + body = AWS[:rds].modify_db_parameter_group('fog-group',[ + {'ParameterName' => 'query_cache_size', + 'ParameterValue' => '12345', + 'ApplyMethod' => 'immediate'} + ]).body + + body + end + + tests('#describe_db_parameters').formats(AWS::RDS::Formats::DESCRIBE_DB_PARAMETERS) do + AWS[:rds].describe_db_parameters('fog-group', :max_records => 20).body + end + + + tests("#describe_db_parameters :source => 'user'")do + body = AWS[:rds].describe_db_parameters('fog-group', :source => 'user').body + returns(1){ body['DescribeDBParametersResult']['Parameters'].length} + + param = body['DescribeDBParametersResult']['Parameters'].first + returns('query_cache_size'){param['ParameterName']} + returns('12345'){param['ParameterValue']} + returns(true){param['IsModifiable']} + returns('query_cache_size'){param['ParameterName']} + end + AWS[:rds].delete_db_parameter_group('fog-group') + + end +end