def reserve_provider_segment(self, session, segment): filters = {} physical_network = segment.get(api.PHYSICAL_NETWORK) if physical_network is not None: filters['physical_network'] = physical_network vlan_id = segment.get(api.SEGMENTATION_ID) if vlan_id is not None: filters['vlan_id'] = vlan_id if self.is_partial_segment(segment): alloc = self.allocate_partially_specified_segment( session, **filters) if not alloc: raise exc.NoNetworkAvailable() else: alloc = self.allocate_fully_specified_segment(session, **filters) if not alloc: raise exc.VlanIdInUse(**filters) return { api.NETWORK_TYPE: p_const.TYPE_VLAN, api.PHYSICAL_NETWORK: alloc.physical_network, api.SEGMENTATION_ID: alloc.vlan_id, api.MTU: self.get_mtu(alloc.physical_network) }
def reserve_specific_vlan(session, physical_network, vlan_id): with session.begin(subtransactions=True): try: alloc = (session.query(ovs_models_v2.VlanAllocation).filter_by( physical_network=physical_network, vlan_id=vlan_id).with_lockmode('update').one()) if alloc.allocated: if vlan_id == constants.FLAT_VLAN_ID: raise q_exc.FlatNetworkInUse( physical_network=physical_network) else: raise q_exc.VlanIdInUse(vlan_id=vlan_id, physical_network=physical_network) LOG.debug( _("Reserving specific vlan %(vlan_id)s on physical " "network %(physical_network)s from pool"), { 'vlan_id': vlan_id, 'physical_network': physical_network }) alloc.allocated = True except exc.NoResultFound: LOG.debug( _("Reserving specific vlan %(vlan_id)s on physical " "network %(physical_network)s outside pool"), { 'vlan_id': vlan_id, 'physical_network': physical_network }) alloc = ovs_models_v2.VlanAllocation(physical_network, vlan_id) alloc.allocated = True session.add(alloc)
def reserve_provider_segment(self, session, segment): physical_network = segment[api.PHYSICAL_NETWORK] vlan_id = segment[api.SEGMENTATION_ID] with session.begin(subtransactions=True): try: alloc = (session.query(VlanAllocation).filter_by( physical_network=physical_network, vlan_id=vlan_id).with_lockmode('update').one()) if alloc.allocated: raise exc.VlanIdInUse(vlan_id=vlan_id, physical_network=physical_network) LOG.debug( _("Reserving specific vlan %(vlan_id)s on physical " "network %(physical_network)s from pool"), { 'vlan_id': vlan_id, 'physical_network': physical_network }) alloc.allocated = True except sa.orm.exc.NoResultFound: LOG.debug( _("Reserving specific vlan %(vlan_id)s on physical " "network %(physical_network)s outside pool"), { 'vlan_id': vlan_id, 'physical_network': physical_network }) alloc = VlanAllocation(physical_network=physical_network, vlan_id=vlan_id, allocated=True) session.add(alloc)
def reserve_specific_vlan(self, session, physical_network, vlan_id): with session.begin(subtransactions=True): try: alloc_q = session.query(hyperv_model.VlanAllocation) alloc_q = alloc_q.filter_by(physical_network=physical_network, vlan_id=vlan_id) alloc = alloc_q.one() if alloc.allocated: if vlan_id == constants.FLAT_VLAN_ID: raise n_exc.FlatNetworkInUse( physical_network=physical_network) else: raise n_exc.VlanIdInUse( vlan_id=vlan_id, physical_network=physical_network) LOG.debug( _("Reserving specific vlan %(vlan_id)s on physical " "network %(physical_network)s from pool"), { 'vlan_id': vlan_id, 'physical_network': physical_network }) alloc.allocated = True except exc.NoResultFound: raise n_exc.NoNetworkAvailable()
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 reserve_specific_vlan(db_session, physical_network, vlan_id): """ Reserve a specific VLAN ID for the network. :param db_session: database session :param physical_network: string representing the name of physical network :param vlan_id: integer value of the segmentation ID to be reserved """ with db_session.begin(subtransactions=True): try: alloc = (db_session.query( n1kv_models_v2.N1kvVlanAllocation).filter_by( physical_network=physical_network, vlan_id=vlan_id).one()) if alloc.allocated: if vlan_id == c_const.FLAT_VLAN_ID: raise q_exc.FlatNetworkInUse( physical_network=physical_network) else: raise q_exc.VlanIdInUse(vlan_id=vlan_id, physical_network=physical_network) LOG.debug( _("Reserving specific vlan %(vlan)s on physical " "network %(network)s from pool"), { "vlan": vlan_id, "network": physical_network }) except exc.NoResultFound: LOG.debug( _("Reserving specific vlan %(vlan)s on physical " "network %(network)s outside pool"), { "vlan": vlan_id, "network": physical_network }) alloc = n1kv_models_v2.N1kvVlanAllocation( physical_network=physical_network, vlan_id=vlan_id) db_session.add(alloc) alloc.allocated = True