[X2Go-Commits] x2gobroker.git - build-main (branch) updated: 0.0.2.2-2-gb0cefb7

X2Go dev team git-admin at x2go.org
Fri Jun 7 23:22:36 CEST 2013


The branch, build-main has been updated
       via  b0cefb72b896ea34c724d0a8b79f9f8edadff7b5 (commit)
      from  285e9cc89d32b49996954fd4a3f6e4f4ad3b4ee0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 debian/changelog                           |    4 ++-
 etc/broker/x2gobroker-sessionprofiles.conf |    8 +++---
 x2gobroker/brokers/base_broker.py          |   12 +++++++++
 x2gobroker/brokers/inifile_broker.py       |   22 +++++++++++++++++
 x2gobroker/tests/test_broker_inifile.py    |   37 ++++++++++++++++++++++++++++
 5 files changed, 79 insertions(+), 4 deletions(-)

The diff of changes is:
diff --git a/debian/changelog b/debian/changelog
index a6b1619..d9e5f35 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
 x2gobroker (0.0.2.3-0~x2go1) UNRELEASED; urgency=low
 
-  * Continue development...
+  * New upstream version (0.0.2.3):
+    - inifile broker: Allow explicit specification combinations of
+      »<hostname> (<address>)« in host= session profile field. (Fixes: #218).
 
  -- Mike Gabriel <mike.gabriel at das-netzwerkteam.de>  Wed, 22 May 2013 17:42:12 +0200
 
diff --git a/etc/broker/x2gobroker-sessionprofiles.conf b/etc/broker/x2gobroker-sessionprofiles.conf
index 84bfc44..6656d9a 100644
--- a/etc/broker/x2gobroker-sessionprofiles.conf
+++ b/etc/broker/x2gobroker-sessionprofiles.conf
@@ -134,7 +134,7 @@ broker-session-autologin=true
 
 [pool-B-server-D-LXDE]
 user=
-host=server-d.domain.internet
+host=server-d (server-d.domain.internet)
 name=LXDE - srv-D
 command=LXDE
 acl-groups-allow=admins
@@ -156,7 +156,9 @@ acl-any-order=deny-allow
 ## get this session profile into their X2Go Clients.
 ##
 ## The pool-C contains 6 X2Go Servers that serve all students users together
-## as a load balance server farm.
+## as a load balance server farm. The servers' hostnames are s-E1, s-E2, ...
+## (as found in /etc/hostname). The hosts, however, are not configured in DNS
+## so we give their IPs explicitly (also works for IPv6).
 ##
 ## Make sure to install x2gobroker-agent on all these 6 X2Go Servers. Also make
 ## sure to once run the script x2gobroker-keygen on the broker host and once
@@ -168,7 +170,7 @@ acl-any-order=deny-allow
 
 [pool-C-XFCE]
 user=
-host=s-E1.pool-c.domain.local,s-E2.pool-c.domain.local,s-E3.pool-c.domain.local,s-E4.pool-c.domain.local,s-E5.pool-c.domain.local,s-E6.pool-c.domain.local
+host=s-E1 (10.0.2.11),s-E2 (10.0.2.12),s-E3 (10.0.2.13),s-E4 (10.0.2.14),s-E5 (10.0.2.15)
 name=XFCE - pool-C
 command=XFCE
 acl-users-allow=testuser-A,testuser-B
diff --git a/x2gobroker/brokers/base_broker.py b/x2gobroker/brokers/base_broker.py
index 2750b43..bb1656b 100644
--- a/x2gobroker/brokers/base_broker.py
+++ b/x2gobroker/brokers/base_broker.py
@@ -928,6 +928,12 @@ class X2GoBroker(object):
             if server_list: best_server = server_list[0]
             else: return { 'server': 'no-server-available', 'port': profile[u'sshport'], }
 
+        # if we have an explicit IP address for best_server, let's use that instead...
+        try:
+            best_server = profile['host={hostname}'.format(hostname=best_server)]
+        except KeyError:
+            pass
+
         selected_session = {
             'server': best_server,
             'port': profile[u'sshport'],
@@ -944,6 +950,12 @@ class X2GoBroker(object):
                     server_name = session_list[0].split('|')[3]
                     session_info = session_list[0]
 
+                    # if we have an explicit IP address for server_name, let's use that instead...
+                    try:
+                        server_name = profile['host={hostname}'.format(hostname=server_name)]
+                    except KeyError:
+                        pass
+
                     selected_session.update({
                         'server': server_name,
                         'session_info': session_info,
diff --git a/x2gobroker/brokers/inifile_broker.py b/x2gobroker/brokers/inifile_broker.py
index 7ab229f..a7c6537 100644
--- a/x2gobroker/brokers/inifile_broker.py
+++ b/x2gobroker/brokers/inifile_broker.py
@@ -26,6 +26,9 @@ and does not support load balancing.
 __NAME__ = 'x2gobroker-pylib'
 
 # modules
+import copy
+import netaddr
+import re
 
 # Python X2GoBroker modules
 import base_broker as base
@@ -76,6 +79,25 @@ class X2GoBroker(base.X2GoBroker):
                 del profile[key]
             if key == 'default':
                 del profile[key]
+            if key == 'host':
+                _hosts = copy.deepcopy(profile[key])
+                profile[key] = []
+                for host in _hosts:
+                    if re.match('^.*\ \(.*\)$', host):
+                        _hostname = host.split(' ')[0]
+                        _address = host.split(' ')[1][1:-1]
+
+                        # test if _address is a valid hostname, a valid DNS name or an IPv4/IPv6 address
+                        if (re.match('(?!-)[A-Z\d-]{1,63}(?<!-)$', _hostname, flags=re.IGNORECASE) or \
+                            re.match('(?=^.{1,254}$)(^(?:(?!\d|-)[a-zA-Z0-9\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)', _hostname, flags=re.IGNORECASE)) and \
+                           (re.match('(?=^.{1,254}$)(^(?:(?!\d|-)[a-zA-Z0-9\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)', _address, flags=re.IGNORECASE) or \
+                            netaddr.valid_ipv4(_address) or netaddr.valid_ipv6(_address)):
+
+                            profile["host={hostname}".format(hostname=_hostname)] = _address
+
+                        profile[key].append(_hostname)
+                    else:
+                        profile[key].append(host)
         return profile
 
     def get_profile_broker(self, profile_id):
diff --git a/x2gobroker/tests/test_broker_inifile.py b/x2gobroker/tests/test_broker_inifile.py
index b7181a4..5952f35 100644
--- a/x2gobroker/tests/test_broker_inifile.py
+++ b/x2gobroker/tests/test_broker_inifile.py
@@ -455,6 +455,23 @@ host = test-2.local
 name = TEST-3
 host = test-3.local
 sshport = 44566
+
+[testprofile4]
+name = TEST-4
+host = test-4 (10.0.2.4)
+
+[testprofile5]
+name = TEST-5
+host = test-5.local (10.0.2.5)
+
+[testprofile6]
+name = TEST-6
+host = test-6.local (test-6.extern)
+
+[testprofile7]
+name = TEST-7
+host = test-7 (-test-6.extern)
+
 """
         tfs = tempfile.NamedTemporaryFile()
         print >> tfs, _session_profiles
@@ -472,9 +489,29 @@ sshport = 44566
             'server': 'test-3.local',
             'port': 44566,
         }
+        _expected_result_4 = {
+            'server': '10.0.2.4',
+            'port': 22,
+        }
+        _expected_result_5 = {
+            'server': '10.0.2.5',
+            'port': 22,
+        }
+        _expected_result_6 = {
+            'server': 'test-6.extern',
+            'port': 22,
+        }
+        _expected_result_7 = {
+            'server': 'test-7',
+            'port': 22,
+        }
         self.assertEqual(inifile_backend.select_session('testprofile1'), _expected_result_1)
         self.assertEqual(inifile_backend.select_session('testprofile2'), _expected_result_2)
         self.assertEqual(inifile_backend.select_session('testprofile3'), _expected_result_3)
+        self.assertEqual(inifile_backend.select_session('testprofile4'), _expected_result_4)
+        self.assertEqual(inifile_backend.select_session('testprofile5'), _expected_result_5)
+        self.assertEqual(inifile_backend.select_session('testprofile6'), _expected_result_6)
+        self.assertEqual(inifile_backend.select_session('testprofile7'), _expected_result_7)
 
 
 def test_suite():


hooks/post-receive
-- 
x2gobroker.git (HTTP(S) Session broker for X2Go)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "x2gobroker.git" (HTTP(S) Session broker for X2Go).




More information about the x2go-commits mailing list