'Delete gw port if attached to an old network.'

def _delete_current_gw_port(self, context, router_id, router, new_network_id):

    port_requires_deletion = (router.gw_port and (router.gw_port['network_id'] != new_network_id))
    if (not port_requires_deletion):
        return
    admin_ctx = context.elevated()
    old_network_id = router.gw_port['network_id']
    if self.router_gw_port_has_floating_ips(admin_ctx, router_id):
        raise l3.RouterExternalGatewayInUseByFloatingIp(router_id=router_id, net_id=router.gw_port['network_id'])
    gw_ips = [x['ip_address'] for x in router.gw_port['fixed_ips']]
    gw_port_id = router.gw_port['id']
    self._delete_router_gw_port_db(context, router)
    self._core_plugin.delete_port(admin_ctx, gw_port_id, l3_port_check=False)
    registry.notify(resources.ROUTER_GATEWAY, events.AFTER_DELETE, self, router_id=router_id, context=context, router=router, network_id=old_network_id, new_network_id=new_network_id, gateway_ips=gw_ips)
