Example #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 == constants.TYPE_VLAN:
                    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_FLAT]:
                    db.reserve_specific_network(session, physical_network,
                                                vlan_id)
                # no reservation needed for TYPE_LOCAL
            net = super(LinuxBridgePluginV2,
                        self).create_network(context, network)
            db.add_network_binding(session, net['id'], 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
        return net
Example #2
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 == constants.TYPE_VLAN:
                    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_FLAT]:
                    db.reserve_specific_network(session, physical_network,
                                                vlan_id)
                # no reservation needed for TYPE_LOCAL
            net = super(LinuxBridgePluginV2, self).create_network(context,
                                                                  network)
            db.add_network_binding(session, net['id'],
                                   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
        return net
Example #3
0
    def test_specific_network_outside_pool(self):
        vlan_id = VLAN_MAX + 5
        self.assertIsNone(lb_db.get_network_state(PHYS_NET, vlan_id))
        lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id)
        self.assertTrue(lb_db.get_network_state(PHYS_NET, vlan_id).allocated)

        with self.assertRaises(q_exc.VlanIdInUse):
            lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id)

        lb_db.release_network(self.session, PHYS_NET, vlan_id, VLAN_RANGES)
        self.assertIsNone(lb_db.get_network_state(PHYS_NET, vlan_id))
Example #4
0
    def test_specific_network_inside_pool(self):
        vlan_id = VLAN_MIN + 5
        self.assertFalse(lb_db.get_network_state(PHYS_NET, vlan_id).allocated)
        lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id)
        self.assertTrue(lb_db.get_network_state(PHYS_NET, vlan_id).allocated)

        with testtools.ExpectedException(q_exc.VlanIdInUse):
            lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id)

        lb_db.release_network(self.session, PHYS_NET, vlan_id, VLAN_RANGES)
        self.assertFalse(lb_db.get_network_state(PHYS_NET, vlan_id).allocated)
Example #5
0
    def test_specific_network_outside_pool(self):
        vlan_id = VLAN_MAX + 5
        self.assertIsNone(lb_db.get_network_state(PHYS_NET, vlan_id))
        lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id)
        self.assertTrue(lb_db.get_network_state(PHYS_NET,
                                                vlan_id).allocated)

        with testtools.ExpectedException(q_exc.VlanIdInUse):
            lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id)

        lb_db.release_network(self.session, PHYS_NET, vlan_id, VLAN_RANGES)
        self.assertIsNone(lb_db.get_network_state(PHYS_NET, vlan_id))
Example #6
0
    def test_specific_network_inside_pool(self):
        vlan_id = VLAN_MIN + 5
        self.assertFalse(lb_db.get_network_state(PHYS_NET,
                                                 vlan_id).allocated)
        lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id)
        self.assertTrue(lb_db.get_network_state(PHYS_NET,
                                                vlan_id).allocated)

        with self.assertRaises(q_exc.VlanIdInUse):
            lb_db.reserve_specific_network(self.session, PHYS_NET, vlan_id)

        lb_db.release_network(self.session, PHYS_NET, vlan_id, VLAN_RANGES)
        self.assertFalse(lb_db.get_network_state(PHYS_NET,
                                                 vlan_id).allocated)
Example #7
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:
                physical_network, vlan_id = db.reserve_network(session)
            else:
                db.reserve_specific_network(session, physical_network, vlan_id)
            net = super(LinuxBridgePluginV2, self).create_network(context,
                                                                  network)
            db.add_network_binding(session, net['id'],
                                   physical_network, vlan_id)
            self._extend_network_dict(context, net)
            # note - exception will rollback entire transaction
        return net
Example #8
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:
                physical_network, vlan_id = db.reserve_network(session)
            else:
                db.reserve_specific_network(session, physical_network, vlan_id)
            net = super(LinuxBridgePluginV2, self).create_network(context,
                                                                  network)
            db.add_network_binding(session, net['id'],
                                   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
        return net