From 06f5184ddd478f24d9ac03cf21bf6026258c05eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Mon, 25 Sep 2017 14:18:19 +0200 Subject: [PATCH 1/3] Fixed OpenGnsys --- server/src/uds/core/__init__.py | 4 ++-- server/src/uds/services/OpenGnsys/Provider.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/uds/core/__init__.py b/server/src/uds/core/__init__.py index cf4c2531..ddec3dc6 100644 --- a/server/src/uds/core/__init__.py +++ b/server/src/uds/core/__init__.py @@ -39,5 +39,5 @@ from uds.core.Environment import Environmentable from uds.core.Serializable import Serializable from uds.core.BaseModule import Module -VERSION = '2.1.0-DEVEL' -VERSION_STAMP = '20161001-DEVEL' +VERSION = '2.2.0-DEVEL' +VERSION_STAMP = '20170901-DEVEL' diff --git a/server/src/uds/services/OpenGnsys/Provider.py b/server/src/uds/services/OpenGnsys/Provider.py index 6a075b9f..e1a0e9e2 100644 --- a/server/src/uds/services/OpenGnsys/Provider.py +++ b/server/src/uds/services/OpenGnsys/Provider.py @@ -48,7 +48,7 @@ import logging import six -__updated__ = '2017-05-23' +__updated__ = '2017-09-25' logger = logging.getLogger(__name__) @@ -122,7 +122,7 @@ class OGProvider(ServiceProvider): @property def endpoint(self): - return 'https://{}:{}/rest'.format(self.host.value, self.port.value) + return 'https://{}:{}/opengnsys/rest'.format(self.host.value, self.port.value) @property def api(self): From c6cc1f2b43088d79c7bcb5121d94fdd10405ee39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Wed, 27 Sep 2017 08:07:43 +0200 Subject: [PATCH 2/3] x2go transport fix --- server/src/uds/transports/X2GO/scripts/linux/direct.py | 4 +++- server/src/uds/transports/X2GO/scripts/linux/tunnel.py | 4 +++- server/src/uds/transports/X2GO/scripts/windows/direct.py | 5 ++++- server/src/uds/transports/X2GO/scripts/windows/tunnel.py | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/server/src/uds/transports/X2GO/scripts/linux/direct.py b/server/src/uds/transports/X2GO/scripts/linux/direct.py index 92788884..7e5e13f4 100644 --- a/server/src/uds/transports/X2GO/scripts/linux/direct.py +++ b/server/src/uds/transports/X2GO/scripts/linux/direct.py @@ -6,13 +6,15 @@ from __future__ import unicode_literals from PyQt4 import QtCore, QtGui # @UnresolvedImport import os import subprocess +from os.path import expanduser from uds import tools # @UnresolvedImport import six +home = expanduser('~') + ':1;' keyFile = tools.saveTempFile('''{m.key}''') -theFile = '''{m.xf}'''.format(export='/:1;', keyFile=keyFile.replace('\\', '/'), ip='{m.ip}', port='22') +theFile = '''{m.xf}'''.format(export=home, keyFile=keyFile.replace('\\', '/'), ip='{m.ip}', port='22') filename = tools.saveTempFile(theFile) # HOME=[temporal folder, where we create a .x2goclient folder and a sessions inside] pyhoca-cli -P UDS/test-session diff --git a/server/src/uds/transports/X2GO/scripts/linux/tunnel.py b/server/src/uds/transports/X2GO/scripts/linux/tunnel.py index 90ae0337..4aa4fa97 100644 --- a/server/src/uds/transports/X2GO/scripts/linux/tunnel.py +++ b/server/src/uds/transports/X2GO/scripts/linux/tunnel.py @@ -8,6 +8,7 @@ from PyQt4 import QtCore, QtGui # @UnresolvedImport import os import subprocess from uds.forward import forward # @UnresolvedImport +from os.path import expanduser from uds import tools # @UnresolvedImport @@ -20,8 +21,9 @@ if forwardThread.status == 2: tools.addTaskToWait(forwardThread) +home = expanduser('~') + ':1;' keyFile = tools.saveTempFile('''{m.key}''') -theFile = '''{m.xf}'''.format(export='/:1;', keyFile=keyFile.replace('\\', '/'), ip='127.0.0.1', port=port) +theFile = '''{m.xf}'''.format(export=home, keyFile=keyFile.replace('\\', '/'), ip='127.0.0.1', port=port) filename = tools.saveTempFile(theFile) # HOME=[temporal folder, where we create a .x2goclient folder and a sessions inside] pyhoca-cli -P UDS/test-session diff --git a/server/src/uds/transports/X2GO/scripts/windows/direct.py b/server/src/uds/transports/X2GO/scripts/windows/direct.py index e3fb313d..0756aa48 100644 --- a/server/src/uds/transports/X2GO/scripts/windows/direct.py +++ b/server/src/uds/transports/X2GO/scripts/windows/direct.py @@ -6,13 +6,16 @@ from __future__ import unicode_literals from PyQt4 import QtCore, QtGui # @UnresolvedImport import os import subprocess +from os.path import expanduser from uds import tools # @UnresolvedImport import six +home = expanduser('~').replace('\\', '\\\\') + '#1;' keyFile = tools.saveTempFile('''{m.key}''') -theFile = '''{m.xf}'''.format(export='c:\\:1;', keyFile=keyFile.replace('\\', '/'), ip='{m.ip}', port='22') +# On windows, the separator beween active and not is "#" +theFile = '''{m.xf}'''.format(export='c:\\\\#1;', keyFile=keyFile.replace('\\', '/'), ip='{m.ip}', port='22') filename = tools.saveTempFile(theFile) x2goPath = os.environ['PROGRAMFILES(X86)'] + '\\x2goclient' diff --git a/server/src/uds/transports/X2GO/scripts/windows/tunnel.py b/server/src/uds/transports/X2GO/scripts/windows/tunnel.py index f8f57ca4..72c3e5ec 100644 --- a/server/src/uds/transports/X2GO/scripts/windows/tunnel.py +++ b/server/src/uds/transports/X2GO/scripts/windows/tunnel.py @@ -8,6 +8,7 @@ from PyQt4 import QtCore, QtGui # @UnresolvedImport import os import subprocess from uds.forward import forward # @UnresolvedImport +from os.path import expanduser from uds import tools # @UnresolvedImport @@ -20,8 +21,9 @@ if forwardThread.status == 2: tools.addTaskToWait(forwardThread) +home = expanduser('~').replace('\\', '\\\\') + '#1;' keyFile = tools.saveTempFile('''{m.key}''') -theFile = '''{m.xf}'''.format(export='c:\\:1;', keyFile=keyFile.replace('\\', '/'), ip='127.0.0.1', port=port) +theFile = '''{m.xf}'''.format(export=home, keyFile=keyFile.replace('\\', '/'), ip='127.0.0.1', port=port) filename = tools.saveTempFile(theFile) x2goPath = os.environ['PROGRAMFILES(X86)'] + '\\x2goclient' From e702ff6bca7b1cedee8f4f6a82493f5d68472445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Fri, 29 Sep 2017 10:02:44 +0200 Subject: [PATCH 3/3] Fixing up OpenGnsys --- server/src/uds/REST/methods/providers.py | 5 +++- server/src/uds/core/services/BaseDeployed.py | 2 +- server/src/uds/models/UserService.py | 2 +- .../uds/services/OpenGnsys/OGDeployment.py | 4 ++- .../src/uds/services/OpenGnsys/OGService.py | 20 +++++++++++++-- server/src/uds/services/OpenGnsys/Provider.py | 25 ++++++++++++++++--- .../src/uds/services/OpenGnsys/og/__init__.py | 15 +++++++++-- server/src/uds/services/OpenGnsys/og/fake.py | 4 ++- server/src/uds/services/OpenGnsys/og/urls.py | 1 + 9 files changed, 65 insertions(+), 13 deletions(-) diff --git a/server/src/uds/REST/methods/providers.py b/server/src/uds/REST/methods/providers.py index 5011163e..82ce86a8 100644 --- a/server/src/uds/REST/methods/providers.py +++ b/server/src/uds/REST/methods/providers.py @@ -158,7 +158,10 @@ class Providers(ModelHandler): self.ensureAccess(spType, permissions.PERMISSION_MANAGEMENT, root=True) logger.debug('spType: {}'.format(spType)) - res = spType.test(Environment.getTempEnv(), self._params) + + dct = self._params.copy() + dct['_request'] = self._request + res = spType.test(Environment.getTempEnv(), dct) if res[0]: return 'ok' else: diff --git a/server/src/uds/core/services/BaseDeployed.py b/server/src/uds/core/services/BaseDeployed.py index d15021cf..8ebcea29 100644 --- a/server/src/uds/core/services/BaseDeployed.py +++ b/server/src/uds/core/services/BaseDeployed.py @@ -36,7 +36,7 @@ from uds.core import Environmentable from uds.core import Serializable from uds.core.util.State import State -__updated__ = '2016-02-26' +__updated__ = '2017-09-29' class UserDeployment(Environmentable, Serializable): diff --git a/server/src/uds/models/UserService.py b/server/src/uds/models/UserService.py index c86d3834..76c4588f 100644 --- a/server/src/uds/models/UserService.py +++ b/server/src/uds/models/UserService.py @@ -55,7 +55,7 @@ from uds.models.Util import getSqlDatetime import logging -__updated__ = '2017-01-26' +__updated__ = '2017-09-29' logger = logging.getLogger(__name__) diff --git a/server/src/uds/services/OpenGnsys/OGDeployment.py b/server/src/uds/services/OpenGnsys/OGDeployment.py index d4ccc018..93db6565 100644 --- a/server/src/uds/services/OpenGnsys/OGDeployment.py +++ b/server/src/uds/services/OpenGnsys/OGDeployment.py @@ -43,7 +43,7 @@ import six import pickle import logging -__updated__ = '2017-05-19' +__updated__ = '2017-09-29' logger = logging.getLogger(__name__) @@ -74,6 +74,7 @@ class OGDeployment(UserDeployment): self._stamp = 0 self._reason = '' self._queue = [] + self._uuid = self.dbservice().uuid # Serializable needed methods def marshal(self): @@ -235,6 +236,7 @@ class OGDeployment(UserDeployment): ''' try: r = self.service().reserve() + self.service().notifyEvents(r['id'], self._uuid) except Exception as e: logger.exception('Creating machine') return self.__error('Error creating reservation: {}'.format(e)) diff --git a/server/src/uds/services/OpenGnsys/OGService.py b/server/src/uds/services/OpenGnsys/OGService.py index 04890d5f..dc6e304c 100644 --- a/server/src/uds/services/OpenGnsys/OGService.py +++ b/server/src/uds/services/OpenGnsys/OGService.py @@ -41,7 +41,7 @@ from uds.core.ui import gui import logging -__updated__ = '2017-05-18' +__updated__ = '2017-09-29' logger = logging.getLogger(__name__) @@ -161,4 +161,20 @@ class OGService(Service): return self.parent().reserve(self.ou.value, self.image.value, self.lab.value, self.maxReservationTime.num()) def unreserve(self, machineId): - return self.parent().unreserve(machineId) + return self.parent().unreserve(self.ou.value, self.lab.value, machineId) + + def notifyEvents(self, machineId, serviceUUID): + return self.parent().notifyEvents(self, self.ou.value, self.lab.value, machineId, self.getLoginNotifyURL(serviceUUID), self.getLogoutNotifyURL(serviceUUID)) + + def _notifyURL(self, uuid, message): + return '{accessURL}rest/actor/{uuid}/{message}'.format( + accessURL=self.parent().getUDSServerAccessUrl(), + uuid=uuid, + message=message + ) + + def getLoginNotifyURL(self, serviceUUID): + return self._notifyURL(serviceUUID, 'login') + + def getLogoutNotifyURL(self, serviceUUID): + return self._notifyURL(serviceUUID, 'logout') diff --git a/server/src/uds/services/OpenGnsys/Provider.py b/server/src/uds/services/OpenGnsys/Provider.py index e1a0e9e2..39bebc7c 100644 --- a/server/src/uds/services/OpenGnsys/Provider.py +++ b/server/src/uds/services/OpenGnsys/Provider.py @@ -48,7 +48,7 @@ import logging import six -__updated__ = '2017-09-25' +__updated__ = '2017-09-29' logger = logging.getLogger(__name__) @@ -120,6 +120,17 @@ class OGProvider(ServiceProvider): self.timeout.value = validators.validateTimeout(self.timeout.value, returnAsInteger=False) logger.debug('Endpoint: {}'.format(self.endpoint)) + try: + request = values['_request'] + + if self.udsServerAccessUrl.value.strip() == '': + self.udsServerAccessUrl.value = request.build_absolute_uri('/') + + if self.udsServerAccessUrl.value != '/': + self.udsServerAccessUrl.value += '/' + except Exception: + pass + @property def endpoint(self): return 'https://{}:{}/opengnsys/rest'.format(self.host.value, self.port.value) @@ -166,16 +177,22 @@ class OGProvider(ServiceProvider): Returns: Array of two elements, first is True of False, depending on test (True is all right, false is error), - second is an String with error, preferably internacionalizated.. + second is an String with error, preferably i18n.. ''' return OGProvider(env, data).testConnection() + def getUDSServerAccessUrl(self): + return self.udsServerAccessUrl.value + def reserve(self, ou, image, lab=0, maxtime=0): return self.api.reserve(ou, image, lab, maxtime) - def unreserve(self, machineId): - return self.api.unreserve(machineId) + def unreserve(self, ou, lab, machineId): + return self.api.unreserve(ou, lab, machineId) + + def notifyEvents(self, ou, lab, machineId, loginURL, logoutURL): + return self.api.notifyURLs(ou, lab, machineId, loginURL, logoutURL) def status(self, machineId): return self.api.status(machineId) diff --git a/server/src/uds/services/OpenGnsys/og/__init__.py b/server/src/uds/services/OpenGnsys/og/__init__.py index f78508d6..a2688f56 100644 --- a/server/src/uds/services/OpenGnsys/og/__init__.py +++ b/server/src/uds/services/OpenGnsys/og/__init__.py @@ -45,7 +45,7 @@ import six import requests import json -__updated__ = '2017-05-18' +__updated__ = '2017-09-29' logger = logging.getLogger(__name__) @@ -211,13 +211,24 @@ class OpenGnsysClient(object): } @ensureConnected - def unreserve(self, id): + def unreserve(self, ou, lab, client): # This method releases the previous reservation # Invoked every time we need to release a reservation (i mean, if a reservation is done, this will be called with the obtained id from that reservation) ou, lab, client = id.split('.') errMsg = 'Unreserving client {} in lab {} in ou {}'.format(client, lab, ou) return self._delete(urls.UNRESERVE.format(ou=ou, lab=lab, client=client), errMsg=errMsg) + @ensureConnected + def notifyURLs(self, ou, lab, client, loginURL, logoutURL): + errMsg = 'Notifying login/logout urls' + data = { + 'urlLogin': loginURL, + 'urlLogout': logoutURL + } + + return self._post(urls.EVENTS.format(ou=ou, lab=lab, client=client), data, errMsg=errMsg) + + @ensureConnected def status(self, id): # This method gets the status of the machine diff --git a/server/src/uds/services/OpenGnsys/og/fake.py b/server/src/uds/services/OpenGnsys/og/fake.py index 2120ee94..931f39fe 100644 --- a/server/src/uds/services/OpenGnsys/og/fake.py +++ b/server/src/uds/services/OpenGnsys/og/fake.py @@ -37,7 +37,7 @@ import random import six import logging -__updated__ = '2017-05-19' +__updated__ = '2017-09-29' logger = logging.getLogger(__name__) @@ -215,6 +215,8 @@ def get(path, errMsg): if rnd < 25: return STATUS_READY_LINUX return STATUS_OFF + elif path[-6:] == 'events': + return '' raise Exception('Unknown FAKE URL on GET: {}'.format(path)) diff --git a/server/src/uds/services/OpenGnsys/og/urls.py b/server/src/uds/services/OpenGnsys/og/urls.py index 3601eb37..573fae5d 100644 --- a/server/src/uds/services/OpenGnsys/og/urls.py +++ b/server/src/uds/services/OpenGnsys/og/urls.py @@ -43,3 +43,4 @@ IMAGES = '/ous/{ou}/images' RESERVE = '/ous/{ou}/images/{image}/reserve' UNRESERVE = '/ous/{ou}/labs/{lab}/clients/{client}/unreserve' STATUS = '/ous/{ou}/labs/{lab}/clients/{client}/status' +EVENTS = '/ous/{ou}/labs/{lab}/clients/{client}/events'