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

(-)a/virtualization/univention-virtual-machine-manager-daemon/umc/python/uvmm/__init__.py (-4 / +1 lines)
 Lines 73-82   def _check_thread_error(self, thread, result, request): Link Here 
73
		if not isinstance(result, BaseException):
73
		if not isinstance(result, BaseException):
74
			return False
74
			return False
75
75
76
		def fake_func(self, request):
76
		self.thread_finished_callback(thread, result, request)
77
			raise thread.exc_info[0], thread.exc_info[1], thread.exc_info[2]
78
		fake_func.__name__ = 'thread %s' % (request.arguments[0],)
79
		error_handling(fake_func)(self, request)
80
		return True
77
		return True
81
78
82
	def _thread_finish(self, thread, result, request):
79
	def _thread_finish(self, thread, result, request):
(-)a/virtualization/univention-virtual-machine-manager-daemon/umc/python/uvmm/nodes.py (-10 lines)
 Lines 46-61   class Nodes(object): Link Here 
46
	UMC functions for UVMM node handling.
46
	UMC functions for UVMM node handling.
47
	"""
47
	"""
48
48
49
	def _node_thread_finished(self, thread, result, request, parent):
50
		"""
51
		This method is invoked when a threaded request for the
52
		navigation is finished. The result is send back to the
53
		client. If the result is an instance of BaseException an error
54
		is returned.
55
		"""
56
		if self._check_thread_error(thread, result, request):
57
			return
58
59
	@sanitize(nodePattern=SearchSanitizer(default='*'))
49
	@sanitize(nodePattern=SearchSanitizer(default='*'))
60
	def node_query(self, request):
50
	def node_query(self, request):
61
		"""
51
		"""
(-)a/virtualization/univention-virtual-machine-manager-daemon/umc/python/uvmm/profiles.py (-15 / +16 lines)
 Lines 38-48    Link Here 
38
38
39
from univention.management.console.log import MODULE
39
from univention.management.console.log import MODULE
40
from univention.management.console.protocol.definitions import MODULE_ERR_COMMAND_FAILED
40
from univention.management.console.protocol.definitions import MODULE_ERR_COMMAND_FAILED
41
from univention.management.console.ldap import machine_connection
41
42
42
from urlparse import urlsplit
43
from urlparse import urlsplit
43
from notifier import Callback
44
from notifier import Callback
44
45
45
from .udm import LDAP_Connection
46
from .tools import object2dict
46
from .tools import object2dict
47
47
48
_ = Translation('univention-management-console-modules-uvmm').translate
48
_ = Translation('univention-management-console-modules-uvmm').translate
 Lines 72-96   class Profiles(object): Link Here 
72
		'kvm-hvm': _('Full virtualization (KVM)'),
72
		'kvm-hvm': _('Full virtualization (KVM)'),
73
		}
73
		}
74
74
75
	@LDAP_Connection
75
	@machine_connection(write=False)
76
	def read_profiles(self, ldap_connection=None, ldap_position=None):
76
	def read_profiles(self, ldap_connection=None, ldap_position=None):
77
		"""
77
		"""
78
		Read all profiles from LDAP.
78
		Read all profiles from LDAP.
79
		"""
79
		"""
80
		base = "%s,%s" % (Profiles.PROFILE_RDN, ldap_position.getDn())
80
		base = "%s,%s" % (Profiles.PROFILE_RDN, ldap_position.getDn())
81
		try:
81
		res = ()
82
			res = uvmm_profile.lookup(
82
		if ldap_connection is not None:
83
				None,
83
			try:
84
				ldap_connection,
84
				res = uvmm_profile.lookup(
85
				'',
85
					None,
86
				base=base,
86
					ldap_connection,
87
				scope='sub',
87
					'',
88
				required=False,
88
					base=base,
89
				unique=False
89
					scope='sub',
90
			)
90
					required=False,
91
		except udm_error as ex:
91
					unique=False
92
			MODULE.error("Failed to read profiles: %s" % (ex,))
92
				)
93
			res = ()
93
			except udm_error as exc:
94
				MODULE.error("Failed to read profiles: %s" % (exc,))
94
		self.profiles = [(obj.dn, Profile(obj.info)) for obj in res]
95
		self.profiles = [(obj.dn, Profile(obj.info)) for obj in res]
95
96
96
	def _filter_profiles(self, node_pd):
97
	def _filter_profiles(self, node_pd):
(-)a/virtualization/univention-virtual-machine-manager-daemon/umc/python/uvmm/udm.py (-93 lines)
 Lines 1-93    Link Here 
1
# -*- coding: utf-8 -*-
2
#
3
# Univention Management Console
4
#  module: management of virtualization servers
5
#
6
# Copyright 2010-2015 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
import univention.admin.uldap as udm_uldap
34
import univention.admin.uexceptions as udm_errors
35
36
from ldap import LDAPError
37
38
# decorator for LDAP connections
39
_ldap_connection = None
40
_ldap_position = None
41
42
43
class LDAP_ConnectionError(Exception):
44
	"""
45
	Error connecting LDAP server.
46
	"""
47
	pass
48
49
50
def LDAP_Connection(func):
51
	"""
52
	This decorator function provides an open LDAP connection that can
53
	be accessed via the variable ldap_connection and a vaild position
54
	within the LDAP directory in the variable ldap_position. It reuses
55
	an already open connection or creates a new one. If the function
56
	fails with an LDAP error the decorators tries to reopen the LDAP
57
	connection and invokes the function again. if it still fails an
58
	LDAP_ConnectionError is raised.
59
60
	When using the decorator the method gets two additional keyword arguments.
61
62
	example:
63
	  @LDAP_Connection
64
	  def do_ldap_stuff(arg1, arg2, ldap_connection=None, ldap_positio=None):
65
		  ...
66
		  ldap_connection.searchDn(..., position=ldap_position)
67
		  ...
68
	"""
69
	def wrapper_func(*args, **kwargs):
70
		global _ldap_connection, _ldap_position
71
72
		if _ldap_connection is not None:
73
			lo = _ldap_connection
74
			po = _ldap_position
75
		else:
76
			try:
77
				lo, po = udm_uldap.getMachineConnection(ldap_master=False)
78
			except LDAPError, ex:
79
				raise LDAP_ConnectionError('Opening LDAP connection failed: %s' % (ex,))
80
81
		kwargs['ldap_connection'] = lo
82
		kwargs['ldap_position'] = po
83
		try:
84
			ret = func(*args, **kwargs)
85
			_ldap_connection = lo
86
			_ldap_position = po
87
			return ret
88
		except udm_errors.base as ex:
89
			raise LDAP_ConnectionError(str(ex))
90
91
		return []
92
93
	return wrapper_func

Return to bug 38634