~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/network/linux_net.py

  • Committer: Tarmac
  • Author(s): Vishvananda Ishaya
  • Date: 2011-09-21 13:31:54 UTC
  • mfrom: (1541.12.4 fix-dhcp)
  • Revision ID: tarmac-20110921133154-sgi5da2en4x1mgp8
Makes sure ips are moved on the bridge for nodes running dnsmasq so that the gateway ip is always first.

Show diffs side-by-side

added added

removed removed

Lines of Context:
472
472
 
473
473
    # NOTE(vish): The ip for dnsmasq has to be the first address on the
474
474
    #             bridge for it to respond to reqests properly
475
 
    suffix = network_ref['cidr'].rpartition('/')[2]
476
 
    out, err = _execute('ip', 'addr', 'add',
477
 
                            '%s/%s' %
478
 
                            (network_ref['dhcp_server'], suffix),
479
 
                            'brd',
480
 
                            network_ref['broadcast'],
481
 
                            'dev',
482
 
                            dev,
483
 
                            run_as_root=True,
484
 
                            check_exit_code=False)
485
 
    if err and err != 'RTNETLINK answers: File exists\n':
486
 
        raise exception.Error('Failed to add ip: %s' % err)
487
 
    if FLAGS.send_arp_for_ha:
488
 
        _execute('arping', '-U', network_ref['gateway'],
489
 
                  '-A', '-I', dev,
490
 
                  '-c', 1, run_as_root=True, check_exit_code=False)
 
475
    full_ip = '%s/%s' % (network_ref['dhcp_server'],
 
476
                         network_ref['cidr'].rpartition('/')[2])
 
477
    new_ip_params = [[full_ip, 'brd', network_ref['broadcast']]]
 
478
    old_ip_params = []
 
479
    out, err = _execute('ip', 'addr', 'show', 'dev', dev,
 
480
                        'scope', 'global', run_as_root=True)
 
481
    for line in out.split('\n'):
 
482
        fields = line.split()
 
483
        if fields and fields[0] == 'inet':
 
484
            ip_params = fields[1:-1]
 
485
            old_ip_params.append(ip_params)
 
486
            if ip_params[0] != full_ip:
 
487
                new_ip_params.append(ip_params)
 
488
    if not old_ip_params or old_ip_params[0][0] != full_ip:
 
489
        for ip_params in old_ip_params:
 
490
            _execute(*_ip_bridge_cmd('del', ip_params, dev),
 
491
                        run_as_root=True)
 
492
        for ip_params in new_ip_params:
 
493
            _execute(*_ip_bridge_cmd('add', ip_params, dev),
 
494
                        run_as_root=True)
 
495
        if FLAGS.send_arp_for_ha:
 
496
            _execute('arping', '-U', network_ref['dhcp_server'],
 
497
                      '-A', '-I', dev,
 
498
                      '-c', 1, run_as_root=True, check_exit_code=False)
491
499
    if(FLAGS.use_ipv6):
492
500
        _execute('ip', '-f', 'inet6', 'addr',
493
501
                     'change', network_ref['cidr_v6'],