1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[AWS|RDS] Support for creating and removing subnet groups.

This commit is contained in:
Akshay Joshi 2013-12-02 01:08:21 -05:00
parent 8a4c909211
commit 21e2c64597
6 changed files with 102 additions and 3 deletions

View file

@ -12,7 +12,18 @@ module Fog
attribute :vpc_id, :aliases => 'VpcId' attribute :vpc_id, :aliases => 'VpcId'
attribute :subnet_ids, :aliases => 'Subnets' attribute :subnet_ids, :aliases => 'Subnets'
# TODO: ready?, save, destroy # TODO: ready?
#
def save
requires :description, :id, :subnet_ids
service.create_db_subnet_group(id, subnet_ids, description)
reload
end
def destroy
requires :id
service.delete_db_subnet_group(id)
end
end end
end end

View file

@ -0,0 +1,35 @@
module Fog
module Parsers
module AWS
module RDS
require 'fog/aws/parsers/rds/subnet_group_parser'
class DeleteDBSubnetGroup < Fog::Parsers::AWS::RDS::SubnetGroupParser
def reset
@response = { 'DeleteDBSubnetGroupResponse' => {}, 'ResponseMetadata' => {} }
super
end
def start_element(name, attrs = [])
super
end
def end_element(name)
case name
when 'RequestId'
@response['ResponseMetadata'][name] = value
else
super
end
end
end
end
end
end
end

View file

@ -49,7 +49,8 @@ module Fog
request :create_db_subnet_group request :create_db_subnet_group
request :describe_db_subnet_groups request :describe_db_subnet_groups
# TODO: :delete_db_subnet_group, :modify_db_subnet_group request :delete_db_subnet_group
# TODO: :modify_db_subnet_group
request :describe_orderable_db_instance_options request :describe_orderable_db_instance_options

View file

@ -33,7 +33,13 @@ module Fog
raise Fog::AWS::RDS::IdentifierTaken.new("DBSubnetGroupAlreadyExists => The subnet group '#{name}' already exists") raise Fog::AWS::RDS::IdentifierTaken.new("DBSubnetGroupAlreadyExists => The subnet group '#{name}' already exists")
end end
subnets = subnet_ids.map { |snid| Fog::Compute[:aws].subnets.get(snid) } # collection = Fog::Compute::AWS.new(:aws_access_key_id => 'mock key', :aws_secret_access_key => 'mock secret')
collection = Fog::Compute[:aws]
subnets = subnet_ids.map do |snid|
subnet = collection.subnets.get(snid)
raise Fog::AWS::RDS::NotFound.new("InvalidSubnet => The subnet '#{snid}' was not found") if subnet.nil?
subnet
end
vpc_id = subnets.first.vpc_id vpc_id = subnets.first.vpc_id
data = { data = {

View file

@ -0,0 +1,42 @@
module Fog
module AWS
class RDS
class Real
require 'fog/aws/parsers/rds/delete_db_subnet_group'
# Deletes a db subnet group
# http://docs.aws.amazon.com/AmazonRDS/2013-09-09/APIReference/API_DeleteDBSubnetGroup.html
# ==== Parameters
# * DBSubnetGroupName <~String> - The name for the DB Subnet Group. This value is stored as a lowercase string. Must contain no more than 255 alphanumeric characters or hyphens. Must not be "Default".
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
def delete_db_subnet_group(name)
params = { 'Action' => 'DeleteDBSubnetGroup',
'DBSubnetGroupName' => name,
:parser => Fog::Parsers::AWS::RDS::DeleteDBSubnetGroup.new }
request(params)
end
end
class Mock
def delete_db_subnet_group(name)
response = Excon::Response.new
unless self.data[:subnet_groups] && self.data[:subnet_groups][name]
raise Fog::AWS::RDS::NotFound.new("DBSubnetGroupNotFound => The subnet group '#{name}' doesn't exists")
end
response.body = {
'ResponseMetadata'=>{ 'RequestId'=> Fog::AWS::Mock.request_id },
'return' => true,
}
response
end
end
end
end
end

View file

@ -38,6 +38,10 @@ Shindo.tests('AWS::RDS | subnet group requests', ['aws', 'rds']) do
Fog::AWS[:rds].describe_db_subnet_groups.body Fog::AWS[:rds].describe_db_subnet_groups.body
end end
tests("#delete_db_subnet_group").formats(AWS::RDS::Formats::BASIC) do
Fog::AWS[:rds].delete_db_subnet_group(@subnet_group_name).body
end
end end
@subnets.each do |sn| @subnets.each do |sn|