1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2023 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
# Python X2Go is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Python X2Go is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
###
### short example for python-x2go usage
###
# import x2go before you import other thread based modules (e.g. paramiko)
import x2go
import sys
import getpass
import gevent
# modify to your needs...
server = "server.mydomain.tld"
port = 22
username = "foo"
password = getpass.getpass()
cli = x2go.X2GoClient(use_cache=False, loglevel=x2go.log.loglevel_DEBUG)
s_uuid = cli.register_session(server, port=port, username=username, geometry="800x600", add_to_known_hosts=True)
cli.connect_session(s_uuid, password=password)
# the next lines will resume the first session in the avail_sessions dictionary
avail_sessions = cli.list_sessions(s_uuid)
if avail_sessions:
session_info = list(avail_sessions.values())[0]
sys.stdout.write("Trying to resume session %s\n" % (session_info.name,))
cli.resume_session(s_uuid, session_name=session_info.name)
try:
while cli.session_ok(s_uuid):
gevent.sleep(2)
except KeyboardInterrupt:
pass
cli.terminate_session(s_uuid)
else:
print("No sessions to be resumed.")
|