~ttx/nova/d4-merge

« back to all changes in this revision

Viewing changes to bin/nova-dhcpbridge

  • Committer: Thierry Carrez
  • Date: 2011-08-23 12:23:07 UTC
  • mfrom: (1130.75.258 nova)
  • Revision ID: thierry@openstack.org-20110823122307-f0vtuyg1ikc14n87
Merge diablo-4 development from trunk (rev1479)

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
flags.DECLARE('network_size', 'nova.network.manager')
49
49
flags.DECLARE('num_networks', 'nova.network.manager')
50
50
flags.DECLARE('update_dhcp_on_disassociate', 'nova.network.manager')
51
 
flags.DEFINE_string('dnsmasq_interface', 'br0', 'Default Dnsmasq interface')
52
51
 
53
52
LOG = logging.getLogger('nova.dhcpbridge')
54
53
 
55
54
 
56
 
def add_lease(mac, ip_address, _hostname, _interface):
 
55
def add_lease(mac, ip_address):
57
56
    """Set the IP that was assigned by the DHCP server."""
58
57
    if FLAGS.fake_rabbit:
59
58
        LOG.debug(_("leasing ip"))
67
66
                  "args": {"address": ip_address}})
68
67
 
69
68
 
70
 
def old_lease(mac, ip_address, hostname, interface):
 
69
def old_lease(mac, ip_address):
71
70
    """Update just as add lease."""
72
 
    LOG.debug(_("Adopted old lease or got a change of mac/hostname"))
73
 
    add_lease(mac, ip_address, hostname, interface)
74
 
 
75
 
 
76
 
def del_lease(mac, ip_address, _hostname, _interface):
 
71
    LOG.debug(_("Adopted old lease or got a change of mac"))
 
72
    add_lease(mac, ip_address)
 
73
 
 
74
 
 
75
def del_lease(mac, ip_address):
77
76
    """Called when a lease expires."""
78
77
    if FLAGS.fake_rabbit:
79
78
        LOG.debug(_("releasing ip"))
87
86
                  "args": {"address": ip_address}})
88
87
 
89
88
 
90
 
def init_leases(interface):
91
 
    """Get the list of hosts for an interface."""
 
89
def init_leases(network_id):
 
90
    """Get the list of hosts for a network."""
92
91
    ctxt = context.get_admin_context()
93
 
    network_ref = db.network_get_by_bridge(ctxt, interface)
 
92
    network_ref = db.network_get(ctxt, network_id)
94
93
    return linux_net.get_dhcp_leases(ctxt, network_ref)
95
94
 
96
95
 
100
99
    utils.default_flagfile(flagfile)
101
100
    argv = FLAGS(sys.argv)
102
101
    logging.setup()
103
 
    # check ENV first so we don't break any older deploys
104
 
    interface = os.environ.get('DNSMASQ_INTERFACE', FLAGS.dnsmasq_interface)
 
102
 
105
103
    if int(os.environ.get('TESTING', '0')):
106
104
        from nova.tests import fake_flags
107
105
 
115
113
    if action in ['add', 'del', 'old']:
116
114
        mac = argv[2]
117
115
        ip = argv[3]
118
 
        hostname = argv[4]
119
 
        msg = _("Called %(action)s for mac %(mac)s with ip %(ip)s and"
120
 
                " hostname %(hostname)s on interface %(interface)s") % locals()
 
116
        msg = _("Called '%(action)s' for mac '%(mac)s' with ip '%(ip)s'") % \
 
117
                    {"action": action,
 
118
                     "mac": mac,
 
119
                     "ip": ip}
121
120
        LOG.debug(msg)
122
 
        globals()[action + '_lease'](mac, ip, hostname, interface)
 
121
        globals()[action + '_lease'](mac, ip)
123
122
    else:
124
 
        print init_leases(interface)
 
123
        try:
 
124
            network_id = int(os.environ.get('NETWORK_ID'))
 
125
        except TypeError:
 
126
            LOG.error(_("Environment variable 'NETWORK_ID' must be set."))
 
127
            sys.exit(1)
 
128
 
 
129
        print init_leases(network_id)
125
130
 
126
131
if __name__ == "__main__":
127
132
    main()