Package x2go :: Module client
[frames] | no frames]

Source Code for Module x2go.client

   1  # -*- coding: utf-8 -*- 
   2   
   3  # Copyright (C) 2010-2014 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de> 
   4   
   5  # 
   6  # Python X2Go is free software; you can redistribute it and/or modify 
   7  # it under the terms of the GNU Affero General Public License as published by 
   8  # the Free Software Foundation; either version 3 of the License, or 
   9  # (at your option) any later version. 
  10  # 
  11  # Python X2Go is distributed in the hope that it will be useful, 
  12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  14  # GNU Affero General Public License for more details. 
  15  # 
  16  # You should have received a copy of the GNU Affero General Public License 
  17  # along with this program; if not, write to the 
  18  # Free Software Foundation, Inc., 
  19  # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 
  20   
  21  """\ 
  22  L{X2GoClient} is a public API class. Use this class in your Python X2Go based  
  23  applications.  Use it as a parent class for your own object oriented L{X2GoClient}'ish 
  24  class implementation. 
  25   
  26  Supported Features 
  27  ================== 
  28      Supported features are: 
  29   
  30          - X2Go multi-session management 
  31          - keep track of initiated sessions 
  32          - grant access to X2Go client config files: C{settings}, C{printing}, C{sessions} 
  33            and C{xconfig} (Windows only) as normally found in C{~/.x2goclient} 
  34          - instantiate an X2Go session by a set of Python parameters 
  35          - load a session profile from x2goclient's C{sessions} configuration file 
  36            and start the---profile-based pre-configured---session 
  37          - sharing of local folders with remote X2Go sessions 
  38          - enabling and mangaging X2Go printing (real printing, viewing as PDF, saving 
  39            to a local folder or executing a custom »print« command 
  40          - transparent tunneling of audio (Pulseaudio, ESD) 
  41          - sharing of other desktops 
  42          - LDAP support for X2Go server clusters (NOT IMPLEMENTED YET) 
  43   
  44  Non-Profile Sessions 
  45  ==================== 
  46      A new non-profile based X2Go session within an L{X2GoClient} instance is setup in the  
  47      following way: 
  48   
  49          - import the Python X2Go module and call the session constructor:: 
  50   
  51              import x2go 
  52              x2go_client = x2go.X2GoClient() 
  53   
  54          - register a new L{X2GoClient} session; this creates an L{X2GoSession} instance 
  55            and calls its constructor method:: 
  56   
  57              x2go_sess_uuid = x2go_client.register_session(<many-options>) 
  58   
  59          - connect to the session's remote X2Go server (SSH/Paramiko):: 
  60   
  61              x2go_client.connect_session(x2go_sess_uuid) 
  62   
  63          - via the connected X2Go client session you can start or resume a remote  
  64            X-windows session on an X2Go server now:: 
  65   
  66              x2go_client.start_session(x2go_sess_uuid) 
  67   
  68            resp.:: 
  69   
  70              x2go_client.resume_session(x2go_sess_uuid, session_name=<session_name_of_resumable_session>) 
  71   
  72          - a list of available sessions on the respective server (for resuming) can be obtained in 
  73            this way:: 
  74   
  75              x2go_client.list_sessions(x2go_sess_uuid, session_name=<session_name_of_resumable_session>) 
  76   
  77  Profiled Sessions 
  78  ================= 
  79      A new profile based X2Go session (i.e. using pre-defined session profiles) within an  
  80      L{X2GoClient} instance is setup in a much easier way: 
  81   
  82          - import the Python X2Go module and call the session constructor:: 
  83   
  84              import x2go 
  85              x2go_client = x2go.X2GoClient() 
  86   
  87          - register an X2GoClient session based on a pre-configured session profile:: 
  88   
  89              x2go_sess_uuid = x2go_client.register_session(profile_name=<session_profile_name>) 
  90   
  91          - or alternatively by the profile id in the »sessions« file (the name of the [<section>] 
  92            in the »sessions« file:: 
  93   
  94              x2go_sess_uuid = x2go_client.register_session(profile_id=<session_profile_id>) 
  95   
  96          - now you proceed in a similar way as shown above:: 
  97   
  98              x2go_client.connect_session(x2go_sess_uuid) 
  99              x2go_client.start_session(x2go_sess_uuid) 
 100   
 101            resp.:: 
 102   
 103              x2go_client.resume_session(x2go_sess_uuid, session_name=<session_name_of_resumable_session>) 
 104   
 105   
 106  Session Suspending/Terminating 
 107  ============================== 
 108   
 109      You can suspend or terminate your sessions by calling the follwing commands:: 
 110   
 111          x2go_client.suspend_session(x2go_sess_uuid) 
 112   
 113      resp.:: 
 114   
 115          x2go_client.terminate_session(x2go_sess_uuid) 
 116   
 117  """ 
 118  __NAME__ = 'x2goclient-pylib' 
 119   
 120  #modules 
 121  import copy 
 122  import sys 
 123  import types 
 124  import os 
 125   
 126  # Python X2Go modules 
 127  from registry import X2GoSessionRegistry 
 128  from guardian import X2GoSessionGuardian 
 129  from cache import X2GoListSessionsCache 
 130  import x2go_exceptions 
 131  import log 
 132  import utils 
 133   
 134  # we hide the default values from epydoc (that's why we transform them to _UNDERSCORE variables) 
 135  from defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS 
 136  from defaults import LOCAL_HOME as _LOCAL_HOME 
 137  from defaults import CURRENT_LOCAL_USER as _CURRENT_LOCAL_USER 
 138  from defaults import X2GO_CLIENT_ROOTDIR as _X2GO_CLIENT_ROOTDIR 
 139  from defaults import X2GO_SESSIONS_ROOTDIR as _X2GO_SESSIONS_ROOTDIR 
 140  from defaults import X2GO_SSH_ROOTDIR as _X2GO_SSH_ROOTDIR 
 141  from defaults import X2GO_SESSIONPROFILES_FILENAME as _X2GO_SESSIONPROFILES_FILENAME 
 142  from defaults import X2GO_SETTINGS_FILENAME as _X2GO_SETTINGS_FILENAME 
 143  from defaults import X2GO_PRINTING_FILENAME as _X2GO_PRINTING_FILENAME 
 144  from defaults import X2GO_XCONFIG_FILENAME as _X2GO_XCONFIG_FILENAME 
 145  from defaults import PUBAPP_MAX_NO_SUBMENUS as _PUBAPP_MAX_NO_SUBMENUS 
 146   
 147  from defaults import BACKENDS_CONTROLSESSION as _BACKENDS_CONTROLSESSION 
 148  from defaults import BACKENDS_TERMINALSESSION as _BACKENDS_TERMINALSESSION 
 149  from defaults import BACKENDS_SERVERSESSIONINFO as _BACKENDS_SERVERSESSIONINFO 
 150  from defaults import BACKENDS_SERVERSESSIONLIST as _BACKENDS_SERVERSESSIONLIST 
 151  from defaults import BACKENDS_PROXY as _BACKENDS_PROXY 
 152  from defaults import BACKENDS_SESSIONPROFILES as _BACKENDS_SESSIONPROFILES 
 153  from defaults import BACKENDS_CLIENTSETTINGS as _BACKENDS_CLIENTSETTINGS 
 154  from defaults import BACKENDS_CLIENTPRINTING as _BACKENDS_CLIENTPRINTING 
 155   
 156  import x2go.backends.control as control 
 157  import x2go.backends.terminal as terminal 
 158  import x2go.backends.info as info 
 159  import x2go.backends.proxy as proxy 
 160  import x2go.backends.profiles as profiles 
 161  import x2go.backends.settings as settings 
 162  import x2go.backends.printing as printing 
 163   
 164  if _X2GOCLIENT_OS == 'Windows': 
 165      from xserver import X2GoClientXConfig, X2GoXServer 
 166      from pulseaudio import X2GoPulseAudio 
167 168 169 -class X2GoClient(object):
170 """\ 171 The X2GoClient implements _THE_ public Python X2Go API. With it you can 172 construct your own X2Go client application in Python. 173 174 Most methods in this class require that you have registered a session 175 with a remote X2Go server (passing of session options, initialization of the 176 session object etc.) and connected to it (authentication). For these two steps 177 use these methods: L{X2GoClient.register_session()} and L{X2GoClient.connect_session()}. 178 179 """ 180 181 lang = 'en' 182
183 - def __init__(self, 184 control_backend=control.X2GoControlSession, 185 terminal_backend=terminal.X2GoTerminalSession, 186 info_backend=info.X2GoServerSessionInfo, 187 list_backend=info.X2GoServerSessionList, 188 proxy_backend=proxy.X2GoProxy, 189 profiles_backend=profiles.X2GoSessionProfiles, 190 settings_backend=settings.X2GoClientSettings, 191 printing_backend=printing.X2GoClientPrinting, 192 client_rootdir=None, 193 sessions_rootdir=None, 194 ssh_rootdir=None, 195 start_xserver=False, 196 start_pulseaudio=False, 197 use_cache=False, 198 use_listsessions_cache=False, 199 auto_update_listsessions_cache=False, 200 auto_update_listdesktops_cache=False, 201 auto_update_listmounts_cache=False, 202 auto_update_sessionregistry=False, 203 auto_register_sessions=False, 204 no_auto_reg_pubapp_sessions=False, 205 refresh_interval=5, 206 pulseaudio_installdir=os.path.join(os.getcwd(), 'pulseaudio'), 207 logger=None, loglevel=log.loglevel_DEFAULT):
208 """\ 209 @param control_backend: X2Go control session backend to use 210 @type control_backend: C{class} 211 @param terminal_backend: X2Go terminal session backend to use 212 @type terminal_backend: C{class} 213 @param info_backend: X2Go session info backend to use 214 @type info_backend: C{class} 215 @param list_backend: X2Go session list backend to use 216 @type list_backend: C{class} 217 @param proxy_backend: X2Go proxy backend to use 218 @type proxy_backend: C{class} 219 @param profiles_backend: X2Go session profiles backend to use 220 @type profiles_backend: C{class} 221 @param settings_backend: X2Go client settings backend to use 222 @type settings_backend: C{class} 223 @param printing_backend: X2Go client printing backend to use 224 @type printing_backend: C{class} 225 @param client_rootdir: client base dir (default: ~/.x2goclient) 226 @type client_rootdir: C{str} 227 @param sessions_rootdir: sessions base dir (default: ~/.x2go) 228 @type sessions_rootdir: C{str} 229 @param ssh_rootdir: ssh base dir (default: ~/.ssh) 230 @type ssh_rootdir: C{str} 231 @param start_xserver: start XServer when registering an L{X2GoClient} instance 232 @type start_xserver: C{bool} 233 @param start_pulseaudio: start Pulseaudio daemon when registering an L{X2GoClient} instance 234 @type start_pulseaudio: C{bool} 235 @param use_cache: alias for C{use_listsessions_cache} 236 @type use_cache: C{bool} 237 @param use_listsessions_cache: activate the X2Go session list cache in (L{X2GoListSessionsCache}) 238 @type use_listsessions_cache: C{bool} 239 @param auto_update_listsessions_cache: activate automatic updates of the X2Go session list cache (L{X2GoListSessionsCache}) 240 @type auto_update_listsessions_cache: C{bool} 241 @param auto_update_listdesktops_cache: activate automatic updates of desktop lists in (L{X2GoListSessionsCache}) 242 @type auto_update_listdesktops_cache: C{bool} 243 @param auto_update_listmounts_cache: activate automatic updates of mount lists in (L{X2GoListSessionsCache}) 244 @type auto_update_listmounts_cache: C{bool} 245 @param auto_update_sessionregistry: activate automatic updates of the X2Go session registry 246 @type auto_update_sessionregistry: C{bool} 247 @param auto_register_sessions: activate automatic X2Go session registration 248 @type auto_register_sessions: C{bool} 249 @param no_auto_reg_pubapp_sessions: skip automatic X2Go session registration for suspended/running published applications sessions 250 @type no_auto_reg_pubapp_sessions: C{bool} 251 @param refresh_interval: refresh session list cache and session status every C{refresh_interval} seconds 252 @type refresh_interval: C{int} 253 @param pulseaudio_installdir: install path of Pulseaudio binary 254 @type pulseaudio_installdir: C{str} 255 @param logger: you can pass an L{X2GoLogger} object to the 256 L{X2GoClient} constructor 257 @type logger: L{X2GoLogger} instance 258 @param loglevel: if no X2GoLogger object has been supplied a new one will be 259 constructed with the given loglevel 260 @type loglevel: C{int} 261 262 """ 263 self.listsessions_cache = None 264 265 if logger is None: 266 self.logger = log.X2GoLogger(loglevel=loglevel) 267 else: 268 self.logger = copy.deepcopy(logger) 269 self._logger_tag = __NAME__ 270 if self.logger.tag is None: 271 self.logger.tag = self._logger_tag 272 273 self.control_backend = control_backend 274 self.terminal_backend = terminal_backend 275 self.info_backend = info_backend 276 self.list_backend = list_backend 277 self.proxy_backend = proxy_backend 278 self.profiles_backend = profiles_backend 279 self.settings_backend = settings_backend 280 self.printing_backend = printing_backend 281 282 self._detect_backend_classes() 283 284 self.client_rootdir = client_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_CLIENT_ROOTDIR)) 285 self.sessions_rootdir = sessions_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_SESSIONS_ROOTDIR)) 286 self.ssh_rootdir = ssh_rootdir or os.path.normpath(os.path.join(_LOCAL_HOME, _X2GO_SSH_ROOTDIR)) 287 288 self.client_rootdir = os.path.normpath(self.client_rootdir) 289 self.sessions_rootdir = os.path.normpath(self.sessions_rootdir) 290 self.ssh_rootdir = os.path.normpath(self.ssh_rootdir) 291 292 self.pulseaudio_installdir = os.path.normpath(pulseaudio_installdir) 293 294 if self.client_rootdir is not None: 295 self._has_custom_client_rootdir = True 296 _sessions_config_file = os.path.join(self.client_rootdir, _X2GO_SESSIONPROFILES_FILENAME) 297 _settings_config_file = os.path.join(self.client_rootdir, _X2GO_SETTINGS_FILENAME) 298 _printing_config_file = os.path.join(self.client_rootdir, _X2GO_PRINTING_FILENAME) 299 _xconfig_config_file = os.path.join(self.client_rootdir, _X2GO_XCONFIG_FILENAME) 300 self.session_profiles = self.profiles_backend(config_files=[_sessions_config_file], logger=self.logger) 301 self.client_settings = self.settings_backend(config_files=[_settings_config_file], logger=self.logger) 302 self.client_printing = self.printing_backend(config_files=[_printing_config_file], client_instance=self, logger=self.logger) 303 else: 304 self.session_profiles = self.profiles_backend(logger=self.logger) 305 self.client_settings = self.settings_backend(logger=self.logger) 306 self.client_printing = self.printing_backend(client_instance=self, logger=self.logger) 307 308 if _X2GOCLIENT_OS == 'Windows' and start_xserver: 309 310 if self.client_rootdir: 311 self.client_xconfig = X2GoClientXConfig(config_files=[_xconfig_config_file], logger=self.logger) 312 else: 313 self.client_xconfig = X2GoClientXConfig(logger=self.logger) 314 315 if not self.client_xconfig.known_xservers: 316 self.HOOK_no_known_xserver_found() 317 else: 318 319 _last_display = None 320 if type(start_xserver) is types.BooleanType: 321 p_xs_name = self.client_xconfig.preferred_xserver_names[0] 322 _last_display = self.client_xconfig.get_xserver_config(p_xs_name)['last_display'] 323 self.client_xconfig.detect_unused_xdisplay_port(p_xs_name) 324 p_xs = (p_xs_name, self.client_xconfig.get_xserver_config(p_xs_name)) 325 elif type(start_xserver) is types.StringType: 326 _last_display = self.client_xconfig.get_xserver_config(start_xserver)['last_display'] 327 self.client_xconfig.detect_unused_xdisplay_port(start_xserver) 328 p_xs = (start_xserver, self.client_xconfig.get_xserver_config(start_xserver)) 329 330 if not self.client_xconfig.running_xservers: 331 332 if p_xs is not None: 333 self.xserver = X2GoXServer(p_xs[0], p_xs[1], logger=self.logger) 334 335 else: 336 337 if p_xs is not None and _last_display is not None: 338 # 339 # FIXME: this trick is nasty, client implementation should rather cleanly shutdown launch X-server processes 340 # 341 # re-use a left behind X-server instance of a previous/crashed run of Python X2Go Client 342 self.logger('found a running (and maybe stray) X-server, trying to re-use it on X DISPLAY port: %s' % _last_display, loglevel=log.loglevel_WARN) 343 os.environ.update({'DISPLAY': str(_last_display)}) 344 else: 345 # presume the running XServer listens on :0 346 self.logger('using fallback display for X-server: localhost:0', loglevel=log.loglevel_WARN) 347 os.environ.update({'DISPLAY': 'localhost:0'}) 348 349 if _X2GOCLIENT_OS == 'Windows' and start_pulseaudio: 350 self.pulseaudio = X2GoPulseAudio(path=self.pulseaudio_installdir, client_instance=self, logger=self.logger) 351 352 self.auto_register_sessions = auto_register_sessions 353 self.no_auto_reg_pubapp_sessions = no_auto_reg_pubapp_sessions 354 self.session_registry = X2GoSessionRegistry(self, logger=self.logger) 355 self.session_guardian = X2GoSessionGuardian(self, auto_update_listsessions_cache=auto_update_listsessions_cache & (use_listsessions_cache|use_cache), 356 auto_update_listdesktops_cache=auto_update_listdesktops_cache & use_listsessions_cache, 357 auto_update_listmounts_cache=auto_update_listmounts_cache & use_listsessions_cache, 358 auto_update_sessionregistry=auto_update_sessionregistry, 359 auto_register_sessions=auto_register_sessions, 360 no_auto_reg_pubapp_sessions=no_auto_reg_pubapp_sessions, 361 refresh_interval=refresh_interval, 362 logger=self.logger 363 ) 364 self.auto_update_sessionregistry = auto_update_sessionregistry 365 366 if use_listsessions_cache: 367 self.listsessions_cache = X2GoListSessionsCache(self, logger=self.logger) 368 369 self.use_listsessions_cache = use_listsessions_cache | use_cache 370 self.auto_update_listsessions_cache = auto_update_listsessions_cache 371 self.auto_update_listdesktops_cache = auto_update_listdesktops_cache 372 self.auto_update_listmounts_cache = auto_update_listmounts_cache
373
374 - def HOOK_profile_auto_connect(self, profile_name='UNKNOWN'):
375 """\ 376 HOOK method: called if a session demands to auto connect the session profile. 377 378 """ 379 self.logger('HOOK_profile_auto_connect: profile ,,%s'' wants to be auto-connected to the X2Go server.' % profile_name, loglevel=log.loglevel_WARN)
380
381 - def HOOK_session_startup_failed(self, profile_name='UNKNOWN'):
382 """\ 383 HOOK method: called if the startup of a session failed. 384 385 """ 386 self.logger('HOOK_session_startup_failed: session startup for session profile ,,%s'' failed.' % profile_name, loglevel=log.loglevel_WARN)
387
388 - def HOOK_desktop_sharing_denied(self, profile_name='UNKNOWN'):
389 """\ 390 HOOK method: called if the startup of a shadow session was denied by the other user. 391 392 """ 393 self.logger('HOOK_desktop_sharing_failed: desktop sharing for profile ,,%s'' was denied by the other user.' % profile_name, loglevel=log.loglevel_WARN)
394
395 - def HOOK_list_desktops_timeout(self, profile_name='UNKNOWN'):
396 """\ 397 HOOK method: called if the x2golistdesktops command generates a timeout due to long execution time. 398 399 """ 400 self.logger('HOOK_list_desktops_timeout: the server-side x2golistdesktops command for session profile %s took too long to return results. This can happen from time to time, please try again.' % profile_name, loglevel=log.loglevel_WARN)
401
402 - def HOOK_no_such_desktop(self, profile_name='UNKNOWN', desktop='UNKNOWN'):
403 """\ 404 HOOK method: called if it is tried to connect to a (seen before) sharable desktop that's not available (anymore). 405 406 """ 407 self.logger('HOOK_no_such_desktop: the desktop %s (via session profile %s) is not available for sharing (anymore).' % (desktop, profile_name), loglevel=log.loglevel_WARN)
408
410 """\ 411 HOOK method: called if the Python X2Go module could not find any usable XServer 412 application to start. You will not be able to start X2Go sessions without an XServer. 413 414 """ 415 self.logger('the Python X2Go module could not find any usable XServer application, you will not be able to start X2Go sessions without an XServer', loglevel=log.loglevel_WARN)
416
417 - def HOOK_open_print_dialog(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
418 """\ 419 HOOK method: called if an incoming print job has been detected by L{X2GoPrintQueue} and a print dialog box is 420 requested. 421 422 @param profile_name: profile name of session that called this hook method 423 @type profile_name: C{str} 424 @param session_name: X2Go session name 425 @type session_name: C{str} 426 427 """ 428 self.logger('HOOK_open_print_dialog: incoming print job detected by X2GoClient hook method', loglevel=log.loglevel_WARN)
429
430 - def HOOK_no_such_command(self, cmd, profile_name='UNKNOWN', session_name='UNKNOWN'):
431 """\ 432 HOOK: the command <cmd> is not available on the connected X2Go server. 433 434 @param cmd: the command that failed 435 @type cmd: C{str} 436 @param profile_name: profile name of session that called this hook method 437 @type profile_name: C{str} 438 @param session_name: X2Go session name 439 @type session_name: C{str} 440 441 """ 442 self.logger('HOOK_no_such_command: the command %s is not available for X2Go server (profile: %s, session: %s)' % (cmd, profile_name, session_name), loglevel=log.loglevel_WARN)
443
444 - def HOOK_open_mimebox_saveas_dialog(self, filename, profile_name='UNKNOWN', session_name='UNKNOWN'):
445 """\ 446 HOOK method: called on detection of an incoming MIME box job ,,<filename>''. 447 448 @param filename: file name of the incoming MIME box job 449 @type filename: C{str} 450 @param profile_name: profile name of session that called this hook method 451 @type profile_name: C{str} 452 @param session_name: X2Go session name 453 @type session_name: C{str} 454 455 """ 456 self.logger('HOOK_open_mimebox_saveas_dialog: incoming MIME box job ,, %s'' detected by X2GoClient hook method' % filename, loglevel=log.loglevel_WARN)
457
458 - def HOOK_printaction_error(self, filename, profile_name='UNKNOWN', session_name='UNKNOWN', err_msg='GENERIC_ERROR', printer=None):
459 """\ 460 HOOK method: called if an incoming print job caused an error. 461 462 @param filename: file name of the print job that failed 463 @type filename: C{str} 464 @param profile_name: profile name of session that called this hook method 465 @type profile_name: C{str} 466 @param session_name: X2Go session name 467 @type session_name: C{str} 468 @param err_msg: if available, an appropriate error message 469 @type err_msg: C{str} 470 @param printer: if available, the printer name the print job failed on 471 @type printer: C{str} 472 473 """ 474 if printer: 475 self.logger('HOOK_printaction_error: incoming print job ,, %s'' on printer %s caused error: %s' % (filename, printer, err_msg), loglevel=log.loglevel_ERROR) 476 else: 477 self.logger('HOOK_printaction_error: incoming print job ,, %s'' caused error: %s' % (filename, err_msg), loglevel=log.loglevel_ERROR)
478
479 - def HOOK_check_host_dialog(self, profile_name='UNKNOWN', host='UNKNOWN', port=22, fingerprint='no fingerprint', fingerprint_type='UNKNOWN'):
480 """\ 481 HOOK method: called if a host check is requested. This hook has to either return C{True} (default) or C{False}. 482 483 @param profile_name: profile name of session that called this hook method 484 @type profile_name: C{str} 485 @param host: SSH server name to validate 486 @type host: C{str} 487 @param port: SSH server port to validate 488 @type port: C{int} 489 @param fingerprint: the server's fingerprint 490 @type fingerprint: C{str} 491 @param fingerprint_type: finger print type (like RSA, DSA, ...) 492 @type fingerprint_type: C{str} 493 494 @return: if host validity is verified, this hook method should return C{True} 495 @rtype: C{bool} 496 497 """ 498 self.logger('HOOK_check_host_dialog: host check requested for session profile %s: Automatically adding host [%s]:%s with fingerprint: ,,%s\'\' as a known host.' % (profile_name, host, port, fingerprint), loglevel=log.loglevel_WARN) 499 # this HOOK has to return either True (accept host connection) or False (deny host conection) 500 return True
501
502 - def HOOK_on_control_session_death(self, profile_name):
503 """\ 504 HOOK method: called if a control session (server connection) has unexpectedly encountered a failure. 505 506 @param profile_name: profile name of session that called this hook method 507 @type profile_name: C{str} 508 509 """ 510 self.logger('HOOK_on_control_session_death: the control session of profile %s has died unexpectedly' % profile_name, loglevel=log.loglevel_WARN)
511
512 - def HOOK_on_failing_SFTP_client(self, profile_name, session_name):
513 """\ 514 HOOK method: called SFTP client support is unavailable for the session. 515 516 @param profile_name: profile name of the session that experiences failing SFTP client support 517 @type profile_name: C{str} 518 @param session_name: name of session experiencing failing SFTP client support 519 @type session_name: C{str} 520 521 """ 522 self.logger('HOOK_on_failing_SFTP_client: new session for profile %s will lack SFTP client support. Check your server setup. Avoid echoing ~/.bashrc files on server.' % profile_name, loglevel=log.loglevel_ERROR)
523
525 """HOOK method: called if trying to run the Pulseaudio daemon within an RDP session, which is not supported by Pulseaudio.""" 526 self.logger('HOOK_pulseaudio_not_supported_in_RDPsession: The pulseaudio daemon cannot be used within RDP sessions', loglevel=log.loglevel_WARN)
527
529 """HOOK method: called if the Pulseaudio daemon startup failed.""" 530 self.logger('HOOK_pulseaudio_server_startup_failed: The pulseaudio daemon could not be started', loglevel=log.loglevel_ERROR)
531
533 """HOOK method: called if the Pulseaudio daemon has died away unexpectedly.""" 534 self.logger('HOOK_pulseaudio_server_died: The pulseaudio daemon has just died away', loglevel=log.loglevel_ERROR)
535
536 - def HOOK_on_sound_tunnel_failed(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
537 """\ 538 HOOK method: called if a sound tunnel setup failed. 539 540 @param profile_name: profile name of session that called this hook method 541 @type profile_name: C{str} 542 @param session_name: X2Go session name 543 @type session_name: C{str} 544 545 """ 546 self.logger('HOOK_on_sound_tunnel_failed: setting up X2Go sound for %s (%s) support failed' % (profile_name, session_name))
547
548 - def HOOK_rforward_request_denied(self, profile_name='UNKNOWN', session_name='UNKNOWN', server_port=0):
549 """\ 550 HOOK method: called if a reverse port forwarding request has been denied. 551 552 @param profile_name: profile name of session that called this hook method 553 @type profile_name: C{str} 554 @param session_name: X2Go session name 555 @type session_name: C{str} 556 @param server_port: remote server port (starting point of reverse forwarding tunnel) 557 @type server_port: C{str} 558 559 """ 560 self.logger('TCP port (reverse) forwarding request for session %s to server port %s has been denied by the X2Go server. This is a common issue with SSH, it might help to restart the X2Go server\'s SSH daemon.' % (session_name, server_port), loglevel=log.loglevel_WARN)
561
562 - def HOOK_forwarding_tunnel_setup_failed(self, profile_name='UNKNOWN', session_name='UNKNOWN', chain_host='UNKNOWN', chain_port=0):
563 """\ 564 HOOK method: called if a port forwarding tunnel setup failed. 565 566 @param profile_name: profile name of session that called this hook method 567 @type profile_name: C{str} 568 @param session_name: X2Go session name 569 @type session_name: C{str} 570 @param chain_host: hostname of chain host (forwarding tunnel end point) 571 @type chain_host: C{str} 572 @param chain_port: port of chain host (forwarding tunnel end point) 573 @type chain_port: C{str} 574 575 """ 576 self.logger('Forwarding tunnel request to [%s]:%s for session %s (%s) was denied by remote X2Go/SSH server. Session startup failed.' % (chain_host, chain_port, session_name, profile_name), loglevel=log.loglevel_ERROR)
577
578 - def HOOK_on_session_has_started_by_me(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
579 """\ 580 HOOK method: called if a session has been started by this instance of L{X2GoClient}. 581 582 @param session_uuid: unique session identifier of the calling session 583 @type session_uuid: C{str} 584 @param profile_name: profile name of session that called this hook method 585 @type profile_name: C{str} 586 @param session_name: X2Go session name 587 @type session_name: C{str} 588 589 """ 590 self.logger('HOOK_on_session_has_started_by_me (session_uuid: %s, profile_name: %s): a new session %s has been started by this application' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
591
592 - def HOOK_on_session_has_started_by_other(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
593 """\ 594 HOOK method: called if a session has been started by another C{x2goclient}. 595 596 @param session_uuid: unique session identifier of the calling session 597 @type session_uuid: C{str} 598 @param profile_name: profile name of session that called this hook method 599 @type profile_name: C{str} 600 @param session_name: X2Go session name 601 @type session_name: C{str} 602 603 """ 604 self.logger('HOOK_on_session_has_started (session_uuid: %s, profile_name: %s): a new session %s has started been started by other application' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
605
606 - def HOOK_on_session_has_resumed_by_me(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
607 """\ 608 HOOK method: called if a session has been resumed by this instance of L{X2GoClient}. 609 610 @param session_uuid: unique session identifier of the calling session 611 @type session_uuid: C{str} 612 @param profile_name: profile name of session that called this hook method 613 @type profile_name: C{str} 614 @param session_name: X2Go session name 615 @type session_name: C{str} 616 617 """ 618 self.logger('HOOK_on_session_has_resumed_by_me (session_uuid: %s, profile_name: %s): suspended session %s has been resumed by this application' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
619
620 - def HOOK_on_session_has_resumed_by_other(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
621 """\ 622 HOOK method: called if a session has been resumed by another C{x2goclient}. 623 624 @param session_uuid: unique session identifier of the calling session 625 @type session_uuid: C{str} 626 @param profile_name: profile name of session that called this hook method 627 @type profile_name: C{str} 628 @param session_name: X2Go session name 629 @type session_name: C{str} 630 631 """ 632 self.logger('HOOK_on_session_has_resumed_by_other (session_uuid: %s, profile_name: %s): suspended session %s has been resumed by other application' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
633
634 - def HOOK_on_found_session_running_after_connect(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
635 """\ 636 HOOK method: called after server connect if an already running session has been found. 637 638 @param session_uuid: unique session identifier of the calling session 639 @type session_uuid: C{str} 640 @param profile_name: profile name of session that called this hook method 641 @type profile_name: C{str} 642 @param session_name: X2Go session name 643 @type session_name: C{str} 644 645 """ 646 self.logger('HOOK_found_session_running_after_connect (session_uuid: %s, profile_name: %s): running session %s has been found after connecting to session profile %s' % (session_uuid, profile_name, session_name, profile_name), loglevel=log.loglevel_NOTICE)
647
648 - def HOOK_on_session_has_been_suspended(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
649 """\ 650 HOOK method: called if a session has been suspended by this instance of L{X2GoClient}. 651 652 @param session_uuid: unique session identifier of the calling session 653 @type session_uuid: C{str} 654 @param profile_name: profile name of session that called this hook method 655 @type profile_name: C{str} 656 @param session_name: X2Go session name 657 @type session_name: C{str} 658 659 """ 660 self.logger('HOOK_on_session_has_been_suspended (session_uuid: %s, profile_name: %s): session %s has been suspended' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
661
662 - def HOOK_on_session_has_terminated(self, session_uuid='UNKNOWN', profile_name='UNKNOWN', session_name='UNKNOWN'):
663 """\ 664 HOOK method: called if a session has been suspended by another C{x2goclient}. 665 666 @param session_uuid: unique session identifier of the calling session 667 @type session_uuid: C{str} 668 @param profile_name: profile name of session that called this hook method 669 @type profile_name: C{str} 670 @param session_name: X2Go session name 671 @type session_name: C{str} 672 673 """ 674 self.logger('HOOK_on_session_has_terminated (session_uuid: %s, profile_name: %s): session %s has terminated' % (session_uuid, profile_name, session_name), loglevel=log.loglevel_NOTICE)
675
676 - def HOOK_printing_not_available(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
677 """\ 678 HOOK method: called if X2Go client-side printing is not available. 679 680 @param profile_name: profile name of session that called this hook method 681 @type profile_name: C{str} 682 @param session_name: X2Go session name 683 @type session_name: C{str} 684 685 """ 686 self.logger('HOOK_foldersharing_not_available: X2Go\'s client-side printing feature is not available with this session (%s) of profile %s.' % (session_name, profile_name), loglevel=log.loglevel_WARN)
687
688 - def HOOK_mimebox_not_available(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
689 """\ 690 HOOK method: called if the X2Go MIME box is not available. 691 692 @param profile_name: profile name of session that called this hook method 693 @type profile_name: C{str} 694 @param session_name: X2Go session name 695 @type session_name: C{str} 696 697 """ 698 self.logger('HOOK_mimebox_not_available: X2Go\'s MIME box feature is not available with this session (%s) of profile %s.' % (session_name, profile_name), loglevel=log.loglevel_WARN)
699
700 - def HOOK_foldersharing_not_available(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
701 """\ 702 HOOK method: called if X2Go client-side folder-sharing is not available. 703 704 @param profile_name: profile name of session that called this hook method 705 @type profile_name: C{str} 706 @param session_name: X2Go session name 707 @type session_name: C{str} 708 709 """ 710 self.logger('HOOK_foldersharing_not_available: X2Go\'s client-side folder sharing feature is not available with this session (%s) of profile %s.' % (session_name, profile_name), loglevel=log.loglevel_WARN)
711
712 - def HOOK_sshfs_not_available(self, profile_name='UNKNOWN', session_name='UNKNOWN'):
713 """\ 714 HOOK method: called if the X2Go server denies SSHFS access. 715 716 @param profile_name: profile name of session that called this hook method 717 @type profile_name: C{str} 718 @param session_name: X2Go session name 719 @type session_name: C{str} 720 721 """ 722 self.logger('HOOK_sshfs_not_available: the remote X2Go server (%s) denies SSHFS access for session %s. This will result in client-side folder sharing, printing and the MIME box feature being unavailable' % (session_name, profile_name), loglevel=log.loglevel_WARN)
723
724 - def _detect_backend_classes(self):
725 """\ 726 Detect backend classes from the command line 727 728 @raise X2GoBackendException: if a given backend name is unknown." 729 730 """ 731 # CONTROL session backend 732 if type(self.control_backend) is types.StringType: 733 try: 734 _classname = _BACKENDS_CONTROLSESSION[self.control_backend] 735 except KeyError: 736 if self.control_backend in _BACKENDS_CONTROLSESSION.values(): 737 _classname = self.control_backend 738 else: 739 raise x2go_exceptions.X2GoBackendException('unknown control session backend name %s' % self.control_backend) 740 self.control_backend = eval('control.%s' % _classname) 741 742 # TERMINAL session backend 743 if type(self.terminal_backend) is types.StringType: 744 try: 745 _classname = _BACKENDS_TERMINALSESSION[self.terminal_backend] 746 except KeyError: 747 if self.terminal_backend in _BACKENDS_TERMINALSESSION.values(): 748 _classname = self.terminal_backend 749 else: 750 raise x2go_exceptions.X2GoBackendException('unknown terminal session backend name %s' % self.terminal_backend) 751 self.terminal_backend = eval('terminal.%s' % _classname) 752 753 # PROXY session backend 754 if type(self.proxy_backend) is types.StringType: 755 try: 756 _classname = _BACKENDS_PROXY[self.proxy_backend] 757 except KeyError: 758 if self.proxy_backend in _BACKENDS_PROXY.values(): 759 _classname = self.proxy_backend 760 else: 761 raise x2go_exceptions.X2GoBackendException('unknown proxy backend name %s' % self.proxy_backend) 762 self.proxy_backend = eval('proxy.%s' % _classname) 763 764 # server session info backend 765 if type(self.info_backend) is types.StringType: 766 try: 767 _classname = _BACKENDS_SERVERSESSIONINFO[self.info_backend] 768 except KeyError: 769 if self.info_backend in _BACKENDS_SERVERSESSIONINFO.values(): 770 _classname = self.info_backend 771 else: 772 raise x2go_exceptions.X2GoBackendException('unknown server session info backend name %s' % self.info_backend) 773 self.info_backend = eval('info.%s' % _classname) 774 775 # server session list backend 776 if type(self.list_backend) is types.StringType: 777 try: 778 _classname = _BACKENDS_SERVERSESSIONLIST[self.list_backend] 779 except KeyError: 780 if self.list_backend in _BACKENDS_SERVERSESSIONLIST.values(): 781 _classname = self.list_backend 782 else: 783 raise x2go_exceptions.X2GoBackendException('unknown server session info backend name %s' % self.list_backend) 784 self.list_backend = eval('info.%s' % _classname) 785 786 # session profiles backend 787 if type(self.profiles_backend) is types.StringType: 788 try: 789 _classname = _BACKENDS_SESSIONPROFILES[self.profiles_backend] 790 except KeyError: 791 if self.profiles_backend in _BACKENDS_SESSIONPROFILES.values(): 792 _classname = self.profiles_backend 793 else: 794 raise x2go_exceptions.X2GoBackendException('unknown session profiles backend name %s' % self.profiles_backend) 795 self.profiles_backend = eval('profiles.%s' % _classname) 796 797 # client settings backend 798 if type(self.settings_backend) is types.StringType: 799 try: 800 _classname = _BACKENDS_CLIENTSETTINGS[self.settings_backend] 801 except KeyError: 802 if self.settings_backend in _BACKENDS_CLIENTSETTINGS.values(): 803 _classname = self.settings_backend 804 else: 805 raise x2go_exceptions.X2GoBackendException('unknown client settings backend name %s' % self.settings_backend) 806 self.settings_backend = eval('settings.%s' % _classname) 807 808 # client printing backend 809 if type(self.printing_backend) is types.StringType: 810 try: 811 _classname = _BACKENDS_CLIENTPRINTING[self.printing_backend] 812 except KeyError: 813 if self.printing_backend in _BACKENDS_CLIENTPRINTING.values(): 814 _classname = self.printing_backend 815 else: 816 raise x2go_exceptions.X2GoBackendException('unknown client printing backend name %s' % self.printing_backend) 817 self.printing_backend = eval('printing.%s' % _classname)
818
819 - def get_client_rootdir(self):
820 """\ 821 Retrieve the settings root directory of this L{X2GoClient} instance. 822 823 @return: X2Go client root directory 824 @rtype: C{str} 825 """ 826 return os.path.normpath(self.client_rootdir)
827 __get_client_rootdir = get_client_rootdir 828 829 @property
830 - def has_custom_client_rootdir(self):
831 """\ 832 Does this L{X2GoClient} instance have a customized root dir path? 833 Equals C{True} in case it has. 834 835 """ 836 return self._has_custom_client_rootdir
837 __has_custom_client_rootdir = has_custom_client_rootdir 838
839 - def get_sessions_rootdir(self):
840 """\ 841 Retrieve the sessions root directory of this L{X2GoClient} instance. 842 843 @return: X2Go sessions root directory 844 @rtype: C{str} 845 """ 846 return os.path.normpath(self.sessions_rootdir)
847 __get_sessions_rootdir = get_sessions_rootdir 848
849 - def get_ssh_rootdir(self):
850 """\ 851 Retrieve the SSH client root dir used with this L{X2GoClient} instance. 852 853 @return: SSH client root directory 854 @rtype: C{str} 855 """ 856 return os.path.normpath(self.ssh_rootdir)
857 __get_ssh_rootdir = get_ssh_rootdir 858
859 - def get_client_username(self):
860 """\ 861 Query the local user's username (i.e. the user running the X2Go client). 862 863 @return: the local username this L{X2GoClient} instance runs as 864 @rtype: C{str} 865 866 """ 867 return _CURRENT_LOCAL_USER
868 __get_client_username = get_client_username 869
870 - def register_all_session_profiles(self, return_objects=False):
871 """\ 872 Register all session profiles found in the C{sessions} configuration node 873 as potential X2Go sessions. 874 875 @param return_objects: if set to C{True} this methods returns a list of L{X2GoSession} 876 instances, otherwise a list of session UUIDs representing the corresponding 877 registered sessions is returned 878 @type return_objects: C{bool} 879 880 @return: a Python dictionary containing one registered session for each available session profile 881 configuration, whereas the profile names are used as dictionary keys and L{X2GoSession} 882 instances as their values 883 @rtype: C{list} 884 885 """ 886 sessions = {} 887 for profile_name in self.session_profiles.profile_names: 888 _obj = self._X2GoClient__register_session(profile_name=profile_name, return_object=True) 889 sessions[_obj.get_profile_name()] = _obj 890 return sessions
891 __register_all_session_profiles = register_all_session_profiles 892
893 - def register_session(self, server=None, profile_id=None, profile_name=None, session_name=None, 894 allow_printing=False, 895 allow_share_local_folders=False, share_local_folders=[], 896 allow_mimebox=False, mimebox_extensions=[], mimebox_action='OPEN', 897 add_to_known_hosts=False, known_hosts=None, forward_sshagent=False, 898 proxy_options={}, 899 return_object=False, **kwargs):
900 """\ 901 Register a new L{X2GoSession}. Within one L{X2GoClient} 902 instance you can manage several L{X2GoSession} instances on serveral 903 remote X2Go servers under different user names. 904 905 These sessions can be instantiated by passing direct L{X2GoSession} 906 parameters to this method or by specifying the name of an existing session profile 907 (as found in the L{X2GoClient}'s C{sessions} configuration node. 908 909 A session profile is a pre-defined set of session options stored in a sessions 910 profile node (e.g. a configuration file). With the FILE backend such session 911 profiles are stored as a file (by default: C{~/.x2goclient/sessions} or globally (for all users on the 912 client) in C{/etc/x2goclient/sessions}). 913 914 Python X2Go also supports starting multiple X2Go sessions for the same 915 session profile simultaneously. 916 917 This method (L{X2GoClient.register_session()}) accepts a similar set of parameters 918 as the L{X2GoSession} constructor itself. For a complete set of session options refer 919 there. 920 921 Alternatively, you can also pass a profile name or a profile id 922 to this method. If you do this, Python X2Go tries to find the specified session 923 in the C{sessions} configuration node and then derives the necessary session parameters 924 from the session profile configuration. Additional L{X2GoSession} parameters can 925 also be passed to this method---they will override the option values retrieved from 926 the session profile. 927 928 @param server: hostname of the remote X2Go server 929 @type server: C{str} 930 @param profile_id: id (config section name) of a session profile to load 931 from your session config 932 @type profile_id: C{str} 933 @param profile_name: name of a session profile to load from your session 934 config 935 @type profile_name: C{str} 936 @param allow_printing: enable X2Go printing support for the to-be-registered X2Go session 937 @type allow_printing: C{bool} 938 @param allow_share_local_folders: set local folder sharing to enabled/disabled 939 @type allow_share_local_folders: C{bool} 940 @param share_local_folders: a list of local folders (as strings) to be shared directly 941 after session start up 942 @type share_local_folders: C{list} 943 @param allow_mimebox: enable X2Go MIME box support for the to-be-registered X2Go session 944 @type allow_mimebox: C{bool} 945 @param mimebox_extensions: MIME box support is only allowed for the given file extensions 946 @type mimebox_extensions: C{list} 947 @param mimebox_action: MIME box action to use on incoming MIME job files 948 @type mimebox_action: C{str} 949 @param add_to_known_hosts: add unknown host keys to the C{known_hosts} file and accept the connection 950 automatically 951 @type add_to_known_hosts: C{bool} 952 @param known_hosts: full path to C{known_hosts} file 953 @type known_hosts: C{str} 954 @param forward_sshagent: forward SSH agent authentication requests to the X2Go client-side 955 @type forward_sshagent: C{bool} 956 @param proxy_options: a set of very C{X2GoProxy*} backend specific options; any option that is not known 957 to the C{X2GoProxy*} backend will simply be ignored 958 @type proxy_options: C{dict} 959 @param return_object: normally this method returns a unique session UUID. If 960 C{return_object} is set to C{True} an X2GoSession object will be returned 961 instead 962 @type return_object: C{bool} 963 @param kwargs: any option that is also valid for the L{X2GoSession} constructor 964 @type kwargs: C{dict} 965 966 @return: a unique identifier (UUID) for the newly registered X2Go session (or an 967 X2GoSession object if C{return_object} is set to True 968 @rtype: C{str} 969 970 """ 971 # detect profile name and profile id properly 972 if profile_id and self.session_profiles.has_profile_id(profile_id): 973 _p = profile_id 974 elif profile_name and self.session_profiles.has_profile_name(profile_name): 975 _p = profile_name 976 else: 977 _p = None 978 979 if _p: 980 981 _profile_id = self.session_profiles.check_profile_id_or_name(_p) 982 _profile_name = self.session_profiles.to_profile_name(_profile_id) 983 984 # test if session_name has already been registered. If yes, return it immediately. 985 if type(session_name) is types.StringType: 986 _retval = self.get_session_of_session_name(session_name, return_object=return_object, match_profile_name=profile_name) 987 if _retval is not None: 988 return _retval 989 990 if known_hosts is None: 991 known_hosts = os.path.join(_LOCAL_HOME, self.ssh_rootdir, 'known_hosts') 992 993 994 if _p: 995 996 _params = self.session_profiles.to_session_params(profile_id=_profile_id) 997 del _params['profile_name'] 998 999 # override any available session parameter passed to this method 1000 for k in _params.keys(): 1001 if k in kwargs.keys(): 1002 _params[k] = kwargs[k] 1003 1004 server = _params['server'] 1005 del _params['server'] 1006 _params['client_instance'] = self 1007 1008 else: 1009 if server is None: 1010 return None 1011 _profile_id = utils._genSessionProfileId() 1012 _profile_name = profile_name or sys.argv[0] 1013 _params = kwargs 1014 _params['printing'] = allow_printing 1015 _params['allow_share_local_folders'] = allow_share_local_folders 1016 _params['share_local_folders'] = share_local_folders 1017 _params['allow_mimebox'] = allow_mimebox 1018 _params['mimebox_extensions'] = mimebox_extensions 1019 _params['mimebox_action'] = mimebox_action 1020 _params['client_instance'] = self 1021 _params['proxy_options'] = proxy_options 1022 _params['forward_sshagent'] = forward_sshagent 1023 1024 session_uuid = self.session_registry.register(server=server, 1025 profile_id=_profile_id, profile_name=_profile_name, 1026 session_name=session_name, 1027 control_backend=self.control_backend, 1028 terminal_backend=self.terminal_backend, 1029 info_backend=self.info_backend, 1030 list_backend=self.list_backend, 1031 proxy_backend=self.proxy_backend, 1032 settings_backend=self.settings_backend, 1033 printing_backend=self.printing_backend, 1034 client_rootdir=self.client_rootdir, 1035 sessions_rootdir=self.sessions_rootdir, 1036 ssh_rootdir=self.ssh_rootdir, 1037 keep_controlsession_alive=True, 1038 add_to_known_hosts=add_to_known_hosts, 1039 known_hosts=known_hosts, 1040 **_params) 1041 1042 self.logger('initializing X2Go session...', log.loglevel_NOTICE, tag=self._logger_tag) 1043 if return_object: 1044 return self.session_registry(session_uuid) 1045 else: 1046 return session_uuid
1047 __register_session = register_session 1048 1049 ### 1050 ### WRAPPER METHODS FOR X2GoSessionRegistry objects 1051 ### 1052
1053 - def get_session_summary(self, session_uuid):
1054 """\ 1055 Retrieves a Python dictionary, containing a short session summary (session status, names, etc.) 1056 1057 @param session_uuid: the X2Go session's UUID registry hash 1058 @type session_uuid: C{str} 1059 1060 """ 1061 return self.session_registry.session_summary(session_uuid)
1062 __get_session_summary = get_session_summary 1063 1064 ### 1065 ### WRAPPER METHODS FOR X2GoSession objects 1066 ### 1067
1068 - def get_session_username(self, session_uuid):
1069 """\ 1070 After an L{X2GoSession} has been set up you can query the 1071 username that the remote sessions runs as. 1072 1073 @param session_uuid: the X2Go session's UUID registry hash 1074 @type session_uuid: C{str} 1075 1076 @return: the remote username the X2Go session runs as 1077 @rtype: C{str} 1078 1079 """ 1080 return self.session_registry(session_uuid).get_username()
1081 __get_session_username = get_session_username 1082
1083 - def get_session_server_peername(self, session_uuid):
1084 """\ 1085 After a session has been set up you can query the 1086 hostname of the host the session is connected to (or 1087 about to connect to). 1088 1089 @param session_uuid: the X2Go session's UUID registry hash 1090 @type session_uuid: C{str} 1091 1092 @return: the host an X2Go session is connected to 1093 (as an C{(addr,port)} tuple) 1094 @rtype: tuple 1095 1096 """ 1097 return self.session_registry(session_uuid).get_server_peername()
1098 __get_session_server_peername = get_session_server_peername 1099
1100 - def get_session_server_hostname(self, session_uuid):
1101 """\ 1102 Retrieve the server hostname as provided by the calling 1103 application (e.g. like it has been specified in the session 1104 profile). 1105 1106 @param session_uuid: the X2Go session's UUID registry hash 1107 @type session_uuid: C{str} 1108 1109 @return: the hostname for the queried X2Go session as specified 1110 by the calling application 1111 @rtype: str 1112 1113 """ 1114 return self.session_registry(session_uuid).get_server_hostname()
1115 __get_session_server_hostname = get_session_server_hostname 1116
1117 - def get_session(self, session_uuid):
1118 """\ 1119 Retrieve the complete L{X2GoSession} object that has been 1120 registered under the given session registry hash. 1121 1122 @param session_uuid: the X2Go session's UUID registry hash 1123 @type session_uuid: C{str} 1124 1125 @return: the L{X2GoSession} instance 1126 @rtype: obj 1127 1128 """ 1129 return self.session_registry(session_uuid)
1130 __get_session = get_session 1131 with_session = __get_session 1132 """Alias for L{get_session()}.""" 1133
1134 - def get_session_of_session_name(self, session_name, return_object=False, match_profile_name=None):
1135 """\ 1136 Retrieve session UUID or L{X2GoSession} for session name 1137 <session_name> from the session registry. 1138 1139 @param session_name: the X2Go session's UUID registry hash 1140 @type session_name: C{str} 1141 @param return_object: session UUID hash or L{X2GoSession} instance wanted? 1142 @type return_object: C{bool} 1143 @param match_profile_name: only return sessions that match this profile name 1144 @type match_profile_name: C{str} 1145 1146 @return: the X2Go session's UUID registry hash or L{X2GoSession} instance 1147 @rtype: C{str} or L{X2GoSession} instance 1148 1149 """ 1150 try: 1151 return self.session_registry.get_session_of_session_name(session_name=session_name, return_object=return_object, match_profile_name=match_profile_name) 1152 except x2go_exceptions.X2GoSessionRegistryException: 1153 return None
1154 __get_session_of_session_name = get_session_of_session_name 1155
1156 - def get_session_name(self, session_uuid):
1157 """\ 1158 Retrieve the server-side X2Go session name for the session that has 1159 been registered under C{session_uuid}. 1160 1161 @param session_uuid: the X2Go session's UUID registry hash 1162 @type session_uuid: C{str} 1163 1164 @return: X2Go session name 1165 @rtype: C{str} 1166 1167 """ 1168 return self.session_registry(session_uuid).get_session_name()
1169 __get_session_name = get_session_name 1170
1171 - def get_session_info(self, session_uuid):
1172 """\ 1173 Retrieve the server-side X2Go session information object for the session that has 1174 been registered under C{session_uuid}. 1175 1176 @param session_uuid: the X2Go session's UUID registry hash 1177 @type session_uuid: C{str} 1178 1179 @return: X2Go session info 1180 @rtype: C{obj} 1181 1182 """ 1183 return self.session_registry(session_uuid).get_session_info()
1184 __get_session_info = get_session_info 1185
1186 - def get_published_applications(self, session_uuid=None, profile_name=None, lang=None, refresh=False, raw=False, very_raw=False, max_no_submenus=_PUBAPP_MAX_NO_SUBMENUS):
1187 """\ 1188 Retrieve the server-side X2Go published applications menu for the session 1189 registered under C{session_uuid} or for profile name C{profile_name}. 1190 1191 @param session_uuid: the X2Go session's UUID registry hash 1192 @type session_uuid: C{str} 1193 @param profile_name: a valid session profile name 1194 @type profile_name: C{str} 1195 1196 @return: a representative of the published applications menu tree 1197 @rtype: C{dict} 1198 1199 """ 1200 if session_uuid is None and profile_name: 1201 _session_uuids = self._X2GoClient__client_pubapp_sessions_of_profile_name(profile_name, return_objects=False) 1202 if len(_session_uuids): session_uuid = _session_uuids[0] 1203 if session_uuid: 1204 try: 1205 if self.session_registry(session_uuid).is_published_applications_provider(): 1206 return self.session_registry(session_uuid).get_published_applications(lang=lang, refresh=refresh, raw=raw, very_raw=False, max_no_submenus=max_no_submenus) 1207 except x2go_exceptions.X2GoSessionRegistryException: 1208 pass 1209 else: 1210 self.logger('Cannot find a terminal session for profile ,,%s\'\' that can be used to query a published applications menu tree' % profile_name, loglevel=log.loglevel_INFO) 1211 return None
1212 __get_published_applications = get_published_applications 1213 profile_get_published_applications = get_published_applications 1214 __profile_get_published_applications = get_published_applications 1215
1216 - def set_session_username(self, session_uuid, username):
1217 """\ 1218 Set the session username for the L{X2GoSession} that has been registered under C{session_uuid}. 1219 This can be helpful for modifying user credentials during an authentication phase. 1220 1221 @param session_uuid: the X2Go session's UUID registry hash 1222 @type session_uuid: C{str} 1223 @param username: new user name to be used for session authentication 1224 @type username: C{str} 1225 1226 @return: return C{True} on success 1227 @rtype: C{bool} 1228 1229 """ 1230 return self.session_registry(session_uuid).set_username(username=username)
1231 __set_session_username = set_session_username 1232
1233 - def check_session_host(self, session_uuid):
1234 """\ 1235 Provide a mechanism to evaluate the validity of an X2Go server host. 1236 1237 @param session_uuid: the X2Go session's UUID registry hash 1238 @type session_uuid: C{str} 1239 1240 @return: return C{True} if host validation has been successful. 1241 @rtype: C{bool} 1242 1243 """ 1244 return self.session_registry(session_uuid).check_host()
1245 __check_session_host = check_session_host 1246
1247 - def session_reuses_sshproxy_authinfo(self, session_uuid):
1248 """\ 1249 Check if session with unique identifier <session_uuid> is configured to re-use the X2Go session's 1250 password / key for proxy authentication, as well. 1251 1252 @return: returns C{True} if the session is configured to re-use session password / key for proxy authentication 1253 @rtype: C{bool} 1254 """ 1255 return self.session_registry(session_uuid).reuses_sshproxy_authinfo()
1256 __session_reuses_sshproxy_authinfo = session_reuses_sshproxy_authinfo 1257
1258 - def session_uses_sshproxy(self, session_uuid):
1259 """\ 1260 Check if session with unique identifier <session_uuid> is configured to use an 1261 intermediate SSH proxy server. 1262 1263 @return: returns C{True} if the session is configured to use an SSH proxy, C{False} otherwise. 1264 @rtype: C{bool} 1265 1266 """ 1267 return self.session_registry(session_uuid).uses_sshproxy()
1268 __session_uses_sshproxy = session_uses_sshproxy 1269
1270 - def session_can_sshproxy_auto_connect(self, session_uuid):
1271 """\ 1272 Check if the SSH proxy of session with unique identifier <session_uuid> is configured adequately 1273 to be able to auto-connect to the SSH proxy server (e.g. by public key authentication). 1274 1275 @param session_uuid: the X2Go session's UUID registry hash 1276 @type session_uuid: C{str} 1277 1278 @return: returns C{True} if the session's SSH proxy can auto-connect, C{False} otherwise, C{None} 1279 if no control session has been set up yet. 1280 @rtype: C{bool} 1281 1282 """ 1283 return self.session_registry(session_uuid).can_sshproxy_auto_connect()
1284 __session_can_sshproxy_auto_connect = session_can_sshproxy_auto_connect 1285
1286 - def session_can_auto_connect(self, session_uuid):
1287 """\ 1288 Check if session with unique identifier <session_uuid> is configured adequately 1289 to be able to auto-connect to the X2Go server (e.g. by public key authentication). 1290 1291 @param session_uuid: the X2Go session's UUID registry hash 1292 @type session_uuid: C{str} 1293 1294 @return: returns C{True} if the session can auto-connect, C{False} otherwise, C{None} 1295 if no control session has been set up yet. 1296 @rtype: C{bool} 1297 1298 """ 1299 return self.session_registry(session_uuid).can_auto_connect()
1300 __session_can_auto_connect = session_can_auto_connect 1301 1302 # user hooks for detecting/notifying what happened during application runtime
1303 - def session_auto_connect(self, session_uuid):
1304 """\ 1305 Auto-connect a given session. This method is called from within the session itself 1306 and can be used to override the auto-connect procedure from within your 1307 client implementation. 1308 1309 @param session_uuid: the X2Go session's UUID registry hash 1310 @type session_uuid: C{str} 1311 1312 @return: returns C{True} if the session could be auto-connected. 1313 @rtype: C{bool} 1314 1315 """ 1316 self.session_registry(session_uuid).do_auto_connect(redirect_to_client=False)
1317 __session_auto_connect = session_auto_connect 1318
1319 - def connect_session(self, session_uuid, 1320 username=None, 1321 password=None, 1322 passphrase=None, 1323 sshproxy_user=None, 1324 sshproxy_password=None, 1325 sshproxy_passphrase=None, 1326 add_to_known_hosts=False, 1327 force_password_auth=False, 1328 sshproxy_force_password_auth=False, 1329 ):
1330 """\ 1331 Connect to a registered X2Go session with registry hash C{session_uuid} 1332 This method basically wraps around paramiko.SSHClient.connect() for the 1333 corresponding session. 1334 1335 @param session_uuid: the X2Go session's UUID registry hash 1336 @type session_uuid: C{str} 1337 @param username: user name to be used for session authentication 1338 @type username: C{str} 1339 @param password: the user's password for the X2Go server that is going to be 1340 connected to 1341 @type password: C{str} 1342 @param passphrase: a passphrase to use for unlocking 1343 a private key in case the password is already needed for 1344 two-factor authentication 1345 @type passphrase: C{str} 1346 @param sshproxy_user: user name to be used for SSH proxy authentication 1347 @type sshproxy_user: C{str} 1348 @param sshproxy_password: the SSH proxy user's password 1349 @type sshproxy_password: C{str} 1350 @param sshproxy_passphrase: a passphrase to use for unlocking 1351 a private key needed for the SSH proxy host in case the sshproxy_password is already needed for 1352 two-factor authentication 1353 @type sshproxy_passphrase: C{str} 1354 @param add_to_known_hosts: non-Paramiko option, if C{True} paramiko.AutoAddPolicy() 1355 is used as missing-host-key-policy. If set to C{False} L{checkhosts.X2GoInteractiveAddPolicy()} 1356 is used 1357 @type add_to_known_hosts: C{bool} 1358 @param force_password_auth: disable SSH pub/priv key authentication mechanisms 1359 completely 1360 @type force_password_auth: C{bool} 1361 @param sshproxy_force_password_auth: disable SSH pub/priv key authentication mechanisms 1362 completely for SSH proxy connection 1363 @type sshproxy_force_password_auth: C{bool} 1364 1365 @return: returns True if this method has been successful 1366 @rtype: C{bool} 1367 1368 """ 1369 _success = self.session_registry(session_uuid).connect(username=username, 1370 password=password, 1371 passphrase=passphrase, 1372 sshproxy_user=sshproxy_user, 1373 sshproxy_password=sshproxy_password, 1374 sshproxy_passphrase=sshproxy_passphrase, 1375 add_to_known_hosts=add_to_known_hosts, 1376 force_password_auth=force_password_auth, 1377 sshproxy_force_password_auth=sshproxy_force_password_auth, 1378 ) 1379 if self.auto_register_sessions: 1380 self.session_registry.register_available_server_sessions(profile_name=self.get_session_profile_name(session_uuid), 1381 newly_connected=True, 1382 ) 1383 return _success
1384 __connect_session = connect_session 1385
1386 - def disconnect_session(self, session_uuid):
1387 """\ 1388 Disconnect an L{X2GoSession} by closing down its Paramiko/SSH Transport thread. 1389 1390 @param session_uuid: the X2Go session's UUID registry hash 1391 @type session_uuid: C{str} 1392 """ 1393 self.session_registry(session_uuid).disconnect() 1394 if self.use_listsessions_cache: 1395 self.__update_cache_all_profiles()
1396 __disconnect_session = disconnect_session 1397
1398 - def set_session_print_action(self, session_uuid, print_action, **kwargs):
1399 """\ 1400 If X2Go client-side printing is enable within an X2Go session you can use 1401 this method to alter the way how incoming print spool jobs are handled/processed. 1402 1403 Currently, there are five different print actions available, each defined as an individual 1404 print action class: 1405 1406 - B{PDFVIEW} (L{X2GoPrintActionPDFVIEW}): view an incoming spool job (a PDF file) 1407 locally in a PDF viewer 1408 - B{PDFSAVE} (L{X2GoPrintActionPDFSAVE}): save an incoming spool job (a PDF file) 1409 under a nice name in a designated folder 1410 - B{PRINT} (L{X2GoPrintActionPRINT}): really print the incoming spool job on a real printing device 1411 - B{PRINTCMD} L{X2GoPrintActionPRINTCMD}: on each incoming spool job execute an 1412 external command that lets the client user handle the further processing of the 1413 print job (PDF) file 1414 - B{DIALOG} (L{X2GoPrintActionDIALOG}): on each incoming spool job this print action 1415 will call L{X2GoClient.HOOK_open_print_dialog()} 1416 1417 Each of the print action classes accepts different print action arguments. For detail 1418 information on these print action arguments please refer to the constructor methods of 1419 each class individually. 1420 1421 @param session_uuid: the X2Go session's UUID registry hash 1422 @type session_uuid: C{str} 1423 @param print_action: one of the named above print actions, either as string or class instance 1424 @type print_action: C{str} or C{instance} 1425 @param kwargs: additional information for the given print action (print 1426 action arguments), for possible print action arguments and their values see each individual 1427 print action class 1428 @type kwargs: C{dict} 1429 1430 """ 1431 self.session_registry(session_uuid).set_print_action(print_action=print_action, **kwargs)
1432 __set_session_print_action = set_session_print_action 1433
1434 - def set_session_window_title(self, session_uuid, title=''):
1435 """\ 1436 Modify session window title. If the session ID does not occur in the 1437 given title, it will be prepended, so that every X2Go session window 1438 always contains the X2Go session ID of that window. 1439 1440 @param session_uuid: the X2Go session's UUID registry hash 1441 @type session_uuid: C{str} 1442 @param title: new title for session window 1443 @type title: C{str} 1444 1445 """ 1446 self.session_registry(session_uuid).set_session_window_title(title=title)
1447 __set_session_window_title = set_session_window_title 1448
1449 - def raise_session_window(self, session_uuid):
1450 """\ 1451 Try to lift the session window above all other windows and bring 1452 it to focus. 1453 1454 @param session_uuid: the X2Go session's UUID registry hash 1455 @type session_uuid: C{str} 1456 """ 1457 self.session_registry(session_uuid).raise_session_window()
1458 __raise_session_window = raise_session_window 1459
1460 - def session_auto_start_or_resume(self, session_uuid, newest=True, oldest=False, all_suspended=False, start=True):
1461 """\ 1462 Automatically start or resume one or several sessions. 1463 1464 This method is called from within the session itself on session registration, so this method 1465 can be used to handle auto-start/-resume events. 1466 1467 @param session_uuid: the X2Go session's UUID registry hash 1468 @type session_uuid: C{str} 1469 @param newest: if resuming, only resume newest/youngest session 1470 @type newest: C{bool} 1471 @param oldest: if resuming, only resume oldest session 1472 @type oldest: C{bool} 1473 @param all_suspended: if resuming, resume all suspended sessions 1474 @type all_suspended: C{bool} 1475 @param start: if no session is to be resumed, start a new session 1476 @type start: C{bool} 1477 1478 """ 1479 self.session_registry(session_uuid).do_auto_start_or_resume(newest=newest, oldest=oldest, all_suspended=all_suspended, start=start, redirect_to_client=False)
1480 __session_auto_start_or_resume = session_auto_start_or_resume 1481
1482 - def start_session(self, session_uuid, **sessionopts):
1483 """\ 1484 Start a new X2Go session on the remote X2Go server. This method 1485 will open---if everything has been successful till here---the X2Go 1486 session window. 1487 1488 Before calling this method you have to register your desired session 1489 with L{register_session} (initialization of session parameters) and 1490 connect to it with L{connect_session} (authentication). 1491 1492 @param session_uuid: the X2Go session's UUID registry hash 1493 @type session_uuid: C{str} 1494 @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.start()} method 1495 @type sessionopts: C{dict} 1496 1497 @return: returns True if this method has been successful 1498 @rtype: C{bool} 1499 1500 """ 1501 # prevent the newly started session from being registered twice 1502 if self.auto_register_sessions: 1503 self.session_registry.disable_session_auto_registration() 1504 1505 # start the actual session 1506 _retval = self.session_registry(session_uuid).start(**sessionopts) 1507 1508 # re-enable session auto-registration... 1509 if self.auto_register_sessions: 1510 self.session_registry.enable_session_auto_registration() 1511 1512 return _retval
1513 __start_session = start_session 1514
1515 - def share_desktop_session(self, session_uuid, desktop=None, user=None, display=None, share_mode=0, check_desktop_list=False, **sessionopts):
1516 """\ 1517 Share another already running desktop session. Desktop sharing can be run 1518 in two different modes: view-only and full-access mode. Like new sessions 1519 a to-be-shared session has be registered first with the L{X2GoClient} 1520 instance. 1521 1522 @param desktop: desktop ID of a sharable desktop in format <user>@<display> 1523 @type desktop: C{str} 1524 @param user: user name and display number can be given separately, here give the 1525 name of the user who wants to share a session with you. 1526 @type user: C{str} 1527 @param display: user name and display number can be given separately, here give the 1528 number of the display that a user allows you to be shared with. 1529 @type display: C{str} 1530 @param share_mode: desktop sharing mode, 0 is VIEW-ONLY, 1 is FULL-ACCESS. 1531 @type share_mode: C{int} 1532 @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.share_desktop()} method 1533 @type sessionopts: C{dict} 1534 1535 @return: True if the session could be successfully shared. 1536 @rtype: C{bool} 1537 1538 @raise X2GoDesktopSharingException: if a given desktop ID does not specify an available desktop session 1539 1540 """ 1541 1542 # X2GoClient.list_desktops() uses caching (if enabled, so we prefer lookups here...) 1543 if desktop: 1544 _desktop = desktop 1545 user = None 1546 display = None 1547 else: 1548 _desktop = '%s@%s' % (user, display) 1549 1550 if not _desktop in self._X2GoClient__list_desktops(session_uuid): 1551 _orig_desktop = _desktop 1552 _desktop = '%s.0' % _desktop 1553 1554 return self.session_registry(session_uuid).share_desktop(desktop=_desktop, share_mode=share_mode, check_desktop_list=check_desktop_list, **sessionopts)
1555 __share_desktop_session = share_desktop_session 1556
1557 - def resume_session(self, session_uuid=None, session_name=None, match_profile_name=None, **sessionopts):
1558 """\ 1559 Resume or continue a suspended / running X2Go session on a 1560 remote X2Go server (as specified when L{register_session} was 1561 called). 1562 1563 @param session_uuid: the X2Go session's UUID registry hash 1564 @type session_uuid: C{str} 1565 @param session_name: the server-side name of an X2Go session 1566 @type session_name: C{str} 1567 @param match_profile_name: only resume a session if this profile name matches 1568 @type match_profile_name: C{str} 1569 @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.resume()} method 1570 @type sessionopts: C{dict} 1571 1572 @return: returns True if this method has been successful 1573 @rtype: C{bool} 1574 1575 @raise X2GoClientException: if the method does not know what session to resume 1576 1577 """ 1578 try: 1579 if session_uuid is None and session_name is None: 1580 raise x2go_exceptions.X2GoClientException('can\'t resume a session without either session_uuid or session_name') 1581 if session_name is None and self.session_registry(session_uuid).session_name is None: 1582 raise x2go_exceptions.X2GoClientException('don\'t know which session to resume') 1583 if session_uuid is None: 1584 session_uuid = self.session_registry.get_session_of_session_name(session_name=session_name, return_object=False, match_profile_name=match_profile_name) 1585 return self.session_registry(session_uuid).resume(session_list=self._X2GoClient__list_sessions(session_uuid=session_uuid), **sessionopts) 1586 else: 1587 return self.session_registry(session_uuid).resume(session_name=session_name, session_list=self._X2GoClient__list_sessions(session_uuid=session_uuid), **sessionopts) 1588 except x2go_exceptions.X2GoControlSessionException: 1589 profile_name = self.get_session_profile_name(session_uuid) 1590 if self.session_registry(session_uuid).connected: self.HOOK_on_control_session_death(profile_name) 1591 self.disconnect_profile(profile_name)
1592 __resume_session = resume_session 1593
1594 - def suspend_session(self, session_uuid, session_name=None, match_profile_name=None, **sessionopts):
1595 """\ 1596 Suspend an X2Go session. 1597 1598 Normally, you will use this method to suspend a registered session that you 1599 have formerly started/resumed from within your recent 1600 L{X2GoClient} instance. For this you simply call this method 1601 using the session's C{session_uuid}, leave the C{session_name} 1602 empty. 1603 1604 Alternatively, you can suspend a non-associated X2Go session: 1605 To do this you simply neeed to register (with the L{register_session} 1606 method) an X2Go session on the to-be-addressed remote X2Go server and 1607 connect (L{connect_session}) to it. Then call this method with 1608 the freshly obtained C{session_uuid} and the remote X2Go session 1609 name (as shown e.g. in x2golistsessions output). 1610 1611 @param session_uuid: the X2Go session's UUID registry hash 1612 @type session_uuid: C{str} 1613 @param session_name: the server-side name of an X2Go session (for 1614 non-associated session suspend) 1615 @type session_name: C{str} 1616 @param match_profile_name: only suspend a session if this profile name matches 1617 @type match_profile_name: C{str} 1618 @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.suspend()} method 1619 @type sessionopts: C{dict} 1620 1621 @return: returns True if this method has been successful 1622 @rtype: C{bool} 1623 1624 """ 1625 try: 1626 if session_name is None: 1627 1628 # make sure that the current list of shared folders is up-to-date before the session suspends 1629 self.get_shared_folders(session_uuid, check_list_mounts=True) 1630 1631 return self.session_registry(session_uuid).suspend(**sessionopts) 1632 else: 1633 if match_profile_name is None: 1634 running_sessions = self.session_registry.running_sessions() 1635 else: 1636 running_sessions = self.session_registry.running_sessions_of_profile_name(match_profile_name) 1637 for session in running_sessions: 1638 if session_name == session.get_session_name(): 1639 return session.suspend() 1640 return self.session_registry(session_uuid).control_session.suspend(session_name=session_name, **sessionopts) 1641 except x2go_exceptions.X2GoControlSessionException: 1642 profile_name = self.get_session_profile_name(session_uuid) 1643 if self.session_registry(session_uuid).conntected: self.HOOK_on_control_session_death(profile_name) 1644 self.disconnect_profile(profile_name)
1645 __suspend_session = suspend_session 1646
1647 - def terminate_session(self, session_uuid, session_name=None, match_profile_name=None, **sessionopts):
1648 """\ 1649 Terminate an X2Go session. 1650 1651 Normally you will use this method to terminate a registered session that you 1652 have formerly started/resumed from within your recent 1653 L{X2GoClient} instance. For this you simply call this method 1654 using the session's C{session_uuid}, leave the C{session_name} 1655 empty. 1656 1657 Alternatively, you can terminate a non-associated X2Go session: 1658 To do this you simply neeed to register (L{register_session}) 1659 an X2Go session on the to-be-addressed remote X2Go server and 1660 connect (L{connect_session}) to it. Then call this method with 1661 the freshly obtained C{session_uuid} and the remote X2Go session 1662 name (as shown in e.g. x2golistsessions output). 1663 1664 @param session_uuid: the X2Go session's UUID registry hash 1665 @type session_uuid: C{str} 1666 @param session_name: the server-side name of an X2Go session 1667 @type session_name: C{str} 1668 @param match_profile_name: only terminate a session if this profile name matches 1669 @type match_profile_name: C{str} 1670 @param sessionopts: pass-through of options directly to the session instance's L{X2GoSession.terminate()} method 1671 @type sessionopts: C{dict} 1672 1673 @return: returns True if this method has been successful 1674 @rtype: C{bool} 1675 1676 """ 1677 try: 1678 if session_name is None: 1679 1680 # make sure that the current list of shared folders is up-to-date before the session terminates 1681 self.get_shared_folders(session_uuid, check_list_mounts=True) 1682 1683 return self.session_registry(session_uuid).terminate(**sessionopts) 1684 else: 1685 if match_profile_name is None: 1686 terminatable_sessions = self.session_registry.running_sessions() + self.session_registry.suspended_sessions() 1687 else: 1688 terminatable_sessions = self.session_registry.running_sessions_of_profile_name(match_profile_name) + self.session_registry.suspended_sessions_of_profile_name(match_profile_name) 1689 for session in terminatable_sessions: 1690 if session_name == session.get_session_name(): 1691 return session.terminate() 1692 return self.session_registry(session_uuid).control_session.terminate(session_name=session_name, **sessionopts) 1693 except x2go_exceptions.X2GoControlSessionException: 1694 profile_name = self.get_session_profile_name(session_uuid) 1695 if self.session_registry(session_uuid).conntected: self.HOOK_on_control_session_death(profile_name) 1696 self.disconnect_profile(profile_name)
1697 __terminate_session = terminate_session 1698
1699 - def get_session_profile_name(self, session_uuid):
1700 """\ 1701 Retrieve the profile name of the session that has been registered 1702 under C{session_uuid}. 1703 1704 For profile based sessions this will be the profile name as used 1705 in x2goclient's »sessions« configuration file. 1706 1707 For non-profile based session this will either be a C{profile_name} that 1708 was passed to L{register_session} or it will be the application that 1709 instantiated this L{X2GoClient} instance. 1710 1711 @param session_uuid: the X2Go session's UUID registry hash 1712 @type session_uuid: C{str} 1713 1714 @return: X2Go session profile name 1715 @rtype: C{str} 1716 1717 """ 1718 return self.session_registry(session_uuid).get_profile_name()
1719 __get_session_profile_name = get_session_profile_name 1720
1721 - def get_session_profile_id(self, session_uuid):
1722 """\ 1723 Retrieve the profile id of the session that has been registered 1724 under C{session_uuid}. 1725 1726 For profile based sessions this will be the profile id as used 1727 in x2goclient's »sessions« configuration node (section header of 1728 a session profile in the config, normally a timestamp created on 1729 session profile creation/modification). 1730 1731 For non-profile based sessions this will be a timestamp created on 1732 X2Go session registration by C{register_session}. 1733 1734 @param session_uuid: the session profile name 1735 @type session_uuid: C{str} 1736 1737 @return: the X2Go session profile's id 1738 @rtype: C{str} 1739 1740 """ 1741 return self.session_registry(session_uuid).profile_id
1742 __get_session_profile_id = get_session_profile_id 1743
1744 - def session_ok(self, session_uuid):
1745 """\ 1746 Test if the X2Go session registered as C{session_uuid} is 1747 in a healthy state. 1748 1749 @param session_uuid: the X2Go session's UUID registry hash 1750 @type session_uuid: C{str} 1751 1752 @return: C{True} if session is ok, C{False} otherwise 1753 @rtype: C{bool} 1754 1755 """ 1756 return self.session_registry(session_uuid).session_ok()
1757 __session_ok = session_ok 1758
1759 - def is_session_connected(self, session_uuid):
1760 """\ 1761 Test if the X2Go session registered as C{session_uuid} connected 1762 to the X2Go server. 1763 1764 @param session_uuid: the X2Go session's UUID registry hash 1765 @type session_uuid: C{str} 1766 1767 @return: C{True} if session is connected, C{False} otherwise 1768 @rtype: C{bool} 1769 1770 """ 1771 return self.session_registry(session_uuid).is_connected()
1772 __is_session_connected = is_session_connected 1773
1774 - def is_profile_connected(self, profile_name):
1775 """\ 1776 Test if the X2Go given session profile has open connections 1777 to the X2Go server. 1778 1779 @param profile_name: a valid session profile name 1780 @type profile_name: C{str} 1781 1782 @return: C{True} if profile has a connected session, C{False} otherwise 1783 @rtype: C{bool} 1784 1785 """ 1786 return bool(self.client_connected_sessions_of_profile_name(profile_name=profile_name))
1787 __is_profile_connected = is_profile_connected 1788
1789 - def is_session_profile(self, profile_id_or_name):
1790 """\ 1791 Test if the X2Go given session profile is configured in the client's C{sessions} file. 1792 1793 @param profile_id_or_name: test existence of this session profile name (or id) 1794 @type profile_id_or_name: C{str} 1795 1796 @return: C{True} if session profile exists, C{False} otherwise 1797 @rtype: C{bool} 1798 1799 """ 1800 return self.session_profiles.has_profile(profile_id_or_name)
1801 __is_session_profile = is_session_profile 1802
1803 - def is_session_running(self, session_uuid, session_name=None):
1804 """\ 1805 Test if the X2Go session registered as C{session_uuid} is up 1806 and running. 1807 1808 @param session_uuid: the X2Go session's UUID registry hash 1809 @type session_uuid: C{str} 1810 @param session_name: the server-side name of an X2Go session 1811 @type session_name: C{str} 1812 1813 @return: C{True} if session is running, C{False} otherwise 1814 @rtype: C{bool} 1815 1816 """ 1817 if session_name is None: 1818 return self.session_registry(session_uuid).is_running() 1819 else: 1820 return session_name in [ s for s in self.server_running_sessions(session_uuid) ]
1821 __is_session_running = is_session_running 1822
1823 - def is_session_suspended(self, session_uuid, session_name=None):
1824 """\ 1825 Test if the X2Go session registered as C{session_uuid} 1826 is in suspended state. 1827 1828 @param session_uuid: the X2Go session's UUID registry hash 1829 @type session_uuid: C{str} 1830 @param session_name: the server-side name of an X2Go session 1831 @type session_name: C{str} 1832 1833 @return: C{True} if session is suspended, C{False} otherwise 1834 @rtype: C{bool} 1835 1836 """ 1837 if session_name is None: 1838 return self.session_registry(session_uuid).is_suspended() 1839 else: 1840 return session_name in [ s for s in self.server_suspended_sessions(session_uuid) ]
1841 __is_session_suspended = is_session_suspended 1842
1843 - def has_session_terminated(self, session_uuid, session_name=None):
1844 """\ 1845 Test if the X2Go session registered as C{session_uuid} 1846 has terminated. 1847 1848 @param session_uuid: the X2Go session's UUID registry hash 1849 @type session_uuid: C{str} 1850 @param session_name: the server-side name of an X2Go session 1851 @type session_name: C{str} 1852 1853 @return: C{True} if session has terminated, C{False} otherwise 1854 @rtype: C{bool} 1855 1856 """ 1857 if session_name is None: 1858 return self.session_registry(session_uuid).has_terminated() 1859 else: 1860 return session_name not in [ s for s in self.server_running_sessions(session_uuid) + self.server_suspended_sessions(session_uuid) ]
1861 __has_session_terminated = has_session_terminated 1862
1863 - def is_folder_sharing_available(self, session_uuid=None, profile_name=None):
1864 """\ 1865 Test if local folder sharing is available for X2Go session with unique ID <session_uuid> or 1866 session profile <profile_name>. 1867 1868 @param session_uuid: the X2Go session's UUID registry hash 1869 @type session_uuid: C{str} 1870 @param profile_name: alternatively, the profile name can be used to perform this query 1871 @type profile_name: C{str} 1872 1873 @return: returns C{True} if the profile/session supports local folder sharing 1874 @rtype: C{bool} 1875 1876 """ 1877 if session_uuid is None and profile_name: 1878 session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False) 1879 if session_uuid: 1880 try: 1881 return self.session_registry(session_uuid).is_folder_sharing_available() 1882 except x2go_exceptions.X2GoSessionRegistryException: 1883 return False 1884 else: 1885 self.logger('Cannot find a terminal session for profile ,,%s\'\' that can be used to query folder sharing capabilities' % profile_name, loglevel=log.loglevel_INFO) 1886 return False
1887 __is_folder_sharing_available = is_folder_sharing_available 1888 __profile_is_folder_sharing_available = is_folder_sharing_available 1889 __session_is_folder_sharing_available = is_folder_sharing_available 1890
1891 - def share_local_folder(self, session_uuid=None, local_path=None, profile_name=None, folder_name=None):
1892 """\ 1893 Share a local folder with the X2Go session registered as C{session_uuid}. 1894 1895 When calling this method the given client-side folder is mounted 1896 on the X2Go server (via sshfs) and (if in desktop mode) provided as a 1897 desktop icon on your remote session's desktop. 1898 1899 @param session_uuid: the X2Go session's UUID registry hash 1900 @type session_uuid: C{str} 1901 @param local_path: the full path to an existing folder on the local (client-side) 1902 file system 1903 @type local_path: C{str} 1904 @param folder_name: synonymous to C{local_path} 1905 @type folder_name: C{str} 1906 @param profile_name: alternatively, the profile name can be used to share local folders 1907 @type profile_name: C{str} 1908 1909 @return: returns C{True} if the local folder has been successfully mounted 1910 @rtype: C{bool} 1911 1912 """ 1913 # compat for Python-X2Go (<=0.1.1.6) 1914 if folder_name: local_path = folder_name 1915 1916 if session_uuid is None and profile_name: 1917 session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False) 1918 if session_uuid: 1919 try: 1920 return self.session_registry(session_uuid).share_local_folder(local_path=local_path) 1921 except x2go_exceptions.X2GoSessionException: 1922 return False 1923 else: 1924 self.logger('Cannot find a terminal session for profile ,,%s\'\' to share a local folder with' % profile_name, loglevel=log.loglevel_WARN) 1925 return False
1926 __share_local_folder = share_local_folder 1927 __share_local_folder_with_session = share_local_folder 1928 __share_local_folder_with_profile = share_local_folder 1929
1930 - def unshare_all_local_folders(self, session_uuid=None, profile_name=None):
1931 """\ 1932 Unshare all local folders mounted in X2Go session registered as 1933 C{session_uuid}. 1934 1935 When calling this method all client-side mounted folders on the X2Go 1936 server (via sshfs) for session with ID <session_uuid> will get 1937 unmounted. 1938 1939 @param session_uuid: the X2Go session's UUID registry hash 1940 @type session_uuid: C{str} 1941 @param profile_name: alternatively, the profile name can be used to unshare 1942 mounted folders 1943 @type profile_name: C{str} 1944 1945 @return: returns C{True} if all local folders could be successfully unmounted 1946 @rtype: C{bool} 1947 1948 """ 1949 if session_uuid is None and profile_name: 1950 session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False) 1951 if session_uuid: 1952 return self.session_registry(session_uuid).unshare_all_local_folders() 1953 else: 1954 self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN) 1955 return False
1956 unshare_all_local_folders_from_session = unshare_all_local_folders 1957 unshare_all_local_folders_from_profile = unshare_all_local_folders 1958 __unshare_all_local_folders_from_session = unshare_all_local_folders 1959 __unshare_all_local_folders_from_profile = unshare_all_local_folders 1960
1961 - def unshare_local_folder(self, session_uuid=None, profile_name=None, local_path=None):
1962 """\ 1963 Unshare local folder that is mounted in the X2Go session registered as 1964 C{session_uuid}. 1965 1966 When calling this method the given client-side mounted folder on the X2Go 1967 server (via sshfs) for session with ID <session_uuid> will get 1968 unmounted. 1969 1970 @param session_uuid: the X2Go session's UUID registry hash 1971 @type session_uuid: C{str} 1972 @param profile_name: alternatively, the profile name can be used to unshare 1973 mounted folders 1974 @type profile_name: C{str} 1975 @param local_path: the full path of a local folder that is mounted within X2Go 1976 session with session ID <session_uuid> (or recognized via profile name) and that 1977 shall be unmounted from that session. 1978 @type local_path: C{str} 1979 1980 @return: returns C{True} if all local folders could be successfully unmounted 1981 @rtype: C{bool} 1982 1983 """ 1984 if session_uuid is None and profile_name: 1985 session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False) 1986 if session_uuid: 1987 return self.session_registry(session_uuid).unshare_local_folder(local_path=local_path) 1988 else: 1989 self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN) 1990 return False
1991 unshare_local_folder_from_session = unshare_local_folder 1992 unshare_local_folder_from_profile = unshare_local_folder 1993 __unshare_local_folder_from_session = unshare_local_folder 1994 __unshare_local_folder_from_profile = unshare_local_folder 1995
1996 - def get_shared_folders(self, session_uuid=None, profile_name=None, check_list_mounts=False):
1997 """\ 1998 Get a list of local folders mounted within X2Go session with session hash <session_uuid> 1999 from this client. 2000 2001 @param session_uuid: the X2Go session's UUID registry hash 2002 @type session_uuid: C{str} 2003 @param profile_name: alternatively, the profile name can be used to get mounted folders of a session connected profile 2004 @type profile_name: C{str} 2005 @param check_list_mounts: query the server-side mount list for up-to-date information 2006 @type check_list_mounts: C{bool} 2007 2008 @return: returns a C{list} of those local folder names that are mounted within X2Go session <session_uuid>. 2009 @rtype: C{list} 2010 2011 """ 2012 if session_uuid is None and profile_name: 2013 session_uuid = self._X2GoClient__get_master_session(profile_name, return_object=False) 2014 2015 if session_uuid and profile_name is None: 2016 profile_name = self.session_registry(session_uuid).get_profile_name() 2017 2018 if session_uuid and profile_name: 2019 2020 mounts = None 2021 if check_list_mounts: 2022 _mounts = self.list_mounts_by_profile_name(profile_name) 2023 mounts = [] 2024 for mount_list in _mounts.values(): 2025 mounts.extend(mount_list) 2026 2027 return self.session_registry(session_uuid).get_shared_folders(check_list_mounts=check_list_mounts, mounts=mounts)
2028 2029 session_get_shared_folders = get_shared_folders 2030 profile_get_shared_folders = get_shared_folders 2031 __session_get_shared_folders = get_shared_folders 2032 __profile_get_shared_folders = get_shared_folders 2033
2034 - def get_master_session(self, profile_name, return_object=True, return_session_name=False):
2035 """\ 2036 Retrieve the master session of a specific profile. 2037 2038 @param profile_name: the profile name that we query the master session of 2039 @type profile_name: C{str} 2040 @param return_object: return L{X2GoSession} instance 2041 @type return_object: C{bool} 2042 @param return_session_name: return X2Go session name 2043 @type return_session_name: C{bool} 2044 2045 @return: a session list (as UUID hashes, objects, profile names/IDs or session names) 2046 @rtype: C{list} 2047 2048 """ 2049 return self.session_registry.get_master_session(profile_name, return_object=return_object, return_session_name=return_session_name)
2050 profile_master_session = get_master_session 2051 __get_master_session = get_master_session 2052 __profile_master_session = profile_master_session 2053 2054 ### 2055 ### Provide access to the X2GoClient's session registry 2056 ### 2057
2058 - def client_connected_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
2059 """\ 2060 Retrieve a list of X2Go sessions that this L{X2GoClient} instance is connected to. 2061 2062 @param return_objects: return as list of X2Go session objects 2063 @type return_objects: C{bool} 2064 @param return_profile_names: return as list of session profile names 2065 @type return_profile_names: C{bool} 2066 @param return_profile_ids: return as list of session profile IDs 2067 @type return_profile_ids: C{bool} 2068 @param return_session_names: return as list of session names 2069 @type return_session_names: C{bool} 2070 2071 @return: list of connected sessions 2072 @rtype: C{list} 2073 2074 """ 2075 return self.session_registry.connected_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
2076 __client_connected_sessions = client_connected_sessions 2077 2078 @property
2080 """\ 2081 Equals C{True} if there are any connected sessions with this L{X2GoClient} instance. 2082 2083 """ 2084 return self.session_registry.has_connected_sessions
2085 __client_has_connected_sessions = client_has_connected_sessions 2086
2087 - def client_associated_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
2088 """\ 2089 Retrieve a list of X2Go sessions associated to this L{X2GoClient} instance. 2090 2091 @param return_objects: return as list of X2Go session objects 2092 @type return_objects: C{bool} 2093 @param return_profile_names: return as list of session profile names 2094 @type return_profile_names: C{bool} 2095 @param return_profile_ids: return as list of session profile IDs 2096 @type return_profile_ids: C{bool} 2097 @param return_session_names: return as list of session names 2098 @type return_session_names: C{bool} 2099 2100 @return: list of associated sessions 2101 @rtype: C{list} 2102 2103 """ 2104 return self.session_registry.associated_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
2105 __client_associated_sessions = client_associated_sessions 2106 2107 @property
2109 """\ 2110 Equals C{True} if there are any associated sessions with this L{X2GoClient} instance. 2111 2112 """ 2113 return self.session_registry.has_associated_sessions
2114 __client_has_associated_sessions = client_has_associated_sessions 2115
2116 - def client_running_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
2117 """\ 2118 Retrieve a list of running X2Go sessions. 2119 2120 @param return_objects: return as list of X2Go session objects 2121 @type return_objects: C{bool} 2122 @param return_profile_names: return as list of session profile names 2123 @type return_profile_names: C{bool} 2124 @param return_profile_ids: return as list of session profile IDs 2125 @type return_profile_ids: C{bool} 2126 @param return_session_names: return as list of session names 2127 @type return_session_names: C{bool} 2128 2129 @return: list of running sessions 2130 @rtype: C{list} 2131 2132 """ 2133 return self.session_registry.running_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
2134 __client_running_sessions = client_running_sessions 2135 2136 @property
2138 """\ 2139 Equals C{True} if there are any running sessions with this L{X2GoClient} instance. 2140 2141 """ 2142 return self.session_registry.has_running_sessions
2143 __client_has_running_sessions = client_has_running_sessions 2144
2145 - def client_suspended_sessions(self, return_objects=False, return_profile_names=False, return_profile_ids=False, return_session_names=False):
2146 """\ 2147 Retrieve a list of suspended X2Go sessions. 2148 2149 @param return_objects: return as list of X2Go session objects 2150 @type return_objects: C{bool} 2151 @param return_profile_names: return as list of session profile names 2152 @type return_profile_names: C{bool} 2153 @param return_profile_ids: return as list of session profile IDs 2154 @type return_profile_ids: C{bool} 2155 @param return_session_names: return as list of session names 2156 @type return_session_names: C{bool} 2157 2158 @return: list of suspended sessions 2159 @rtype: C{list} 2160 2161 """ 2162 return self.session_registry.running_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
2163 __client_suspended_sessions = client_suspended_sessions 2164 2165 @property
2167 """\ 2168 Equals C{True} if there are any suspended sessions with this L{X2GoClient} instance. 2169 2170 """ 2171 return self.session_registry.has_suspended_sessions
2172 __client_has_suspended_sessions = client_has_suspended_sessions 2173
2174 - def client_registered_sessions(self, return_objects=True, return_profile_names=False, return_profile_ids=False, return_session_names=False):
2175 """\ 2176 Retrieve a list of registered X2Go sessions. 2177 2178 @param return_objects: return as list of X2Go session objects 2179 @type return_objects: C{bool} 2180 @param return_profile_names: return as list of session profile names 2181 @type return_profile_names: C{bool} 2182 @param return_profile_ids: return as list of session profile IDs 2183 @type return_profile_ids: C{bool} 2184 @param return_session_names: return as list of session names 2185 @type return_session_names: C{bool} 2186 2187 @return: list of registered sessions 2188 @rtype: C{list} 2189 2190 """ 2191 return self.session_registry.registered_sessions(return_objects=return_objects, return_profile_names=return_profile_names, return_profile_ids=return_profile_ids, return_session_names=return_session_names)
2192 __client_registered_sessions = client_registered_sessions 2193 2194 @property
2195 - def client_control_sessions(self):
2196 """\ 2197 Equals a list of all registered X2Go control sessions. 2198 2199 """ 2200 return self.session_registry.control_sessions
2201 __client_control_sessions = client_control_sessions 2202
2203 - def client_control_session_of_profile_name(self, profile_name):
2204 """\ 2205 Retrieve control session for profile name <profile_name>. 2206 2207 @param profile_name: profile name 2208 @type profile_name: C{str} 2209 2210 @return: control session instance 2211 @rtype: C{X2GoControlSession} instance 2212 2213 """ 2214 return self.session_registry.control_session_of_profile_name(profile_name)
2215 __client_control_session_of_profile_name = client_control_session_of_profile_name 2216
2217 - def get_server_versions(self, profile_name, component=None, force=False):
2218 """\ 2219 Query the server configured in session profile <profile_name> for the list of install X2Go components 2220 and its versions. 2221 2222 @param profile_name: use the control session of this profile to query the X2Go server for its component list 2223 @type profile_name: C{str} 2224 @param component: only return the version of a specific component 2225 @type component: C{str} 2226 @param force: refresh component/version data by a query to the server 2227 @type force: C{bool} 2228 2229 @return: dictionary of server components (as keys) and their versions (as values) or the version of the given <component> 2230 @rtype: C{dict} or C{str} 2231 2232 @raise X2GoClientException: if component is not available on the X2Go Server. 2233 2234 """ 2235 control_session = self.client_control_session_of_profile_name(profile_name) 2236 if component is None: 2237 return control_session.get_server_versions(force=force) 2238 else: 2239 try: 2240 return control_session.get_server_versions(force=force)[component] 2241 except KeyError: 2242 raise x2go_exceptions.X2GoClientException('No such component on X2Go Server')
2243 __get_server_versions = get_server_versions 2244 get_server_components = get_server_versions 2245 __get_server_components = get_server_components 2246
2247 - def get_server_features(self, profile_name, force=False):
2248 """\ 2249 Query the server configured in session profile <profile_name> for the list of server-side 2250 X2Go features. 2251 2252 @param profile_name: use the control session of this profile to query the X2Go server for its feature list 2253 @type profile_name: C{str} 2254 @param force: refresh feature list by a query to the server 2255 @type force: C{bool} 2256 2257 @return: list of server feature names (as returned by server-side command ,,x2gofeaturelist'' 2258 @rtype: C{list} 2259 2260 """ 2261 control_session = self.client_control_session_of_profile_name(profile_name) 2262 return control_session.get_server_features(force=force)
2263 __get_server_features = get_server_features 2264
2265 - def has_server_feature(self, profile_name, feature):
2266 """\ 2267 Query the server configured in session profile <profile_name> for the availability 2268 of a certain server feature. 2269 2270 @param profile_name: use the control session of this profile to query the X2Go server for its feature 2271 @type profile_name: C{str} 2272 @param feature: test the availability of this feature on the X2Go server 2273 @type feature: C{str} 2274 2275 @return: C{True} if the feature is available on the queried server 2276 @rtype: C{bool} 2277 2278 """ 2279 control_session = self.client_control_session_of_profile_name(profile_name) 2280 return feature in control_session.get_server_features()
2281 __has_server_feature = has_server_feature 2282
2283 - def client_registered_session_of_name(self, session_name, return_object=False):
2284 """\ 2285 Retrieve X2Go session of a given session name. 2286 2287 @param session_name: session name 2288 @type session_name: C{str} 2289 2290 @return: session instance of the given name 2291 @rtype: C{X2GoSession} or C{str} 2292 2293 """ 2294 return self.session_registry.get_session_of_session_name(session_name, return_object=return_object)
2295 __client_registered_session_of_name = client_registered_session_of_name 2296
2297 - def client_has_registered_session_of_name(self, session_name):
2298 """\ 2299 Equals C{True} if there is a registered session of name <session_name>. 2300 2301 @param session_name: session name 2302 @type session_name: C{str} 2303 2304 @return: C{True} if the given session is registered 2305 @rtype: C{bool} 2306 2307 """ 2308 return self.client_registered_session_of_name(session_name) is not None
2309 __client_has_registered_session_of_name = client_registered_session_of_name 2310
2311 - def client_registered_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
2312 """\ 2313 Retrieve registered X2Go sessions of profile name <profile_name>. 2314 2315 @param profile_name: profile name 2316 @type profile_name: C{str} 2317 @param return_objects: return as list of X2Go session objects 2318 @type return_objects: C{bool} 2319 @param return_session_names: return as list of session names 2320 @type return_session_names: C{bool} 2321 2322 @return: list of registered sessions of profile name 2323 @rtype: C{list} 2324 2325 """ 2326 return self.session_registry.registered_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2327 __client_registered_sessions_of_profile_name = client_registered_sessions_of_profile_name 2328
2329 - def client_connected_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
2330 """\ 2331 Retrieve connected X2Go sessions of profile name <profile_name>. 2332 2333 @param profile_name: profile name 2334 @type profile_name: C{str} 2335 @param return_objects: return as list of X2Go session objects 2336 @type return_objects: C{bool} 2337 @param return_session_names: return as list of session names 2338 @type return_session_names: C{bool} 2339 2340 @return: list of connected sessions of profile name 2341 @rtype: C{list} 2342 2343 """ 2344 return self.session_registry.connected_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2345 __client_connected_sessions_of_profile_name = client_connected_sessions_of_profile_name 2346
2347 - def client_associated_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
2348 """\ 2349 Retrieve associated X2Go sessions of profile name <profile_name>. 2350 2351 @param profile_name: profile name 2352 @type profile_name: C{str} 2353 @param return_objects: return as list of X2Go session objects 2354 @type return_objects: C{bool} 2355 @param return_session_names: return as list of session names 2356 @type return_session_names: C{bool} 2357 2358 @return: list of associated sessions of profile name 2359 @rtype: C{list} 2360 2361 """ 2362 return self.session_registry.associated_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2363 __client_associated_sessions_of_profile_name = client_associated_sessions_of_profile_name 2364
2365 - def client_pubapp_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
2366 """\ 2367 Retrieve X2Go sessions of profile name <profile_name> that provide published applications. 2368 2369 @param profile_name: profile name 2370 @type profile_name: C{str} 2371 @param return_objects: return as list of X2Go session objects 2372 @type return_objects: C{bool} 2373 @param return_session_names: return as list of session names 2374 @type return_session_names: C{bool} 2375 2376 @return: list of application publishing sessions of profile name 2377 @rtype: C{list} 2378 2379 """ 2380 return self.session_registry.pubapp_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2381 __client_pubapp_sessions_of_profile_name = client_pubapp_sessions_of_profile_name 2382 2383
2384 - def client_running_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
2385 """\ 2386 Retrieve running X2Go sessions of profile name <profile_name>. 2387 2388 @param profile_name: profile name 2389 @type profile_name: C{str} 2390 @param return_objects: return as list of X2Go session objects 2391 @type return_objects: C{bool} 2392 @param return_session_names: return as list of session names 2393 @type return_session_names: C{bool} 2394 2395 @return: list of running sessions of profile name 2396 @rtype: C{list} 2397 2398 """ 2399 return self.session_registry.running_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2400 __client_running_sessions_of_profile_name = client_running_sessions_of_profile_name 2401
2402 - def client_suspended_sessions_of_profile_name(self, profile_name, return_objects=False, return_session_names=False):
2403 """\ 2404 Retrieve suspended X2Go sessions of profile name <profile_name>. 2405 2406 @param profile_name: profile name 2407 @type profile_name: C{str} 2408 @param return_objects: return as list of X2Go session objects 2409 @type return_objects: C{bool} 2410 @param return_session_names: return as list of session names 2411 @type return_session_names: C{bool} 2412 2413 @return: list of suspended sessions of profile name 2414 @rtype: C{list} 2415 2416 """ 2417 return self.session_registry.suspended_sessions_of_profile_name(profile_name, return_objects=return_objects, return_session_names=return_session_names)
2418 __client_suspended_sessions_of_profile_name = client_suspended_sessions_of_profile_name 2419 2420 ### 2421 ### Provide access to the X2Go server's sessions DB 2422 ### 2423
2424 - def server_is_alive(self, session_uuid):
2425 """\ 2426 Test if server that corresponds to the terminal session C{session_uuid} is alive. 2427 2428 If the session is not connected anymore the L{X2GoClient.HOOK_on_control_session_death()} gets called. 2429 2430 @param session_uuid: the X2Go session's UUID registry hash 2431 @type session_uuid: C{str} 2432 2433 @return: C{True} if X2Go server connection for L{X2GoSession} instance with <session_uuid> is alive. 2434 @rtype: C{bool} 2435 2436 @raise X2GoControlSessionException: if the session is not connected anymore; in that case the L{HOOK_on_control_session_death} gets called. 2437 2438 """ 2439 try: 2440 return self.session_registry(session_uuid).is_alive() 2441 except x2go_exceptions.X2GoControlSessionException: 2442 profile_name = self.get_session_profile_name(session_uuid) 2443 if self.session_registry(session_uuid).conntected: self.HOOK_on_control_session_death(profile_name) 2444 self.disconnect_profile(profile_name) 2445 return False
2446 __server_is_alive = server_is_alive 2447
2448 - def all_servers_are_alive(self):
2449 """\ 2450 Test vitality of all connected X2Go servers. 2451 2452 @return: C{True} if all connected X2Go servers are alive. 2453 @rtype: C{bool} 2454 2455 """ 2456 _all_alive = True 2457 for session_uuid in self.client_connected_sessions(): 2458 _all_alive = _all_alive and self.server_is_alive(session_uuid) 2459 return _all_alive
2460 __all_servers_are_alive = all_servers_are_alive 2461
2462 - def server_valid_x2gouser(self, session_uuid, username=None):
2463 """\ 2464 Check if user is allowed to start an X2Go session on a remote server. 2465 2466 @param session_uuid: the X2Go session's UUID registry hash 2467 @type session_uuid: C{str} 2468 @param username: user name to test validity for 2469 @type username: C{str} 2470 2471 @return: Is remote user allowed to start an X2Go session? 2472 @rtype: C{str} 2473 2474 """ 2475 return self.session_registry(session_uuid).user_is_x2gouser(username=username)
2476 __server_valid_x2gouser = server_valid_x2gouser 2477
2478 - def server_running_sessions(self, session_uuid):
2479 """\ 2480 Retrieve a list of session names of all server-side running sessions (including those not 2481 instantiated by our L{X2GoClient} instance). 2482 2483 @param session_uuid: the X2Go session's UUID registry hash 2484 @type session_uuid: C{str} 2485 2486 @return: list of session names 2487 @rtype: C{list} 2488 2489 @raise X2GoClientException: if the session with UUID C{session_uuid} is not connected 2490 2491 """ 2492 if self._X2GoClient__is_session_connected(session_uuid): 2493 session_list = self._X2GoClient__list_sessions(session_uuid) 2494 return [ key for key in session_list.keys() if session_list[key].status == 'R' ] 2495 else: 2496 raise x2go_exceptions.X2GoClientException('X2Go session with UUID %s is not connected' % session_uuid)
2497 __server_running_sessions = server_running_sessions 2498
2499 - def server_has_running_sessions(self, session_uuid):
2500 """\ 2501 Equals C{True} if the X2Go server has any running sessions. 2502 2503 @param session_uuid: the X2Go session's UUID registry hash 2504 @type session_uuid: C{str} 2505 @return: C{True}, if there are running sessions 2506 @rtype: C{bool} 2507 2508 """ 2509 return len(self._X2GoClient__server_running_sessions(session_uuid)) > 0
2510 __server_has_running_sessions = server_has_running_sessions 2511
2512 - def server_has_running_session_of_name(self, session_uuid, session_name):
2513 """\ 2514 Equals C{True} if the X2Go server has a running session of name <session_name>. 2515 2516 @param session_uuid: the X2Go session's UUID registry hash 2517 @type session_uuid: C{str} 2518 @param session_name: session name 2519 @type session_name: C{str} 2520 2521 """ 2522 return session_name in self._X2GoClient__server_running_sessions(session_uuid)
2523 __server_has_running_session_of_name = server_has_running_session_of_name 2524
2525 - def server_suspended_sessions(self, session_uuid):
2526 """\ 2527 Retrieve a list of session names of all server-side suspended sessions (including those not 2528 instantiated by our L{X2GoClient} instance). 2529 2530 @param session_uuid: the X2Go session's UUID registry hash 2531 @type session_uuid: C{str} 2532 2533 @return: list of session names 2534 @rtype: C{list} 2535 2536 @raise X2GoClientException: if the session with UUID C{session_uuid} is not connected 2537 2538 """ 2539 if self._X2GoClient__is_session_connected(session_uuid): 2540 session_list = self._X2GoClient__list_sessions(session_uuid) 2541 return [ key for key in session_list.keys() if session_list[key].status == 'S' ] 2542 else: 2543 raise x2go_exceptions.X2GoClientException('X2Go session with UUID %s is not connected' % session_uuid)
2544 __server_suspended_sessions = server_suspended_sessions 2545
2546 - def server_has_suspended_sessions(self, session_uuid):
2547 """\ 2548 Equals C{True} if the X2Go server has any suspended sessions. 2549 2550 @param session_uuid: the X2Go session's UUID registry hash 2551 @type session_uuid: C{str} 2552 2553 """ 2554 return len(self._X2GoClient__server_suspended_sessions(session_uuid)) > 0
2555 __server_has_suspended_sessions = server_has_suspended_sessions 2556
2557 - def server_has_suspended_session_of_name(self, session_uuid, session_name):
2558 """\ 2559 Equals C{True} if the X2Go server has a suspended session of name <session_name>. 2560 2561 @param session_uuid: the X2Go session's UUID registry hash 2562 @type session_uuid: C{str} 2563 @param session_name: session name 2564 @type session_name: C{str} 2565 @return: C{True}, if there are running sessions 2566 @rtype: C{bool} 2567 2568 """ 2569 return session_name in self._X2GoClient__server_suspended_sessions(session_uuid)
2570 __server_has_suspended_session_of_name = server_has_suspended_session_of_name 2571 2572 ### 2573 ### CLIENT OPERATIONS ON SESSIONS (listing sessions, terminating non-associated sessions etc.) 2574 ### 2575
2576 - def clean_sessions(self, session_uuid, published_applications=False):
2577 """\ 2578 Find running X2Go sessions that have previously been started by the 2579 connected user on the remote X2Go server and terminate them. 2580 2581 Before calling this method you have to setup a pro forma remote X2Go session 2582 with L{X2GoClient.register_session()} (even if you do not intend to open 2583 a real X2Go session window on the remote server) and connect to this session (with 2584 L{X2GoClient.connect_session()}. 2585 2586 @param session_uuid: the X2Go session's UUID registry hash 2587 @type session_uuid: C{str} 2588 @param published_applications: if C{True}, also terminate sessions that are published applications 2589 provider 2590 @type published_applications: C{bool} 2591 2592 """ 2593 _destroy_terminals = not ( self.auto_update_sessionregistry == True) 2594 try: 2595 session = self.session_registry(session_uuid) 2596 session.clean_sessions(destroy_terminals=_destroy_terminals, published_applications=published_applications) 2597 except x2go_exceptions.X2GoSessionRegistryException: 2598 # silently ignore a non-registered session UUID (mostly occurs during disconnects) 2599 pass
2600 __clean_sessions = clean_sessions 2601
2602 - def list_sessions(self, session_uuid=None, 2603 profile_name=None, profile_id=None, 2604 no_cache=False, refresh_cache=False, 2605 update_sessionregistry=True, 2606 register_sessions=False, 2607 raw=False):
2608 """\ 2609 Use the X2Go session registered under C{session_uuid} to 2610 retrieve a list of running or suspended X2Go sessions from the 2611 connected X2Go server (for the authenticated user). 2612 2613 Before calling this method you have to setup a pro forma remote X2Go session 2614 with L{X2GoClient.register_session()} (even if you do not intend to open 2615 a real X2Go session window on the remote server) and connect to this session (with 2616 L{X2GoClient.connect_session()}. 2617 2618 @param session_uuid: the X2Go session's UUID registry hash 2619 @type session_uuid: C{str} 2620 @param profile_name: use profile name instead of <session_uuid> 2621 @type profile_name: C{str} 2622 @param profile_id: use profile id instead of <profile_name> or <session_uuid> 2623 @type profile_id: C{str} 2624 @param no_cache: do not get the session list from cache, query the X2Go server directly 2625 @type no_cache: C{bool} 2626 @param refresh_cache: query the X2Go server directly and update the session list cache 2627 with the new information 2628 @type refresh_cache: C{bool} 2629 @param update_sessionregistry: query the X2Go server directly and update the 2630 session registry according to the obtained information 2631 @type update_sessionregistry: C{bool} 2632 @param register_sessions: query the X2Go server directly and register newly found X2Go session 2633 as L{X2GoSession} instances associated to this L{X2GoClient} instance 2634 @type register_sessions: C{bool} 2635 @param raw: output the session list in X2Go's raw C{x2golistsessions} format 2636 @type raw: C{bool} 2637 2638 @raise X2GoClientException: if the session profile specified by C{session_uuid}, C{profile_name} or C{profile_id} is not connected 2639 or if none of the named parameters has been specified 2640 2641 """ 2642 if profile_id is not None: 2643 profile_name = self.to_profile_name(profile_id) 2644 2645 if profile_name is not None: 2646 2647 _connected_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True) 2648 if _connected_sessions: 2649 # it does not really matter which session to use for getting a server-side session list 2650 # thus, we simply grab the first that comes in... 2651 session_uuid = _connected_sessions[0].get_uuid() 2652 else: 2653 raise x2go_exceptions.X2GoClientException('profile ,,%s\'\' is not connected' % profile_name) 2654 2655 elif session_uuid is not None: 2656 pass 2657 else: 2658 raise x2go_exceptions.X2GoClientException('must either specify session UUID or profile name') 2659 2660 if raw: 2661 return self.session_registry(session_uuid).list_sessions(raw=raw) 2662 2663 if not self.use_listsessions_cache or not self.auto_update_listsessions_cache or no_cache: 2664 _session_list = self.session_registry(session_uuid).list_sessions() 2665 elif refresh_cache: 2666 self.update_cache_by_session_uuid(session_uuid) 2667 _session_list = self.listsessions_cache.list_sessions(session_uuid) 2668 else: 2669 # if there is no cache for this session_uuid available, make sure the cache gets updated 2670 # before reading from it... 2671 if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type='sessions') or refresh_cache): 2672 self.__update_cache_by_session_uuid(session_uuid) 2673 _session_list = self.listsessions_cache.list_sessions(session_uuid) 2674 2675 if update_sessionregistry: 2676 self.update_sessionregistry_status_by_profile_name(profile_name=self.get_session_profile_name(session_uuid), session_list=_session_list) 2677 2678 if register_sessions: 2679 self.session_registry.register_available_server_sessions(profile_name=self.get_session_profile_name(session_uuid), 2680 session_list=_session_list) 2681 2682 return _session_list
2683 __list_sessions = list_sessions 2684
2685 - def list_desktops(self, session_uuid=None, 2686 profile_name=None, profile_id=None, 2687 no_cache=False, refresh_cache=False, 2688 exclude_session_types=[], 2689 raw=False):
2690 """\ 2691 Use the X2Go session registered under C{session_uuid} to 2692 retrieve a list of X2Go desktop sessions that are available 2693 for desktop sharing. 2694 2695 Before calling this method you have to setup a pro forma remote X2Go session 2696 with L{X2GoClient.register_session()} (even if you do not intend to open 2697 a real X2Go session window on the remote server) and connect to this session (with 2698 L{X2GoClient.connect_session()}. 2699 2700 @param session_uuid: the X2Go session's UUID registry hash 2701 @type session_uuid: C{str} 2702 @param profile_name: use profile name instead of <session_uuid> 2703 @type profile_name: C{str} 2704 @param profile_id: use profile id instead of <profile_name> or <session_uuid> 2705 @type profile_id: C{str} 2706 @param no_cache: do not get the desktop list from cache, query the X2Go server directly 2707 @type no_cache: C{bool} 2708 @param refresh_cache: query the X2Go server directly and update the desktop list cache 2709 with the new information 2710 @type refresh_cache: C{bool} 2711 @param exclude_session_types: session types (e.g. "D", "R", "S" or "P") to be excluded from the 2712 returned list of sharable desktops (this only works for sharing someone's own sessions, for 2713 sharing other users' sessions, the X2Go Desktop Sharing decides on what is sharable and what not). 2714 @type exclude_session_types: C{list} 2715 @param raw: output the session list in X2Go's raw C{x2golistdesktops} format 2716 @type raw: C{bool} 2717 2718 @return: a list of available desktops to be shared 2719 @rtype: C{list} 2720 2721 @raise X2GoClientException: if the session profile specified by C{session_uuid}, C{profile_name} or C{profile_id} is not connected 2722 or if none of the named parameters has been specified 2723 2724 """ 2725 if profile_id is not None: 2726 profile_name = self.to_profile_name(profile_id) 2727 2728 if profile_name is not None: 2729 2730 _connected_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True) 2731 if _connected_sessions: 2732 # it does not really matter which session to use for getting a server-side session list 2733 # thus, we simply grab the first that comes in... 2734 session_uuid = _connected_sessions[0].get_uuid() 2735 else: 2736 raise x2go_exceptions.X2GoClientException('profile ,,%s\'\' is not connected' % profile_name) 2737 2738 elif session_uuid is not None: 2739 pass 2740 else: 2741 raise x2go_exceptions.X2GoClientException('must either specify session UUID or profile name') 2742 2743 if raw: 2744 return self.session_registry(session_uuid).list_desktops(raw=raw) 2745 2746 if not self.use_listsessions_cache or not self.auto_update_listdesktops_cache or no_cache: 2747 _desktop_list = self.session_registry(session_uuid).list_desktops() 2748 else: 2749 if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type='desktops') or refresh_cache): 2750 self.__update_cache_by_session_uuid(session_uuid, update_sessions=False, update_desktops=True) 2751 _desktop_list = self.listsessions_cache.list_desktops(session_uuid) 2752 2753 # attempt to exclude session types that are requested to be excluded 2754 if exclude_session_types: 2755 2756 # create an X2GoServerSessionList* instance and operate on that 2757 session_list = self.list_backend() 2758 session_list.set_sessions(self._X2GoClient__list_sessions(session_uuid)) 2759 2760 # search for a match among the listed sessions 2761 for desktop in copy.deepcopy(_desktop_list): 2762 user = desktop.split('@')[0] 2763 if user == self.get_session_username(session_uuid): 2764 display = desktop.split('@')[1] 2765 session = session_list.get_session_with('display', display, hostname=self.get_session_server_hostname(session_uuid)) 2766 if session is None: continue 2767 if session.get_session_type() in exclude_session_types: 2768 _desktop_list.remove(desktop) 2769 2770 return _desktop_list
2771 __list_desktops = list_desktops 2772
2773 - def list_mounts_by_profile_name(self, profile_name, 2774 no_cache=False, refresh_cache=False, 2775 raw=False):
2776 """ 2777 For a given profil C{profile_name} to 2778 retrieve its list of mounted client shares for that session. 2779 2780 @param profile_name: a valid profile name 2781 @type profile_name: C{str} 2782 @param no_cache: do not get the session list from cache, query the X2Go server directly 2783 @type no_cache: C{bool} 2784 @param raw: output the session list in X2Go's raw C{x2golistmounts} format 2785 @type raw: C{bool} 2786 2787 @return: list of server-side mounted shares for a given profile name 2788 @rtype: C{list} 2789 2790 """ 2791 sessions = [ s for s in self.client_running_sessions(return_objects=True) if s.get_profile_name() == profile_name ] 2792 2793 if raw: 2794 _list_mounts = "" 2795 for session in sessions: 2796 _list_mounts += self.__list_mounts(session_uuid=session(), no_cache=no_cache, refresh_cache=refresh_cache, raw=True) 2797 else: 2798 _list_mounts = {} 2799 for session in sessions: 2800 _list_mounts.update(self.__list_mounts(session_uuid=session(), no_cache=no_cache, refresh_cache=refresh_cache, raw=False)) 2801 return _list_mounts
2802 __list_mounts_by_profile_name = list_mounts_by_profile_name 2803
2804 - def list_mounts(self, session_uuid, 2805 no_cache=False, refresh_cache=False, 2806 raw=False):
2807 """\ 2808 Use the X2Go session registered under C{session_uuid} to 2809 retrieve its list of mounted client shares for that session. 2810 2811 @param session_uuid: the X2Go session's UUID registry hash 2812 @type session_uuid: C{str} 2813 @param no_cache: do not get the session list from cache, query the X2Go server directly 2814 @type no_cache: C{bool} 2815 @param raw: output the session list in X2Go's raw C{x2golistmounts} format 2816 @type raw: C{bool} 2817 2818 @return: list of server-side mounted shares for a given session UUID 2819 @rtype: C{list} 2820 2821 """ 2822 if raw: 2823 return self.session_registry(session_uuid).list_mounts(raw=raw) 2824 2825 if not self.use_listsessions_cache or not self.auto_update_listmounts_cache or no_cache: 2826 _mounts_list = self.session_registry(session_uuid).list_mounts() 2827 else: 2828 if self.use_listsessions_cache and (not self.listsessions_cache.is_cached(session_uuid=session_uuid, cache_type='mounts') or refresh_cache): 2829 self.__update_cache_by_session_uuid(session_uuid, update_sessions=False, update_mounts=True) 2830 _mounts_list = self.listsessions_cache.list_mounts(session_uuid) 2831 2832 return _mounts_list
2833 __list_mounts = list_mounts 2834 2835 ### 2836 ### Provide access to config file class objects 2837 ### 2838
2839 - def get_profiles(self):
2840 """\ 2841 Returns the L{X2GoClient} instance's C{X2GoSessionProfiles*} object. 2842 2843 Use this method for object retrieval if you want to modify the »sessions« 2844 configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your 2845 Python X2Go based application. 2846 2847 return: returns the client's session profiles instance 2848 rtype: C{X2GoSessionProfiles*} instance 2849 2850 """ 2851 return self.session_profiles
2852 __get_profiles = get_profiles 2853 get_session_profiles = get_profiles 2854 """Alias for L{get_profiles()}.""" 2855 2856 @property
2857 - def profile_names(self):
2858 """\ 2859 Equals a list of all profile names that are known to this L{X2GoClient} instance. 2860 2861 """ 2862 return self.session_profiles.profile_names
2863 __profile_names = profile_names 2864
2865 - def get_client_settings(self):
2866 """\ 2867 Returns the L{X2GoClient} instance's C{X2GoClientSettings*} object. 2868 2869 Use this method for object retrieval if you want to modify the »settings« 2870 configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your 2871 Python X2Go based application. 2872 2873 return: returns the client's settings configuration node 2874 rtype: C{bool} 2875 2876 """ 2877 return self.client_settings
2878 __get_client_settings = get_client_settings 2879
2880 - def get_client_printing(self):
2881 """\ 2882 Returns the L{X2GoClient} instance's C{X2GoClientPrinting*} object. 2883 2884 Use this method for object retrieval if you want to modify the printing 2885 configuration node (e.g. in ~/.x2goclient with the FILE backend) from within your 2886 Python X2Go based application. 2887 2888 return: returns the client's printing configuration node 2889 rtype: C{bool} 2890 2891 """ 2892 return self.client_printing
2893 __get_client_printing = get_client_printing 2894 2895 ### 2896 ### Session profile oriented methods 2897 ### 2898
2899 - def get_profile_config(self, profile_id_or_name, parameter=None):
2900 """\ 2901 Returns a dictionary with session options and values that represent 2902 the session profile for C{profile_id_or_name}. 2903 2904 @param profile_id_or_name: name or id of an X2Go session profile as found 2905 in the sessions configuration file 2906 @type profile_id_or_name: C{str} 2907 @param parameter: if specified, only the value for the given parameter is returned 2908 @type parameter: C{str} 2909 2910 @return: a Python dictionary with session profile options 2911 @rtype: C{dict} or C{bool}, C{int}, C{str} 2912 2913 """ 2914 return self.session_profiles.get_profile_config(profile_id_or_name, parameter=parameter)
2915 __get_profile_config = get_profile_config 2916 with_profile_config = get_profile_config 2917
2918 - def set_profile_config(self, profile_id_or_name, parameter, value):
2919 """\ 2920 Set individual session profile parameters for session profile C{profile_id_or_name}. 2921 2922 @param profile_id_or_name: name or id of an X2Go session profile as found 2923 in the sessions configuration file 2924 @type profile_id_or_name: C{str} 2925 @param parameter: set this parameter with the given C{value} 2926 @type parameter: C{str} 2927 @param value: set this value for the given C{parameter} 2928 @type value: C{bool}, C{int}, C{str}, C{list} or C{dict} 2929 2930 @return: returns C{True} if this operation has been successful 2931 @rtype: C{dict} 2932 2933 """ 2934 self.session_profiles.update_value(profile_id_or_name, parameter, value) 2935 self.session_profiles.write_user_config = True 2936 self.session_profiles.write()
2937 __set_profile_config = set_profile_config 2938
2939 - def to_profile_id(self, profile_name):
2940 """\ 2941 Retrieve the session profile ID of the session whose profile name 2942 is C{profile_name} 2943 2944 @param profile_name: the session profile name 2945 @type profile_name: C{str} 2946 2947 @return: the session profile's ID 2948 @rtype: C{str} 2949 2950 """ 2951 return self.session_profiles.to_profile_id(profile_name)
2952 __to_profile_id = to_profile_id 2953
2954 - def to_profile_name(self, profile_id):
2955 """\ 2956 Retrieve the session profile name of the session whose profile ID 2957 is C{profile_id} 2958 2959 @param profile_id: the session profile ID 2960 @type profile_id: C{str} 2961 2962 @return: the session profile's name 2963 @rtype: C{str} 2964 2965 """ 2966 return self.session_profiles.to_profile_name(profile_id)
2967 __to_profile_name = to_profile_name 2968
2969 - def get_profile_metatype(self, profile_name):
2970 """\ 2971 Evaluate a session profile and return a human readable meta type 2972 (classification) for the session profile C{profile_name}. 2973 2974 @param profile_name: a profile name 2975 @type profile_name: C{str} 2976 2977 @return: the profile's meta type 2978 @rtype: C{str} 2979 2980 """ 2981 return self.session_profiles.get_profile_metatype(profile_name)
2982 __get_profile_metatype = get_profile_metatype 2983
2984 - def client_connected_profiles(self, return_profile_names=False):
2985 """\ 2986 Retrieve a list of session profiles that are currently connected to an X2Go server. 2987 2988 @param return_profile_names: return as list of session profile names 2989 @type return_profile_names: C{bool} 2990 @return: a list of profile names or IDs 2991 @rtype: C{list} 2992 2993 """ 2994 if return_profile_names: 2995 return [ self.to_profile_name(p_id) for p_id in self.session_registry.connected_profiles() ] 2996 else: 2997 return self.session_registry.connected_profiles()
2998 __client_connected_profiles = client_connected_profiles 2999
3000 - def disconnect_profile(self, profile_name):
3001 """\ 3002 Disconnect all L{X2GoSession} instances that relate to C{profile_name} by closing down their 3003 Paramiko/SSH Transport thread. 3004 3005 @param profile_name: the X2Go session profile name 3006 @type profile_name: C{str} 3007 @return: a return value 3008 @rtype: C{bool} 3009 3010 """ 3011 _retval = False 3012 _session_uuid_list = [] 3013 # disconnect individual sessions and make a list of session UUIDs for later cleanup (s. below) 3014 for s in self.session_registry.registered_sessions_of_profile_name(profile_name, return_objects=True): 3015 _session_uuid_list.append(s.get_uuid()) 3016 _retval = s.disconnect() | _retval 3017 3018 # tell session registry to forget attached sessions completely on disconnect action 3019 for uuid in _session_uuid_list: 3020 self.session_registry.forget(uuid) 3021 3022 # clear cache, as well... 3023 if self.use_listsessions_cache: 3024 self.listsessions_cache.delete(profile_name) 3025 return _retval
3026 __disconnect_profile = disconnect_profile 3027
3028 - def update_sessionregistry_status_by_profile_name(self, profile_name, session_list=None):
3029 """\ 3030 Update the session registry stati by profile name. 3031 3032 @param profile_name: the X2Go session profile name 3033 @type profile_name: C{str} 3034 @param session_list: a manually passed on list of X2Go sessions 3035 @type session_list: C{X2GoServerList*} instances 3036 3037 """ 3038 session_uuids = self.client_registered_sessions_of_profile_name(profile_name, return_objects=False) 3039 if session_uuids: 3040 if session_list is None: 3041 session_list = self._X2GoClient__list_sessions(session_uuids[0], 3042 update_sessionregistry=False, 3043 register_sessions=False, 3044 ) 3045 try: 3046 self.session_registry.update_status(profile_name=profile_name, session_list=session_list) 3047 except x2go_exceptions.X2GoControlSessionException: 3048 if self.session_registry(session_uuids[0]).connected: self.HOOK_on_control_session_death(profile_name) 3049 self.disconnect_profile(profile_name)
3050 __update_sessionregistry_status_by_profile_name = update_sessionregistry_status_by_profile_name 3051
3052 - def update_sessionregistry_status_by_session_uuid(self, session_uuid):
3053 """\ 3054 Update the session registry status of a specific L{X2GoSession} instance with 3055 session identifier <session_uuid>. 3056 3057 @param session_uuid: the X2Go session's UUID registry hash 3058 @type session_uuid: C{str} 3059 3060 """ 3061 session_list = self._X2GoClient__list_sessions(session_uuid, update_sessionregistry=False, register_sessions=False) 3062 if session_list: 3063 self.session_registry.update_status(session_uuid=session_uuid, session_list=session_list)
3064 __update_sessionregistry_status_by_session_uuid = update_sessionregistry_status_by_session_uuid 3065
3067 """\ 3068 Update the session registry stati of all session profiles. 3069 3070 """ 3071 for profile_name in self.client_connected_profiles(return_profile_names=True): 3072 self.__update_sessionregistry_status_by_profile_name(profile_name)
3073 __update_sessionregistry_status_all_profiles = update_sessionregistry_status_all_profiles 3074 3075
3076 - def update_cache_by_profile_name(self, profile_name, cache_types=('sessions'), update_sessions=None, update_desktops=None, update_mounts=None):
3077 """\ 3078 Update the session list cache by profile name. 3079 3080 @param profile_name: the X2Go session profile name 3081 @type profile_name: C{str} 3082 @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops}, C{mounts}) 3083 @type cache_types: C{tuple} or C{list} 3084 @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if 3085 you want to update sessions in the session list cache. 3086 @type update_sessions: C{bool} 3087 @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if 3088 you want to update available desktops in the desktop list cache. 3089 @type update_desktops: C{bool} 3090 @param update_mounts: instead of giving a list of cache types, plainly say C{True} here, if 3091 you want to update mounted shares in the mount list cache. 3092 @type update_mounts: C{bool} 3093 3094 """ 3095 if self.listsessions_cache is not None: 3096 _update_sessions = ('sessions' in cache_types) or update_sessions 3097 _update_desktops = ('desktops' in cache_types) or update_desktops 3098 _update_mounts = ('mounts' in cache_types) or update_mounts 3099 try: 3100 self.listsessions_cache.update(profile_name, update_sessions=_update_sessions, update_desktops=_update_desktops, update_mounts=_update_mounts, ) 3101 except x2go_exceptions.X2GoControlSessionException: 3102 c_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True) 3103 if len(c_sessions) and c_sessions[0].connected: self.HOOK_on_control_session_death(profile_name) 3104 self.disconnect_profile(profile_name)
3105 __update_cache_by_profile_name = update_cache_by_profile_name 3106
3107 - def update_cache_by_session_uuid(self, session_uuid, cache_types=('sessions'), update_sessions=None, update_desktops=None, update_mounts=None):
3108 """\ 3109 Update the session list cache of a specific L{X2GoSession} instance with 3110 session identifier <session_uuid>. 3111 3112 @param session_uuid: the X2Go session's UUID registry hash 3113 @type session_uuid: C{str} 3114 @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops}, C{mounts}) 3115 @type cache_types: C{tuple} or C{list} 3116 @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if 3117 you want to update sessions in the session list cache. 3118 @type update_sessions: C{bool} 3119 @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if 3120 you want to update available desktops in the desktop list cache. 3121 @type update_desktops: C{bool} 3122 @param update_mounts: instead of giving a list of cache types, plainly say C{True} here, if 3123 you want to update mounted shares in the mount list cache. 3124 @type update_mounts: C{bool} 3125 3126 """ 3127 profile_name = self.get_session_profile_name(session_uuid) 3128 self.__update_cache_by_profile_name(profile_name, 3129 cache_types=cache_types, 3130 update_sessions=update_sessions, 3131 update_desktops=update_desktops, 3132 update_mounts=update_mounts, 3133 )
3134 __update_cache_by_session_uuid = update_cache_by_session_uuid 3135
3136 - def update_cache_all_profiles(self, cache_types=('sessions'), update_sessions=None, update_desktops=None, update_mounts=None):
3137 """\ 3138 Update the session list cache of all session profiles. 3139 3140 @param cache_types: specify what cache type to update (available: C{sessions}, C{desktops}, C{mounts}) 3141 @type cache_types: C{tuple} or C{list} 3142 @param update_sessions: instead of giving a list of cache types, plainly say C{True} here, if 3143 you want to update sessions in the session list cache. 3144 @type update_sessions: C{bool} 3145 @param update_desktops: instead of giving a list of cache types, plainly say C{True} here, if 3146 you want to update available desktops in the desktop list cache. 3147 @type update_desktops: C{bool} 3148 @param update_mounts: instead of giving a list of cache types, plainly say C{True} here, if 3149 you want to update mounted shares in the mount list cache. 3150 @type update_mounts: C{bool} 3151 3152 """ 3153 if self.listsessions_cache is not None: 3154 for profile_name in self.client_connected_profiles(return_profile_names=True): 3155 self.__update_cache_by_profile_name(profile_name, 3156 cache_types=cache_types, 3157 update_sessions=update_sessions, 3158 update_desktops=update_desktops, 3159 update_mounts=update_mounts, 3160 ) 3161 3162 # remove profiles that are not connected any more from cache object 3163 self.listsessions_cache.check_cache()
3164 3165 __update_cache_all_profiles = update_cache_all_profiles 3166
3167 - def register_available_server_sessions_by_profile_name(self, profile_name, re_register=False, skip_pubapp_sessions=False):
3168 """\ 3169 Register available sessions that are found on the X2Go server the profile 3170 of name C{profile_name} is connected to. 3171 3172 @param profile_name: the X2Go session profile name 3173 @type profile_name: C{str} 3174 @param re_register: re-register available sessions, needs to be done after session profile changes 3175 @type re_register: C{bool} 3176 @param skip_pubapp_sessions: Do not auto-register published applications sessions. 3177 @type skip_pubapp_sessions: C{bool} 3178 3179 """ 3180 if profile_name not in self.client_connected_profiles(return_profile_names=True): 3181 return 3182 session_list = self._X2GoClient__list_sessions(profile_name=profile_name, 3183 update_sessionregistry=False, 3184 register_sessions=False, 3185 ) 3186 try: 3187 self.session_registry.register_available_server_sessions(profile_name, session_list=session_list, re_register=re_register, skip_pubapp_sessions=skip_pubapp_sessions) 3188 except x2go_exceptions.X2GoControlSessionException, e: 3189 c_sessions = self.client_connected_sessions_of_profile_name(profile_name, return_objects=True) 3190 if len(c_sessions) and c_sessions[0].connected: self.HOOK_on_control_session_death(profile_name) 3191 self.disconnect_profile(profile_name) 3192 raise e
3193 __register_available_server_sessions_by_profile_name = register_available_server_sessions_by_profile_name 3194
3195 - def register_available_server_sessions_by_session_uuid(self, session_uuid, skip_pubapp_sessions=False):
3196 """\ 3197 Register available sessions that are found on the X2Go server that the L{X2GoSession} instance 3198 with session identifier <session_uuid> is connected to. 3199 3200 @param session_uuid: the X2Go session's UUID registry hash 3201 @type session_uuid: C{str} 3202 @param skip_pubapp_sessions: Do not auto-register published applications sessions. 3203 @type skip_pubapp_sessions: C{bool} 3204 3205 """ 3206 profile_name = self.get_session_profile_name(session_uuid) 3207 self.__register_available_server_sessions_by_profile_name(profile_name, skip_pubapp_sessions=skip_pubapp_sessions)
3208 __register_available_server_sessions_by_session_uuid = register_available_server_sessions_by_session_uuid 3209
3210 - def register_available_server_sessions_all_profiles(self, skip_pubapp_sessions=False):
3211 """\ 3212 Register all available sessions found on an X2Go server for each session profile. 3213 3214 @param skip_pubapp_sessions: Do not auto-register published applications sessions. 3215 @type skip_pubapp_sessions: C{bool} 3216 3217 """ 3218 for profile_name in self.client_connected_profiles(return_profile_names=True): 3219 try: 3220 self.__register_available_server_sessions_by_profile_name(profile_name, skip_pubapp_sessions=skip_pubapp_sessions) 3221 except x2go_exceptions.X2GoSessionRegistryException: 3222 pass
3223 __register_available_server_sessions_all_profiles = register_available_server_sessions_all_profiles
3224