View | Details | Raw Unified | Return to bug 44873
Collapse All | Expand All

(-)a/ucs-school-4.1r2/ucs-school-import/usr/share/ucs-school-import/scripts/ucs-school-import (-62 / +62 lines)
 Lines 1723-1809   def create_network(schoolNr, network, iprange=None, defaultrouter=None, nameserv Link Here 
1723
	@param	nameserver	IP-Adress, if no netmask is profided it's derived from network
1723
	@param	nameserver	IP-Adress, if no netmask is profided it's derived from network
1724
	@param	netbiosserver	IP-Adress, if no netmask is profided it's derived from network
1724
	@param	netbiosserver	IP-Adress, if no netmask is profided it's derived from network
1725
	"""
1725
	"""
1726
	success = True
1726
	success = True
1727
	dn = None
1727
	dn = None
1728
	verify_school_ou(schoolNr, co, lo, baseDN)
1728
	verify_school_ou(schoolNr, co, lo, baseDN)
1729
1729
1730
	if check_network(schoolNr, network):
1730
	if check_network(schoolNr, network):
1731
		print "Network %s/%d exists in school %s!" % (network.network, network.prefixlen, schoolNr)
1731
		print "Network %s/%d exists in school %s!" % (network.network, network.prefixlen, schoolNr)
1732
		return (False, dn)
1732
		success = True
1733
1734
	print "generate network %s/%d" % (network.network, network.prefixlen)
1735
	if iprange:
1736
		print "iprange: %s-%s" % (iprange[0], iprange[1])
1737
	if defaultrouter:
1738
		print "defaultrouter: %s" % defaultrouter
1739
	if nameserver:
1740
		print "nameserver: %s" % nameserver
1741
	if netbiosserver:
1742
		print "netbiosserver: %s" % netbiosserver
1743
1744
	# WORKAROUND for Bug #14795
1745
	subnetbytes = 0
1746
	tmp = str(network.netmask).split('.')
1747
	for i in tmp:
1748
		if i == '255':
1749
			subnetbytes += 1
1750
		else:
1751
			break
1752
	subnet = '.'.join(str(network.network).split('.')[:subnetbytes])
1753
	# END WORKAROUND
1754
1755
	position.setDn("cn=dns,%s" % (baseDN))
1756
	object = dns_reverse_zone_module.object(co, lo, position=position, superordinate=superordinate)
1757
	object.open()
1758
	object['subnet'] = subnet
1759
	# the nameserver/SOA at the dns_reverse_zone object is always the ldap/master server!
1760
	object['nameserver'] = configRegistry['ldap/master']
1761
	object['contact'] = 'root@%s' % domainname
1762
	try:
1763
		create_object(object, ignore_exists=True)
1764
	except CreateObjectError:
1765
		pass
1766
1767
	position.setDn("cn=%s,cn=dhcp,%s" % (ldap.dn.escape_dn_chars(schoolNr.lower()), getDN(schoolNr)))
1768
	dhcp_service_objects = univention.admin.modules.lookup(
1769
		dhcp_service_module, co, lo, scope='sub', superordinate=superordinate,
1770
		base=baseDN, filter=univention.admin.filter.expression('cn', ldap.filter.escape_filter_chars(schoolNr.lower())))
1771
	if not dhcp_service_objects:
1772
		print 'ERROR: DHCP service object for %r not found' % (schoolNr.lower(),)
1773
		success = False
1774
	else:
1733
	else:
1775
		object = dhcp_subnet_module.object(co, lo, position=position, superordinate=dhcp_service_objects[0])
1734
		print "generate network %s/%d" % (network.network, network.prefixlen)
1735
		if iprange:
1736
			print "iprange: %s-%s" % (iprange[0], iprange[1])
1737
		if defaultrouter:
1738
			print "defaultrouter: %s" % defaultrouter
1739
		if nameserver:
1740
			print "nameserver: %s" % nameserver
1741
		if netbiosserver:
1742
			print "netbiosserver: %s" % netbiosserver
1743
1744
		# WORKAROUND for Bug #14795
1745
		subnetbytes = 0
1746
		tmp = str(network.netmask).split('.')
1747
		for i in tmp:
1748
			if i == '255':
1749
				subnetbytes += 1
1750
			else:
1751
				break
1752
		subnet = '.'.join(str(network.network).split('.')[:subnetbytes])
1753
		# END WORKAROUND
1754
1755
		position.setDn("cn=dns,%s" % (baseDN))
1756
		object = dns_reverse_zone_module.object(co, lo, position=position, superordinate=superordinate)
1776
		object.open()
1757
		object.open()
1777
		object['subnet'] = str(network.network)
1758
		object['subnet'] = subnet
1778
		object['subnetmask'] = str(network.netmask)
1759
		# the nameserver/SOA at the dns_reverse_zone object is always the ldap/master server!
1779
		object['broadcastaddress'] = str(network.broadcast)
1760
		object['nameserver'] = configRegistry['ldap/master']
1761
		object['contact'] = 'root@%s' % domainname
1780
		try:
1762
		try:
1781
			create_object(object, ignore_exists=True)
1763
			create_object(object, ignore_exists=True)
1782
		except CreateObjectError:
1764
		except CreateObjectError:
1783
			print '%r already existed - usually no problem' % (object.dn,)
1765
			pass
1784
1766
1785
	position.setDn("cn=networks,%s" % (getDN(schoolNr), ))
1767
		position.setDn("cn=%s,cn=dhcp,%s" % (ldap.dn.escape_dn_chars(schoolNr.lower()), getDN(schoolNr)))
1786
	object = network_module.object(co, lo, position=position, superordinate=superordinate)
1768
		dhcp_service_objects = univention.admin.modules.lookup(
1787
	object.open()
1769
			dhcp_service_module, co, lo, scope='sub', superordinate=superordinate,
1788
	object['name'] = '%s-%s' % (schoolNr.lower(), network.network)
1770
			base=baseDN, filter=univention.admin.filter.expression('cn', ldap.filter.escape_filter_chars(schoolNr.lower())))
1789
	object['netmask'] = str(network.prefixlen)
1771
		if not dhcp_service_objects:
1790
	object['network'] = str(network.network)
1772
			print 'ERROR: DHCP service object for %r not found' % (schoolNr.lower(),)
1791
	if iprange:
1773
			success = False
1792
		object['ipRange'] = [[str(iprange[0]), str(iprange[1])]]
1774
		else:
1793
	object['dhcpEntryZone'] = 'cn=%s,cn=dhcp,%s' % (schoolNr.lower(), getDN(schoolNr))
1775
			object = dhcp_subnet_module.object(co, lo, position=position, superordinate=dhcp_service_objects[0])
1794
	object['dnsEntryZoneForward'] = 'zoneName=%s,cn=dns,%s' % (domainname, baseDN)
1776
			object.open()
1795
	object['dnsEntryZoneReverse'] = 'zoneName=%s.in-addr.arpa,cn=dns,%s' % ('.'.join(reversed(subnet.split('.'))), baseDN)
1777
			object['subnet'] = str(network.network)
1778
			object['subnetmask'] = str(network.netmask)
1779
			object['broadcastaddress'] = str(network.broadcast)
1780
			try:
1781
				create_object(object, ignore_exists=True)
1782
			except CreateObjectError:
1783
				print '%r already existed - usually no problem' % (object.dn,)
1796
1784
1797
	try:
1785
		position.setDn("cn=networks,%s" % (getDN(schoolNr), ))
1798
		exists, dn = create_object(object, ignore_exists=True)
1786
		object = network_module.object(co, lo, position=position, superordinate=superordinate)
1799
	except CreateObjectError:
1787
		object.open()
1800
		success = False
1788
		object['name'] = '%s-%s' % (schoolNr.lower(), network.network)
1789
		object['netmask'] = str(network.prefixlen)
1790
		object['network'] = str(network.network)
1791
		if iprange:
1792
			object['ipRange'] = [[str(iprange[0]), str(iprange[1])]]
1793
		object['dhcpEntryZone'] = 'cn=%s,cn=dhcp,%s' % (schoolNr.lower(), getDN(schoolNr))
1794
		object['dnsEntryZoneForward'] = 'zoneName=%s,cn=dns,%s' % (domainname, baseDN)
1795
		object['dnsEntryZoneReverse'] = 'zoneName=%s.in-addr.arpa,cn=dns,%s' % ('.'.join(reversed(subnet.split('.'))), baseDN)
1796
1797
		try:
1798
			exists, dn = create_object(object, ignore_exists=True)
1799
		except CreateObjectError:
1800
			success = False
1801
1801
1802
	# set netbios and router for dhcp subnet
1802
	# set netbios and router for dhcp subnet
1803
	if defaultrouter:
1803
	if defaultrouter:
1804
		print 'setting default router'
1804
		print 'setting default router'
1805
		set_router_for_subnet(network, defaultrouter, schoolNr)
1805
		set_router_for_subnet(network, defaultrouter, schoolNr)
1806
1806
1807
	if netbiosserver:
1807
	if netbiosserver:
1808
		print 'setting netbios server'
1808
		print 'setting netbios server'
1809
		set_netbiosserver_for_subnet(network, netbiosserver, schoolNr)
1809
		set_netbiosserver_for_subnet(network, netbiosserver, schoolNr)

Return to bug 44873