28
#TODO(joshua): there is concern that the user dnsmasq runs under will not
29
# have nova in the path. This should be verified and if it is
30
# not true the ugly line below can be removed
31
sys.path.append(os.path.abspath(os.path.join(__file__, "../../")))
28
# If ../nova/__init__.py exists, add ../ to Python search path, so that
29
# it will override what happens to be installed in /usr/(local/)lib/python...
30
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
33
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
34
sys.path.insert(0, possible_topdir)
33
37
from nova import flags
34
38
from nova import rpc
35
39
from nova import utils
36
40
from nova.network import linux_net
37
from nova.network import model
38
from nova.network import service
40
42
FLAGS = flags.FLAGS
43
def add_lease(_mac, ip_address, _hostname, _interface):
43
flags.DECLARE('auth_driver', 'nova.auth.manager')
44
flags.DECLARE('redis_db', 'nova.datastore')
45
flags.DECLARE('network_size', 'nova.network.manager')
46
flags.DECLARE('num_networks', 'nova.network.manager')
47
flags.DECLARE('update_dhcp_on_disassociate', 'nova.network.manager')
50
def add_lease(mac, ip_address, _hostname, _interface):
44
51
"""Set the IP that was assigned by the DHCP server."""
45
52
if FLAGS.fake_rabbit:
46
service.VlanNetworkService().lease_ip(ip_address)
53
logging.debug("leasing ip")
54
network_manager = utils.import_object(FLAGS.network_manager)
55
network_manager.lease_fixed_ip(None, mac, ip_address)
48
rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name),
49
{"method": "lease_ip",
50
"args": {"fixed_ip": ip_address}})
57
rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.host),
58
{"method": "lease_fixed_ip",
59
"args": {"context": None,
61
"address": ip_address}})
53
64
def old_lease(_mac, _ip_address, _hostname, _interface):
55
66
logging.debug("Adopted old lease or got a change of mac/hostname")
58
def del_lease(_mac, ip_address, _hostname, _interface):
69
def del_lease(mac, ip_address, _hostname, _interface):
59
70
"""Called when a lease expires."""
60
71
if FLAGS.fake_rabbit:
61
service.VlanNetworkService().release_ip(ip_address)
72
logging.debug("releasing ip")
73
network_manager = utils.import_object(FLAGS.network_manager)
74
network_manager.release_fixed_ip(None, mac, ip_address)
63
rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name),
64
{"method": "release_ip",
65
"args": {"fixed_ip": ip_address}})
76
rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.host),
77
{"method": "release_fixed_ip",
78
"args": {"context": None,
80
"address": ip_address}})
68
83
def init_leases(interface):
69
84
"""Get the list of hosts for an interface."""
70
net = model.get_network_by_interface(interface)
72
for address in net.assigned_objs:
73
res += "%s\n" % linux_net.host_dhcp(address)
85
network_ref = db.network_get_by_bridge(None, interface)
86
return linux_net.get_dhcp_hosts(None, network_ref['id'])
83
95
if int(os.environ.get('TESTING', '0')):
84
96
FLAGS.fake_rabbit = True
86
FLAGS.network_size = 32
98
FLAGS.network_size = 16
87
99
FLAGS.connection_type = 'fake'
88
100
FLAGS.fake_network = True
89
101
FLAGS.auth_driver = 'nova.auth.ldapdriver.FakeLdapDriver'
102
FLAGS.num_networks = 5
103
path = os.path.abspath(os.path.join(os.path.dirname(__file__),
107
FLAGS.sql_connection = 'sqlite:///%s' % path
91
109
if action in ['add', 'del', 'old']: