diff --git a/server/src/uds/services/OpenGnsys/OGDeployment.py b/server/src/uds/services/OpenGnsys/OGDeployment.py index 95eb83c46..8583af765 100644 --- a/server/src/uds/services/OpenGnsys/OGDeployment.py +++ b/server/src/uds/services/OpenGnsys/OGDeployment.py @@ -104,21 +104,13 @@ class OGDeployment(UserDeployment): def setReady(self): ''' - Right now, this does nothing on OG. + Notifies the current "deadline" to the user, before accessing by UDS The machine has been already been started. The problem is that currently there is no way that a machine is in FACT started. OpenGnsys will try it best by sending an WOL ''' - # if self.cache.get('ready') == '1': - # return State.FINISHED + self.service().notifyDeadline(self.dbservice().deployed_service.getDeadline()) - # status = self.service().status(self._machineId) - # possible status are ("off", "oglive", "busy", "linux", "windows", "macos" o "unknown"). - # if status['status'] != 'off': - # self.cache.put('ready', '1') - # return State.FINISHED - - # Return back machine to preparing?... return State.FINISHED def deployForUser(self, user): @@ -236,8 +228,7 @@ class OGDeployment(UserDeployment): ''' try: r = self.service().reserve() - deadLine = self.dbservice().deployed_service.getDeadline() - self.service().notifyEvents(r['id'], self._uuid, deadLine) + 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 77007acdc..3169a7ed3 100644 --- a/server/src/uds/services/OpenGnsys/OGService.py +++ b/server/src/uds/services/OpenGnsys/OGService.py @@ -163,8 +163,11 @@ class OGService(Service): def unreserve(self, machineId): return self.parent().unreserve(machineId) - def notifyEvents(self, machineId, serviceUUID, deadLine): - return self.parent().notifyEvents(machineId, self.getLoginNotifyURL(serviceUUID), self.getLogoutNotifyURL(serviceUUID), deadLine) + def notifyEvents(self, machineId, serviceUUID): + return self.parent().notifyEvents(machineId, self.getLoginNotifyURL(serviceUUID), self.getLogoutNotifyURL(serviceUUID)) + + def notifyDeadline(self, machineId, deadLine): + return self.parent().notifyDeadline(machineId, deadLine) def _notifyURL(self, uuid, message): # The URL is "GET messages URL". diff --git a/server/src/uds/services/OpenGnsys/Provider.py b/server/src/uds/services/OpenGnsys/Provider.py index 5f25c107b..8b53a2b30 100644 --- a/server/src/uds/services/OpenGnsys/Provider.py +++ b/server/src/uds/services/OpenGnsys/Provider.py @@ -191,8 +191,11 @@ class OGProvider(ServiceProvider): def unreserve(self, machineId): return self.api.unreserve(machineId) - def notifyEvents(self, machineId, loginURL, logoutURL, deadLine): - return self.api.notifyURLs(machineId, loginURL, logoutURL, deadLine) + def notifyEvents(self, machineId, loginURL, logoutURL): + return self.api.notifyURLs(machineId, loginURL, logoutURL) + + def notifyDeadline(self, machineId, deadLine): + return self.api.notifyDeadline(machineId, deadLine) 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 0cb6affb0..645833c73 100644 --- a/server/src/uds/services/OpenGnsys/og/__init__.py +++ b/server/src/uds/services/OpenGnsys/og/__init__.py @@ -45,8 +45,6 @@ import six import requests import json -__updated__ = '2017-10-16' - logger = logging.getLogger(__name__) # URLS @@ -216,17 +214,26 @@ class OpenGnsysClient(object): return self._delete(urls.UNRESERVE.format(ou=ou, lab=lab, client=client), errMsg=errMsg) @ensureConnected - def notifyURLs(self, machineId, loginURL, logoutURL, deadLine): + def notifyURLs(self, machineId, loginURL, logoutURL): ou, lab, client = machineId.split('.') errMsg = 'Notifying login/logout urls' data = { 'urlLogin': loginURL, - 'urlLogout': logoutURL, - 'deadLine': deadLine + 'urlLogout': logoutURL } return self._post(urls.EVENTS.format(ou=ou, lab=lab, client=client), data, errMsg=errMsg) + @ensureConnected + def notifyDeadline(self, machineId, deadLine): + ou, lab, client = machineId.split('.') + errMsg = 'Notifying deadline' + data = { + 'deadLine': deadLine + } + + return self._post(urls.SESSIONS.format(ou=ou, lab=lab, client=client), data, errMsg=errMsg) + @ensureConnected def status(self, id): diff --git a/server/src/uds/services/OpenGnsys/og/urls.py b/server/src/uds/services/OpenGnsys/og/urls.py index 573fae5d8..0efb8c4d7 100644 --- a/server/src/uds/services/OpenGnsys/og/urls.py +++ b/server/src/uds/services/OpenGnsys/og/urls.py @@ -44,3 +44,4 @@ 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' +SESSIONS = '/ous/{ou}/labs/{lab}/clients/{client}/session'