Detach virtual private gateway support

This commit is contained in:
Tyler Sanders 2014-12-02 10:40:05 -06:00
parent 166fd69515
commit db7757347a
3 changed files with 51 additions and 2 deletions

View File

@ -2494,6 +2494,14 @@ class VpnGatewayBackend(object):
raise InvalidVpnGatewayIdError(vpn_gateway_id)
return deleted
def detach_vpn_gateway(self, vpn_gateway_id, vpc_id):
vpn_gateway = self.get_vpn_gateway(vpn_gateway_id)
self.get_vpc(vpc_id)
detached = vpn_gateway.attachments.pop(vpc_id, None)
if not detached:
raise InvalidVPCIdError(vpc_id)
return detached
class EC2Backend(BaseBackend, InstanceBackend, TagBackend, AmiBackend,
RegionsAndZonesBackend, SecurityGroupBackend, EBSBackend,

View File

@ -34,8 +34,14 @@ class VirtualPrivateGateways(BaseResponse):
return template.render(vpn_gateways=vpn_gateways)
def detach_vpn_gateway(self):
raise NotImplementedError('VirtualPrivateGateways(AmazonVPC).detach_vpn_gateway is not yet implemented')
vpn_gateway_id = self.querystring.get('VpnGatewayId')[0]
vpc_id = self.querystring.get('VpcId')[0]
attachment = self.ec2_backend.detach_vpn_gateway(
vpn_gateway_id,
vpc_id
)
template = Template(DETACH_VPN_GATEWAY_RESPONSE)
return template.render(attachment=attachment)
CREATE_VPN_GATEWAY_RESPONSE = """
<CreateVpnGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2014-10-01/">
@ -107,4 +113,11 @@ DELETE_VPN_GATEWAY_RESPONSE = """
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
<return>true</return>
</DeleteVpnGatewayResponse>
"""
DETACH_VPN_GATEWAY_RESPONSE = """
<DetachVpnGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2014-10-01/">
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
<return>true</return>
</DetachVpnGatewayResponse>
"""

View File

@ -74,3 +74,31 @@ def test_vpn_gateway_tagging():
vpn_gateway = conn.get_all_vpn_gateways()[0]
vpn_gateway.tags.should.have.length_of(1)
vpn_gateway.tags["a key"].should.equal("some value")
@mock_ec2
def test_detach_vpn_gateway():
conn = boto.connect_vpc('the_key', 'the_secret')
vpc = conn.create_vpc("10.0.0.0/16")
vpn_gateway = conn.create_vpn_gateway('ipsec.1', 'us-east-1a')
conn.attach_vpn_gateway(
vpn_gateway_id=vpn_gateway.id,
vpc_id=vpc.id
)
gateway = conn.get_all_vpn_gateways()[0]
attachments = gateway.attachments
attachments.should.have.length_of(1)
attachments[0].vpc_id.should.equal(vpc.id)
attachments[0].state.should.equal('attached')
conn.detach_vpn_gateway(
vpn_gateway_id=vpn_gateway.id,
vpc_id=vpc.id
)
gateway = conn.get_all_vpn_gateways()[0]
attachments = gateway.attachments
attachments.should.have.length_of(0)