Package x2go :: Module session :: Class X2goSession
[frames] | no frames]

Class X2goSession

source code

object --+
         |
        X2goSession

Public API class for launching X2go sessions. Recommended is to manage X2go sessions from within an X2goClient instance. However, Python X2go is designed in a way that it also allows the management of singel X2goSession instance.

Thus, you can use the X2goSession class to manually set up X2go sessions without X2goClient context (session registry, session list cache, auto-registration of new sessions etc.).

Instance Methods
 
__init__(self, server=None, control_session=None, use_sshproxy=False, profile_id=None, profile_name='UNKNOWN', session_name=None, printing=False, allow_mimebox=False, mimebox_extensions=[], mimebox_action='OPEN', allow_share_local_folders=False, share_local_folders=[], control_backend=<class 'x2go.backends.control._stdout.X2goControlSessionSTDOUT'>, terminal_backend=<class 'x2go.backends.terminal._stdout.X2goTerminalSessionSTDO..., info_backend=<class 'x2go.backends.info._stdout.X2goServerSessionInfoSTDOUT'>, list_backend=<class 'x2go.backends.info._stdout.X2goServerSessionListSTDOUT'>, proxy_backend=<class 'x2go.backends.proxy._nx3.X2goProxyNX3'>, settings_backend=<class 'x2go.backends.settings._file.X2goClientSettingsFILE'>, printing_backend=<class 'x2go.backends.printing._file.X2goClientPrintingFILE'>, client_rootdir='/home/buildd/.x2goclient', sessions_rootdir='/home/buildd/.x2go', ssh_rootdir='/home/buildd/.ssh', keep_controlsession_alive=False, add_to_known_hosts=False, known_hosts=None, logger=None, loglevel=56, connected=False, virgin=True, running=None, suspended=None, terminated=None, faulty=None, client_instance=None, **params)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
HOOK_session_startup_failed(self)
HOOK method: called if the startup of a session failed.
source code
 
HOOK_rforward_request_denied(self, server_port=0)
HOOK method: called if a reverse port forwarding request has been denied.
source code
 
HOOK_forwarding_tunnel_setup_failed(self, chain_host='UNKNOWN', chain_port=0)
HOOK method: called if a port forwarding tunnel setup failed.
source code
bool
HOOK_check_host_dialog(self, host, port, fingerprint='no fingerprint', fingerprint_type='RSA')
HOOK method: called if a host check is requested.
source code
 
init_control_session(self)
Initialize a new control session (X2goControlSession*).
source code
 
set_server(self, server)
Modify server name after X2goSession has already been initialized.
source code
 
set_profile_name(self, profile_name)
Modify session profile name after X2goSession has already been initialized.
source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
repr(x)
source code
 
__call__(self) source code
 
__del__(self)
Class destructor.
source code
 
update_params(self, params)
This method can be used to modify X2goSession parameters after the X2goSession instance has already been initialized.
source code
 
get_uuid(self)
Retrieve session UUID hash for this X2goSession.
source code
str
get_username(self)
After a session has been set up you can query the username the sessions runs as.
source code
bool
user_is_x2gouser(self, username=None)
Check if a given user is valid server-side X2go user.
source code
str
get_password(self)
After a session has been setup up you can query the username's password from the session.
source code
tuple
get_server_peername(self)
After a session has been setup up you can query the peername of the host this session is connected to (or about to connect to).
source code
str
get_server_hostname(self)
After a session has been setup up you can query the hostname of the host this session is connected to (or about to connect to).
source code
str
get_server_port(self)
After a session has been setup up you can query the IP socket port used for connecting the remote X2go server.
source code
str
get_session_name(self)
Retrieve the server-side X2go session name for this session.
source code
str
get_session_cmd(self)
Retrieve the server-side command that is used to start a session on the remote X2go server.
source code
X2goControlSession* instance
get_control_session(self)
Retrieve the control session (X2goControlSession* backend) of this X2goSession.
source code
bool
has_control_session(self)
Check if this X2goSession instance has an associated control session.
source code
X2goControlTerminal* instance
get_terminal_session(self)
Retrieve the terminal session (X2goTerminalSession* backend) of this X2goSession.
source code
bool
has_terminal_session(self)
Check if this X2goSession instance has an associated terminal session.
source code
bool
check_host(self)
Provide a host check mechanism.
source code
bool
uses_sshproxy(self)
Check if a session is configured to use an intermediate SSH proxy server.
source code
bool
can_sshproxy_auto_connect(self)
Check if a session's SSH proxy (if used) is configured adequately to be able to auto-connect to the SSH proxy server (e.g.
source code
bool
can_auto_connect(self)
Check if a session is configured adequately to be able to auto-connect to the X2go server (e.g.
source code
 
connect(self, username='', password='', add_to_known_hosts=False, force_password_auth=False, use_sshproxy=False, sshproxy_user='', sshproxy_password='')
Connects to the X2goSession's server host.
source code
bool
disconnect(self)
Disconnect this X2goSession instance.
source code
 
set_print_action(self, print_action, **kwargs)
If X2go client-side printing is enable within this X2go session you can use this method to alter the way how incoming print spool jobs are handled/processed.
source code
bool
is_alive(self)
Find out if this X2go session is still alive (that is: connected to the server).
source code
 
clean_sessions(self, destroy_terminals=True)
Clean all running sessions for the authenticated user on the remote X2go server.
source code
X2goServerSessionList* instance or list
list_sessions(self, raw=False)
List all sessions on the remote X2go server that are owned by the authenticated user
source code
list
list_desktops(self, raw=False)
List X2go desktops sessions available for desktop sharing on the remote X2go server.
source code
 
update_status(self, session_list=None, force_update=False)
Update the current session status.
source code
bool
resume(self, session_name=None)
Resume or continue a suspended / running X2go session on the remote X2go server.
source code
bool
start(self)
Start a new X2go session on the remote X2go server.
source code
bool
share_desktop(self, desktop=None, user=None, display=None, share_mode=0, check_desktop_list=True)
Share an already running X2go session on the remote X2go server locally.
source code
bool
suspend(self)
Suspend this X2go session.
source code
bool
terminate(self)
Terminate this X2go session.
source code
str
get_profile_name(self)
Retrieve the profile name of this X2goSession instance.
source code
str
get_profile_id(self)
Retrieve the profile ID of this X2goSession instance.
source code
bool
session_ok(self)
Test if this X2goSession is in a healthy state.
source code
str
color_depth_from_session_name(self)
Extract color depth from session name.
source code
 
is_color_depth_ok(self)
Check if this session will display properly with the local screen's color depth.
source code
bool
is_connected(self)
Test if the X2goSession's control session is connected to the remote X2go server.
source code
bool
is_running(self)
Test if the X2goSession's terminal session is up and running.
source code
bool
is_suspended(self)
Test if the X2goSession's terminal session is in suspended state.
source code
bool
has_terminated(self)
Test if the X2goSession's terminal session has terminated.
source code
bool
is_folder_sharing_available(self)
Test if the remote session allows sharing of local folders with the session.
source code
bool
share_local_folder(self, local_path=None, folder_name=None)
Share a local folder with this registered X2go session.
source code
bool
unshare_all_local_folders(self, force_all=False)
Unshare all local folders mounted within this X2go session.
source code
bool
unshare_local_folder(self, local_path=None)
Unshare a local folder that is mounted within this X2go session.
source code
list
get_shared_folders(self)
Get a list of local folders mounted within this X2go session from this client.
source code
bool
is_locked(self)
Query session if it is locked by some command being processed.
source code
 
session_cleanup(self)
Clean up X2go session.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, server=None, control_session=None, use_sshproxy=False, profile_id=None, profile_name='UNKNOWN', session_name=None, printing=False, allow_mimebox=False, mimebox_extensions=[], mimebox_action='OPEN', allow_share_local_folders=False, share_local_folders=[], control_backend=<class 'x2go.backends.control._stdout.X2goControlSessionSTDOUT'>, terminal_backend=<class 'x2go.backends.terminal._stdout.X2goTerminalSessionSTDO..., info_backend=<class 'x2go.backends.info._stdout.X2goServerSessionInfoSTDOUT'>, list_backend=<class 'x2go.backends.info._stdout.X2goServerSessionListSTDOUT'>, proxy_backend=<class 'x2go.backends.proxy._nx3.X2goProxyNX3'>, settings_backend=<class 'x2go.backends.settings._file.X2goClientSettingsFILE'>, printing_backend=<class 'x2go.backends.printing._file.X2goClientPrintingFILE'>, client_rootdir='/home/buildd/.x2goclient', sessions_rootdir='/home/buildd/.x2go', ssh_rootdir='/home/buildd/.ssh', keep_controlsession_alive=False, add_to_known_hosts=False, known_hosts=None, logger=None, loglevel=56, connected=False, virgin=True, running=None, suspended=None, terminated=None, faulty=None, client_instance=None, **params)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • server (str) - hostname of X2go server
  • control_session (X2goControlSession* instance) - an already initialized X2goControlSession* instance
  • use_sshproxy (bool) - for communication with X2go server use an SSH proxy host
  • profile_id (str) - profile ID
  • profile_name (str) - profile name
  • session_name (str) - session name (if available)
  • printing (bool) - enable X2go printing
  • allow_mimebox (bool) - enable X2go MIME box support
  • mimebox_extensions (list) - whitelist of allowed X2go MIME box extensions
  • mimebox_action (X2goMimeBoxAction* or str) - action for incoming X2go MIME box files
  • allow_share_local_folders (bool) - enable local folder sharing support
  • share_local_folders (list) - list of local folders to share with the remote X2go session
  • control_backend (class) - X2go control session backend to use
  • terminal_backend (class) - X2go terminal session backend to use
  • info_backend (class) - X2go session info backend to use
  • list_backend (class) - X2go session list backend to use
  • proxy_backend (class) - X2go proxy backend to use
  • settings_backend (class) - X2go client settings backend to use
  • printing_backend (class) - X2go client printing backend to use
  • client_rootdir (str) - client base dir (default: ~/.x2goclient)
  • sessions_rootdir (str) - sessions base dir (default: ~/.x2go)
  • ssh_rootdir (str) - ssh base dir (default: ~/.ssh)
  • keep_controlsession_alive - On last X2goSession.disconnect() keep the associated X2goControlSession* instance alive? @ŧype keep_controlsession_alive: bool
  • add_to_known_hosts (bool) - Auto-accept server host validity?
  • known_hosts (str) - the underlying Paramiko/SSH systems known_hosts file
  • connected (bool) - manipulate session state »connected« by giving a pre-set value
  • virgin (bool) - manipulate session state »virgin« by giving a pre-set value
  • running (bool) - manipulate session state »running« by giving a pre-set value
  • suspended (bool) - manipulate session state »suspended« by giving a pre-set value
  • terminated (bool) - manipulate session state »terminated« by giving a pre-set value
  • faulty (bool) - manipulate session state »faulty« by giving a pre-set value
  • client_instance (X2goClient instance) - if available, the underlying X2goClient instance
  • params (dict) - further control session, terminal session and SSH proxy class options
Overrides: object.__init__

HOOK_rforward_request_denied(self, server_port=0)

source code 

HOOK method: called if a reverse port forwarding request has been denied.

Parameters:
  • server_port (str) - remote server port (starting point of reverse forwarding tunnel)

HOOK_forwarding_tunnel_setup_failed(self, chain_host='UNKNOWN', chain_port=0)

source code 

HOOK method: called if a port forwarding tunnel setup failed.

Parameters:
  • chain_host (str) - hostname of chain host (forwarding tunnel end point)
  • chain_port (str) - port of chain host (forwarding tunnel end point)

HOOK_check_host_dialog(self, host, port, fingerprint='no fingerprint', fingerprint_type='RSA')

source code 

HOOK method: called if a host check is requested. This hook has to either return True (default) or False.

Parameters:
  • host (str) - SSH server name to validate
  • port (int) - SSH server port to validate
  • fingerprint (str) - the server's fingerprint
  • fingerprint_type (str) - finger print type (like RSA, DSA, ...)
Returns: bool
if host validity is verified, this hook method should return True

set_server(self, server)

source code 

Modify server name after X2goSession has already been initialized.

Parameters:
  • server (str) - new server name

set_profile_name(self, profile_name)

source code 

Modify session profile name after X2goSession has already been initialized.

Parameters:
  • profile_name (str) - new session profile name

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

update_params(self, params)

source code 

This method can be used to modify X2goSession parameters after the X2goSession instance has already been initialized.

Parameters:
  • params (dict) - a Python dictionary with X2goSession parameters

get_username(self)

source code 

After a session has been set up you can query the username the sessions runs as.

Returns: str
the remote username the X2go session runs as

user_is_x2gouser(self, username=None)

source code 

Check if a given user is valid server-side X2go user.

Parameters:
  • username (str) - username to check validity for
Returns: bool
return True if the username is allowed to launch X2go sessions

get_password(self)

source code 

After a session has been setup up you can query the username's password from the session.

Returns: str
the username's password

get_server_peername(self)

source code 

After a session has been setup up you can query the peername of the host this session is connected to (or about to connect to).

Returns: tuple
the address of the server the X2go session is connected to (as an (addr,port) tuple)

get_server_hostname(self)

source code 

After a session has been setup up you can query the hostname of the host this session is connected to (or about to connect to).

Returns: str
the hostname of the server the X2go session is connected to / about to connect to

get_server_port(self)

source code 

After a session has been setup up you can query the IP socket port used for connecting the remote X2go server.

Returns: str
the server-side IP socket port that is used by the X2go session to connect to the server

get_session_name(self)

source code 

Retrieve the server-side X2go session name for this session.

Returns: str
X2go session name

get_session_cmd(self)

source code 

Retrieve the server-side command that is used to start a session on the remote X2go server.

Returns: str
server-side session command

get_control_session(self)

source code 

Retrieve the control session (X2goControlSession* backend) of this X2goSession.

Returns: X2goControlSession* instance
the X2goSession's control session

has_control_session(self)

source code 

Check if this X2goSession instance has an associated control session.

Returns: bool
returns True if this X2goSession has a control session associated to itself

get_terminal_session(self)

source code 

Retrieve the terminal session (X2goTerminalSession* backend) of this X2goSession.

Returns: X2goControlTerminal* instance
the X2goSession's terminal session

has_terminal_session(self)

source code 

Check if this X2goSession instance has an associated terminal session.

Returns: bool
returns True if this X2goSession has a terminal session associated to itself

check_host(self)

source code 

Provide a host check mechanism. This method basically calls the HOOK_check_host_dialog() method which by itself calls the X2goClient.HOOK_check_host_dialog() method. Make sure you override any of these to enable user interaction on X2go server validity checks.

Returns: bool
returns True if an X2go server host is valid for authentication

uses_sshproxy(self)

source code 

Check if a session is configured to use an intermediate SSH proxy server.

Returns: bool
returns True if the session is configured to use an SSH proxy, False otherwise.

can_sshproxy_auto_connect(self)

source code 

Check if a session's SSH proxy (if used) is configured adequately to be able to auto-connect to the SSH proxy server (e.g. by public key authentication).

Returns: bool
returns True if the session's SSH proxy can auto-connect, False otherwise, None if no SSH proxy is used for this session, None is returned.

can_auto_connect(self)

source code 

Check if a session is configured adequately to be able to auto-connect to the X2go server (e.g. public key authentication).

Returns: bool
returns True if the session can auto-connect, False otherwise, None if no control session has been set up yet.

connect(self, username='', password='', add_to_known_hosts=False, force_password_auth=False, use_sshproxy=False, sshproxy_user='', sshproxy_password='')

source code 

Connects to the X2goSession's server host. This method basically wraps around the X2goControlSession*.connect() method.

Parameters:
  • username (str) - the username for the X2go server that is going to be connected to (as a last minute way of changing the session username)
  • password (str) - the user's password for the X2go server that is going to be connected to
  • add_to_known_hosts (bool) - non-paramiko option, if True paramiko.AutoAddPolicy() is used as missing-host-key-policy. If set to False paramiko.RejectPolicy() is used
  • force_password_auth (bool) - disable SSH pub/priv key authentication mechanisms completely
  • use_sshproxy (bool) - use an SSH proxy host for connecting the target X2go server
  • sshproxy_user (str) - username for authentication against the SSH proxy host
  • sshproxy_password (str) - password for authentication against the SSH proxy host
Returns:
returns True is the connection to the X2go server has been successful @rtype bool

disconnect(self)

source code 

Disconnect this X2goSession instance.

Returns: bool
returns True if the disconnect operation has been successful

set_print_action(self, print_action, **kwargs)

source code 

If X2go client-side printing is enable within this X2go session you can use this method to alter the way how incoming print spool jobs are handled/processed.

For further information, please refer to the documentation of the X2goClient.set_session_print_action() method.

Parameters:
  • print_action (str or instance) - one of the named above print actions, either as string or class instance
  • kwargs (dict) - additional information for the given print action (print action arguments), for possible print action arguments and their values see each individual print action class

is_alive(self)

source code 

Find out if this X2go session is still alive (that is: connected to the server).

Returns: bool
returns True if the server connection is still alive

list_sessions(self, raw=False)

source code 

List all sessions on the remote X2go server that are owned by the authenticated user

Parameters:
  • raw (bool) - if True the output of this method equals the output of the server-side x2golistsessions command
Returns: X2goServerSessionList* instance or list
a session list (as data object or list of strings when called with raw=True option)

list_desktops(self, raw=False)

source code 

List X2go desktops sessions available for desktop sharing on the remote X2go server.

Parameters:
  • raw (bool) - if True the output of this method equals the output of the server-side x2golistdesktops command
Returns: list
a list of strings representing available desktop sessions

update_status(self, session_list=None, force_update=False)

source code 

Update the current session status. The X2goSession instance uses an internal session status cache that allows to query the session status without the need of retrieving data from the remote X2go server for each query.

The session status (if initialized properly with the X2goClient constructor gets updated in regularly intervals.

In case you use the X2goSession class in standalone instances (that is: without being embedded into an X2goSession context) then run this method in regular intervals to make sure the X2goSession's internal status cache information is always up-to-date.

Parameters:
  • session_list (X2goServerSessionList* instance) - provide an X2goServerSessionList* that refers to X2go sessions we want to update. This option is mainly for reducing server/client traffic.
  • force_update (bool) - force a session status update, if if the last update is less then 1 second ago

resume(self, session_name=None)

source code 

Resume or continue a suspended / running X2go session on the remote X2go server.

Parameters:
  • session_name (str) - the server-side name of an X2go session
Returns: bool
returns True if resuming the session has been successful, False otherwise

start(self)

source code 

Start a new X2go session on the remote X2go server.

Returns: bool
returns True if starting the session has been successful, False otherwise

share_desktop(self, desktop=None, user=None, display=None, share_mode=0, check_desktop_list=True)

source code 

Share an already running X2go session on the remote X2go server locally. The shared session may be either owned by the same user or by a user that grants access to his/her desktop session by the local user.

Parameters:
  • desktop (str) - desktop ID of a sharable desktop in format <user>@<display>
  • user (str) - user name and display number can be given separately, here give the name of the user who wants to share a session with you.
  • display (str) - user name and display number can be given separately, here give the number of the display that a user allows you to be shared with.
  • share_mode (int) - desktop sharing mode, 0 is VIEW-ONLY, 1 is FULL-ACCESS.
  • check_desktop_list (bool) - check if the given desktop is available on the X2go server; handle with care as the server-side x2golistdesktops command might block client I/O.
Returns: bool
returns True if starting the session has been successful, False otherwise

suspend(self)

source code 

Suspend this X2go session.

Returns: bool
returns True if suspending the session has been successful, False otherwise

terminate(self)

source code 

Terminate this X2go session.

Returns: bool
returns True if terminating the session has been successful, False otherwise

get_profile_name(self)

source code 

Retrieve the profile name of this X2goSession instance.

Returns: str
X2go client profile name of the session

get_profile_id(self)

source code 

Retrieve the profile ID of this X2goSession instance.

Returns: str
the session profile's id

session_ok(self)

source code 

Test if this X2goSession is in a healthy state.

Returns: bool
BTrue if session is ok, False otherwise

color_depth_from_session_name(self)

source code 

Extract color depth from session name.

Returns: str
the session's color depth (as found in the session name)

is_color_depth_ok(self)

source code 

Check if this session will display properly with the local screen's color depth.

Returns:
True if the session will display on this client screen, False otherwise. If no terminal session is yet registered with this session, None is returned. @rtype bool

is_connected(self)

source code 

Test if the X2goSession's control session is connected to the remote X2go server.

Returns: bool
True if session is connected, False otherwise

is_running(self)

source code 

Test if the X2goSession's terminal session is up and running.

Returns: bool
True if session is running, False otherwise

is_suspended(self)

source code 

Test if the X2goSession's terminal session is in suspended state.

Returns: bool
True if session is suspended, False otherwise

has_terminated(self)

source code 

Test if the X2goSession's terminal session has terminated.

Returns: bool
True if session has terminated, False otherwise

is_folder_sharing_available(self)

source code 

Test if the remote session allows sharing of local folders with the session.

Returns: bool
returns True if local folder sharing is available in the remote session

share_local_folder(self, local_path=None, folder_name=None)

source code 

Share a local folder with this registered X2go session.

Parameters:
  • local_path (str) - the full path to an existing folder on the local file system
  • folder_name (str) - synonymous to local_path
Returns: bool
returns True if the local folder has been successfully mounted within this X2go session

unshare_all_local_folders(self, force_all=False)

source code 

Unshare all local folders mounted within this X2go session.

Parameters:
  • force_all (bool) - Really unmount _all_ shared folders, including the print spool folder and the MIME box spool dir (not recommended).
Returns: bool
returns True if all local folders could be successfully unmounted inside this X2go session

unshare_local_folder(self, local_path=None)

source code 

Unshare a local folder that is mounted within this X2go session.

Parameters:
  • local_path (str) - the full path to an existing folder on the local file system that is mounted in this X2go session and shall be unmounted
Returns: bool
returns True if all local folders could be successfully unmounted inside this X2go session

get_shared_folders(self)

source code 

Get a list of local folders mounted within this X2go session from this client.

Returns: list
returns a list of those folder names that are mounted with this X2go session.

is_locked(self)

source code 

Query session if it is locked by some command being processed.

Returns: bool
return True is the session is locked, False if not; returns None, if there is no control session yet.