def reserve_specific_network(session, physical_network, segmentation_id): with session.begin(subtransactions=True): log_args = {'seg_id': segmentation_id, 'phy_net': physical_network} try: entry = (session.query(mlnx_models_v2.SegmentationIdAllocation). filter_by(physical_network=physical_network, segmentation_id=segmentation_id). with_lockmode('update').one()) if entry.allocated: raise n_exc.VlanIdInUse(vlan_id=segmentation_id, physical_network=physical_network) LOG.debug(_("Reserving specific vlan %(seg_id)s " "on physical network %(phy_net)s from pool"), log_args) entry.allocated = True except exc.NoResultFound: LOG.debug(_("Reserving specific vlan %(seg_id)s on " "physical network %(phy_net)s outside pool"), log_args) entry = mlnx_models_v2.SegmentationIdAllocation(physical_network, segmentation_id) entry.allocated = True session.add(entry)
def _add_missing_allocatable_vlans(session, physical_network, vlan_ids): for vlan_id in sorted(vlan_ids): entry = mlnx_models_v2.SegmentationIdAllocation( physical_network, vlan_id) session.add(entry)