2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
# Copyright 2010 United States Government as represented by the
5
# Administrator of the National Aeronautics and Space Administration.
8
# Copyright 2010 Anso Labs, LLC
10
# Licensed under the Apache License, Version 2.0 (the "License"); you may
11
# not use this file except in compliance with the License. You may obtain
12
# a copy of the License at
14
# http://www.apache.org/licenses/LICENSE-2.0
16
# Unless required by applicable law or agreed to in writing, software
17
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
19
# License for the specific language governing permissions and limitations
25
Handle lease database updates from DHCP servers.
31
sys.path.append(os.path.abspath(os.path.join(__file__, "../../")))
33
logging.debug(sys.path)
35
from os import environ
36
from nova.compute import linux_net
37
from nova.compute import network
40
from nova import flags
44
def add_lease(mac, ip, hostname, interface):
48
rpc.cast(FLAGS.cloud_topic, {"method": "lease_ip",
49
"args" : {"address": ip}})
51
def old_lease(mac, ip, hostname, interface):
52
logging.debug("Adopted old lease or got a change of mac/hostname")
54
def del_lease(mac, ip, hostname, interface):
56
network.release_ip(ip)
58
rpc.cast(FLAGS.cloud_topic, {"method": "release_ip",
59
"args" : {"address": ip}})
61
def init_leases(interface):
62
net = network.get_network_by_interface(interface)
64
for host_name in net.hosts:
65
res += "%s\n" % linux_net.hostDHCP(net, host_name, net.hosts[host_name])
72
interface = environ.get('DNSMASQ_INTERFACE', 'br0')
73
if int(environ.get('TESTING', '0')):
74
FLAGS.fake_rabbit = True
76
FLAGS.network_size = 32
77
FLAGS.fake_libvirt=True
78
FLAGS.fake_network=True
79
FLAGS.fake_users = True
81
if action in ['add','del','old']:
85
logging.debug("Called %s for mac %s with ip %s and hostname %s on interface %s" % (action, mac, ip, hostname, interface))
86
globals()[action+'_lease'](mac, ip, hostname, interface)
88
print init_leases(interface)
91
if __name__ == "__main__":