#NEWLINE# @ contextlib . contextmanager #NEWLINE# def router_with_ext_gw( self , name = 'router1' , admin_state_up = True , fmt = None , tenant_id = str ( uuid . uuid4 ( ) ) , external_gateway_info = None , subnet = None , set_context = False , **kwargs ) : #NEWLINE# #INDENT# router = self . _make_router ( ( fmt or self . fmt ) , tenant_id , name , admin_state_up , external_gateway_info , set_context , ** kwargs ) #NEWLINE# self . _add_external_gateway_to_router ( router [ 'router' ] [ 'id' ] , subnet [ 'subnet' ] [ 'network_id' ] ) #NEWLINE# ( yield router ) #NEWLINE# self . _remove_external_gateway_from_router ( router [ 'router' ] [ 'id' ] , subnet [ 'subnet' ] [ 'network_id' ] ) #NEWLINE# self . _delete ( 'routers' , router [ 'router' ] [ 'id' ] )