Merge lp:~reldan/nova/l-m-n-fix-network-info into lp:~openstack-gd/nova/libvirt-multinic-nova

Proposed by Eldar Nugaev
Status: Merged
Merged at revision: 821
Proposed branch: lp:~reldan/nova/l-m-n-fix-network-info
Merge into: lp:~openstack-gd/nova/libvirt-multinic-nova
Diff against target: 148 lines (+19/-51)
3 files modified
nova/tests/test_virt.py (+2/-1)
nova/utils.py (+9/-5)
nova/virt/libvirt_conn.py (+8/-45)
To merge this branch: bzr merge lp:~reldan/nova/l-m-n-fix-network-info
Reviewer Review Type Date Requested Status
Ilya Alekseyev (community) Approve
Review via email: mp+54613@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ilya Alekseyev (ilyaalekseyev) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/tests/test_virt.py'
2--- nova/tests/test_virt.py 2011-03-14 17:59:41 +0000
3+++ nova/tests/test_virt.py 2011-03-23 21:38:23 +0000
4@@ -785,7 +785,8 @@
5
6 instance_ref = db.instance_create(self.context,
7 {'user_id': 'fake',
8- 'project_id': 'fake'})
9+ 'project_id': 'fake',
10+ 'mac_address': '00:A0:C9:14:C8:29'})
11 inst_id = instance_ref['id']
12
13 ip = '10.11.12.13'
14
15=== modified file 'nova/utils.py'
16--- nova/utils.py 2011-03-17 21:11:58 +0000
17+++ nova/utils.py 2011-03-23 21:38:23 +0000
18@@ -309,11 +309,15 @@
19
20
21 def to_global_ipv6(prefix, mac):
22- mac64 = netaddr.EUI(mac).eui64().words
23- int_addr = int(''.join(['%02x' % i for i in mac64]), 16)
24- mac64_addr = netaddr.IPAddress(int_addr)
25- maskIP = netaddr.IPNetwork(prefix).ip
26- return (mac64_addr ^ netaddr.IPAddress('::0200:0:0:0') | maskIP).format()
27+ try:
28+ mac64 = netaddr.EUI(mac).eui64().words
29+ int_addr = int(''.join(['%02x' % i for i in mac64]), 16)
30+ mac64_addr = netaddr.IPAddress(int_addr)
31+ maskIP = netaddr.IPNetwork(prefix).ip
32+ return (mac64_addr ^ netaddr.IPAddress('::0200:0:0:0') | maskIP).\
33+ format()
34+ except TypeError:
35+ raise TypeError(_("Bad mac for to_global_ipv6: %s" % mac))
36
37
38 def to_mac(ipv6_address):
39
40=== modified file 'nova/virt/libvirt_conn.py'
41--- nova/virt/libvirt_conn.py 2011-03-23 19:08:22 +0000
42+++ nova/virt/libvirt_conn.py 2011-03-23 21:38:23 +0000
43@@ -757,7 +757,7 @@
44 if FLAGS.libvirt_type == 'uml':
45 utils.execute('sudo', 'chown', 'root', basepath('disk'))
46
47- def _get_nic_for_xml(self, instance_id, network, mapping):
48+ def _get_nic_for_xml(self, network, mapping):
49 # Assume that the gateway also acts as the dhcp server.
50 dhcp_server = network['gateway']
51 gateway_v6 = network['gateway_v6']
52@@ -802,8 +802,6 @@
53 return result
54
55 def to_xml(self, instance, rescue=False, network_info=None):
56- admin_context = context.get_admin_context()
57-
58 # TODO(termie): cache?
59 LOG.debug(_('instance %s: starting toXML method'), instance['name'])
60
61@@ -814,8 +812,7 @@
62
63 nics = []
64 for (network, mapping) in network_info:
65- nics.append(self._get_nic_for_xml(instance['id'],
66- network,
67+ nics.append(self._get_nic_for_xml(network,
68 mapping))
69 # FIXME(vish): stick this in db
70 instance_type_name = instance['instance_type']
71@@ -1392,16 +1389,6 @@
72 """
73 raise NotImplementedError()
74
75- def _gateway_v6_for_instance(self, instance):
76- network = db.network_get_by_instance(context.get_admin_context(),
77- instance['id'])
78- return network['gateway_v6']
79-
80- def _all_gateway_v6_for_instance(self, instance):
81- networks = db.network_get_all_by_instance(context.get_admin_context(),
82- instance['id'])
83- return [network['gateway_v6'] for network in networks]
84-
85
86 class NWFilterFirewall(FirewallDriver):
87 """
88@@ -1604,6 +1591,8 @@
89 it makes sure the filters for the security groups as well as
90 the base filter are all in place.
91 """
92+ if not network_info:
93+ network_info = _get_network_info(instance)
94 if instance['image_id'] == FLAGS.vpn_image_id:
95 base_filter = 'nova-vpn'
96 else:
97@@ -1616,7 +1605,8 @@
98 'nova-base-ipv6',
99 'nova-allow-dhcp-server']
100 if FLAGS.use_ipv6:
101- gateways_v6 = self._all_gateway_v6_for_instance(instance)
102+ gateways_v6 = [network['gateway_v6'] for (network, _) in
103+ network_info]
104 if gateways_v6:
105 instance_secgroup_filter_children += ['nova-allow-ra-server']
106
107@@ -1803,7 +1793,8 @@
108 # they're not worth the clutter.
109 if FLAGS.use_ipv6:
110 # Allow RA responses
111- gateways_v6 = self._all_gateway_v6_for_instance(instance)
112+ gateways_v6 = [network['gateway_v6'] for (network, _) in
113+ network_info]
114 for gateway_v6 in gateways_v6:
115 ipv6_rules.append(
116 '-s %s/128 -p icmpv6 -j ACCEPT' % (gateway_v6,))
117@@ -1896,31 +1887,3 @@
118
119 def _instance_chain_name(self, instance):
120 return 'inst-%s' % (instance['id'],)
121-
122- def _ip_for_instance(self, instance):
123- return db.instance_get_fixed_address(context.get_admin_context(),
124- instance['id'])
125-
126- def _ip_for_instance_v6(self, instance):
127- return db.instance_get_fixed_address_v6(context.get_admin_context(),
128- instance['id'])
129-
130- def _dhcp_server_for_instance(self, instance):
131- network = db.network_get_by_instance(context.get_admin_context(),
132- instance['id'])
133- return network['gateway']
134-
135- def _gateway_v6_for_instance(self, instance):
136- network = db.network_get_by_instance(context.get_admin_context(),
137- instance['id'])
138- return network['gateway_v6']
139-
140- def _project_cidr_for_instance(self, instance):
141- network = db.network_get_by_instance(context.get_admin_context(),
142- instance['id'])
143- return network['cidr']
144-
145- def _project_cidrv6_for_instance(self, instance):
146- network = db.network_get_by_instance(context.get_admin_context(),
147- instance['id'])
148- return network['cidr_v6']

Subscribers

People subscribed via source and target branches

to all changes: