Пример #1
0
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)
Пример #2
0
 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)
Пример #3
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()
Пример #4
0
def reserve_specific_network(session, physical_network, vlan_id):
    with session.begin(subtransactions=True):
        try:
            state = (session.query(l2network_models_v2.NetworkState).filter_by(
                physical_network=physical_network, vlan_id=vlan_id).one())
            if state.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 %s on physical network %s "
                      "from pool" % (vlan_id, physical_network))
            state.allocated = True
        except exc.NoResultFound:
            LOG.debug("reserving specific vlan %s on physical network %s "
                      "outside pool" % (vlan_id, physical_network))
            state = l2network_models_v2.NetworkState(physical_network, vlan_id)
            state.allocated = True
            session.add(state)