~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/network/quantumv2/api.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-08-09 10:12:27 UTC
  • mto: This revision was merged to the branch mainline in revision 107.
  • Revision ID: package-import@ubuntu.com-20130809101227-flqfubhwpot76pob
Tags: upstream-2013.1.3
ImportĀ upstreamĀ versionĀ 2013.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from nova.network import quantumv2
32
32
from nova.network.security_group import openstack_driver
33
33
from nova.openstack.common import excutils
 
34
from nova.openstack.common import jsonutils
34
35
from nova.openstack.common import log as logging
35
36
from nova.openstack.common import uuidutils
36
37
 
182
183
 
183
184
        nets = self._get_available_networks(context, instance['project_id'],
184
185
                                            net_ids)
 
186
 
 
187
        if not nets:
 
188
            LOG.warn(_("No network configured!"), instance=instance)
 
189
            return []
 
190
 
185
191
        security_groups = kwargs.get('security_groups', [])
186
192
        security_group_ids = []
187
193
 
553
559
 
554
560
    def get_all(self, context):
555
561
        client = quantumv2.get_client(context)
556
 
        networks = client.list_networks().get('networks') or {}
 
562
        networks = client.list_networks().get('networks')
557
563
        for network in networks:
558
564
            network['label'] = network['name']
559
565
        return networks
787
793
        data = client.list_ports(**search_opts)
788
794
        ports = data.get('ports', [])
789
795
        if networks is None:
 
796
            # retrieve networks from info_cache to get correct nic order
 
797
            network_cache = self.conductor_api.instance_get_by_uuid(
 
798
                context, instance['uuid'])['info_cache']['network_info']
 
799
            network_cache = jsonutils.loads(network_cache)
 
800
            net_ids = [iface['network']['id'] for iface in network_cache]
790
801
            networks = self._get_available_networks(context,
791
802
                                                    instance['project_id'])
792
803
 
793
804
        # ensure ports are in preferred network order, and filter out
794
805
        # those not attached to one of the provided list of networks
795
 
        net_ids = [n['id'] for n in networks]
 
806
        else:
 
807
            net_ids = [n['id'] for n in networks]
796
808
        ports = [port for port in ports if port['network_id'] in net_ids]
797
809
        _ensure_requested_network_ordering(lambda x: x['network_id'],
798
810
                                           ports, net_ids)