示例#1
0
    def test_ensure_requested_network_ordering_with_preference(self):
        l = [{'id': 3}, {'id': 1}, {'id': 2}]

        quantumapi._ensure_requested_network_ordering(lambda x: x['id'], l,
                                                      [1, 2, 3])

        self.assertEqual(l, [{'id': 1}, {'id': 2}, {'id': 3}])
示例#2
0
    def test_ensure_requested_network_ordering_no_preference(self):
        l = [1, 2, 3]

        quantumapi._ensure_requested_network_ordering(
            lambda x: x,
            l,
            None)
示例#3
0
    def _get_available_networks(self, context, project_id,
                                net_ids=None):
        """Return only specified networks if provided.

        Standard implementation uses public nets if empty list
        provided, this is not desirable behavior."""
        if net_ids is None:
            return super(QuantumUdpApi, self)._get_available_networks(
                context, project_id)
        elif not net_ids:
            return []

        # If user has specified to attach instance only to specific
        # networks, add them to **search_opts
        quantum = quantumv2.get_client(context)
        search_opts = {"tenant_id": project_id, 'shared': False, 'id': net_ids}
        nets = quantum.list_networks(**search_opts).get('networks', [])
        found_nets = map(lambda x: x['id'], nets)
        if len(nets) != len(found_nets):
            set(net_ids).difference(found_nets)
            raise exception.NetworkNotFound(network_id=found_nets)

        _ensure_requested_network_ordering(lambda x: x['id'], nets, net_ids)
        LOG.debug("Nets for instance: %s" % nets)
        return nets
示例#4
0
    def test_ensure_requested_network_ordering_with_preference(self):
        l = [{'id': 3}, {'id': 1}, {'id': 2}]

        quantumapi._ensure_requested_network_ordering(
            lambda x: x['id'],
            l,
            [1, 2, 3])

        self.assertEqual(l, [{'id': 1}, {'id': 2}, {'id': 3}])
示例#5
0
    def test_ensure_requested_network_ordering_no_preference_hashes(self):
        l = [{'id': 3}, {'id': 1}, {'id': 2}]

        quantumapi._ensure_requested_network_ordering(
            lambda x: x['id'],
            l,
            None)

        self.assertEqual(l, [{'id': 3}, {'id': 1}, {'id': 2}])
示例#6
0
    def _get_available_networks(self, context, project_id, net_ids=None):
        """Return only specified networks if provided.

        Standard implementation uses public nets if empty list
        provided, this is not desirable behavior."""
        if net_ids is None:
            return super(QuantumUdpApi,
                         self)._get_available_networks(context, project_id)
        elif not net_ids:
            return []

        # If user has specified to attach instance only to specific
        # networks, add them to **search_opts
        quantum = quantumv2.get_client(context)
        search_opts = {"tenant_id": project_id, 'shared': False, 'id': net_ids}
        nets = quantum.list_networks(**search_opts).get('networks', [])
        found_nets = map(lambda x: x['id'], nets)
        if len(nets) != len(found_nets):
            set(net_ids).difference(found_nets)
            raise exception.NetworkNotFound(network_id=found_nets)

        _ensure_requested_network_ordering(lambda x: x['id'], nets, net_ids)
        LOG.debug("Nets for instance: %s" % nets)
        return nets
示例#7
0
    def test_ensure_requested_network_ordering_no_preference(self):
        l = [1, 2, 3]

        quantumapi._ensure_requested_network_ordering(lambda x: x, l, None)
示例#8
0
    def test_ensure_requested_network_ordering_no_preference(self):
        l = [{"id": 3}, {"id": 1}, {"id": 2}]

        quantumapi._ensure_requested_network_ordering(lambda x: x["id"], l, None)

        self.assertEqual(l, [{"id": 3}, {"id": 1}, {"id": 2}])