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

(-)a/ucs-school-s4-branch-site/ucsschool-s4-branch-site.py (-21 / +9 lines)
 Lines 35-55   __package__ = '' # workaround for PEP 366 Link Here 
35
import listener
35
import listener
36
import univention.debug as ud
36
import univention.debug as ud
37
import univention.admin.uexceptions as udm_errors
37
import univention.admin.uexceptions as udm_errors
38
import univention.uldap
39
import univention.config_registry
38
import univention.config_registry
40
39
41
# import s4-connector listener module code, but don't generate pyc file
40
# import s4-connector listener module code, but don't generate pyc file
42
import os
41
import os
43
import sys
42
import sys
44
import ldap
43
import ldap
45
sys.dont_write_bytecode = True
46
import imp
44
import imp
47
s4_connector_listener_path = '/usr/lib/univention-directory-listener/system/s4-connector.py'
48
s4_connector_listener = imp.load_source('s4_connector', s4_connector_listener_path)
49
from ucsschool.lib.schoolldap import LDAP_Connection, MACHINE_READ, SchoolSearchBase
45
from ucsschool.lib.schoolldap import LDAP_Connection, MACHINE_READ, SchoolSearchBase
50
import traceback
46
import traceback
51
import subprocess
47
import subprocess
52
48
49
sys.dont_write_bytecode = True
50
s4_connector_listener_path = '/usr/lib/univention-directory-listener/system/s4-connector.py'
51
s4_connector_listener = imp.load_source('s4_connector', s4_connector_listener_path)
52
53
# Listener registration data
53
# Listener registration data
54
name = 'ucsschool-s4-branch-site'
54
name = 'ucsschool-s4-branch-site'
55
description = 'UCS@school S4 branch site module'
55
description = 'UCS@school S4 branch site module'
 Lines 76-82   def load_hooks(): Link Here 
76
		try:
76
		try:
77
			hook = imp.load_source(modulename, file_path)
77
			hook = imp.load_source(modulename, file_path)
78
		except Exception as ex:
78
		except Exception as ex:
79
			ud.debug(ud.LISTENER, ud.ERROR, "Error importing %s as %s:" % (file_path, modulename))
79
			ud.debug(ud.LISTENER, ud.ERROR, "Error importing %s as %s: %s" % (file_path, modulename, ex))
80
			ud.debug(ud.LISTENER, ud.ERROR, traceback.format_exc())
80
			ud.debug(ud.LISTENER, ud.ERROR, traceback.format_exc())
81
		hooks.append(hook)
81
		hooks.append(hook)
82
82
 Lines 84-97   def load_hooks(): Link Here 
84
84
85
85
86
def run_hooks(fname, *args):
86
def run_hooks(fname, *args):
87
	global _hooks
88
	for hook in _hooks:
87
	for hook in _hooks:
89
		if hasattr(hook, fname):
88
		if hasattr(hook, fname):
90
			try:
89
			try:
91
				hook_func = getattr(hook, fname)
90
				hook_func = getattr(hook, fname)
92
				hook_func(*args)
91
				hook_func(*args)
93
			except Exception as ex:
92
			except Exception as ex:
94
				ud.debug(ud.LISTENER, ud.ERROR, "Error running %s.%s():" % (hook.__name__, fname))
93
				ud.debug(ud.LISTENER, ud.ERROR, "Error running %s.%s(): %s" % (hook.__name__, fname, ex))
95
				ud.debug(ud.LISTENER, ud.ERROR, traceback.format_exc())
94
				ud.debug(ud.LISTENER, ud.ERROR, traceback.format_exc())
96
# </Hooks handling> ##############
95
# </Hooks handling> ##############
97
96
 Lines 107-120   _hooks = [] Link Here 
107
106
108
@LDAP_Connection(MACHINE_READ)
107
@LDAP_Connection(MACHINE_READ)
109
def on_load(ldap_machine_read=None, ldap_position=None):
108
def on_load(ldap_machine_read=None, ldap_position=None):
110
	global _ldap_hostdn
111
	global _hooks
109
	global _hooks
112
	_hooks = load_hooks()
110
	_hooks = load_hooks()
113
111
114
	global _ucsschool_service_specialization_filter
112
	global _ucsschool_service_specialization_filter
115
	try:
113
	try:
116
		res = ldap_machine_read.search(base=_ldap_hostdn, scope='base', attr=('univentionService',))
114
		res = ldap_machine_read.search(base=_ldap_hostdn, scope='base', attr=('univentionService',))
117
	except udm_errors.ldapError, e:
115
	except udm_errors.ldapError as e:
118
		ud.debug(ud.LISTENER, ud.ERROR, '%s: Error accessing LDAP: %s' % (name, e))
116
		ud.debug(ud.LISTENER, ud.ERROR, '%s: Error accessing LDAP: %s' % (name, e))
119
		return
117
		return
