~jaypipes/nova/nova-tests-apitest

« back to all changes in this revision

Viewing changes to bin/nova-dhcpbridge

  • Committer: jaypipes at gmail
  • Date: 2010-08-10 14:00:43 UTC
  • mfrom: (212.1.5 trunk)
  • Revision ID: jaypipes@gmail.com-20100810140043-h4qpq80fbyzivx57
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#    under the License.
19
19
 
20
20
"""
21
 
nova-dhcpbridge
22
 
 
23
21
Handle lease database updates from DHCP servers.
24
22
"""
25
23
 
42
40
FLAGS = flags.FLAGS
43
41
 
44
42
 
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)
48
47
    else:
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}})
52
 
 
53
 
def old_lease(mac, ip, hostname, interface):
 
50
                  "args": {"fixed_ip": ip}})
 
51
 
 
52
 
 
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")
55
56
 
56
 
def del_lease(mac, ip, hostname, interface):
 
57
 
 
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)
59
62
    else:
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}})
 
66
 
63
67
 
64
68
def init_leases(interface):
 
69
    """Get the list of hosts for an interface."""
65
70
    net = model.get_network_by_interface(interface)
66
71
    res = ""
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,
 
74
                                           net.hosts[host_name])
69
75
    return res
70
76
 
71
77
 
72
78
def main():
 
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)
79
86
        FLAGS.redis_db = 8
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'
84
91
    action = argv[1]
85
 
    if action in ['add','del','old']:
 
92
    if action in ['add', 'del', 'old']:
86
93
        mac = argv[2]
87
94
        ip = argv[3]
88
95
        hostname = argv[4]
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)
91
100
    else:
92
101
        print init_leases(interface)
93
 
    exit(0)
94
102
 
95
103
if __name__ == "__main__":
96
 
    sys.exit(main())
 
104
    main()