def sync_allocations(self):
<EOL>vxlan_vnis = set()<EOL>for tun_min, tun_max in self.tunnel_ranges:<EOL><INDENT>vxlan_vnis |= set(six.moves.range(tun_min, tun_max + <NUM_LIT:1>))<EOL><DEDENT>session = bc.get_writer_session()<EOL>with session.begin(subtransactions=True):<EOL><INDENT>allocs = (session.query(nexus_models_v2.NexusVxlanAllocation).<EOL>with_lockmode("<STR_LIT>").all())<EOL>existing_vnis = set(alloc.vxlan_vni for alloc in allocs)<EOL>vnis_to_remove = [alloc.vxlan_vni for alloc in allocs<EOL>if (alloc.vxlan_vni not in vxlan_vnis and<EOL>not alloc.allocated)]<EOL>bulk_size = <NUM_LIT:100><EOL>chunked_vnis = (vnis_to_remove[i:i + bulk_size] for i in<EOL>range(<NUM_LIT:0>, len(vnis_to_remove), bulk_size))<EOL>for vni_list in chunked_vnis:<EOL><INDENT>session.query(nexus_models_v2.NexusVxlanAllocation).filter(<EOL>nexus_models_v2.NexusVxlanAllocation.<EOL>vxlan_vni.in_(vni_list)).delete(<EOL>synchronize_session=False)<EOL><DEDENT>vnis = list(vxlan_vnis - existing_vnis)<EOL>chunked_vnis = (vnis[i:i + bulk_size] for i in<EOL>range(<NUM_LIT:0>, len(vnis), bulk_size))<EOL>for vni_list in chunked_vnis:<EOL><INDENT>bulk = [{'<STR_LIT>': vni, '<STR_LIT>': False}<EOL>for vni in vni_list]<EOL>session.execute(nexus_models_v2.NexusVxlanAllocation.<EOL>__table__.insert(), bulk)<EOL><DEDENT><DEDENT>
Synchronize vxlan_allocations table with configured tunnel ranges.