Beispiel #1
0
    def create_network(self, context, network):
        (network_type, physical_network, segmentation_id) = self._process_provider_create(context, network["network"])

        session = context.session
        # set up default security groups
        tenant_id = self._get_tenant_id_for_create(context, network["network"])
        self._ensure_default_security_group(context, tenant_id)

        with session.begin(subtransactions=True):
            if not network_type:
                # tenant network
                network_type = self.tenant_network_type
                if network_type == svc_constants.TYPE_NONE:
                    raise q_exc.TenantNetworksDisabled()
                elif network_type == svc_constants.TYPE_VLAN:
                    (physical_network, segmentation_id) = ovs_db_v2.reserve_vlan(session)
                elif network_type in constants.TUNNEL_NETWORK_TYPES:
                    segmentation_id = ovs_db_v2.reserve_tunnel(session)
                # no reservation needed for TYPE_LOCAL
            else:
                # provider network
                if network_type in [svc_constants.TYPE_VLAN, svc_constants.TYPE_FLAT]:
                    ovs_db_v2.reserve_specific_vlan(session, physical_network, segmentation_id)
                elif network_type in constants.TUNNEL_NETWORK_TYPES:
                    ovs_db_v2.reserve_specific_tunnel(session, segmentation_id)
                # no reservation needed for TYPE_LOCAL
            net = super(OVSNeutronPluginV2, self).create_network(context, network)
            binding = ovs_db_v2.add_network_binding(session, net["id"], network_type, physical_network, segmentation_id)

            self._process_l3_create(context, net, network["network"])
            # passing None as db model to use binding object
            self._extend_network_dict_provider_ovs(net, None, binding)
            # note - exception will rollback entire transaction
        LOG.debug(_("Created network: %s"), net["id"])
        return net
Beispiel #2
0
    def test_specific_tunnel_outside_pool(self):
        tunnel_id = TUN_MAX + 5
        self.assertIsNone(ovs_db_v2.get_tunnel_allocation(tunnel_id))
        ovs_db_v2.reserve_specific_tunnel(self.session, tunnel_id)
        self.assertTrue(ovs_db_v2.get_tunnel_allocation(tunnel_id).allocated)

        with testtools.ExpectedException(n_exc.TunnelIdInUse):
            ovs_db_v2.reserve_specific_tunnel(self.session, tunnel_id)

        ovs_db_v2.release_tunnel(self.session, tunnel_id, TUNNEL_RANGES)
        self.assertIsNone(ovs_db_v2.get_tunnel_allocation(tunnel_id))
Beispiel #3
0
    def test_specific_tunnel_outside_pool(self):
        tunnel_id = TUN_MAX + 5
        self.assertIsNone(ovs_db_v2.get_tunnel_allocation(tunnel_id))
        ovs_db_v2.reserve_specific_tunnel(self.session, tunnel_id)
        self.assertTrue(ovs_db_v2.get_tunnel_allocation(tunnel_id).allocated)

        with testtools.ExpectedException(n_exc.TunnelIdInUse):
            ovs_db_v2.reserve_specific_tunnel(self.session, tunnel_id)

        ovs_db_v2.release_tunnel(self.session, tunnel_id, TUNNEL_RANGES)
        self.assertIsNone(ovs_db_v2.get_tunnel_allocation(tunnel_id))
Beispiel #4
0
    def create_network(self, context, network):
        (network_type, physical_network,
         segmentation_id) = self._process_provider_create(context,
                                                          network['network'])

        session = context.session
        #set up default security groups
        tenant_id = self._get_tenant_id_for_create(
            context, network['network'])
        self._ensure_default_security_group(context, tenant_id)

        with session.begin(subtransactions=True):
            if not network_type:
                # tenant network
                network_type = self.tenant_network_type
                if network_type == svc_constants.TYPE_NONE:
                    raise q_exc.TenantNetworksDisabled()
                elif network_type == svc_constants.TYPE_VLAN:
                    (physical_network,
                     segmentation_id) = ovs_db_v2.reserve_vlan(session)
                elif network_type in constants.TUNNEL_NETWORK_TYPES:
                    segmentation_id = ovs_db_v2.reserve_tunnel(session)
                # no reservation needed for TYPE_LOCAL
            else:
                # provider network
                if network_type in [svc_constants.TYPE_VLAN,
                                    svc_constants.TYPE_FLAT]:
                    ovs_db_v2.reserve_specific_vlan(session, physical_network,
                                                    segmentation_id)
                elif network_type in constants.TUNNEL_NETWORK_TYPES:
                    ovs_db_v2.reserve_specific_tunnel(session, segmentation_id)
                # no reservation needed for TYPE_LOCAL
            net = super(OVSNeutronPluginV2, self).create_network(context,
                                                                 network)
            binding = ovs_db_v2.add_network_binding(session, net['id'],
                                                    network_type,
                                                    physical_network,
                                                    segmentation_id)

            self._process_l3_create(context, net, network['network'])
            # passing None as db model to use binding object
            self._extend_network_dict_provider_ovs(net, None, binding)
            # note - exception will rollback entire transaction
        LOG.debug(_("Created network: %s"), net['id'])
        return net