# append subnet configuration to shared network subnet list
config['subnet'].append(subnet)
# append shared network configuration to config dictionary
dhcp['shared_network'].append(config)
returndhcp
defverify(dhcp):
if(dhcpisNone)or(dhcp['disabled']isTrue):
returnNone
# If DHCP is enabled we need one share-network
iflen(dhcp['shared_network'])==0:
raiseConfigError('No DHCP shared networks configured. At least one DHCP shared network must be configured.')
# A shared-network requires a subnet definition
fornetworkindhcp['shared_network']:
iflen(network['subnet'])==0:
raiseConfigError('No DHCP lease subnets configured for "{0}". At least one DHCP lease subnet must be configured for each shared network.'.format(network['name']))
# Inspect our subnet configuration
failover_names=[]
listen_ok=False
subnets=[]
fornetworkindhcp['shared_network']:
forsubnetinnetwork['subnet']:
# Subnet static route declaration requires destination and router
raiseConfigError('DHCP range start IP "{0}" is not in subnet "{1}" specified in network "{2}."'.format(range['start'],subnet['network'],network['name']))
raiseConfigError('DHCP range stop IP "{0}" is not in subnet "{1}" specified in network "{2}."'.format(range['stop'],subnet['network'],network['name']))
# Stop address must be greater or equal to start address
raiseConfigError('Exclude IP "{0}" is outside of the DHCP lease network "{1}" under shared network "{2}".'.format(exclude,subnet['network'],network['name']))
# At least one DHCP address range or static-mapping required
active_mapping=False
if(len(subnet['range'])==0):
formappinginsubnet['static_mapping']:
# we need at least one active mapping
if(notactive_mapping)and(notmapping['disable']):
active_mapping=True
else:
active_mapping=True
ifnotactive_mapping:
raiseConfigError('No DHCP address range or active static-mapping set for subnet "{0}".'.format(subnet['network']))
# Static IP address mappings require both an IP address and MAC address
formappinginsubnet['static_mapping']:
# Static IP address must be configured
ifnotmapping['ip_address']:
raiseConfigError('No static lease IP address specified for static mapping "{0}" under shared network name "{1}".'.format(mapping['name'],network['name']))
raiseConfigError('Static DHCP lease IP "{0}" under static mapping "{1}" in shared network "{2}" is outside DHCP lease network "{3}".'.format(mapping['ip_address'],mapping['name'],network['name'],subnet['network'],))
# Static mapping requires MAC address
ifnotmapping['mac_address']:
raiseConfigError('No static lease MAC address specified for static mapping "{0}" under shared network name "{1}".'.format(mapping['name'],network['name']))
#
# There must be one subnet connected to a real interface
raiseConfigError('None of the DHCP lease subnets are inside any configured subnet on broadcast interfaces. At least one lease subnet must be set such that DHCP server listens on a one broadcast interface')
returnNone
defgenerate(dhcp):
ifdhcpisNone:
returnNone
ifdhcp['disabled']isTrue:
print('Warning: DHCP server will be deactivated because it is disabled')