Merge lp:~vishvananda/nova/automatic-metadata into lp:~hudson-openstack/nova/trunk

Proposed by Vish Ishaya
Status: Merged
Approved by: Devin Carlen
Approved revision: 951
Merged at revision: 957
Proposed branch: lp:~vishvananda/nova/automatic-metadata
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 54 lines (+11/-1)
2 files modified
nova/network/linux_net.py (+10/-1)
nova/network/manager.py (+1/-0)
To merge this branch: bzr merge lp:~vishvananda/nova/automatic-metadata
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Soren Hansen (community) Approve
Review via email: mp+56672@code.launchpad.net

Description of the change

Automatically add the metadata address to the network host. This allows guests to ARP for the address properly.

I also uncovered an issue with moving the gateway. Apparently specifying route add 0.0.0.0 doesn't actually work, you have use route add 'default'. I also added a line to specifically delete the old gateway since it doesn't always automatically get deleted.

To post a comment you must log in.
Revision history for this message
Soren Hansen (soren) wrote :

2011/4/7 Vish Ishaya <email address hidden>:
> === modified file 'nova/network/linux_net.py'
> --- nova/network/linux_net.py   2011-03-25 02:04:13 +0000
> +++ nova/network/linux_net.py   2011-04-06 23:14:24 +0000
> @@ -391,6 +391,13 @@
>              'dev', FLAGS.public_interface)
>
>
> +def ensure_metadata_ip(interface):
> +    """Sets up local metadata ip"""
> +    _execute('sudo', 'ip', 'addr', 'add', '169.254.169.254/32',
> +             'scope', 'link', 'dev', interface,
> +             check_exit_code=False)
> +
> +

Does the interface really matter? What if it were "lo"?

> @@ -504,7 +514,7 @@
>                 _execute(*_ip_bridge_cmd('del', params, fields[-1]))
>                 _execute(*_ip_bridge_cmd('add', params, bridge))
>         if gateway:
> -            _execute('sudo', 'route', 'add', '0.0.0.0', 'gw', gateway)
> +            _execute('sudo', 'route', 'add', 'default', 'gw', gateway)

I never really noticed this bit of code before. We really ought to
apply policy routing here. It's perfectly reasonable to have the VM's
use one routing table and the host use another. I've filed bug #753280
about this.

"route" is a dreadful interface for modifying routes, but if we're
using it, you should be passing "-net" as you're not adding a host
route. It must be special casing "default" and behind the scenes
pretending like you passed "-net" as well, since even 0.0.0.0/0 does
not work.

--
Soren Hansen        | http://linux2go.dk/
Ubuntu Developer    | http://www.ubuntu.com/
OpenStack Developer | http://www.openstack.org/

Revision history for this message
Chuck Short (zulcss) wrote :

looks good to me

Revision history for this message
Vish Ishaya (vishvananda) wrote :

On Apr 7, 2011, at 1:21 AM, Soren Hansen wrote:

>
> Does the interface really matter? What if it were "lo"?

I haven't tested adding the ip to the loopback interface. Do you want me to give it a shot?

>
> I never really noticed this bit of code before. We really ought to
> apply policy routing here. It's perfectly reasonable to have the VM's
> use one routing table and the host use another. I've filed bug #753280
> about this.
>
> "route" is a dreadful interface for modifying routes, but if we're
> using it, you should be passing "-net" as you're not adding a host
> route. It must be special casing "default" and behind the scenes
> pretending like you passed "-net" as well, since even 0.0.0.0/0 does
> not work.

Ah good point, i was wondering why 0.0.0.0/0 wasn't working.

>
> --
> Soren Hansen | http://linux2go.dk/
> Ubuntu Developer | http://www.ubuntu.com/
> OpenStack Developer | http://www.openstack.org/
>
> https://code.launchpad.net/~vishvananda/nova/automatic-metadata/+merge/56672
> You are the owner of lp:~vishvananda/nova/automatic-metadata.

951. By Vish Ishaya

Simplify by always adding to loopback

Revision history for this message
Vish Ishaya (vishvananda) wrote :

Tested loopback, it does work. The flag seems extraneous now, so I removed it. It automatically adds the address to the loopback device now.

Revision history for this message
Soren Hansen (soren) wrote :

> > "route" is a dreadful interface for modifying routes, but if we're
> > using it, you should be passing "-net" as you're not adding a host
> > route. It must be special casing "default" and behind the scenes
> > pretending like you passed "-net" as well, since even 0.0.0.0/0 does
> > not work.
> Ah good point, i was wondering why 0.0.0.0/0 wasn't working.

There's probably a (not necessarily good) reason why, but it seems that a route to "0.0.0.0/0" really ends up being a route to "0.0.0.0/32" which really isn't very useful. meh.

Revision history for this message
Soren Hansen (soren) wrote :

> Tested loopback, it does work. The flag seems extraneous now, so I removed
> it. It automatically adds the address to the loopback device now.

Excellent. lgtm now.

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

great patch, lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/network/linux_net.py'
2--- nova/network/linux_net.py 2011-03-25 02:04:13 +0000
3+++ nova/network/linux_net.py 2011-04-07 17:39:32 +0000
4@@ -391,6 +391,12 @@
5 'dev', FLAGS.public_interface)
6
7
8+def ensure_metadata_ip():
9+ """Sets up local metadata ip"""
10+ _execute('sudo', 'ip', 'addr', 'add', '169.254.169.254/32',
11+ 'scope', 'link', 'dev', 'lo', check_exit_code=False)
12+
13+
14 def ensure_vlan_forward(public_ip, port, private_ip):
15 """Sets up forwarding rules for vlan"""
16 iptables_manager.ipv4['filter'].add_rule("FORWARD",
17@@ -442,6 +448,7 @@
18 return interface
19
20
21+@utils.synchronized('ensure_bridge', external=True)
22 def ensure_bridge(bridge, interface, net_attrs=None):
23 """Create a bridge unless it already exists.
24
25@@ -495,6 +502,8 @@
26 fields = line.split()
27 if fields and fields[0] == "0.0.0.0" and fields[-1] == interface:
28 gateway = fields[1]
29+ _execute('sudo', 'route', 'del', 'default', 'gw', gateway,
30+ 'dev', interface)
31 out, err = _execute('sudo', 'ip', 'addr', 'show', 'dev', interface,
32 'scope', 'global')
33 for line in out.split("\n"):
34@@ -504,7 +513,7 @@
35 _execute(*_ip_bridge_cmd('del', params, fields[-1]))
36 _execute(*_ip_bridge_cmd('add', params, bridge))
37 if gateway:
38- _execute('sudo', 'route', 'add', '0.0.0.0', 'gw', gateway)
39+ _execute('sudo', 'route', 'add', 'default', 'gw', gateway)
40 out, err = _execute('sudo', 'brctl', 'addif', bridge, interface,
41 check_exit_code=False)
42
43
44=== modified file 'nova/network/manager.py'
45--- nova/network/manager.py 2011-03-25 02:04:13 +0000
46+++ nova/network/manager.py 2011-04-07 17:39:32 +0000
47@@ -126,6 +126,7 @@
48 standalone service.
49 """
50 self.driver.init_host()
51+ self.driver.ensure_metadata_ip()
52 # Set up networking for the projects for which we're already
53 # the designated network host.
54 ctxt = context.get_admin_context()