42
40
FLAGS = flags.FLAGS
45
def add_lease(mac, ip, hostname, interface):
43
def add_lease(_mac, ip, _hostname, _interface):
44
"""Set the IP that was assigned by the DHCP server."""
46
45
if FLAGS.fake_rabbit:
47
46
service.VlanNetworkService().lease_ip(ip)
49
rpc.cast("%s.%s" (FLAGS.network_topic, FLAGS.node_name),
48
rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name),
50
49
{"method": "lease_ip",
51
"args" : {"fixed_ip": ip}})
53
def old_lease(mac, ip, hostname, interface):
50
"args": {"fixed_ip": ip}})
53
def old_lease(_mac, _ip, _hostname, _interface):
54
"""Do nothing, just an old lease update."""
54
55
logging.debug("Adopted old lease or got a change of mac/hostname")
56
def del_lease(mac, ip, hostname, interface):
58
def del_lease(_mac, ip, _hostname, _interface):
59
"""Remove the leased IP from the databases."""
57
60
if FLAGS.fake_rabbit:
58
61
service.VlanNetworkService().release_ip(ip)
60
rpc.cast("%s.%s" (FLAGS.network_topic, FLAGS.node_name),
63
rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name),
61
64
{"method": "release_ip",
62
"args" : {"fixed_ip": ip}})
65
"args": {"fixed_ip": ip}})
64
68
def init_leases(interface):
69
"""Get the list of hosts for an interface."""
65
70
net = model.get_network_by_interface(interface)
67
72
for host_name in net.hosts:
68
res += "%s\n" % linux_net.hostDHCP(net, host_name, net.hosts[host_name])
73
res += "%s\n" % linux_net.hostDHCP(net, host_name,
79
"""Parse environment and arguments and call the approproate action."""
73
80
flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile)
74
81
utils.default_flagfile(flagfile)
75
82
argv = FLAGS(sys.argv)
80
87
FLAGS.network_size = 32
81
88
FLAGS.connection_type = 'fake'
82
FLAGS.fake_network=True
83
FLAGS.auth_driver='nova.auth.ldapdriver.FakeLdapDriver'
89
FLAGS.fake_network = True
90
FLAGS.auth_driver = 'nova.auth.ldapdriver.FakeLdapDriver'
85
if action in ['add','del','old']:
92
if action in ['add', 'del', 'old']:
89
logging.debug("Called %s for mac %s with ip %s and hostname %s on interface %s" % (action, mac, ip, hostname, interface))
90
globals()[action+'_lease'](mac, ip, hostname, interface)
96
logging.debug("Called %s for mac %s with ip %s and "
97
"hostname %s on interface %s",
98
action, mac, ip, hostname, interface)
99
globals()[action + '_lease'](mac, ip, hostname, interface)
92
101
print init_leases(interface)
95
103
if __name__ == "__main__":