~cloudbuilders/nova/os-keypair-integration

« back to all changes in this revision

Viewing changes to nova/api/openstack/views/addresses.py

  • Committer: Jesse Andrews
  • Date: 2011-08-26 21:57:53 UTC
  • mfrom: (1455.1.45 nova)
  • Revision ID: anotherjesse@gmail.com-20110826215753-0sfp6dubujsl23wa
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
from nova import flags
19
19
from nova import utils
 
20
from nova import log as logging
20
21
from nova.api.openstack import common
21
22
 
22
23
FLAGS = flags.FLAGS
 
24
LOG = logging.getLogger('nova.api.openstack.views.addresses')
23
25
 
24
26
 
25
27
class ViewBuilder(object):
48
50
    def build(self, interfaces):
49
51
        networks = {}
50
52
        for interface in interfaces:
51
 
            network_label = interface['network']['label']
 
53
            try:
 
54
                network_label = self._extract_network_label(interface)
 
55
            except TypeError:
 
56
                continue
52
57
 
53
58
            if network_label not in networks:
54
59
                networks[network_label] = []
64
69
 
65
70
        return networks
66
71
 
67
 
    def build_network(self, interfaces, network_label):
 
72
    def build_network(self, interfaces, requested_network):
68
73
        for interface in interfaces:
69
 
            if interface['network']['label'] == network_label:
 
74
            try:
 
75
                network_label = self._extract_network_label(interface)
 
76
            except TypeError:
 
77
                continue
 
78
 
 
79
            if network_label == requested_network:
70
80
                ips = list(self._extract_ipv4_addresses(interface))
71
81
                ipv6 = self._extract_ipv6_address(interface)
72
82
                if ipv6 is not None:
74
84
                return {network_label: ips}
75
85
        return None
76
86
 
 
87
    def _extract_network_label(self, interface):
 
88
        try:
 
89
            return interface['network']['label']
 
90
        except (TypeError, KeyError) as exc:
 
91
            LOG.exception(exc)
 
92
            raise TypeError
 
93
 
77
94
    def _extract_ipv4_addresses(self, interface):
78
95
        for fixed_ip in interface['fixed_ips']:
79
96
            yield self._build_ip_entity(fixed_ip['address'], 4)