summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJoshua McKenty <jmckenty@joshua-mckentys-macbook-pro.local>2010-07-07 12:15:11 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2010-07-07 12:15:11 -0700
commitdbe324f7254dd3e01de44bb908150fb8397fe118 (patch)
tree7b2949e0f04402f936553622b2c84e682476ac25 /bin
parentb7ea2f70581f6acd927ea7b65adaffeeb4b8d2ba (diff)
downloadnova-dbe324f7254dd3e01de44bb908150fb8397fe118.tar.gz
nova-dbe324f7254dd3e01de44bb908150fb8397fe118.tar.xz
nova-dbe324f7254dd3e01de44bb908150fb8397fe118.zip
Got dhcpleasor working, with test ENV for testing, and rpc.cast for real world.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/dhcpleasor.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/bin/dhcpleasor.py b/bin/dhcpleasor.py
index 07e63884f..63ed52420 100755
--- a/bin/dhcpleasor.py
+++ b/bin/dhcpleasor.py
@@ -27,32 +27,50 @@ sys.path.append(os.path.abspath(os.path.join(__file__, "../../")))
logging.debug(sys.path)
import getopt
from os import environ
+from nova.compute import linux_net
from nova.compute import network
+from nova import rpc
+
from nova import flags
FLAGS = flags.FLAGS
def add_lease(mac, ip, hostname, interface):
- pass
+ if FLAGS.fake_rabbit:
+ network.lease_ip(ip)
+ else:
+ rpc.cast(FLAGS.cloud_topic, {"method": "lease_ip",
+ "args" : {"address": ip}})
def old_lease(mac, ip, hostname, interface):
- pass
+ logging.debug("Adopted old lease or got a change of mac/hostname")
def del_lease(mac, ip, hostname, interface):
- # TODO - get net from interface instead
- net = network.get_network_by_address(ip)
- net.release_ip(ip)
+ if FLAGS.fake_rabbit:
+ network.release_ip(ip)
+ else:
+ rpc.cast(FLAGS.cloud_topic, {"method": "release_ip",
+ "args" : {"address": ip}})
def init_leases(interface):
- return ""
+ net = network.get_network_by_interface(interface)
+ res = ""
+ for host_name in net.hosts:
+ res += "%s\n" % linux_net.hostDHCP(net, host_name, net.hosts[host_name])
+ return res
def main(argv=None):
if argv is None:
argv = sys.argv
interface = environ.get('DNSMASQ_INTERFACE', 'br0')
- old_redis_db = FLAGS.redis_db
- FLAGS.redis_db = int(environ.get('REDIS_DB', '0'))
+ if int(environ.get('TESTING', '0')):
+ FLAGS.fake_rabbit = True
+ FLAGS.redis_db = 8
+ FLAGS.network_size = 32
+ FLAGS.fake_libvirt=True
+ FLAGS.fake_network=True
+ FLAGS.fake_users = True
action = argv[1]
if action in ['add','del','old']:
mac = argv[2]
@@ -62,7 +80,7 @@ def main(argv=None):
globals()[action+'_lease'](mac, ip, hostname, interface)
else:
print init_leases(interface)
- FLAGS.redis_db = old_redis_db
+ exit(0)
if __name__ == "__main__":
sys.exit(main())