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

(-)debian/control (-2 lines)
 Lines 49-55    Link Here 
49
 Alive Events while the DVS Session is open. Via HTTPS
49
 Alive Events while the DVS Session is open. Via HTTPS
50
 it listens for commands issued by the Sessionbroker.
50
 it listens for commands issued by the Sessionbroker.
51
51
52
53
Package: univention-thin-client-dvs-client
52
Package: univention-thin-client-dvs-client
54
Architecture: all
53
Architecture: all
55
Depends: rdesktop,
54
Depends: rdesktop,
 Lines 79-82    Link Here 
79
Description: UCS DVS Webaccess
78
Description: UCS DVS Webaccess
80
 This package provides the Webaccess html for UCS DVS.
79
 This package provides the Webaccess html for UCS DVS.
81
 Primarily intended for installation on an xrdp server.
80
 Primarily intended for installation on an xrdp server.
82
(-)debian/changelog (+6 lines)
 Lines 1-3    Link Here 
1
univention-dvs-sessionbroker (0.4.3-1) unstable; urgency=low
2
3
  * Query IP-address of Session-Broker for Web-Client (Bug #19955)
4
5
 -- Philipp Hahn <hahn@univention.de>  Fri, 10 Dec 2010 21:42:00 +0100
6
1
univention-dvs-sessionbroker (0.4.2-1) unstable; urgency=low
7
univention-dvs-sessionbroker (0.4.2-1) unstable; urgency=low
2
8
3
  * add option for base64 encoded passord file (Bug #18191)
9
  * add option for base64 encoded passord file (Bug #18191)
(-)univention-dvs-sessionbroker-client (-52 / +1 lines)
 Lines 46-53    Link Here 
46
import gettext
46
import gettext
47
import socket
47
import socket
48
import errno
48
import errno
49
import DNS
49
from univention.dvs.sessionbroker import SRV_Resolver
50
import random
51
try:
50
try:
52
	import cPickle as pickle
51
	import cPickle as pickle
53
except ImportError:
52
except ImportError:
 Lines 322-377    Link Here 
322
	conn2.close()
321
	conn2.close()
323
322
324
323
325
class SRV_Resolver:
326
	'''DNS SRV Record Resolver'''
327
328
	def __init__(self, srv_record):	# query entries for given SRV record from DNS
329
		self.servers = []
330
		DNS.ParseResolvConf()
331
		r = DNS.Request(name=srv_record, qtype='srv')
332
		for record in r.req().answers:
333
			prio, weight, port, target = record['data']
334
			self.servers.append((prio, weight, target, port))
335
336
	def __iter__(self):
337
		return self
338
339
	def next(self):
340
		if not self.servers:	# out of stock
341
			raise StopIteration
342
343
		self.servers.sort(self._serverCmp)
344
		minPriority = self.servers[0][0]
345
346
		weightIndex = zip(xrange(len(self.servers)), [x[1] for x in self.servers if x[0] == minPriority])
347
		if len(weightIndex) == 1:
348
			index, weight = weightIndex[0]
349
			prio, weight, host, port = self.servers[index]
350
			del self.servers[index]	# drop this server from the list
351
			return host, port
352
		else:
353
			weightSum = reduce(lambda x, y: (None, x[1]+y[1]), weightIndex, (None, 0))[1]
354
			offset = random.randint(0, weightSum-1)	# random variable
355
			for index, weight in weightIndex:
356
				if offset < weight:					# probability according to weight
357
					prio, weight, host, port = self.servers[index]
358
					del self.servers[index]	# drop this server from the list
359
					return host, port
360
				offset -= weight
361
362
	def _serverCmp(self, a, b):	# sort by prio (and weight)
363
		if a[0]!=b[0]:
364
			return cmp(a[0], b[0])
365
		else:
366
			return cmp(a[1], b[1])
367
368
	def getavailable(self):		# return first available host:port
369
		for host, port in self:	# try in order of SRV RR priority and weight
370
			retcode = subprocess.call(["nc", "-z", "-w1", host, '%s' % port])
371
			if retcode == 0:
372
				return host, port
373
		return (None , None)	# fallback for no open host:port
374
375
def connect_xrdp(response_dict, options):
324
def connect_xrdp(response_dict, options):
376
	"""Print the ip of the desktop vm to stdout for xrdp ."""
325
	"""Print the ip of the desktop vm to stdout for xrdp ."""
377
	print "ip: %s" % response_dict['desktop_host']
326
	print "ip: %s" % response_dict['desktop_host']
(-)univention/dvs/sessionbroker/__init__.py (+53 lines)
 Lines 30-32    Link Here 
30
# License with the Debian GNU/Linux or Univention distribution in file
30
# License with the Debian GNU/Linux or Univention distribution in file
31
# /usr/share/common-licenses/AGPL-3; if not, see
31
# /usr/share/common-licenses/AGPL-3; if not, see
32
# <http://www.gnu.org/licenses/>.
32
# <http://www.gnu.org/licenses/>.
33
import DNS
34
import random
35
import subprocess
36
class SRV_Resolver:
37
	'''DNS SRV Record Resolver'''
38
39
	def __init__(self, srv_record):
40
		"""query entries for given SRV record from DNS."""
41
		self.servers = []
42
		DNS.ParseResolvConf()
43
		r = DNS.Request(name=srv_record, qtype='srv')
44
		for record in r.req().answers:
45
			prio, weight, port, target = record['data']
46
			self.servers.append((prio, weight, target, port))
47
48
	def __iter__(self):
49
		return self
50
51
	def next(self):
52
		if not self.servers:	# out of stock
53
			raise StopIteration
54
55
		self.servers.sort(self._serverCmp)
56
		minPriority = self.servers[0][0]
57
58
		weightIndex = zip(xrange(len(self.servers)), [x[1] for x in self.servers if x[0] == minPriority])
59
		if len(weightIndex) == 1:
60
			index, weight = weightIndex[0]
61
			prio, weight, host, port = self.servers[index]
62
			del self.servers[index]	# drop this server from the list
63
			return host, port
64
		else:
65
			weightSum = reduce(lambda x, y: (None, x[1]+y[1]), weightIndex, (None, 0))[1]
66
			offset = random.randint(0, weightSum-1)	# random variable
67
			for index, weight in weightIndex:
68
				if offset < weight:					# probability according to weight
69
					prio, weight, host, port = self.servers[index]
70
					del self.servers[index]	# drop this server from the list
71
					return host, port
72
				offset -= weight
73
74
	def _serverCmp(self, a, b):	# sort by prio (and weight)
75
		if a[0]!=b[0]:
76
			return cmp(a[0], b[0])
77
		else:
78
			return cmp(a[1], b[1])
79
80
	def getavailable(self):		# return first available host:port
81
		for host, port in self:	# try in order of SRV RR priority and weight
82
			retcode = subprocess.call(["nc", "-z", "-w1", host, '%s' % port])
83
			if retcode == 0:
84
				return host, port
85
		return (None , None)	# fallback for no open host:port
(-)conffiles/var/www/DVS/index.html (-2 / +8 lines)
 Lines 310-317    Link Here 
310
		  
310
		  
311
<!-- Column 4 -->		  
311
<!-- Column 4 -->		  
312
	<td id="ServerKeyWidth" width="40%" valign="bottom">
312
	<td id="ServerKeyWidth" width="40%" valign="bottom">
313
	<br>&nbsp;&nbsp;<input type="text" name="Server" value="@%@interfaces/eth0/address@%@" size="41" id="editServer">
313
	<br>&nbsp;&nbsp;<input type="text" name="Server" value="@!@
314
	
314
import sys
315
from univention.dvs.sessionbroker import SRV_Resolver
316
srv_record = "_dvs_sessionbroker._tcp.%(domainname)s" % baseConfig
317
srv_resolver = SRV_Resolver(srv_record)
318
sessionbrokerhost, port = srv_resolver.getavailable()
319
sys.stdout.write("%s" % sessionbrokerhost)@!@" size="41" id="editServer">
320
@!@" size="41" id="editServer">
315
	</td>
321
	</td>
316
	</tr>
322
	</tr>
317
<!-- Row 2 -->
323
<!-- Row 2 -->

Return to bug 19955