<s> from ec2api . api import common <EOL> from ec2api . api import ec2utils <EOL> from ec2api . db import api as db_api <EOL> from ec2api import exception <EOL> from ec2api . i18n import _ <EOL> """<STR_LIT>""" <EOL> Validator = common . Validator <EOL> DEFAULT_BGP_ASN = <NUM_LIT> <EOL> def create_customer_gateway ( context , ip_address , type , bgp_asn = None ) : <EOL> if bgp_asn and bgp_asn != DEFAULT_BGP_ASN : <EOL> raise exception . Unsupported ( "<STR_LIT>" ) <EOL> customer_gateway = next ( ( cgw for cgw in db_api . get_items ( context , '<STR_LIT>' ) <EOL> if cgw [ '<STR_LIT>' ] == ip_address ) , None ) <EOL> if not customer_gateway : <EOL> customer_gateway = db_api . add_item ( context , '<STR_LIT>' , <EOL> { '<STR_LIT>' : ip_address } ) <EOL> return { '<STR_LIT>' : _format_customer_gateway ( customer_gateway ) } <EOL> def delete_customer_gateway ( context , customer_gateway_id ) : <EOL> customer_gateway = ec2utils . get_db_item ( context , customer_gateway_id ) <EOL> vpn_connections = db_api . get_items ( context , '<STR_LIT>' ) <EOL> if any ( vpn [ '<STR_LIT>' ] == customer_gateway [ '<STR_LIT:id>' ] <EOL> for vpn in vpn_connections ) : <EOL> raise exception . IncorrectState ( <EOL> reason = _ ( '<STR_LIT>' ) ) <EOL> db_api . delete_item ( context , customer_gateway [ '<STR_LIT:id>' ] ) <EOL> return True <EOL> def describe_customer_gateways ( context , customer_gateway_id = None , <EOL> filter = None ) : <EOL> formatted_cgws = CustomerGatewayDescriber ( ) . describe ( <EOL> context , ids = customer_gateway_id , filter = filter ) <EOL> return { '<STR_LIT>' : formatted_cgws } <EOL> class CustomerGatewayDescriber ( common . TaggableItemsDescriber , <EOL> common . NonOpenstackItemsDescriber ) : <EOL> KIND = '<STR_LIT>' <EOL> FILTER_MAP = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:state>' : '<STR_LIT:state>' , <EOL> '<STR_LIT:type>' : '<STR_LIT:type>' } <EOL> def format ( self , customer_gateway ) : <EOL> return _format_customer_gateway ( customer_gateway ) <EOL> def _format_customer_gateway ( customer_gateway ) : <EOL> return { '<STR_LIT>' : customer_gateway [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : customer_gateway [ '<STR_LIT>' ] , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : DEFAULT_BGP_ASN } </s>
