forked from shaba/openuds
Merge remote-tracking branch 'origin/v2.2'
This commit is contained in:
commit
ac8a661182
@ -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:
|
||||
|
@ -38,7 +38,6 @@ from __future__ import unicode_literals
|
||||
from uds.core.Environment import Environmentable
|
||||
from uds.core.Serializable import Serializable
|
||||
from uds.core.BaseModule import Module
|
||||
import time
|
||||
|
||||
VERSION = '2.x.x-DEVEL'
|
||||
VERSION_STAMP = '{}-DEVEL'.format(time.strftime("%Y%m%d"))
|
||||
|
@ -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):
|
||||
|
@ -57,7 +57,7 @@ import six
|
||||
import pickle
|
||||
import logging
|
||||
|
||||
__updated__ = '2017-05-19'
|
||||
__updated__ = '2017-09-29'
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -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))
|
||||
|
@ -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')
|
||||
|
@ -48,7 +48,7 @@ import logging
|
||||
import six
|
||||
|
||||
|
||||
__updated__ = '2017-05-23'
|
||||
__updated__ = '2017-09-29'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -120,9 +120,20 @@ 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://{}:{}/rest'.format(self.host.value, self.port.value)
|
||||
return 'https://{}:{}/opengnsys/rest'.format(self.host.value, self.port.value)
|
||||
|
||||
@property
|
||||
def api(self):
|
||||
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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'
|
||||
|
@ -5,13 +5,15 @@ from __future__ import unicode_literals
|
||||
# pylint: disable=import-error, no-name-in-module
|
||||
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
|
||||
|
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
||||
import os
|
||||
import subprocess
|
||||
from uds.forward import forward # @UnresolvedImport
|
||||
from os.path import expanduser
|
||||
|
||||
from uds import tools # @UnresolvedImport
|
||||
|
||||
@ -19,8 +20,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
|
||||
|
@ -5,13 +5,16 @@ from __future__ import unicode_literals
|
||||
# pylint: disable=import-error, no-name-in-module
|
||||
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'
|
||||
|
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
||||
import os
|
||||
import subprocess
|
||||
from uds.forward import forward # @UnresolvedImport
|
||||
from os.path import expanduser
|
||||
|
||||
from uds import tools # @UnresolvedImport
|
||||
|
||||
@ -19,8 +20,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'
|
||||
|
Loading…
Reference in New Issue
Block a user