コード例 #1
0
    def create_network(self, context, network):
        (network_type, physical_network,
         vlan_id) = self._process_provider_create(context, network['network'])
        session = context.session
        with session.begin(subtransactions=True):
            if not network_type:
                # tenant network
                network_type = self.tenant_network_type
                if network_type == constants.TYPE_NONE:
                    raise q_exc.TenantNetworksDisabled()
                elif network_type in [constants.TYPE_VLAN, constants.TYPE_IB]:
                    physical_network, vlan_id = db.reserve_network(session)
                else:  # TYPE_LOCAL
                    vlan_id = constants.LOCAL_VLAN_ID
            else:
                # provider network
                if network_type in [
                        constants.TYPE_VLAN, constants.TYPE_IB,
                        constants.TYPE_FLAT
                ]:
                    db.reserve_specific_network(session, physical_network,
                                                vlan_id)
            net = super(MellanoxEswitchPlugin,
                        self).create_network(context, network)
            db.add_network_binding(session, net['id'], network_type,
                                   physical_network, vlan_id)

            self._process_l3_create(context, network['network'], net['id'])
            self._extend_network_dict_provider(context, net)
            self._extend_network_dict_l3(context, net)
            # note - exception will rollback entire transaction
            LOG.debug(_("Created network: %s"), net['id'])
            return net
コード例 #2
0
 def create_network(self, context, network):              
     session = context.session
     with session.begin(subtransactions=True):
         (network_type, physical_network,vlan_id) = self._process_provider_create(context, network['network'])       
         if not network_type:
             # tenant network
             network_type = self.tenant_network_type
             if network_type == constants.TYPE_NONE:
                 raise q_exc.TenantNetworksDisabled()
             elif network_type in [constants.TYPE_VLAN,constants.TYPE_IB]:
                 physical_network, vlan_id = db.reserve_network(session)
             else:  # TYPE_LOCAL
                 vlan_id = constants.LOCAL_VLAN_ID
         else:
             # provider network
             if network_type in [constants.TYPE_VLAN, constants.TYPE_IB,constants.TYPE_FLAT]:
                 db.reserve_specific_network(session, 
                                             physical_network,
                                             vlan_id)
         net = super(MellanoxEswitchPlugin, self).create_network(context,
                                                               network)
         db.add_network_binding(session, net['id'],
                                network_type,
                                physical_network, 
                                vlan_id)
         
         self._process_l3_create(context, network['network'], net['id'])
         self._extend_network_dict_provider(context, net)
         self._extend_network_dict_l3(context, net)
         # note - exception will rollback entire transaction
         LOG.debug(_("Created network: %s"), net['id'])
         return net    
コード例 #3
0
 def test_add_network_binding(self):
     self.assertIsNone(mlnx_db.get_network_binding(self.session,
                                                 TEST_NETWORK_ID))
     mlnx_db.add_network_binding(self.session, TEST_NETWORK_ID,NET_TYPE, PHYS_NET,
                               1234)
     binding = mlnx_db.get_network_binding(self.session, TEST_NETWORK_ID)
     self.assertIsNotNone(binding)
     self.assertEqual(binding.network_id, TEST_NETWORK_ID)
     self.assertEqual(binding.network_type,NET_TYPE)
     self.assertEqual(binding.physical_network, PHYS_NET)
     self.assertEqual(binding.segmentation_id, 1234)
コード例 #4
0
ファイル: test_mlnx_db.py プロジェクト: soheilhy/quantum
 def test_add_network_binding(self):
     with self.network() as network:
         TEST_NETWORK_ID = network['network']['id']
         self.assertIsNone(
             mlnx_db.get_network_binding(self.session, TEST_NETWORK_ID))
         mlnx_db.add_network_binding(self.session, TEST_NETWORK_ID,
                                     NET_TYPE, PHYS_NET, 1234)
         binding = mlnx_db.get_network_binding(self.session,
                                               TEST_NETWORK_ID)
         self.assertIsNotNone(binding)
         self.assertEqual(binding.network_id, TEST_NETWORK_ID)
         self.assertEqual(binding.network_type, NET_TYPE)
         self.assertEqual(binding.physical_network, PHYS_NET)
         self.assertEqual(binding.segmentation_id, 1234)