Ejemplo n.º 1
0
 def allocate_tenant_segment(self, session):
     for network_type in self.tenant_network_types:
         driver = self.drivers.get(network_type)
         segment = driver.obj.allocate_tenant_segment(session)
         if segment:
             return segment
     raise exc.NoNetworkAvailable()
Ejemplo n.º 2
0
    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)
        }
Ejemplo n.º 3
0
def reserve_tunnel(session):
    with session.begin(subtransactions=True):
        alloc = (session.query(ovs_models_v2.TunnelAllocation).filter_by(
            allocated=False).with_lockmode('update').first())
        if alloc:
            LOG.debug(_("Reserving tunnel %s from pool"), alloc.tunnel_id)
            alloc.allocated = True
            return alloc.tunnel_id
    raise q_exc.NoNetworkAvailable()
Ejemplo n.º 4
0
 def reserve_vlan(self, session):
     with session.begin(subtransactions=True):
         alloc = (session.query(OmniVlanAllocation).
                  filter_by(allocated=False).
                  first())
         if alloc:
             LOG.debug("reserving vlan %s on physical network %s from pool" %
                       (alloc.vlan_id, alloc.physical_network))
             alloc.allocated = True
             return (alloc.physical_network, alloc.vlan_id)
     raise q_exc.NoNetworkAvailable()
Ejemplo n.º 5
0
Archivo: db.py Proyecto: pjh03/quantum
 def reserve_flat_net(self, session):
     with session.begin(subtransactions=True):
         alloc_q = session.query(hyperv_model.VlanAllocation)
         alloc_q = alloc_q.filter_by(allocated=False,
                                     vlan_id=constants.FLAT_VLAN_ID)
         alloc = alloc_q.first()
         if alloc:
             LOG.debug(_("Reserving flat physical network "
                         "%(physical_network)s from pool"),
                       {'physical_network': alloc.physical_network})
             alloc.allocated = True
             return alloc.physical_network
     raise n_exc.NoNetworkAvailable()
Ejemplo n.º 6
0
Archivo: db.py Proyecto: pjh03/quantum
 def reserve_vlan(self, session):
     with session.begin(subtransactions=True):
         alloc_q = session.query(hyperv_model.VlanAllocation)
         alloc_q = alloc_q.filter_by(allocated=False)
         alloc = alloc_q.first()
         if alloc:
             LOG.debug(_("Reserving vlan %(vlan_id)s on physical network "
                         "%(physical_network)s from pool"),
                       {'vlan_id': alloc.vlan_id,
                        'physical_network': alloc.physical_network})
             alloc.allocated = True
             return (alloc.physical_network, alloc.vlan_id)
     raise n_exc.NoNetworkAvailable()
Ejemplo n.º 7
0
def reserve_network(session):
    with session.begin(subtransactions=True):
        entry = (session.query(mlnx_models_v2.SegmentationIdAllocation).
                 filter_by(allocated=False).
                 first())
        if not entry:
            raise q_exc.NoNetworkAvailable()
        LOG.debug(_("Reserving vlan %(seg_id)s on physical network "
                    "%(net)s from pool"),
                  {'seg_id': entry.segmentation_id,
                   'net': entry.physical_network})
        entry.allocated = True
        return (entry.physical_network, entry.segmentation_id)
Ejemplo n.º 8
0
def reserve_vlan(session):
    with session.begin(subtransactions=True):
        alloc = (session.query(ovs_models_v2.VlanAllocation).filter_by(
            allocated=False).with_lockmode('update').first())
        if alloc:
            LOG.debug(
                _("Reserving vlan %(vlan_id)s on physical network "
                  "%(physical_network)s from pool"), {
                      'vlan_id': alloc.vlan_id,
                      'physical_network': alloc.physical_network
                  })
            alloc.allocated = True
            return (alloc.physical_network, alloc.vlan_id)
    raise q_exc.NoNetworkAvailable()
Ejemplo n.º 9
0
def reserve_network(session):
    with session.begin(subtransactions=True):
        state = (session.query(l2network_models_v2.NetworkState).filter_by(
            allocated=False).with_lockmode('update').first())
        if not state:
            raise n_exc.NoNetworkAvailable()
        LOG.debug(
            _("Reserving vlan %(vlan_id)s on physical network "
              "%(physical_network)s from pool"), {
                  'vlan_id': state.vlan_id,
                  'physical_network': state.physical_network
              })
        state.allocated = True
    return (state.physical_network, state.vlan_id)
Ejemplo n.º 10
0
 def reserve_provider_segment(self, session, segment):
     if self.is_partial_segment(segment):
         alloc = self.allocate_partially_specified_segment(session)
         if not alloc:
             raise exc.NoNetworkAvailable()
     else:
         segmentation_id = segment.get(api.SEGMENTATION_ID)
         alloc = self.allocate_fully_specified_segment(
             session, **{self.segmentation_key: segmentation_id})
         if not alloc:
             raise exc.TunnelIdInUse(tunnel_id=segmentation_id)
     return {api.NETWORK_TYPE: self.get_type(),
             api.PHYSICAL_NETWORK: None,
             api.SEGMENTATION_ID: getattr(alloc, self.segmentation_key)}
Ejemplo n.º 11
0
def reserve_vlan(db_session, network_profile):
    """
    Reserve a VLAN ID within the range of the network profile.

    :param db_session: database session
    :param network_profile: network profile object
    """
    seg_min, seg_max = get_segment_range(network_profile)
    segment_type = c_const.NETWORK_TYPE_VLAN

    with db_session.begin(subtransactions=True):
        alloc = (db_session.query(n1kv_models_v2.N1kvVlanAllocation).filter(
            and_(n1kv_models_v2.N1kvVlanAllocation.vlan_id >= seg_min,
                 n1kv_models_v2.N1kvVlanAllocation.vlan_id <= seg_max,
                 n1kv_models_v2.N1kvVlanAllocation.allocated == False))
                 ).first()
        if alloc:
            segment_id = alloc.vlan_id
            physical_network = alloc.physical_network
            alloc.allocated = True
            return (physical_network, segment_type, segment_id, "0.0.0.0")
        raise q_exc.NoNetworkAvailable()
Ejemplo n.º 12
0
 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()
Ejemplo n.º 13
0
 def _allocate_ext_net_segment(self, session):
     network_type = cfg.CONF.ml2.external_network_type
     segment = self._allocate_segment(session, network_type)
     if segment:
         return segment
     raise exc.NoNetworkAvailable()
Ejemplo n.º 14
0
 def _allocate_tenant_net_segment(self, session):
     for network_type in self.tenant_network_types:
         segment = self._allocate_segment(session, network_type)
         if segment:
             return segment
     raise exc.NoNetworkAvailable()