Add message when starting DHCP server

This commit is contained in:
Joshua Boniface 2018-09-30 13:05:21 -04:00
parent 31f35da91d
commit 7ebc8ddb74
2 changed files with 7 additions and 2 deletions

View File

@ -39,6 +39,7 @@ import select
import ipaddress
from socket import *
import daemon_lib.ansiiprint as ansiiprint
import daemon_lib.zkhandler as zkhandler
# see https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol
@ -715,7 +716,8 @@ class HostDatabase(object):
return list(map(Host.from_tuple, self.db.get(pattern)))
def add(self, host):
self.db.add(host.to_tuple())
host_tuple = host.to_tuple()
self.db.add(host_tuple)
def delete(self, host = None, **kw):
if host is None:
@ -833,6 +835,7 @@ class DHCPServer(object):
if not any([host.ip == ip for host in known_hosts]):
print('add', mac_address, ip, packet.host_name)
self.hosts.replace(Host(mac_address, ip, packet.host_name or '', time.time()))
ansiiprint.echo('DHCP client allocated - {} {} {}'.format(mac_address, ip, packet.host_name), '', 'i')
return ip
@property

View File

@ -78,6 +78,7 @@ class VXNetworkInstance():
if data != None and self.dhcp_flag != data.decode('ascii'):
self.dhcp_flag = ( data.decode('ascii') == 'True' )
if self.dhcp_flag:
ansiiprint.echo('Starting DHCP server for network "{}".'.format(self.ip_network), '', 'o')
dhcp_config = DHCPServer.DHCPServerConfiguration(
zk_conn=self.zk_conn,
ipaddr=self.ip_gateway,
@ -88,8 +89,9 @@ class VXNetworkInstance():
dns_servers=[]
)
self.dhcp_instance = DHCPServer.DHCPServer(dhcp_config)
self.dhcp_instance.start()
else:
self.dhcp_instance.remove()
self.dhcp_instance.close()
self.dhcp_instance = None