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] with session.begin(subtransactions=True): try: LOG.debug("Reserving flat network on physical " "network %s", physical_network) alloc = FlatAllocation(physical_network=physical_network) alloc.save(session) except db_exc.DBDuplicateEntry: raise exc.FlatNetworkInUse(physical_network=physical_network) return segment
def reserve_provider_segment(self, context, segment): physical_network = segment[api.PHYSICAL_NETWORK] try: LOG.debug("Reserving flat network on physical " "network %s", physical_network) alloc = flat_obj.FlatAllocation(context, physical_network=physical_network) alloc.create() except obj_base.NeutronDbObjectDuplicateEntry: raise n_exc.FlatNetworkInUse(physical_network=physical_network) segment[api.MTU] = self.get_mtu(alloc.physical_network) return segment
def reserve_provider_segment(self, session, segment): physical_network = segment[api.PHYSICAL_NETWORK] with session.begin(subtransactions=True): try: alloc = (session.query(FlatAllocation).filter_by( physical_network=physical_network).with_lockmode( 'update').one()) raise exc.FlatNetworkInUse(physical_network=physical_network) except sa.orm.exc.NoResultFound: LOG.debug( _("Reserving flat network on physical " "network %s"), physical_network) alloc = FlatAllocation(physical_network=physical_network) session.add(alloc)
def reserve_provider_segment(self, context, segment): physical_network = segment[api.PHYSICAL_NETWORK] with context.session.begin(subtransactions=True): try: LOG.debug("Reserving flat network on physical " "network %s", physical_network) alloc = type_flat_model.FlatAllocation( physical_network=physical_network) alloc.save(context.session) except db_exc.DBDuplicateEntry: raise n_exc.FlatNetworkInUse( physical_network=physical_network) segment[api.MTU] = self.get_mtu(alloc.physical_network) return segment
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_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