~jk0/nova/lp754944

« back to all changes in this revision

Viewing changes to nova/network/linux_net.py

  • Committer: Tarmac
  • Author(s): Vishvananda Ishaya
  • Date: 2011-04-07 22:12:42 UTC
  • mfrom: (948.1.3 automatic-metadata)
  • Revision ID: tarmac-20110407221242-59gc1x9q79r5webc
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
391
391
             'dev', FLAGS.public_interface)
392
392
 
393
393
 
 
394
def ensure_metadata_ip():
 
395
    """Sets up local metadata ip"""
 
396
    _execute('sudo', 'ip', 'addr', 'add', '169.254.169.254/32',
 
397
             'scope', 'link', 'dev', 'lo', check_exit_code=False)
 
398
 
 
399
 
394
400
def ensure_vlan_forward(public_ip, port, private_ip):
395
401
    """Sets up forwarding rules for vlan"""
396
402
    iptables_manager.ipv4['filter'].add_rule("FORWARD",
442
448
    return interface
443
449
 
444
450
 
 
451
@utils.synchronized('ensure_bridge', external=True)
445
452
def ensure_bridge(bridge, interface, net_attrs=None):
446
453
    """Create a bridge unless it already exists.
447
454
 
495
502
            fields = line.split()
496
503
            if fields and fields[0] == "0.0.0.0" and fields[-1] == interface:
497
504
                gateway = fields[1]
 
505
                _execute('sudo', 'route', 'del', 'default', 'gw', gateway,
 
506
                         'dev', interface)
498
507
        out, err = _execute('sudo', 'ip', 'addr', 'show', 'dev', interface,
499
508
                            'scope', 'global')
500
509
        for line in out.split("\n"):
504
513
                _execute(*_ip_bridge_cmd('del', params, fields[-1]))
505
514
                _execute(*_ip_bridge_cmd('add', params, bridge))
506
515
        if gateway:
507
 
            _execute('sudo', 'route', 'add', '0.0.0.0', 'gw', gateway)
 
516
            _execute('sudo', 'route', 'add', 'default', 'gw', gateway)
508
517
        out, err = _execute('sudo', 'brctl', 'addif', bridge, interface,
509
518
                            check_exit_code=False)
510
519