def sync_tunnel_allocations(tunnel_id_ranges):
 tunnel_ids = set()
 for tunnel_id_range in tunnel_id_ranges:
  (tun_min, tun_max) = tunnel_id_range
  if (((tun_max + 1) - tun_min) > 1000000):
   LOG.error(_('Skipping unreasonable tunnel ID range %(tun_min)s:%(tun_max)s'), locals())
  else:
   tunnel_ids |= set(xrange(tun_min, (tun_max + 1)))
 session = db.get_session()
 with session.begin():
  allocs = session.query(ovs_models_v2.TunnelAllocation).all()
  for alloc in allocs:
   try:
    tunnel_ids.remove(alloc.tunnel_id)
   except KeyError:
    if (not alloc.allocated):
     LOG.debug(_('Removing tunnel %s from pool'), alloc.tunnel_id)
     session.delete(alloc)
  for tunnel_id in sorted(tunnel_ids):
   alloc = ovs_models_v2.TunnelAllocation(tunnel_id)
   session.add(alloc)

def sync_tunnel_allocations ( tunnel_id_ranges ) : tunnel_ids = set ( ) for tunnel_id_range in tunnel_id_ranges : ( tun_min , tun_max ) = tunnel_id_range if ( ( ( tun_max + 1 ) - tun_min ) > 1000000 ) : LOG . error ( _ ( 'Skipping unreasonable tunnel ID range %(tun_min)s:%(tun_max)s' ) , locals ( ) ) else : tunnel_ids |= set ( xrange ( tun_min , ( tun_max + 1 ) ) ) session = db . get_session ( ) with session . begin ( ) : allocs = session . query ( ovs_models_v2 . TunnelAllocation ) . all ( ) for alloc in allocs : try : tunnel_ids . remove ( alloc . tunnel_id ) except KeyError : if ( not alloc . allocated ) : LOG . debug ( _ ( 'Removing tunnel %s from pool' ) , alloc . tunnel_id ) session . delete ( alloc ) for tunnel_id in sorted ( tunnel_ids ) : alloc = ovs_models_v2 . TunnelAllocation ( tunnel_id ) session . add ( alloc )
synchronize tunnel_allocations table with configured tunnel ranges .