[X2Go-Commits] [python-x2go] 02/03: Allow user interaction via a HOOK if broker connection problems occur.

git-admin at x2go.org git-admin at x2go.org
Sat Apr 5 01:15:54 CEST 2014


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository python-x2go.

commit db36b7017c8b7677c32a6032c86cc6151b8702f8
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Sat Apr 5 01:13:03 2014 +0200

    Allow user interaction via a HOOK if broker connection problems occur.
---
 debian/changelog |    1 +
 x2go/client.py   |   35 +++++++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index c088159..191781c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -22,6 +22,7 @@ python-x2go (0.5.0.0-0x2go1) UNRELEASED; urgency=low
       allocated.
     - Capture broker connection problems during selectsession calls to the
       broker via a HOOK method.
+    - Allow user interaction via a HOOK if broker connection problems occur.
   * debian/control:
     + Add dependencies: python-requests, python-simplejson.
   * python-x2go.spec:
diff --git a/x2go/client.py b/x2go/client.py
index 428f352..a219950 100644
--- a/x2go/client.py
+++ b/x2go/client.py
@@ -383,15 +383,33 @@ class X2GoClient(object):
         """
         self.logger('HOOK_profile_auto_connect: profile ,,%s'' wants to be auto-connected to the X2Go server.' % profile_name, loglevel=log.loglevel_WARN)
 
-    def HOOK_broker_connection_exception(self, profile_id='UNKNOWN'):
+    def HOOK_broker_connection_exception(self, profile_name='UNKNOWN'):
         """\
         HOOK method: called if a session demands to auto connect the session profile.
 
-        @param profile_id: profile ID of a session that triggered this hook method
-        @type profile_id: C{str}
+        @param profile_name: profile name of a session that triggered this hook method
+        @type profile_name: C{str}
+
+        """
+        self.logger('HOOK_broker_connection_exception: a broker connection problem occurred triggered by an action on profile ,,%s''.' % profile_name, loglevel=log.loglevel_WARN)
+
+    def HOOK_broker_ignore_connection_problems(self, profile_name='UNKNOWN', is_profile_connected=False):
+        """\
+        HOOK method: called after a broker connection failed for a certain profile. This hook can
+        be used to allow the user to decide how to proceed after connection problems with the broker.
+
+        @param profile_name: profile name of a session that triggered this hook method
+        @type profile_name: C{str}
+        @param is_profile_connected: C{True} if the given session profile is already conneced to the server
+        @type is_profile_connected: C{bool}
+
+        @return: If this hook returns C{True}, the session startup/resumption will be continued, even if the
+            broker connection is down. (Default: broker connection problems cause session start-up to fail).
+        @rtype: C{bool}
 
         """
-        self.logger('HOOK_profile_broker_connection_exception: a broker connection problem occurred triggered by an action on profile ,,%s''.' % self.session_profiles.to_profile_name(profile_id), loglevel=log.loglevel_WARN)
+        self.logger('HOOK_broker_ignore_connection_problems: use this hook to let the user to decide how to proceed on connection failures (profile name: %s, connected: %s)' % (profile_name, is_profile_connected), loglevel=log.loglevel_WARN)
+        return False
 
     def HOOK_session_startup_failed(self, profile_name='UNKNOWN'):
         """\
@@ -937,8 +955,13 @@ class X2GoClient(object):
                 server = self.session_profiles.get_server_hostname(_profile_id)
                 _params['port'] = self.session_profiles.get_server_port(_profile_id)
                 _pkey = self.session_profiles.get_pkey_object(_profile_id)
-            except x2go_exceptions.X2GoBrokerConnectionException:
-                self.HOOK_broker_connection_exception(_profile_id)
+            except x2go_exceptions.X2GoBrokerConnectionException, e:
+                _profile_name = self.to_profile_name(_profile_id)
+                self.HOOK_broker_connection_exception(_profile_name)
+                if not self.HOOK_broker_ignore_connection_problems(_profile_name, is_profile_connected=self.is_profile_connected(_profile_name)):
+                    raise e
+                server = self.session_profiles.get_profile_config(_profile_name, parameter='host')[0]
+                _params['port'] = self.session_profiles.get_profile_config(_profile_name, parameter='sshport')
 
             if _pkey is not None:
                 self.logger('received PKey object for authentication, ignoring all other auth mechanisms', log.loglevel_NOTICE, tag=self._logger_tag)

--
Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/python-x2go.git



More information about the x2go-commits mailing list