120
118
 Lines 189-195   STD_S4_SRV_RECORDS = { Link Here 
189
187
190
@LDAP_Connection(MACHINE_READ)
188
@LDAP_Connection(MACHINE_READ)
191
def visible_samba4_school_dcs(excludeDN=None, ldap_machine_read=None, ldap_position=None):
189
def visible_samba4_school_dcs(excludeDN=None, ldap_machine_read=None, ldap_position=None):
192
	global filter
193
	_visible_samba4_school_dcs = []
190
	_visible_samba4_school_dcs = []
194
	try:
191
	try:
195
		res = ldap_machine_read.search(base=ldap_position.getDn(), filter=filter, attr=['cn', 'associatedDomain'])
192
		res = ldap_machine_read.search(base=ldap_position.getDn(), filter=filter, attr=['cn', 'associatedDomain'])
 Lines 201-218   def visible_samba4_school_dcs(excludeDN=None, ldap_machine_read=None, ldap_posit Link Here 
201
				else:
198
				else:
202
					domainname = _local_domainname
199
					domainname = _local_domainname
203
				_visible_samba4_school_dcs.append('.'.join((obj['cn'][0], domainname)))
200
				_visible_samba4_school_dcs.append('.'.join((obj['cn'][0], domainname)))
204
	except udm_errors.ldapError, e:
201
	except udm_errors.ldapError as e:
205
		ud.debug(ud.LISTENER, ud.ERROR, '%s: Error accessing LDAP: %s' % (name, e))
202
		ud.debug(ud.LISTENER, ud.ERROR, '%s: Error accessing LDAP: %s' % (name, e))
206
203
207
	return _visible_samba4_school_dcs
204
	return _visible_samba4_school_dcs
208
205
209
206
210
def update_ucr_overrides(excludeDN=None):
207
def update_ucr_overrides(excludeDN=None):
211
	global STD_S4_SRV_RECORDS
212
	global _record_type
213
	global _local_domainname
214
	global _s4_connector_restart
208
	global _s4_connector_restart
215
	global _relativeDomainName_trigger_set
216
209
217
	server_fqdn_list = visible_samba4_school_dcs(excludeDN=excludeDN)
210
	server_fqdn_list = visible_samba4_school_dcs(excludeDN=excludeDN)
218
	server_fqdn_list.sort()
211
	server_fqdn_list.sort()
 Lines 299-308   def update_ucr_overrides(excludeDN=None): Link Here 
299
292
300
@LDAP_Connection(MACHINE_READ)
293
@LDAP_Connection(MACHINE_READ)
301
def trigger_sync_ucs_to_s4(ldap_machine_read=None, ldap_position=None):
294
def trigger_sync_ucs_to_s4(ldap_machine_read=None, ldap_position=None):
302
	global _record_type
303
	global _local_domainname
304
	global _relativeDomainName_trigger_set
305
306
	for relativeDomainName in list(_relativeDomainName_trigger_set):
295
	for relativeDomainName in list(_relativeDomainName_trigger_set):
307
		# trigger S4 Connector
296
		# trigger S4 Connector
308
		ldap_filter = '(&(univentionObjectType=dns/%s)(zoneName=%s)(relativeDomainName=%s))' % (_record_type, _local_domainname, relativeDomainName)
297
		ldap_filter = '(&(univentionObjectType=dns/%s)(zoneName=%s)(relativeDomainName=%s))' % (_record_type, _local_domainname, relativeDomainName)
 Lines 312-318   def trigger_sync_ucs_to_s4(ldap_machine_read=None, ldap_position=None): Link Here 
312
			for (record_dn, obj) in res:
301
			for (record_dn, obj) in res:
313
				s4_connector_listener.handler(record_dn, obj, obj, 'm')
302
				s4_connector_listener.handler(record_dn, obj, obj, 'm')
314
				_relativeDomainName_trigger_set.remove(relativeDomainName)
303
				_relativeDomainName_trigger_set.remove(relativeDomainName)
315
		except udm_errors.ldapError, e:
304
		except udm_errors.ldapError as e:
316
			ud.debug(ud.LISTENER, ud.ERROR, '%s: Error accessing LDAP: %s' % (name, e))
305
			ud.debug(ud.LISTENER, ud.ERROR, '%s: Error accessing LDAP: %s' % (name, e))
317
306
318
307
 Lines 369-375   def handler(dn, new, old, command): Link Here 
369
358
370
def postrun():
359
def postrun():
371
	global _s4_connector_restart
360
	global _s4_connector_restart
372
	global _relativeDomainName_trigger_set
373
361
374
	if not listener.configRegistry.is_true('connector/s4/autostart', True):
362
	if not listener.configRegistry.is_true('connector/s4/autostart', True):
375
		univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, '%s: S4 Connector restart skipped, disabled via connector/s4/autostart.' % (name,))
363
		univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, '%s: S4 Connector restart skipped, disabled via connector/s4/autostart.' % (name,))

Return to bug 45478