Files
8eb531becb7e67169fddb8f7d1547589ab733dc7
nova /bin /nova-dhcpbridge

105 lines
3.5 KiB
Plaintext
Raw Normal View History

2010年07月07日 12:25:22 -07:00
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2010年07月07日 12:25:22 -07:00
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
2010年07月07日 12:25:22 -07:00
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
Handle lease database updates from DHCP servers.
"""
import logging
2010年07月15日 23:11:33 +00:00
import os
import sys
#TODO(joshua): there is concern that the user dnsmasq runs under will not
# have nova in the path. This should be verified and if it is
# not true the ugly line below can be removed
sys.path.append(os.path.abspath(os.path.join(__file__, "../../")))
from nova import flags
2010年07月15日 23:11:33 +00:00
from nova import rpc
from nova import utils
from nova.network import service
2010年07月18日 13:25:43 -05:00
FLAGS = flags.FLAGS
def add_lease(_mac, ip, _hostname, _interface):
"""Set the IP that was assigned by the DHCP server."""
if FLAGS.fake_rabbit:
2010年08月17日 20:33:37 -07:00
logging.debug("leasing_ip")
rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name),
2010年08月17日 20:33:37 -07:00
"args": {"fixed_ip_str": ip}})
def old_lease(_mac, _ip, _hostname, _interface):
"""Do nothing, just an old lease update."""
logging.debug("Adopted old lease or got a change of mac/hostname")
2010年07月07日 12:25:22 -07:00
def del_lease(_mac, ip, _hostname, _interface):
2010年08月09日 23:44:13 -07:00
"""Called when a lease expires."""
if FLAGS.fake_rabbit:
2010年08月17日 20:33:37 -07:00
logging.debug("releasing_ip")
rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name),
2010年08月17日 20:33:37 -07:00
"args": {"fixed_ip_str": ip}})
2010年07月07日 12:25:22 -07:00
def init_leases(interface):
"""Get the list of hosts for an interface."""
2010年08月17日 20:33:37 -07:00
network = service.get_network_by_interface(interface)
return linux_net.get_dhcp_hosts(network)
2010年07月15日 23:11:33 +00:00
def main():
"""Parse environment and arguments and call the approproate action."""
2010年07月15日 23:11:33 +00:00
flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile)
utils.default_flagfile(flagfile)
argv = FLAGS(sys.argv)
interface = os.environ.get('DNSMASQ_INTERFACE', 'br0')
2010年08月17日 20:33:37 -07:00
LOG_FILENAME = 'example.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug("this is a test")
2010年07月15日 23:11:33 +00:00
if int(os.environ.get('TESTING', '0')):
FLAGS.fake_rabbit = True
FLAGS.redis_db = 8
FLAGS.network_size = 32
FLAGS.auth_driver = 'nova.auth.ldapdriver.FakeLdapDriver'
action = argv[1]
mac = argv[2]
ip = argv[3]
hostname = argv[4]
logging.debug("Called %s for mac %s with ip %s and "
"hostname %s on interface %s",
action, mac, ip, hostname, interface)
globals()[action + '_lease'](mac, ip, hostname, interface)
print init_leases(interface)
if __name__ == "__main__":