Esempio 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()
Esempio n. 2
0
def reserve_tunnel(session):
    with session.begin(subtransactions=True):
        alloc = (session.query(
            ovs_models_v2.TunnelAllocation).filter_by(allocated=False).first())
        if alloc:
            LOG.debug("reserving tunnel %s from pool" % alloc.tunnel_id)
            alloc.allocated = True
            return alloc.tunnel_id
    raise q_exc.NoNetworkAvailable()
Esempio n. 3
0
def reserve_vlan(session):
    with session.begin(subtransactions=True):
        alloc = (session.query(
            ovs_models_v2.VlanAllocation).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()
Esempio n. 4
0
def reserve_network(session):
    with session.begin(subtransactions=True):
        state = (session.query(l2network_models_v2.NetworkState).filter_by(
            allocated=False).first())
        if not state:
            raise q_exc.NoNetworkAvailable()
        LOG.debug("reserving vlan %s on physical network %s from pool" %
                  (state.vlan_id, state.physical_network))
        state.allocated = True
    return (state.physical_network, state.vlan_id)
Esempio n. 5
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 q_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)
Esempio n. 6
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()
Esempio n. 7
0
 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 q_exc.NoNetworkAvailable()
Esempio n. 8
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)
Esempio n. 9
0
 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 q_exc.NoNetworkAvailable()
Esempio n. 10
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 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"), locals())
             alloc.allocated = True
         except exc.NoResultFound:
             raise q_exc.NoNetworkAvailable()