forked from shaba/openuds
pep related fixes
This commit is contained in:
parent
429eead46d
commit
62abc85191
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from __future__ import unicode_literals
|
||||
@ -72,19 +72,19 @@ SECURE_OWNER = 'SACTOR'
|
||||
|
||||
# Enclosed methods under /actor path
|
||||
class Actor(Handler):
|
||||
'''
|
||||
"""
|
||||
Processes actor requests
|
||||
'''
|
||||
"""
|
||||
authenticated = False # Actor requests are not authenticated
|
||||
|
||||
@staticmethod
|
||||
def result(result=None, error=None):
|
||||
'''
|
||||
"""
|
||||
Helper method to create a "result" set for actor response
|
||||
:param result: Result value to return (can be None, in which case it is converted to empty string '')
|
||||
:param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code
|
||||
:return: A dictionary, suitable for response to Caller
|
||||
'''
|
||||
"""
|
||||
result = result if result is not None else ''
|
||||
res = {'result': result, 'date': datetime.datetime.now()}
|
||||
if error is not None:
|
||||
@ -92,15 +92,15 @@ class Actor(Handler):
|
||||
return res
|
||||
|
||||
def test(self):
|
||||
'''
|
||||
"""
|
||||
Executes and returns the test
|
||||
'''
|
||||
"""
|
||||
return Actor.result(_('Correct'))
|
||||
|
||||
def validateRequestKey(self):
|
||||
'''
|
||||
"""
|
||||
Validates a request key (in "key" parameter)
|
||||
'''
|
||||
"""
|
||||
# Ensures that key is first parameter
|
||||
# Here, path will be .../actor/ACTION/KEY (probably /rest/actor/KEY/...)
|
||||
# logger.debug('{} == {}'.format(self._params.get('key'), actorKey.get()))
|
||||
@ -109,9 +109,9 @@ class Actor(Handler):
|
||||
return None
|
||||
|
||||
def getUserServiceByIds(self):
|
||||
'''
|
||||
"""
|
||||
This will get the client from the IDs passed from parameters
|
||||
'''
|
||||
"""
|
||||
logger.debug('Getting User services from ids: {}'.format(self._params.get('id')))
|
||||
|
||||
try:
|
||||
@ -143,9 +143,9 @@ class Actor(Handler):
|
||||
return Actor.result({})
|
||||
|
||||
def get(self):
|
||||
'''
|
||||
"""
|
||||
Processes get requests
|
||||
'''
|
||||
"""
|
||||
logger.debug("Actor args for GET: {0}".format(self._args))
|
||||
|
||||
if len(self._args) < 1:
|
||||
@ -190,9 +190,9 @@ class Actor(Handler):
|
||||
|
||||
# Must be invoked as '/rest/actor/UUID/[message], with message data in post body
|
||||
def post(self):
|
||||
'''
|
||||
"""
|
||||
Processes post requests
|
||||
'''
|
||||
"""
|
||||
if len(self._args) != 2:
|
||||
raise RequestError('Invalid request')
|
||||
|
||||
|
@ -84,7 +84,7 @@ class Authenticators(ModelHandler):
|
||||
def getGui(self, type_):
|
||||
try:
|
||||
return self.addDefaultFields(auths.factory().lookup(type_).guiDescription(), ['name', 'comments', 'tags', 'priority', 'small_name'])
|
||||
except:
|
||||
except Exception:
|
||||
raise NotFound('type not found')
|
||||
|
||||
def item_as_dict(self, auth):
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
@ -59,21 +59,21 @@ REQUIRED_CLIENT_VERSION = '2.5.0'
|
||||
|
||||
# Enclosed methods under /actor path
|
||||
class Client(Handler):
|
||||
'''
|
||||
"""
|
||||
Processes actor requests
|
||||
'''
|
||||
"""
|
||||
authenticated = False # Client requests are not authenticated
|
||||
|
||||
@staticmethod
|
||||
def result(result=None, error=None, errorCode=0, retryable=False):
|
||||
'''
|
||||
"""
|
||||
Helper method to create a "result" set for actor response
|
||||
:param result: Result value to return (can be None, in which case it is converted to empty string '')
|
||||
:param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code
|
||||
:param errorCode: Code of the error to return, if error is not None
|
||||
:param retryable: If True, this operation can (and must) be retryed
|
||||
:return: A dictionary, suitable for response to Caller
|
||||
'''
|
||||
"""
|
||||
result = result if result is not None else ''
|
||||
res = {'result': result}
|
||||
if error is not None:
|
||||
@ -90,15 +90,15 @@ class Client(Handler):
|
||||
return res
|
||||
|
||||
def test(self):
|
||||
'''
|
||||
"""
|
||||
Executes and returns the test
|
||||
'''
|
||||
"""
|
||||
return Client.result(_('Correct'))
|
||||
|
||||
def get(self):
|
||||
'''
|
||||
"""
|
||||
Processes get requests
|
||||
'''
|
||||
"""
|
||||
logger.debug("Client args for GET: {0}".format(self._args))
|
||||
|
||||
if len(self._args) == 0: # Gets version
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
@ -54,21 +54,21 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
# Enclosed methods under /actor path
|
||||
class Connection(Handler):
|
||||
'''
|
||||
"""
|
||||
Processes actor requests
|
||||
'''
|
||||
"""
|
||||
authenticated = True # Actor requests are not authenticated
|
||||
needs_admin = False
|
||||
needs_staff = False
|
||||
|
||||
@staticmethod
|
||||
def result(result=None, error=None, errorCode=0, retryable=False):
|
||||
'''
|
||||
"""
|
||||
Helper method to create a "result" set for connection response
|
||||
:param result: Result value to return (can be None, in which case it is converted to empty string '')
|
||||
:param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code
|
||||
:return: A dictionary, suitable for response to Caller
|
||||
'''
|
||||
"""
|
||||
result = result if result is not None else ''
|
||||
res = {'result': result, 'date': datetime.datetime.now()}
|
||||
if error is not None:
|
||||
@ -199,9 +199,9 @@ class Connection(Handler):
|
||||
return password
|
||||
|
||||
def get(self):
|
||||
'''
|
||||
"""
|
||||
Processes get requests
|
||||
'''
|
||||
"""
|
||||
logger.debug("Connection args for GET: {0}".format(self._args))
|
||||
|
||||
if len(self._args) == 0:
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
@ -52,14 +52,14 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Login(Handler):
|
||||
'''
|
||||
"""
|
||||
Responsible of user authentication
|
||||
'''
|
||||
"""
|
||||
path = 'auth'
|
||||
authenticated = False # Public method
|
||||
|
||||
def post(self):
|
||||
'''
|
||||
"""
|
||||
This login uses parameters to generate auth token
|
||||
The alternative is to use the template tag inside "REST" that is called auth_token, that extracts an auth token from an user session
|
||||
We can use any of this forms due to the fact that the auth token is in fact a session key
|
||||
@ -87,7 +87,7 @@ class Login(Handler):
|
||||
|
||||
Locale comes on "Header", as any HTTP Request (Accept-Language header)
|
||||
Calls to any method of REST that must be authenticated needs to be called with "X-Auth-Token" Header added
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
if 'authId' not in self._params and 'authSmallName' not in self._params and 'auth' not in self._params:
|
||||
raise RequestError('Invalid parameters (no auth)')
|
||||
@ -136,9 +136,9 @@ class Login(Handler):
|
||||
|
||||
|
||||
class Logout(Handler):
|
||||
'''
|
||||
"""
|
||||
Responsible of user de-authentication
|
||||
'''
|
||||
"""
|
||||
path = 'auth'
|
||||
authenticated = True # By default, all handlers needs authentication
|
||||
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
@ -55,9 +55,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Services(DetailHandler): # pylint: disable=too-many-public-methods
|
||||
'''
|
||||
"""
|
||||
Detail handler for Services, whose parent is a Provider
|
||||
'''
|
||||
"""
|
||||
|
||||
custom_methods = ['servicesPools']
|
||||
|
||||
@ -82,11 +82,11 @@ class Services(DetailHandler): # pylint: disable=too-many-public-methods
|
||||
|
||||
@staticmethod
|
||||
def serviceToDict(item, perm, full=False):
|
||||
'''
|
||||
"""
|
||||
Convert a service db item to a dict for a rest response
|
||||
:param item: Service item (db)
|
||||
:param full: If full is requested, add "extra" fields to complete information
|
||||
'''
|
||||
"""
|
||||
itemType = item.getType()
|
||||
retVal = {
|
||||
'id': item.uuid,
|
||||
@ -125,10 +125,10 @@ class Services(DetailHandler): # pylint: disable=too-many-public-methods
|
||||
return {'field': 'maintenance_mode', 'prefix': 'row-maintenance-'}
|
||||
|
||||
def _deleteIncompleteService(self, service): # pylint: disable=no-self-use
|
||||
'''
|
||||
"""
|
||||
Deletes a service if it is needed to (that is, if it is not None) and silently catch any exception of this operation
|
||||
:param service: Service to delete (may be None, in which case it does nothing)
|
||||
'''
|
||||
"""
|
||||
if service is not None:
|
||||
try:
|
||||
service.delete()
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||
@ -55,9 +55,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ServicesPools(ModelHandler):
|
||||
'''
|
||||
"""
|
||||
Handles Services Pools REST requests
|
||||
'''
|
||||
"""
|
||||
model = DeployedService
|
||||
detail = {
|
||||
'services': AssignedService,
|
||||
|
@ -74,7 +74,7 @@ class InternalDBAuth(Authenticator):
|
||||
if self.reverseDns.isTrue():
|
||||
try:
|
||||
return str(dns.resolver.query(dns.reversename.from_address(ip), 'PTR')[0])
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
return ip
|
||||
|
||||
|
@ -132,7 +132,7 @@ class RegexLdap(auths.Authenticator):
|
||||
pattern = '(' + pattern + ')'
|
||||
try:
|
||||
re.search(pattern, '')
|
||||
except:
|
||||
except Exception:
|
||||
raise auths.Authenticator.ValidationException('Invalid pattern in {0}: {1}'.format(fieldLabel, line))
|
||||
|
||||
def __getAttrsFromField(self, field):
|
||||
@ -408,7 +408,7 @@ class RegexLdap(auths.Authenticator):
|
||||
try:
|
||||
if len(con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(%s=*)' % vals, sizelimit=1)) == 1:
|
||||
continue
|
||||
except:
|
||||
except Exception:
|
||||
continue
|
||||
return [False, _('Ldap group id attribute seems to be incorrect (no group found by that attribute)')]
|
||||
|
||||
|
@ -27,40 +27,40 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.core.util import encoders
|
||||
|
||||
|
||||
class Serializable(object):
|
||||
'''
|
||||
"""
|
||||
This class represents the interface that all serializable objects must provide.
|
||||
|
||||
Every single serializable class must implement marshall & unmarshall methods. Also, the class must allow
|
||||
to be initialized without parameters, so we can:
|
||||
- Initialize the object with default values
|
||||
- Read values from seralized data
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def marshal(self):
|
||||
'''
|
||||
"""
|
||||
This is the method that must be overriden in order to serialize an object.
|
||||
|
||||
The system will use in fact 'seralize' and 'deserialize' methods, but theese are
|
||||
only suitable methods to "codify" serialized values
|
||||
|
||||
:note: This method must be overridden
|
||||
'''
|
||||
"""
|
||||
raise Exception('Base marshaler called!!!')
|
||||
|
||||
def unmarshal(self, str_):
|
||||
'''
|
||||
"""
|
||||
This is the method that must be overriden in order to unserialize an object.
|
||||
|
||||
The system will use in fact 'seralize' and 'deserialize' methods, but these are
|
||||
@ -73,17 +73,17 @@ class Serializable(object):
|
||||
str_ _ : String readed from persistent storage to deseralilize
|
||||
|
||||
:note: This method must be overridden
|
||||
'''
|
||||
"""
|
||||
raise Exception('Base unmarshaler called!!!')
|
||||
|
||||
def serialize(self):
|
||||
'''
|
||||
"""
|
||||
Serializes and "obfuscates' the data.
|
||||
'''
|
||||
"""
|
||||
return encoders.encode(self.marshal(), 'base64', asText=True)
|
||||
|
||||
def unserialize(self, str_):
|
||||
'''
|
||||
"""
|
||||
des-obfuscates the data and then de-serializes it via unmarshal method
|
||||
'''
|
||||
"""
|
||||
return self.unmarshal(encoders.decode(str_, 'base64'))
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import transaction, connection
|
||||
@ -51,9 +51,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DelayedTaskThread(threading.Thread):
|
||||
'''
|
||||
"""
|
||||
Class responsible of executing a delayed task in its own thread
|
||||
'''
|
||||
"""
|
||||
def __init__(self, taskInstance):
|
||||
super(DelayedTaskThread, self).__init__()
|
||||
self._taskInstance = taskInstance
|
||||
@ -66,9 +66,9 @@ class DelayedTaskThread(threading.Thread):
|
||||
|
||||
|
||||
class DelayedTaskRunner(object):
|
||||
'''
|
||||
"""
|
||||
Delayed task runner class
|
||||
'''
|
||||
"""
|
||||
# How often tasks r checked
|
||||
granularity = 2
|
||||
|
||||
@ -81,19 +81,19 @@ class DelayedTaskRunner(object):
|
||||
self._keepRunning = True
|
||||
|
||||
def notifyTermination(self):
|
||||
'''
|
||||
"""
|
||||
Invoke this whenever you want to terminate the delayed task runner thread
|
||||
It will mark the thread to "stop" ASAP
|
||||
'''
|
||||
"""
|
||||
self._keepRunning = False
|
||||
|
||||
@staticmethod
|
||||
def runner():
|
||||
'''
|
||||
"""
|
||||
Static method that returns an instance (singleton instance) to a Delayed Runner.
|
||||
There is only one instance of DelayedTaksRunner, but its "run" method is executed on
|
||||
many thread (depending on configuration). They all share common Instance data
|
||||
'''
|
||||
"""
|
||||
if DelayedTaskRunner._runner is None:
|
||||
DelayedTaskRunner._runner = DelayedTaskRunner()
|
||||
return DelayedTaskRunner._runner
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
@ -128,10 +128,10 @@ class CryptoManager(object):
|
||||
return six.text_type(hashlib.sha1(value).hexdigest())
|
||||
|
||||
def uuid(self, obj=None):
|
||||
'''
|
||||
"""
|
||||
Generates an uuid from obj. (lower case)
|
||||
If obj is None, returns an uuid based on current datetime + counter
|
||||
'''
|
||||
"""
|
||||
if obj is None:
|
||||
obj = six.text_type(datetime.datetime.now()) + six.text_type(self._counter)
|
||||
self._counter += 1
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
@ -78,10 +78,10 @@ class UserServiceManager(object):
|
||||
return Q(state__in=[State.PREPARING, State.USABLE])
|
||||
|
||||
def __checkMaxDeployedReached(self, deployedService):
|
||||
'''
|
||||
"""
|
||||
Checks if maxDeployed for the service has been reached, and, if so,
|
||||
raises an exception that no more services of this kind can be reached
|
||||
'''
|
||||
"""
|
||||
serviceInstance = deployedService.service.getInstance()
|
||||
# Early return, so no database count is needed
|
||||
if serviceInstance.maxDeployed == Service.UNLIMITED:
|
||||
@ -93,9 +93,9 @@ class UserServiceManager(object):
|
||||
raise MaxServicesReachedError('Max number of allowed deployments for service reached')
|
||||
|
||||
def __createCacheAtDb(self, deployedServicePublication, cacheLevel):
|
||||
'''
|
||||
"""
|
||||
Private method to instatiate a cache element at database with default states
|
||||
'''
|
||||
"""
|
||||
# Checks if maxDeployed has been reached and if so, raises an exception
|
||||
self.__checkMaxDeployedReached(deployedServicePublication.deployed_service)
|
||||
now = getSqlDatetime()
|
||||
@ -105,9 +105,9 @@ class UserServiceManager(object):
|
||||
user=None, in_use=False)
|
||||
|
||||
def __createAssignedAtDb(self, deployedServicePublication, user):
|
||||
'''
|
||||
"""
|
||||
Private method to instatiate an assigned element at database with default state
|
||||
'''
|
||||
"""
|
||||
self.__checkMaxDeployedReached(deployedServicePublication.deployed_service)
|
||||
now = getSqlDatetime()
|
||||
return deployedServicePublication.userServices.create(cache_level=0, state=State.PREPARING, os_state=State.PREPARING,
|
||||
@ -116,20 +116,20 @@ class UserServiceManager(object):
|
||||
user=user, in_use=False)
|
||||
|
||||
def __createAssignedAtDbForNoPublication(self, deployedService, user):
|
||||
'''
|
||||
"""
|
||||
__createCacheAtDb and __createAssignedAtDb uses a publication for create the UserService.
|
||||
There is cases where deployed services do not have publications (do not need them), so we need this method to create
|
||||
an UserService with no publications, and create them from an DeployedService
|
||||
'''
|
||||
"""
|
||||
self.__checkMaxDeployedReached(deployedService)
|
||||
now = getSqlDatetime()
|
||||
return deployedService.userServices.create(cache_level=0, state=State.PREPARING, os_state=State.PREPARING,
|
||||
state_date=now, creation_date=now, data='', publication=None, user=user, in_use=False)
|
||||
|
||||
def createCacheFor(self, deployedServicePublication, cacheLevel):
|
||||
'''
|
||||
"""
|
||||
Creates a new cache for the deployed service publication at level indicated
|
||||
'''
|
||||
"""
|
||||
logger.debug('Creating a new cache element at level {0} for publication {1}'.format(cacheLevel, deployedServicePublication))
|
||||
cache = self.__createCacheAtDb(deployedServicePublication, cacheLevel)
|
||||
ci = cache.getInstance()
|
||||
@ -139,9 +139,9 @@ class UserServiceManager(object):
|
||||
return cache
|
||||
|
||||
def createAssignedFor(self, ds, user):
|
||||
'''
|
||||
"""
|
||||
Creates a new assigned deployed service for the publication and user indicated
|
||||
'''
|
||||
"""
|
||||
if ds.service.getType().publicationType is not None:
|
||||
dsp = ds.activePublication()
|
||||
logger.debug('Creating a new assigned element for user {0} por publication {1}'.format(user, dsp))
|
||||
@ -158,9 +158,9 @@ class UserServiceManager(object):
|
||||
return assigned
|
||||
|
||||
def createAssignable(self, ds, deployed, user):
|
||||
'''
|
||||
"""
|
||||
Creates an assignable service
|
||||
'''
|
||||
"""
|
||||
now = getSqlDatetime()
|
||||
assignable = ds.userServices.create(cache_level=0, state=State.PREPARING, os_state=State.PREPARING,
|
||||
state_date=now, creation_date=now, data='', user=user, in_use=False)
|
||||
@ -173,10 +173,10 @@ class UserServiceManager(object):
|
||||
return assignable
|
||||
|
||||
def moveToLevel(self, cache, cacheLevel):
|
||||
'''
|
||||
"""
|
||||
Moves a cache element from one level to another
|
||||
@return: cache element
|
||||
'''
|
||||
"""
|
||||
cache = UserService.objects.get(id=cache.id)
|
||||
logger.debug('Moving cache {0} to level {1}'.format(cache, cacheLevel))
|
||||
ci = cache.getInstance()
|
||||
@ -189,10 +189,10 @@ class UserServiceManager(object):
|
||||
UserServiceOpChecker.makeUnique(cache, ci, state)
|
||||
|
||||
def cancel(self, uService):
|
||||
'''
|
||||
"""
|
||||
Cancels a user service creation
|
||||
@return: the Uservice canceling
|
||||
'''
|
||||
"""
|
||||
uService = UserService.objects.get(pk=uService.id)
|
||||
logger.debug('Canceling uService {0} creation'.format(uService))
|
||||
if uService.isPreparing() is False:
|
||||
@ -208,10 +208,10 @@ class UserServiceManager(object):
|
||||
return uService
|
||||
|
||||
def remove(self, uService):
|
||||
'''
|
||||
"""
|
||||
Removes a uService element
|
||||
@return: the uService removed (marked for removal)
|
||||
'''
|
||||
"""
|
||||
with transaction.atomic():
|
||||
uService = UserService.objects.select_for_update().get(id=uService.id)
|
||||
logger.debug('Removing uService {0}'.format(uService))
|
||||
@ -320,16 +320,16 @@ class UserServiceManager(object):
|
||||
return self.createAssignedFor(ds, user)
|
||||
|
||||
def getServicesInStateForProvider(self, provider_id, state):
|
||||
'''
|
||||
"""
|
||||
Returns the number of services of a service provider in the state indicated
|
||||
'''
|
||||
"""
|
||||
return UserService.objects.filter(deployed_service__service__provider__id=provider_id, state=state).count()
|
||||
|
||||
def canRemoveServiceFromDeployedService(self, ds):
|
||||
'''
|
||||
"""
|
||||
checks if we can do a "remove" from a deployed service
|
||||
serviceIsntance is just a helper, so if we already have unserialized deployedService
|
||||
'''
|
||||
"""
|
||||
removing = self.getServicesInStateForProvider(ds.service.provider_id, State.REMOVING)
|
||||
serviceInstance = ds.service.getInstance()
|
||||
if removing >= serviceInstance.parent().getMaxRemovingServices() and serviceInstance.parent().getIgnoreLimits() is False:
|
||||
@ -337,9 +337,9 @@ class UserServiceManager(object):
|
||||
return True
|
||||
|
||||
def canInitiateServiceFromDeployedService(self, ds):
|
||||
'''
|
||||
"""
|
||||
Checks if we can start a new service
|
||||
'''
|
||||
"""
|
||||
preparing = self.getServicesInStateForProvider(ds.service.provider_id, State.PREPARING)
|
||||
serviceInstance = ds.service.getInstance()
|
||||
if preparing >= serviceInstance.parent().getMaxPreparingServices() and serviceInstance.parent().getIgnoreLimits() is False:
|
||||
@ -475,9 +475,9 @@ class UserServiceManager(object):
|
||||
# All done
|
||||
|
||||
def requestLogoff(self, uService):
|
||||
'''
|
||||
"""
|
||||
Ask client to logoff user
|
||||
'''
|
||||
"""
|
||||
url = uService.getCommsUrl()
|
||||
if url is None:
|
||||
logger.error('Can\'t connect with actor (no actor or legacy actor)')
|
||||
@ -562,9 +562,9 @@ class UserServiceManager(object):
|
||||
return userService
|
||||
|
||||
def getService(self, user, srcIp, idService, idTransport, doTest=True):
|
||||
'''
|
||||
"""
|
||||
Get service info from
|
||||
'''
|
||||
"""
|
||||
userService = self.locateUserService(user, idService, create=True)
|
||||
|
||||
if userService.isInMaintenance() is True:
|
||||
|
@ -261,10 +261,10 @@ class OSManager(Module):
|
||||
userService.save()
|
||||
|
||||
def isPersistent(self):
|
||||
'''
|
||||
"""
|
||||
When a publication if finished, old assigned machines will be removed if this value is True.
|
||||
Defaults to False
|
||||
'''
|
||||
"""
|
||||
return False
|
||||
|
||||
def __str__(self):
|
||||
|
@ -116,7 +116,7 @@ class Report(UserInterface):
|
||||
css = f.read()
|
||||
|
||||
css = (
|
||||
css.replace("{header}", _('Report') if header is None else header)
|
||||
css.replace("{header}", _('Report') if header is None else header)
|
||||
.replace('{page}', _('Page'))
|
||||
.replace('{of}', _('of'))
|
||||
.replace('{water}', 'UDS Report' if water is None else water)
|
||||
|
@ -575,10 +575,10 @@ class UserDeployment(Environmentable, Serializable):
|
||||
raise Exception('cancel method for class {0} not provided!'.format(self.__class__.__name__))
|
||||
|
||||
def reset(self):
|
||||
'''
|
||||
"""
|
||||
This method is invoked for "reset" an user service
|
||||
This method is not intended to be a task right now, it's more like the
|
||||
'''
|
||||
"""
|
||||
raise Exception('reset method for class {0} not provided!'.format(self.__class__.__name__))
|
||||
|
||||
def __str__(self):
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
@ -41,7 +41,7 @@ __updated__ = '2018-03-14'
|
||||
|
||||
|
||||
class Service(Module):
|
||||
'''
|
||||
"""
|
||||
This class is in fact an interface, and represents a service, that is the
|
||||
definition of an offering for consumers (users).
|
||||
|
||||
@ -76,7 +76,7 @@ class Service(Module):
|
||||
only need data that is keeped at form fields, marshal and unmarshal and in fact
|
||||
not needed.
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
# : Constant for indicating that max elements this service can deploy is unlimited.
|
||||
UNLIMITED = -1
|
||||
@ -179,17 +179,17 @@ class Service(Module):
|
||||
servicesTypeProvided = types.ALL
|
||||
|
||||
def __init__(self, environment, parent, values=None):
|
||||
'''
|
||||
"""
|
||||
Do not forget to invoke this in your derived class using "super(self.__class__, self).__init__(environment, parent, values)".
|
||||
We want to use the env, parent methods outside class. If not called, you must implement your own methods
|
||||
cache and storage are "convenient" methods to access _env.cache and _env.storage
|
||||
'''
|
||||
"""
|
||||
super(Service, self).__init__(environment, values)
|
||||
self._provider = parent
|
||||
self.initialize(values)
|
||||
|
||||
def initialize(self, values):
|
||||
'''
|
||||
"""
|
||||
This method will be invoked from __init__ constructor.
|
||||
This is provided so you don't have to provide your own __init__ method,
|
||||
and invoke base methods.
|
||||
@ -202,47 +202,47 @@ class Service(Module):
|
||||
be called after this.
|
||||
|
||||
Default implementation does nothing
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
def parent(self):
|
||||
'''
|
||||
"""
|
||||
Utility method to access parent provider for this service
|
||||
|
||||
Returns
|
||||
|
||||
Parent provider instance object (not database object)
|
||||
'''
|
||||
"""
|
||||
return self._provider
|
||||
|
||||
def requestServicesForAssignation(self, **kwargs):
|
||||
'''
|
||||
"""
|
||||
override this if mustAssignManualy is True
|
||||
@params kwargs: Named arguments
|
||||
@return an array with the services that we can assign (they must be of type deployedType)
|
||||
We will access the returned array in "name" basis. This means that the service will be assigned by "name", so be care that every single service
|
||||
returned are not repeated... :-)
|
||||
'''
|
||||
"""
|
||||
raise Exception('The class {0} has been marked as manually asignable but no requestServicesForAssignetion provided!!!'.format(self.__class__.__name__))
|
||||
|
||||
def macGenerator(self):
|
||||
'''
|
||||
"""
|
||||
Utility method to access provided macs generator (inside environment)
|
||||
|
||||
Returns the environment unique mac addresses generator
|
||||
'''
|
||||
"""
|
||||
return self.idGenerators('mac')
|
||||
|
||||
def nameGenerator(self):
|
||||
'''
|
||||
"""
|
||||
Utility method to access provided names generator (inside environment)
|
||||
|
||||
Returns the environment unique name generator
|
||||
'''
|
||||
"""
|
||||
return self.idGenerators('name')
|
||||
|
||||
def __str__(self):
|
||||
'''
|
||||
"""
|
||||
String method, mainly used for debugging purposes
|
||||
'''
|
||||
"""
|
||||
return "Base Service Provider"
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import get_language, ugettext as _, ugettext_noop
|
||||
@ -44,7 +44,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class gui(object):
|
||||
'''
|
||||
"""
|
||||
This class contains the representations of fields needed by UDS modules and
|
||||
administation interface.
|
||||
|
||||
@ -76,7 +76,7 @@ class gui(object):
|
||||
At class instantiation, this data is extracted and processed, so the admin
|
||||
can access this form to let users
|
||||
create new instances of this module.
|
||||
'''
|
||||
"""
|
||||
|
||||
# : True string value
|
||||
TRUE = 'true'
|
||||
@ -96,11 +96,11 @@ class gui(object):
|
||||
# Helpers
|
||||
@staticmethod
|
||||
def convertToChoices(vals):
|
||||
'''
|
||||
"""
|
||||
Helper to convert from array of strings to the same dict used in choice,
|
||||
multichoice, ..
|
||||
The id is set to values in the array (strings), while text is left empty.
|
||||
'''
|
||||
"""
|
||||
res = []
|
||||
for v in vals:
|
||||
res.append({'id': v, 'text': ''})
|
||||
@ -114,7 +114,7 @@ class gui(object):
|
||||
|
||||
@staticmethod
|
||||
def choiceItem(id_, text):
|
||||
'''
|
||||
"""
|
||||
Helper method to create a single choice item.
|
||||
|
||||
Args:
|
||||
@ -128,7 +128,7 @@ class gui(object):
|
||||
|
||||
:note: Text can be anything, the method converts it first to text before
|
||||
assigning to dictionary
|
||||
'''
|
||||
"""
|
||||
return {'id': str(id_), 'text': six.text_type(text)}
|
||||
|
||||
@staticmethod
|
||||
@ -141,7 +141,7 @@ class gui(object):
|
||||
|
||||
@staticmethod
|
||||
def strToBool(str_):
|
||||
'''
|
||||
"""
|
||||
Converts the string "true" (case insensitive) to True (boolean).
|
||||
Anything else is converted to false
|
||||
|
||||
@ -150,7 +150,7 @@ class gui(object):
|
||||
|
||||
Returns:
|
||||
True if the string is "true" (case insensitive), False else.
|
||||
'''
|
||||
"""
|
||||
if isinstance(str_, bool):
|
||||
return str_
|
||||
if six.text_type(str_).lower() == gui.TRUE:
|
||||
@ -159,7 +159,7 @@ class gui(object):
|
||||
|
||||
@staticmethod
|
||||
def boolToStr(bol):
|
||||
'''
|
||||
"""
|
||||
Converts a boolean to the string representation. True is converted to
|
||||
"true", False to "false".
|
||||
|
||||
@ -168,7 +168,7 @@ class gui(object):
|
||||
|
||||
Returns:
|
||||
"true" if bol evals to True, "false" if don't.
|
||||
'''
|
||||
"""
|
||||
if bol:
|
||||
return gui.TRUE
|
||||
return gui.FALSE
|
||||
@ -176,7 +176,7 @@ class gui(object):
|
||||
# Classes
|
||||
|
||||
class InputField(object):
|
||||
'''
|
||||
"""
|
||||
Class representing an simple input field.
|
||||
This class is not directly usable, must be used by any inherited class
|
||||
(fields all of them)
|
||||
@ -211,7 +211,7 @@ class gui(object):
|
||||
Take into account also that "value" has precedence over "defValue",
|
||||
so if you use both, the used one will be "value". This is valid for
|
||||
all form fields.
|
||||
'''
|
||||
"""
|
||||
TEXT_TYPE = 'text'
|
||||
TEXTBOX_TYPE = 'textbox'
|
||||
NUMERIC_TYPE = 'numeric'
|
||||
@ -243,50 +243,50 @@ class gui(object):
|
||||
self._data['tab'] = options.get('tab')
|
||||
|
||||
def _type(self, type_):
|
||||
'''
|
||||
"""
|
||||
Sets the type of this field.
|
||||
|
||||
Args:
|
||||
type: Type to set (from constants of this class)
|
||||
'''
|
||||
"""
|
||||
self._data['type'] = type_
|
||||
|
||||
def isType(self, type_):
|
||||
'''
|
||||
"""
|
||||
Returns true if this field is of specified type
|
||||
'''
|
||||
"""
|
||||
return self._data['type'] == type_
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
'''
|
||||
"""
|
||||
Obtains the stored value.
|
||||
If the stored value is None (this will only happens if value is forced to be so, by default empty value is ''),
|
||||
returns default value instead.
|
||||
This is mainly used for hidden fields, so we have correctly initialized
|
||||
'''
|
||||
"""
|
||||
return self._data['value'] if self._data['value'] is not None else self.defValue
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
'''
|
||||
"""
|
||||
Stores new value (not the default one)
|
||||
'''
|
||||
"""
|
||||
self._setValue(value)
|
||||
|
||||
def _setValue(self, value):
|
||||
'''
|
||||
"""
|
||||
So we can override value setting at descendants
|
||||
'''
|
||||
"""
|
||||
self._data['value'] = value
|
||||
|
||||
def guiDescription(self):
|
||||
'''
|
||||
"""
|
||||
Returns the dictionary with the description of this item.
|
||||
We copy it, cause we need to translate the label and tooltip fields
|
||||
and don't want to
|
||||
alter original values.
|
||||
'''
|
||||
"""
|
||||
data = self._data.copy()
|
||||
data['label'] = data['label'] != '' and _(data['label']) or ''
|
||||
data['tooltip'] = data['tooltip'] != '' and _(data['tooltip']) or ''
|
||||
@ -296,9 +296,9 @@ class gui(object):
|
||||
|
||||
@property
|
||||
def defValue(self):
|
||||
'''
|
||||
"""
|
||||
Returns the default value for this field
|
||||
'''
|
||||
"""
|
||||
return self._data['defvalue']
|
||||
|
||||
@defValue.setter
|
||||
@ -306,12 +306,12 @@ class gui(object):
|
||||
self.setDefValue(defValue)
|
||||
|
||||
def setDefValue(self, defValue):
|
||||
'''
|
||||
"""
|
||||
Sets the default value of the field·
|
||||
|
||||
Args:
|
||||
defValue: Default value (string)
|
||||
'''
|
||||
"""
|
||||
self._data['defvalue'] = defValue
|
||||
|
||||
@property
|
||||
@ -319,7 +319,7 @@ class gui(object):
|
||||
return self._data['label']
|
||||
|
||||
class TextField(InputField):
|
||||
'''
|
||||
"""
|
||||
This represents a text field.
|
||||
|
||||
The values of parameters are inherited from :py:class:`InputField`
|
||||
@ -348,7 +348,7 @@ class gui(object):
|
||||
other = gui.TextField(length=64, label = _('Other'), order = 1,
|
||||
tooltip = _('Other info'), rdonly = True)
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
@ -359,7 +359,7 @@ class gui(object):
|
||||
self._data['multiline'] = multiline
|
||||
|
||||
class NumericField(InputField):
|
||||
'''
|
||||
"""
|
||||
This represents a numeric field. It apears with an spin up/down button.
|
||||
|
||||
The values of parameres are inherited from :py:class:`InputField`
|
||||
@ -377,7 +377,7 @@ class gui(object):
|
||||
num = gui.NumericField(length=5, label = _('Port'),
|
||||
defvalue = '443', order = 1, tooltip = _('Port (usually 443)'),
|
||||
required = True)
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
@ -389,9 +389,9 @@ class gui(object):
|
||||
self._type(gui.InputField.NUMERIC_TYPE)
|
||||
|
||||
def num(self):
|
||||
'''
|
||||
"""
|
||||
Return value as integer
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
v = int(self.value)
|
||||
except Exception:
|
||||
@ -399,7 +399,7 @@ class gui(object):
|
||||
return v
|
||||
|
||||
class DateField(InputField):
|
||||
'''
|
||||
"""
|
||||
This represents a date field.
|
||||
|
||||
The values of parameres are inherited from :py:class:`InputField`
|
||||
@ -416,7 +416,7 @@ class gui(object):
|
||||
order = 4, tooltip = _('Ending date'),
|
||||
required = True)
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
def processValue(self, valueName, options):
|
||||
val = options.get(valueName, '')
|
||||
@ -447,7 +447,7 @@ class gui(object):
|
||||
return int(time.mktime(datetime.datetime.strptime(self.value, '%Y-%m-%d').timetuple()))
|
||||
|
||||
class PasswordField(InputField):
|
||||
'''
|
||||
"""
|
||||
This represents a password field. It appears with "*" at input, so the contents is not displayed
|
||||
|
||||
The values of parameres are inherited from :py:class:`InputField`
|
||||
@ -466,14 +466,14 @@ class gui(object):
|
||||
order = 4, tooltip = _('Password of the user'),
|
||||
required = True)
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
self._type(gui.InputField.PASSWORD_TYPE)
|
||||
|
||||
class HiddenField(InputField):
|
||||
'''
|
||||
"""
|
||||
This represents a hidden field. It is not displayed to the user. It use
|
||||
is for keeping info at form needed
|
||||
by module, but not editable by user (i.e., one service can keep info
|
||||
@ -502,7 +502,7 @@ class gui(object):
|
||||
# value for current instance
|
||||
self.hidden.setDefValue(self.parent().serialize())
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
@ -513,7 +513,7 @@ class gui(object):
|
||||
return self._isSerializable
|
||||
|
||||
class CheckBoxField(InputField):
|
||||
'''
|
||||
"""
|
||||
This represents a check box field, with values "true" and "false"
|
||||
|
||||
The values of parameters are inherited from :py:class:`InputField`
|
||||
@ -530,20 +530,20 @@ class gui(object):
|
||||
ssl = gui.CheckBoxField(label = _('Use SSL'), order = 3,
|
||||
tooltip = _('If checked, will use a ssl connection'))
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
self._type(gui.InputField.CHECKBOX_TYPE)
|
||||
|
||||
def isTrue(self):
|
||||
'''
|
||||
"""
|
||||
Checks that the value is true
|
||||
'''
|
||||
"""
|
||||
return self.value is True or self.value == gui.TRUE
|
||||
|
||||
class ChoiceField(InputField):
|
||||
'''
|
||||
"""
|
||||
This represents a simple combo box with single selection.
|
||||
|
||||
The values of parameters are inherited from :py:class:`InputField`
|
||||
@ -634,7 +634,7 @@ class gui(object):
|
||||
vc = gui.HiddenField()
|
||||
ev = gui.HiddenField() # ....
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
@ -649,9 +649,9 @@ class gui(object):
|
||||
self._type(gui.InputField.CHOICE_TYPE)
|
||||
|
||||
def setValues(self, values):
|
||||
'''
|
||||
"""
|
||||
Set the values for this choice field
|
||||
'''
|
||||
"""
|
||||
self._data['values'] = values
|
||||
|
||||
class ImageChoiceField(InputField):
|
||||
@ -663,13 +663,13 @@ class gui(object):
|
||||
self._type(gui.InputField.IMAGECHOICE_TYPE)
|
||||
|
||||
def setValues(self, values):
|
||||
'''
|
||||
"""
|
||||
Set the values for this choice field
|
||||
'''
|
||||
"""
|
||||
self._data['values'] = values
|
||||
|
||||
class MultiChoiceField(InputField):
|
||||
'''
|
||||
"""
|
||||
Multichoices are list of items that are multi-selectable.
|
||||
|
||||
There is a new parameter here, not covered by InputField:
|
||||
@ -700,7 +700,7 @@ class gui(object):
|
||||
values = [ {'id': '0', 'text': 'datastore0' },
|
||||
{'id': '1', 'text': 'datastore1' } ]
|
||||
)
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
@ -709,13 +709,13 @@ class gui(object):
|
||||
self._type(gui.InputField.MULTI_CHOICE_TYPE)
|
||||
|
||||
def setValues(self, values):
|
||||
'''
|
||||
"""
|
||||
Set the values for this multi choice field
|
||||
'''
|
||||
"""
|
||||
self._data['values'] = values
|
||||
|
||||
class EditableList(InputField):
|
||||
'''
|
||||
"""
|
||||
Editables list are lists of editable elements (i.e., a list of IPs, macs,
|
||||
names, etcc) treated as simple strings with no id
|
||||
|
||||
@ -739,7 +739,7 @@ class gui(object):
|
||||
#
|
||||
ipList = gui.EditableList(label=_('List of IPS'))
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
# : Constant for separating values at "value" method
|
||||
SEPARATOR = '\001'
|
||||
@ -750,25 +750,25 @@ class gui(object):
|
||||
self._type(gui.InputField.EDITABLE_LIST)
|
||||
|
||||
def _setValue(self, values):
|
||||
'''
|
||||
"""
|
||||
So we can override value setting at descendants
|
||||
'''
|
||||
"""
|
||||
super(self.__class__, self)._setValue(values)
|
||||
self._data['values'] = gui.convertToList(values)
|
||||
|
||||
class ImageField(InputField):
|
||||
'''
|
||||
"""
|
||||
Image field
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
self._type(gui.InputField.TEXT_TYPE)
|
||||
|
||||
class InfoField(InputField):
|
||||
'''
|
||||
"""
|
||||
Informational field (no input is done)
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
@ -795,7 +795,7 @@ class UserInterfaceType(type):
|
||||
|
||||
#@six.add_metaclass(UserInterfaceType)
|
||||
class UserInterface(object, metaclass=UserInterfaceType):
|
||||
'''
|
||||
"""
|
||||
This class provides the management for gui descriptions (user forms)
|
||||
|
||||
Once a class is derived from this one, that class can contain Field
|
||||
@ -804,7 +804,7 @@ class UserInterface(object, metaclass=UserInterfaceType):
|
||||
|
||||
By default, the values passed to this class constructor are used to fill
|
||||
the gui form fields values.
|
||||
'''
|
||||
"""
|
||||
# __metaclass__ = UserInterfaceType
|
||||
|
||||
def __init__(self, values=None):
|
||||
@ -824,7 +824,7 @@ class UserInterface(object, metaclass=UserInterfaceType):
|
||||
logger.warning('Field {} not found'.format(k))
|
||||
|
||||
def initGui(self):
|
||||
'''
|
||||
"""
|
||||
This method gives the oportunity to initialize gui fields before they
|
||||
are send to administration client.
|
||||
We need this because at initialization time we probably don't have the
|
||||
@ -841,11 +841,11 @@ class UserInterface(object, metaclass=UserInterfaceType):
|
||||
but may happen that two services of same type are requested at same
|
||||
time, and returned data will be probable a nonsense. We will take care
|
||||
of this posibility in a near version...
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
def valuesDict(self):
|
||||
'''
|
||||
"""
|
||||
Returns own data needed for user interaction as a dict of key-names ->
|
||||
values. The values returned must be strings.
|
||||
|
||||
@ -870,7 +870,7 @@ class UserInterface(object, metaclass=UserInterfaceType):
|
||||
:note: By default, the provided method returns the correct values
|
||||
extracted from form fields
|
||||
|
||||
'''
|
||||
"""
|
||||
dic = {}
|
||||
for k, v in six.iteritems(self._gui):
|
||||
if v.isType(gui.InputField.EDITABLE_LIST):
|
||||
@ -887,7 +887,7 @@ class UserInterface(object, metaclass=UserInterfaceType):
|
||||
return dic
|
||||
|
||||
def serializeForm(self):
|
||||
'''
|
||||
"""
|
||||
All values stored at form fields are serialized and returned as a single
|
||||
string
|
||||
Separating char is
|
||||
@ -896,7 +896,7 @@ class UserInterface(object, metaclass=UserInterfaceType):
|
||||
|
||||
Note: Hidens are not serialized, they are ignored
|
||||
|
||||
'''
|
||||
"""
|
||||
|
||||
# import inspect
|
||||
# logger.debug('Caller is : {}'.format(inspect.stack()))
|
||||
@ -925,11 +925,11 @@ class UserInterface(object, metaclass=UserInterfaceType):
|
||||
return encoders.encode('\002'.join(arr), 'zip')
|
||||
|
||||
def unserializeForm(self, values):
|
||||
'''
|
||||
"""
|
||||
This method unserializes the values previously obtained using
|
||||
:py:meth:`serializeForm`, and stores
|
||||
the valid values form form fileds inside its corresponding field
|
||||
'''
|
||||
"""
|
||||
if values == b'': # Has nothing
|
||||
return
|
||||
|
||||
@ -964,7 +964,7 @@ class UserInterface(object, metaclass=UserInterfaceType):
|
||||
|
||||
@classmethod
|
||||
def guiDescription(cls, obj=None):
|
||||
'''
|
||||
"""
|
||||
This simple method generates the theGui description needed by the
|
||||
administration client, so it can
|
||||
represent it at user interface and manage it.
|
||||
@ -972,7 +972,7 @@ class UserInterface(object, metaclass=UserInterfaceType):
|
||||
Args:
|
||||
object: If not none, object that will get its "initGui" invoked
|
||||
This will only happen (not to be None) in Services.
|
||||
'''
|
||||
"""
|
||||
logger.debug('Active language for theGui translation: {0}'.format(get_language()))
|
||||
theGui = cls
|
||||
if obj is not None:
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -65,13 +65,13 @@ class Attribute(object):
|
||||
|
||||
# noinspection PyMissingConstructor
|
||||
class AutoAttributes(Serializable):
|
||||
'''
|
||||
"""
|
||||
Easy creation of attributes to marshal & unmarshal at modules
|
||||
usage as base class (First class so yours inherits this "marshal" and "unmarshal"
|
||||
initialize at init with super(myclass,self).__init__(attr1=type, attr2=type, ...)
|
||||
or with declare(attr1=type,attr2=type,..)
|
||||
Access attrs as "self._attr1, self._attr2"
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.dict = None
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
from django.db import transaction
|
||||
import uds.models.Cache
|
||||
@ -90,10 +90,10 @@ class Cache(object):
|
||||
return defValue
|
||||
|
||||
def remove(self, skey):
|
||||
'''
|
||||
"""
|
||||
Removes an stored cached item
|
||||
If cached item does not exists, nothing happens (no exception thrown)
|
||||
'''
|
||||
"""
|
||||
# logger.debug('Removing key "%s" for uService "%s"' % (skey, self._owner))
|
||||
try:
|
||||
key = self.__getKey(skey)
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import transaction
|
||||
@ -116,15 +116,15 @@ class Storage(object):
|
||||
pass
|
||||
|
||||
def lock(self):
|
||||
'''
|
||||
"""
|
||||
Use with care. If locked, it must be unlocked before returning
|
||||
'''
|
||||
"""
|
||||
dbStorage.objects.lock() # @UndefinedVariable
|
||||
|
||||
def unlock(self):
|
||||
'''
|
||||
"""
|
||||
Must be used to unlock table
|
||||
'''
|
||||
"""
|
||||
dbStorage.objects.unlock() # @UndefinedVariable
|
||||
|
||||
def locateByAttr1(self, attr1):
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
# pylint: disable=maybe-no-member
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -132,11 +132,11 @@ class CalendarChecker(object):
|
||||
return next_event
|
||||
|
||||
def check(self, dtime=None):
|
||||
'''
|
||||
"""
|
||||
Checks if the given time is a valid event on calendar
|
||||
@param dtime: Datetime object to check
|
||||
TODO: We can improve performance of this by getting from a cache first if we can
|
||||
'''
|
||||
"""
|
||||
if dtime is None:
|
||||
dtime = getSqlDatetime()
|
||||
|
||||
@ -159,10 +159,10 @@ class CalendarChecker(object):
|
||||
return data[dtime.hour * 60 + dtime.minute]
|
||||
|
||||
def nextEvent(self, checkFrom=None, startEvent=True, offset=None):
|
||||
'''
|
||||
"""
|
||||
Returns next event for this interval
|
||||
Returns a list of two elements. First is datetime of event begining, second is timedelta of duration
|
||||
'''
|
||||
"""
|
||||
logger.debug('Obtaining nextEvent')
|
||||
if checkFrom is None:
|
||||
checkFrom = getSqlDatetime()
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
import six
|
||||
import codecs
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.core.managers import logManager
|
||||
@ -63,9 +63,9 @@ __valueLevels = dict((v, k) for k, v in __nameLevels.items())
|
||||
|
||||
|
||||
def logLevelFromStr(str_):
|
||||
'''
|
||||
"""
|
||||
Gets the numeric log level from an string.
|
||||
'''
|
||||
"""
|
||||
return __nameLevels.get(str_.upper(), OTHER)
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ def logStrFromLevel(level):
|
||||
|
||||
|
||||
def useLog(type_, serviceUniqueId, serviceIp, username, srcIP=None, srcUser=None, userServiceName=None, poolName=None):
|
||||
'''
|
||||
"""
|
||||
Logs an "use service" event (logged from actors)
|
||||
:param type_: Type of event (commonly 'login' or 'logout' )
|
||||
:param serviceUniqueId: Unique id of service
|
||||
@ -82,7 +82,7 @@ def useLog(type_, serviceUniqueId, serviceIp, username, srcIP=None, srcUser=None
|
||||
:param username: Username notified from service (internal "user service" user name
|
||||
:param srcIP: IP of user holding that service at time of event
|
||||
:param srcUser: Username holding that service at time of evet
|
||||
'''
|
||||
"""
|
||||
srcIP = 'unknown' if srcIP is None else srcIP
|
||||
srcUser = 'unknown' if srcUser is None else srcUser
|
||||
userServiceName = 'unknown' if userServiceName is None else userServiceName
|
||||
@ -97,9 +97,9 @@ def doLog(wichObject, level, message, source=UNKNOWN, avoidDuplicates=True):
|
||||
|
||||
|
||||
def getLogs(wichObject, limit=None):
|
||||
'''
|
||||
"""
|
||||
Get the logs associated with "wichObject", limiting to "limit" (default is GlobalConfig.MAX_LOGS_PER_ELEMENT)
|
||||
'''
|
||||
"""
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
|
||||
if limit is None:
|
||||
@ -109,7 +109,7 @@ def getLogs(wichObject, limit=None):
|
||||
|
||||
|
||||
def clearLogs(wichObject):
|
||||
'''
|
||||
"""
|
||||
Clears the logs associated with the object using the logManager
|
||||
'''
|
||||
"""
|
||||
return logManager().clearLogs(wichObject)
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
import re
|
||||
import six
|
||||
@ -48,9 +48,9 @@ reHost = re.compile(r'^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$')
|
||||
|
||||
|
||||
def ipToLong(ip):
|
||||
'''
|
||||
"""
|
||||
convert decimal dotted quad string to long integer
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
hexn = int(''.join(["%02X" % int(i) for i in ip.split('.')]), 16)
|
||||
logger.debug('IP {} is {}'.format(ip, hexn))
|
||||
@ -61,9 +61,9 @@ def ipToLong(ip):
|
||||
|
||||
|
||||
def longToIp(n):
|
||||
'''
|
||||
"""
|
||||
convert long int to dotted quad string
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
d = 1 << 24
|
||||
q = []
|
||||
@ -78,7 +78,7 @@ def longToIp(n):
|
||||
|
||||
|
||||
def networksFromString(strNets, allowMultipleNetworks=True):
|
||||
'''
|
||||
"""
|
||||
Parses the network from strings in this forms:
|
||||
- A.* (or A.*.* or A.*.*.*)
|
||||
- A.B.* (or A.B.*.* )
|
||||
@ -89,7 +89,7 @@ def networksFromString(strNets, allowMultipleNetworks=True):
|
||||
- A.B.C.D
|
||||
If allowMultipleNetworks is True, it allows ',' and ';' separators (and, ofc, more than 1 network)
|
||||
Returns a list of networks tuples in the form [(start1, end1), (start2, end2) ...]
|
||||
'''
|
||||
"""
|
||||
|
||||
inputString = strNets
|
||||
logger.debug('Getting network from {}'.format(strNets))
|
||||
|
@ -43,9 +43,10 @@ def __init__():
|
||||
try:
|
||||
logger.info('Loading dispatcher {}'.format(name))
|
||||
__import__(name, globals(), locals(), [], 1)
|
||||
except:
|
||||
except Exception:
|
||||
logger.exception('Loading dispatcher {}'.format(name))
|
||||
|
||||
logger.debug('Dispatchers initialized')
|
||||
|
||||
|
||||
__init__()
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -177,10 +177,10 @@ class Authenticator(ManagedObjectModel, TaggingMixin):
|
||||
|
||||
@staticmethod
|
||||
def getByTag(tag=None):
|
||||
'''
|
||||
"""
|
||||
Gets authenticator by tag name.
|
||||
Special tag name "disabled" is used to exclude customAuth
|
||||
'''
|
||||
"""
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
|
||||
auths = []
|
||||
|
@ -28,9 +28,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -55,9 +55,9 @@ class Calendar(UUIDModel, TaggingMixin):
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
'''
|
||||
"""
|
||||
Meta class to declare db table
|
||||
'''
|
||||
"""
|
||||
db_table = 'uds_calendar'
|
||||
app_label = 'uds'
|
||||
|
||||
@ -68,7 +68,8 @@ class Calendar(UUIDModel, TaggingMixin):
|
||||
|
||||
# Basically, recalculates all related actions next execution time...
|
||||
try:
|
||||
for v in self.calendaraction_set.all(): v.save()
|
||||
for v in self.calendaraction_set.all():
|
||||
v.save()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
@ -53,8 +53,8 @@ logger = logging.getLogger(__name__)
|
||||
# Current posible actions
|
||||
# Each line describes:
|
||||
#
|
||||
CALENDAR_ACTION_PUBLISH = {'id' : 'PUBLISH', 'description': _('Publish'), 'params': ()}
|
||||
CALENDAR_ACTION_CACHE_L1 = {'id': 'CACHEL1', 'description': _('Set cache size'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Cache size'), 'default': '1'},) }
|
||||
CALENDAR_ACTION_PUBLISH = {'id': 'PUBLISH', 'description': _('Publish'), 'params': ()}
|
||||
CALENDAR_ACTION_CACHE_L1 = {'id': 'CACHEL1', 'description': _('Set cache size'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Cache size'), 'default': '1'},)}
|
||||
CALENDAR_ACTION_CACHE_L2 = {'id': 'CACHEL2', 'description': _('Set L2 cache size'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Cache L2 size'), 'default': '1'},)}
|
||||
CALENDAR_ACTION_INITIAL = {'id': 'INITIAL', 'description': _('Set initial services'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Initial services'), 'default': '1'},)}
|
||||
CALENDAR_ACTION_MAX = {'id': 'MAX', 'description': _('Set maximum number of services'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Maximum services'), 'default': '10'},)}
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -91,6 +91,7 @@ dunit_to_mins = {
|
||||
weekdays = [rules.SU, rules.MO, rules.TU, rules.WE, rules.TH, rules.FR, rules.SA]
|
||||
|
||||
|
||||
# noinspection PyPep8
|
||||
@python_2_unicode_compatible
|
||||
class CalendarRule(UUIDModel):
|
||||
name = models.CharField(max_length=128)
|
||||
@ -106,9 +107,9 @@ class CalendarRule(UUIDModel):
|
||||
calendar = models.ForeignKey(Calendar, related_name='rules', on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
'''
|
||||
"""
|
||||
Meta class to declare db table
|
||||
'''
|
||||
"""
|
||||
db_table = 'uds_calendar_rules'
|
||||
app_label = 'uds'
|
||||
|
||||
|
@ -28,9 +28,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -70,9 +70,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DeployedService(UUIDModel, TaggingMixin):
|
||||
'''
|
||||
"""
|
||||
A deployed service is the Service produced element that is assigned finally to an user (i.e. a Virtual Machine, etc..)
|
||||
'''
|
||||
"""
|
||||
# pylint: disable=model-missing-unicode
|
||||
name = models.CharField(max_length=128, default='')
|
||||
short_name = models.CharField(max_length=32, default='')
|
||||
@ -112,27 +112,27 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
# meta_pools = models.ManyToManyField('self', symmetrical=False)
|
||||
|
||||
class Meta(UUIDModel.Meta):
|
||||
'''
|
||||
"""
|
||||
Meta class to declare the name of the table at database
|
||||
'''
|
||||
"""
|
||||
db_table = 'uds__deployed_service'
|
||||
app_label = 'uds'
|
||||
|
||||
def getEnvironment(self):
|
||||
'''
|
||||
"""
|
||||
Returns an environment valid for the record this object represents
|
||||
'''
|
||||
"""
|
||||
return Environment.getEnvForTableElement(self._meta.verbose_name, self.id)
|
||||
|
||||
def activePublication(self):
|
||||
'''
|
||||
"""
|
||||
Returns the current valid publication for this deployed service.
|
||||
|
||||
Returns:
|
||||
Publication db record if this deployed service has an valid active publication.
|
||||
|
||||
None if there is no valid publication for this deployed service.
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
return self.publications.filter(state=states.publication.USABLE)[0]
|
||||
except Exception:
|
||||
@ -142,14 +142,14 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
return self.osmanager.getType().transformsUserOrPasswordForService()
|
||||
|
||||
def processUserPassword(self, username, password):
|
||||
'''
|
||||
"""
|
||||
This method is provided for consistency between UserService and DeployedService
|
||||
There is no posibility to check the username and password that a user will use to
|
||||
connect to a service at this level, because here there is no relation between both.
|
||||
|
||||
The only function of this method is allow Transport to transform username/password in
|
||||
getConnectionInfo without knowing if it is requested by a DeployedService or an UserService
|
||||
'''
|
||||
"""
|
||||
return [username, password]
|
||||
|
||||
@staticmethod
|
||||
@ -182,7 +182,7 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
return six.text_type(self.name)
|
||||
|
||||
def isRestrained(self):
|
||||
'''
|
||||
"""
|
||||
Maybe this deployed service is having problems, and that may block some task in some
|
||||
situations.
|
||||
|
||||
@ -194,7 +194,7 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
|
||||
The time that a service is in restrain mode is 20 minutes by default (1200 secs), but it can be modified
|
||||
at globalconfig variables
|
||||
'''
|
||||
"""
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
|
||||
if GlobalConfig.RESTRAINT_TIME.getInt() <= 0:
|
||||
@ -229,9 +229,9 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
return None
|
||||
|
||||
def isAccessAllowed(self, chkDateTime=None):
|
||||
'''
|
||||
"""
|
||||
Checks if the access for a service pool is allowed or not (based esclusively on associated calendars)
|
||||
'''
|
||||
"""
|
||||
if chkDateTime is None:
|
||||
chkDateTime = getSqlDatetime()
|
||||
|
||||
@ -245,9 +245,9 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
return access == states.action.ALLOW
|
||||
|
||||
def getDeadline(self, chkDateTime=None):
|
||||
'''
|
||||
"""
|
||||
Gets the deadline for an access on chkDateTime
|
||||
'''
|
||||
"""
|
||||
if chkDateTime is None:
|
||||
chkDateTime = getSqlDatetime()
|
||||
|
||||
@ -275,17 +275,17 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
return int((deadLine - chkDateTime).total_seconds())
|
||||
|
||||
def storeValue(self, name, value):
|
||||
'''
|
||||
"""
|
||||
Stores a value inside custom storage
|
||||
|
||||
Args:
|
||||
name: Name of the value to store
|
||||
value: Value of the value to store
|
||||
'''
|
||||
"""
|
||||
self.getEnvironment().storage.put(name, value)
|
||||
|
||||
def recoverValue(self, name):
|
||||
'''
|
||||
"""
|
||||
Recovers a value from custom storage
|
||||
|
||||
Args:
|
||||
@ -293,11 +293,11 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
|
||||
Returns:
|
||||
Stored value, None if no value was stored
|
||||
'''
|
||||
"""
|
||||
return self.getEnvironment().storage.get(name)
|
||||
|
||||
def setState(self, state, save=True):
|
||||
'''
|
||||
"""
|
||||
Updates the state of this object and, optionally, saves it
|
||||
|
||||
Args:
|
||||
@ -305,26 +305,26 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
|
||||
save: Defaults to true. If false, record will not be saved to db, just modified
|
||||
|
||||
'''
|
||||
"""
|
||||
self.state = state
|
||||
self.state_date = getSqlDatetime()
|
||||
if save is True:
|
||||
self.save()
|
||||
|
||||
def remove(self):
|
||||
'''
|
||||
"""
|
||||
Marks the deployed service for removing.
|
||||
|
||||
The background worker will be the responsible for removing the deployed service
|
||||
'''
|
||||
"""
|
||||
self.setState(states.servicePool.REMOVABLE)
|
||||
|
||||
def removed(self):
|
||||
'''
|
||||
"""
|
||||
Mark the deployed service as removed.
|
||||
|
||||
A background worker will check for removed deloyed services and clean database of them.
|
||||
'''
|
||||
"""
|
||||
# self.transports.clear()
|
||||
# self.assignedGroups.clear()
|
||||
# self.osmanager = None
|
||||
@ -333,7 +333,7 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
self.delete()
|
||||
|
||||
def markOldUserServicesAsRemovables(self, activePub):
|
||||
'''
|
||||
"""
|
||||
Used when a new publication is finished.
|
||||
|
||||
Marks all user deployed services that belongs to this deployed service, that do not belongs
|
||||
@ -345,7 +345,7 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
|
||||
Args:
|
||||
activePub: Active publication used as "current" publication to make checks
|
||||
'''
|
||||
"""
|
||||
now = getSqlDatetime()
|
||||
if activePub is None:
|
||||
logger.error('No active publication, don\'t know what to erase!!! (ds = {0})'.format(self))
|
||||
@ -358,19 +358,19 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
ap.userServices.filter(cache_level=0, state=states.userService.USABLE, in_use=False).update(state=states.userService.REMOVABLE, state_date=now)
|
||||
|
||||
def validateGroups(self, grps):
|
||||
'''
|
||||
"""
|
||||
Ensures that at least a group of grps (database groups) has access to this Service Pool
|
||||
raise an InvalidUserException if fails check
|
||||
'''
|
||||
"""
|
||||
from uds.core import auths
|
||||
if len(set(grps) & set(self.assignedGroups.all())) == 0:
|
||||
raise auths.Exceptions.InvalidUserException()
|
||||
|
||||
def validatePublication(self):
|
||||
'''
|
||||
"""
|
||||
Ensures that, if this service has publications, that a publication is active
|
||||
raises an IvalidServiceException if check fails
|
||||
'''
|
||||
"""
|
||||
if self.activePublication() is None and self.service.getType().publicationType is not None:
|
||||
raise InvalidServiceException()
|
||||
|
||||
@ -381,7 +381,7 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
raise InvalidServiceException()
|
||||
|
||||
def validateUser(self, user):
|
||||
'''
|
||||
"""
|
||||
Validates that the user has access to this deployed service
|
||||
|
||||
Args:
|
||||
@ -395,7 +395,7 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
|
||||
InvalidServiceException() if user has rights to access, but the deployed service is not ready (no active publication)
|
||||
|
||||
'''
|
||||
"""
|
||||
# We have to check if at least one group from this user is valid for this deployed service
|
||||
|
||||
logger.debug('User: {0}'.format(user.id))
|
||||
@ -413,7 +413,7 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
|
||||
@staticmethod
|
||||
def getDeployedServicesForGroups(groups):
|
||||
'''
|
||||
"""
|
||||
Return deployed services with publications for the groups requested.
|
||||
|
||||
Args:
|
||||
@ -421,7 +421,7 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
|
||||
Returns:
|
||||
List of accesible deployed services
|
||||
'''
|
||||
"""
|
||||
from uds.core import services
|
||||
# Get services that HAS publications
|
||||
list1 = DeployedService.objects.filter(assignedGroups__in=groups, assignedGroups__state=states.group.ACTIVE,
|
||||
@ -433,50 +433,50 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
return list(set([r for r in list1] + [r for r in list2]))
|
||||
|
||||
def publish(self, changeLog=None):
|
||||
'''
|
||||
"""
|
||||
Launches the publication of this deployed service.
|
||||
|
||||
No check is done, it simply redirects the request to PublicationManager, where checks are done.
|
||||
'''
|
||||
"""
|
||||
from uds.core.managers.PublicationManager import PublicationManager
|
||||
PublicationManager.manager().publish(self, changeLog)
|
||||
|
||||
def unpublish(self):
|
||||
'''
|
||||
"""
|
||||
Unpublish (removes) current active publcation.
|
||||
|
||||
It checks that there is an active publication, and then redirects the request to the publication itself
|
||||
'''
|
||||
"""
|
||||
pub = self.activePublication()
|
||||
if pub is not None:
|
||||
pub.unpublish()
|
||||
|
||||
def cachedUserServices(self):
|
||||
'''
|
||||
"""
|
||||
Utility method to access the cached user services (level 1 and 2)
|
||||
|
||||
Returns:
|
||||
A list of db records (userService) with cached user services
|
||||
'''
|
||||
"""
|
||||
return self.userServices.exclude(cache_level=0)
|
||||
|
||||
def assignedUserServices(self):
|
||||
'''
|
||||
"""
|
||||
Utility method to access the assigned user services
|
||||
|
||||
Returns:
|
||||
A list of db records (userService) with assinged user services
|
||||
'''
|
||||
"""
|
||||
return self.userServices.filter(cache_level=0)
|
||||
|
||||
def erroneousUserServices(self):
|
||||
'''
|
||||
"""
|
||||
Utility method to locate invalid assigned user services.
|
||||
|
||||
If an user deployed service is assigned, it MUST have an user associated.
|
||||
|
||||
If it don't has an user associated, the user deployed service is wrong.
|
||||
'''
|
||||
"""
|
||||
return self.userServices.filter(cache_level=0, user=None)
|
||||
|
||||
def testServer(self, host, port, timeout=4):
|
||||
@ -484,14 +484,14 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
|
||||
@staticmethod
|
||||
def beforeDelete(sender, **kwargs):
|
||||
'''
|
||||
"""
|
||||
Used to invoke the Service class "Destroy" before deleting it from database.
|
||||
|
||||
The main purpuse of this hook is to call the "destroy" method of the object to delete and
|
||||
to clear related data of the object (environment data such as own storage, cache, etc...
|
||||
|
||||
:note: If destroy raises an exception, the deletion is not taken.
|
||||
'''
|
||||
"""
|
||||
from uds.core.util.permissions import clean
|
||||
toDelete = kwargs['instance']
|
||||
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
# pylint: disable=model-missing-unicode, too-many-public-methods
|
||||
|
||||
@ -62,10 +62,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class UserService(UUIDModel):
|
||||
'''
|
||||
"""
|
||||
This is the base model for assigned user service and cached user services.
|
||||
This are the real assigned services to users. DeployedService is the container (the group) of this elements.
|
||||
'''
|
||||
"""
|
||||
|
||||
# The reference to deployed service is used to accelerate the queries for different methods, in fact its redundant cause we can access to the deployed service
|
||||
# through publication, but queries are much more simple
|
||||
@ -98,9 +98,9 @@ class UserService(UUIDModel):
|
||||
# objects = LockingManager() This model is on an innoDb table, so we do not need the locking manager anymore
|
||||
|
||||
class Meta(UUIDModel.Meta):
|
||||
'''
|
||||
"""
|
||||
Meta class to declare default order and unique multiple field index
|
||||
'''
|
||||
"""
|
||||
db_table = 'uds__user_service'
|
||||
ordering = ('creation_date',)
|
||||
app_label = 'uds'
|
||||
@ -112,13 +112,13 @@ class UserService(UUIDModel):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
'''
|
||||
"""
|
||||
Simple accessor to deployed service name plus unique name
|
||||
'''
|
||||
"""
|
||||
return "{}\\{}".format(self.deployed_service.name, self.friendly_name)
|
||||
|
||||
def getEnvironment(self):
|
||||
'''
|
||||
"""
|
||||
Returns an environment valid for the record this object represents.
|
||||
|
||||
In the case of the user, there is an instatiation of "generators".
|
||||
@ -128,7 +128,7 @@ class UserService(UUIDModel):
|
||||
To access this generators, use the Envirnment class, and the keys 'name' and 'mac'.
|
||||
|
||||
(see related classes uds.core.util.UniqueNameGenerator and uds.core.util.UniqueMacGenerator)
|
||||
'''
|
||||
"""
|
||||
return Environment.getEnvForTableElement(
|
||||
self._meta.verbose_name,
|
||||
self.id,
|
||||
@ -140,7 +140,7 @@ class UserService(UUIDModel):
|
||||
)
|
||||
|
||||
def getInstance(self):
|
||||
'''
|
||||
"""
|
||||
Instantiates the object this record contains. In this case, the instantiated object needs also
|
||||
the os manager and the publication, so we also instantiate those here.
|
||||
|
||||
@ -154,7 +154,7 @@ class UserService(UUIDModel):
|
||||
The instance Instance of the class this provider represents
|
||||
|
||||
Raises:
|
||||
'''
|
||||
"""
|
||||
# We get the service instance, publication instance and osmanager instance
|
||||
ds = self.deployed_service
|
||||
serviceInstance = ds.service.getInstance()
|
||||
@ -179,20 +179,20 @@ class UserService(UUIDModel):
|
||||
return us
|
||||
|
||||
def updateData(self, us):
|
||||
'''
|
||||
"""
|
||||
Updates the data field with the serialized :py:class:uds.core.services.UserDeployment
|
||||
|
||||
Args:
|
||||
dsp: :py:class:uds.core.services.UserDeployment to serialize
|
||||
|
||||
:note: This method do not saves the updated record, just updates the field
|
||||
'''
|
||||
"""
|
||||
self.data = us.serialize()
|
||||
|
||||
def getName(self):
|
||||
'''
|
||||
"""
|
||||
Returns the name of the user deployed service
|
||||
'''
|
||||
"""
|
||||
if self.friendly_name == '':
|
||||
si = self.getInstance()
|
||||
self.friendly_name = si.getName()
|
||||
@ -201,9 +201,9 @@ class UserService(UUIDModel):
|
||||
return self.friendly_name
|
||||
|
||||
def getUniqueId(self):
|
||||
'''
|
||||
"""
|
||||
Returns the unique id of the user deployed service
|
||||
'''
|
||||
"""
|
||||
if self.unique_id == '':
|
||||
si = self.getInstance()
|
||||
self.unique_id = si.getUniqueId()
|
||||
@ -211,18 +211,18 @@ class UserService(UUIDModel):
|
||||
return self.unique_id
|
||||
|
||||
def storeValue(self, name, value):
|
||||
'''
|
||||
"""
|
||||
Stores a value inside custom storage
|
||||
|
||||
Args:
|
||||
name: Name of the value to store
|
||||
value: Value of the value to store
|
||||
'''
|
||||
"""
|
||||
# Store value as a property
|
||||
self.setProperty(name, value)
|
||||
|
||||
def recoverValue(self, name):
|
||||
'''
|
||||
"""
|
||||
Recovers a value from custom storage
|
||||
|
||||
Args:
|
||||
@ -230,7 +230,7 @@ class UserService(UUIDModel):
|
||||
|
||||
Returns:
|
||||
Stored value, None if no value was stored
|
||||
'''
|
||||
"""
|
||||
val = self.getProperty(name)
|
||||
|
||||
# To transition between old stor at storage table and new properties table
|
||||
@ -240,7 +240,7 @@ class UserService(UUIDModel):
|
||||
return val
|
||||
|
||||
def setConnectionSource(self, ip, hostname=''):
|
||||
'''
|
||||
"""
|
||||
Notifies that the last access to this service was initiated from provided params
|
||||
|
||||
Args:
|
||||
@ -249,39 +249,39 @@ class UserService(UUIDModel):
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
'''
|
||||
"""
|
||||
self.src_ip = ip
|
||||
self.src_hostname = hostname
|
||||
self.save()
|
||||
|
||||
def getConnectionSource(self):
|
||||
'''
|
||||
"""
|
||||
Returns stored connection source data (ip & hostname)
|
||||
|
||||
Returns:
|
||||
An array of two elements, first is the ip & second is the hostname
|
||||
|
||||
:note: If the transport did not notified this data, this may be "empty"
|
||||
'''
|
||||
"""
|
||||
return [self.src_ip, self.src_hostname]
|
||||
|
||||
def getOsManager(self):
|
||||
return self.deployed_service.osmanager
|
||||
|
||||
def needsOsManager(self):
|
||||
'''
|
||||
"""
|
||||
Returns True if this User Service needs an os manager (i.e. parent services pools is marked to use an os manager)
|
||||
'''
|
||||
"""
|
||||
return self.getOsManager() is not None
|
||||
|
||||
def transformsUserOrPasswordForService(self):
|
||||
'''
|
||||
"""
|
||||
If the os manager changes the username or the password, this will return True
|
||||
'''
|
||||
"""
|
||||
return self.deployed_service.transformsUserOrPasswordForService()
|
||||
|
||||
def processUserPassword(self, username, password):
|
||||
'''
|
||||
"""
|
||||
Before accessing a service by a transport, we can request
|
||||
the service to "transform" the username & password that the transport
|
||||
will use to connect to that service.
|
||||
@ -298,7 +298,7 @@ class UserService(UUIDModel):
|
||||
transformed password.
|
||||
|
||||
:note: This method MUST be invoked by transport before using credentials passed to getHtml.
|
||||
'''
|
||||
"""
|
||||
ds = self.deployed_service
|
||||
serviceInstance = ds.service.getInstance()
|
||||
if serviceInstance.needsManager is False:
|
||||
@ -307,7 +307,7 @@ class UserService(UUIDModel):
|
||||
return ds.osmanager.getInstance().processUserPassword(self, username, password)
|
||||
|
||||
def setState(self, state):
|
||||
'''
|
||||
"""
|
||||
Updates the state of this object and, optionally, saves it
|
||||
|
||||
Args:
|
||||
@ -315,13 +315,13 @@ class UserService(UUIDModel):
|
||||
|
||||
save: Defaults to true. If false, record will not be saved to db, just modified
|
||||
|
||||
'''
|
||||
"""
|
||||
if state != self.state:
|
||||
self.state_date = getSqlDatetime()
|
||||
self.state = state
|
||||
|
||||
def setOsState(self, state):
|
||||
'''
|
||||
"""
|
||||
Updates the os state (state of the os) of this object and, optionally, saves it
|
||||
|
||||
Args:
|
||||
@ -329,31 +329,31 @@ class UserService(UUIDModel):
|
||||
|
||||
save: Defaults to true. If false, record will not be saved to db, just modified
|
||||
|
||||
'''
|
||||
"""
|
||||
if state != self.os_state:
|
||||
self.state_date = getSqlDatetime()
|
||||
self.os_state = state
|
||||
|
||||
def assignToUser(self, user):
|
||||
'''
|
||||
"""
|
||||
Assigns this user deployed service to an user.
|
||||
|
||||
Args:
|
||||
user: User to assing to (db record)
|
||||
'''
|
||||
"""
|
||||
self.cache_level = 0
|
||||
self.state_date = getSqlDatetime()
|
||||
self.user = user
|
||||
|
||||
def setInUse(self, state):
|
||||
'''
|
||||
"""
|
||||
Set the "in_use" flag for this user deployed service
|
||||
|
||||
Args:
|
||||
state: State to set to the "in_use" flag of this record
|
||||
|
||||
:note: If the state is Fase (set to not in use), a check for removal of this deployed service is launched.
|
||||
'''
|
||||
"""
|
||||
from uds.core.managers.UserServiceManager import UserServiceManager
|
||||
self.in_use = state
|
||||
self.in_use_date = getSqlDatetime()
|
||||
@ -387,21 +387,21 @@ class UserService(UUIDModel):
|
||||
self.deployed_service.account.stopUsageAccounting(self)
|
||||
|
||||
def isUsable(self):
|
||||
'''
|
||||
"""
|
||||
Returns if this service is usable
|
||||
'''
|
||||
"""
|
||||
return State.isUsable(self.state)
|
||||
|
||||
def isPreparing(self):
|
||||
'''
|
||||
"""
|
||||
Returns if this service is in preparation (not ready to use, but in its way to be so...)
|
||||
'''
|
||||
"""
|
||||
return State.isPreparing(self.state)
|
||||
|
||||
def isReady(self):
|
||||
'''
|
||||
"""
|
||||
Returns if this service is ready (not preparing or marked for removal)
|
||||
'''
|
||||
"""
|
||||
# Call to isReady of the instance
|
||||
from uds.core.managers.UserServiceManager import UserServiceManager
|
||||
return UserServiceManager.manager().isReady(self)
|
||||
@ -410,53 +410,53 @@ class UserService(UUIDModel):
|
||||
return self.deployed_service.isInMaintenance()
|
||||
|
||||
def remove(self):
|
||||
'''
|
||||
"""
|
||||
Mark this user deployed service for removal
|
||||
'''
|
||||
"""
|
||||
self.setState(State.REMOVABLE)
|
||||
self.save()
|
||||
|
||||
def release(self):
|
||||
'''
|
||||
"""
|
||||
A much more convenient method name that "remove" (i think :) )
|
||||
'''
|
||||
"""
|
||||
self.remove()
|
||||
|
||||
def cancel(self):
|
||||
'''
|
||||
"""
|
||||
Asks the UserServiceManager to cancel the current operation of this user deployed service.
|
||||
'''
|
||||
"""
|
||||
from uds.core.managers.UserServiceManager import UserServiceManager
|
||||
UserServiceManager.manager().cancel(self)
|
||||
|
||||
def removeOrCancel(self):
|
||||
'''
|
||||
"""
|
||||
Marks for removal or cancels it, depending on state
|
||||
'''
|
||||
"""
|
||||
if self.isUsable():
|
||||
self.remove()
|
||||
else:
|
||||
self.cancel()
|
||||
|
||||
def moveToLevel(self, cacheLevel):
|
||||
'''
|
||||
"""
|
||||
Moves cache items betwen levels, managed directly
|
||||
|
||||
Args:
|
||||
cacheLevel: New cache level to put object in
|
||||
'''
|
||||
"""
|
||||
from uds.core.managers.UserServiceManager import UserServiceManager
|
||||
UserServiceManager.manager().moveToLevel(self, cacheLevel)
|
||||
|
||||
@staticmethod
|
||||
def getUserAssignedServices(user):
|
||||
'''
|
||||
"""
|
||||
Return DeployedUserServices (not deployed services) that this user owns and are assignable
|
||||
For this to happen, we locate all user services assigned to this user, and we keep those that:
|
||||
* Must assign service manually
|
||||
This method is probably slow, but i don't think a user will have more than a bunch of services assigned
|
||||
@returns and array of dicts with id, name and transports
|
||||
'''
|
||||
"""
|
||||
logger.debug("Filtering assigned services for user {0}".format(user))
|
||||
res = []
|
||||
for us in UserService.objects.filter(user=user):
|
||||
@ -476,10 +476,10 @@ class UserService(UUIDModel):
|
||||
return default
|
||||
|
||||
def getProperties(self):
|
||||
'''
|
||||
"""
|
||||
Retrieves all properties as a dictionary
|
||||
The number of properties per item is expected to be "relatively small" (no more than 5 items?)
|
||||
'''
|
||||
"""
|
||||
dct = {}
|
||||
for v in self.properties.all():
|
||||
dct[v.name] = v.value
|
||||
@ -503,9 +503,9 @@ class UserService(UUIDModel):
|
||||
return self.getProperty('ip', '0.0.0.0')
|
||||
|
||||
def isValidPublication(self):
|
||||
'''
|
||||
"""
|
||||
Returns True if this user service does not needs an publication, or if this deployed service publication is the current one
|
||||
'''
|
||||
"""
|
||||
return self.deployed_service.service.getType().publicationType is None or self.publication == self.deployed_service.activePublication()
|
||||
|
||||
def testServer(self, host, port, timeout=4):
|
||||
@ -517,14 +517,14 @@ class UserService(UUIDModel):
|
||||
|
||||
@staticmethod
|
||||
def beforeDelete(sender, **kwargs):
|
||||
'''
|
||||
"""
|
||||
Used to invoke the Service class "Destroy" before deleting it from database.
|
||||
|
||||
The main purpuse of this hook is to call the "destroy" method of the object to delete and
|
||||
to clear related data of the object (environment data such as own storage, cache, etc...
|
||||
|
||||
:note: If destroy raises an exception, the deletion is not taken.
|
||||
'''
|
||||
"""
|
||||
toDelete = kwargs['instance']
|
||||
toDelete.getEnvironment().clearRelatedData()
|
||||
|
||||
|
@ -84,9 +84,9 @@ def getSqlDatetime(unix=False):
|
||||
|
||||
|
||||
def getSqlFnc(fncName):
|
||||
'''
|
||||
"""
|
||||
Convert different sql functions for different platforms
|
||||
'''
|
||||
"""
|
||||
if connection.vendor == 'microsoft':
|
||||
return { 'CEIL': 'CEILING'}.get(fncName, fncName)
|
||||
|
||||
|
@ -63,4 +63,5 @@ def __init__():
|
||||
for cls in p.__subclasses__():
|
||||
osmanagers.factory().insert(cls)
|
||||
|
||||
|
||||
__init__()
|
||||
|
@ -185,9 +185,9 @@ class OVirtLinkedDeployment(UserDeployment):
|
||||
return State.FINISHED
|
||||
|
||||
def reset(self):
|
||||
'''
|
||||
"""
|
||||
o oVirt, reset operation just shutdowns it until v3 support is removed
|
||||
'''
|
||||
"""
|
||||
if self._vmid != '':
|
||||
self.service().stopMachine(self._vmid)
|
||||
|
||||
|
@ -228,7 +228,7 @@ class OpenGnsysClient(object):
|
||||
@ensureConnected
|
||||
def notifyDeadline(self, machineId, deadLine):
|
||||
ou, lab, client = machineId.split('.')
|
||||
if deadLine is None:
|
||||
if deadLine is None:
|
||||
deadLine = 0
|
||||
errMsg = 'Notifying deadline'
|
||||
data = {
|
||||
|
@ -232,9 +232,9 @@ class Provider(ServiceProvider):
|
||||
return True
|
||||
|
||||
def resetMachine(self, machineId):
|
||||
'''
|
||||
"""
|
||||
Resets a machine (hard-reboot)
|
||||
'''
|
||||
"""
|
||||
on.vm.resetMachine(self.api, machineId)
|
||||
|
||||
def removeMachine(self, machineId):
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
import logging
|
||||
import six
|
||||
@ -45,7 +45,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def getMachineState(api, machineId):
|
||||
'''
|
||||
"""
|
||||
Returns the state of the machine
|
||||
This method do not uses cache at all (it always tries to get machine state from OpenNebula server)
|
||||
|
||||
@ -54,7 +54,7 @@ def getMachineState(api, machineId):
|
||||
|
||||
Returns:
|
||||
one of the on.VmState Values
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
# vm = oca.VirtualMachine.new_with_id(api, int(machineId))
|
||||
# vm.info()
|
||||
@ -67,9 +67,9 @@ def getMachineState(api, machineId):
|
||||
|
||||
|
||||
def getMachineSubstate(api, machineId):
|
||||
'''
|
||||
"""
|
||||
Returns the lcm_state
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
return api.getVMSubState(machineId)
|
||||
except Exception as e:
|
||||
@ -79,7 +79,7 @@ def getMachineSubstate(api, machineId):
|
||||
|
||||
|
||||
def startMachine(api, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to start a machine. No check is done, it is simply requested to OpenNebula.
|
||||
|
||||
This start also "resume" suspended/paused machines
|
||||
@ -88,7 +88,7 @@ def startMachine(api, machineId):
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
api.VMAction(machineId, 'resume')
|
||||
except Exception as e:
|
||||
@ -96,14 +96,14 @@ def startMachine(api, machineId):
|
||||
pass
|
||||
|
||||
def stopMachine(api, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to start a machine. No check is done, it is simply requested to OpenNebula
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
api.VMAction(machineId, 'poweroff-hard')
|
||||
except Exception as e:
|
||||
@ -111,14 +111,14 @@ def stopMachine(api, machineId):
|
||||
|
||||
|
||||
def suspendMachine(api, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to suspend a machine. No check is done, it is simply requested to OpenNebula
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
api.VMAction(machineId, 'suspend')
|
||||
except Exception as e:
|
||||
@ -126,14 +126,14 @@ def suspendMachine(api, machineId):
|
||||
|
||||
|
||||
def resetMachine(api, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to suspend a machine. No check is done, it is simply requested to OpenNebula
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
api.VMAction(machineId, 'reboot-hard')
|
||||
except Exception as e:
|
||||
@ -141,14 +141,14 @@ def resetMachine(api, machineId):
|
||||
|
||||
|
||||
def removeMachine(api, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to delete a machine. No check is done, it is simply requested to OpenNebula
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
# vm = oca.VirtualMachine.new_with_id(api, int(machineId))
|
||||
# vm.delete()
|
||||
@ -159,7 +159,7 @@ def removeMachine(api, machineId):
|
||||
|
||||
|
||||
def enumerateMachines(api):
|
||||
'''
|
||||
"""
|
||||
Obtains the list of machines inside OpenNebula.
|
||||
Machines starting with UDS are filtered out
|
||||
|
||||
@ -172,14 +172,14 @@ def enumerateMachines(api):
|
||||
'name'
|
||||
'id'
|
||||
'cluster_id'
|
||||
'''
|
||||
"""
|
||||
return api.enumVMs()
|
||||
|
||||
|
||||
def getNetInfo(api, machineId, networkId=None):
|
||||
'''
|
||||
"""
|
||||
Changes the mac address of first nic of the machine to the one specified
|
||||
'''
|
||||
"""
|
||||
# md = minidom.parseString(api.call('vm.info', int(machineId)))
|
||||
md = minidom.parseString(api.VMInfo(machineId)[1])
|
||||
node = md
|
||||
@ -207,10 +207,10 @@ def getNetInfo(api, machineId, networkId=None):
|
||||
raise Exception('No network interface found on template. Please, add a network and republish.')
|
||||
|
||||
def getDisplayConnection(api, machineId):
|
||||
'''
|
||||
"""
|
||||
If machine is not running or there is not a display, will return NONE
|
||||
SPICE connections should check that 'type' is 'SPICE'
|
||||
'''
|
||||
"""
|
||||
md = minidom.parseString(api.VMInfo(machineId)[1])
|
||||
try:
|
||||
graphics = md.getElementsByTagName('GRAPHICS')[0]
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
@ -55,7 +55,7 @@ def statusIsLost(status):
|
||||
return status in [DELETED, ERROR, UNKNOWN, SOFT_DELETED]
|
||||
|
||||
def sanitizeName(name):
|
||||
'''
|
||||
"""
|
||||
machine names with [a-zA-Z0-9_-]
|
||||
'''
|
||||
"""
|
||||
return re.sub("[^a-zA-Z0-9._-]", "_", name)
|
||||
|
@ -322,14 +322,14 @@ class XenLinkedService(Service):
|
||||
return self.parent().stopVM(machineId, async)
|
||||
|
||||
def resetVM(self, machineId, async=True):
|
||||
'''
|
||||
"""
|
||||
Tries to stop a machine. No check is done, it is simply requested to Xen
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
return self.parent().resetVM(machineId, async)
|
||||
|
||||
def canSuspendVM(self, machineId):
|
||||
|
@ -318,14 +318,14 @@ class Provider(ServiceProvider):
|
||||
return self.__getApi().stopVM(machineId, async)
|
||||
|
||||
def resetVM(self, machineId, async=True):
|
||||
'''
|
||||
"""
|
||||
Tries to start a machine. No check is done, it is simply requested to XenServer
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
return self.__getApi().resetVM(machineId, async)
|
||||
|
||||
def canSuspendVM(self, machineId):
|
||||
|
@ -29,7 +29,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import six
|
||||
import XenAPI # From PIP, will remove this when dropped Python 2.7 support
|
||||
import XenAPI # From PIP, will remove this when dropped Python 2.7 support
|
||||
|
||||
import ssl
|
||||
|
||||
@ -477,7 +477,7 @@ class XenServer(object):
|
||||
tags = self.VM.get_tags(vmId)
|
||||
try:
|
||||
del tags[tags.index(TAG_MACHINE)]
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
tags.append(TAG_TEMPLATE)
|
||||
self.VM.set_tags(vmId, tags)
|
||||
|
@ -70,4 +70,5 @@ def __init__():
|
||||
continue
|
||||
services.factory().insert(cls)
|
||||
|
||||
|
||||
__init__()
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -54,10 +54,10 @@ READY_CACHE_TIMEOUT = 30
|
||||
|
||||
|
||||
class HTML5RDPTransport(Transport):
|
||||
'''
|
||||
"""
|
||||
Provides access via RDP to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
typeName = _('HTML5 RDP')
|
||||
typeType = 'HTML5RDPTransport'
|
||||
typeDescription = _('RDP protocol using HTML5 client')
|
||||
@ -131,10 +131,10 @@ class HTML5RDPTransport(Transport):
|
||||
|
||||
# Same check as normal RDP transport
|
||||
def isAvailableFor(self, userService, ip):
|
||||
'''
|
||||
"""
|
||||
Checks if the transport is available for the requested destination ip
|
||||
Override this in yours transports
|
||||
'''
|
||||
"""
|
||||
logger.debug('Checking availability for {0}'.format(ip))
|
||||
ready = self.cache.get(ip)
|
||||
if ready is None:
|
||||
|
@ -28,11 +28,11 @@
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
'''
|
||||
"""
|
||||
Created on Jul 29, 2011
|
||||
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
from uds.core.ui.UserInterface import gui
|
||||
@ -50,10 +50,10 @@ READY_CACHE_TIMEOUT = 30
|
||||
|
||||
|
||||
class NXTransport(Transport):
|
||||
'''
|
||||
"""
|
||||
Provides access via NX to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
typeName = _('NX v3.5')
|
||||
typeType = 'NXTransport'
|
||||
typeDescription = _('NX Protocol v3.5. Direct connection.')
|
||||
@ -119,9 +119,9 @@ class NXTransport(Transport):
|
||||
self._cacheMem = ''
|
||||
|
||||
def marshal(self):
|
||||
'''
|
||||
"""
|
||||
Serializes the transport data so we can store it in database
|
||||
'''
|
||||
"""
|
||||
return str.join('\t', ['v1', gui.boolToStr(self._useEmptyCreds), self._fixedName, self._fixedPassword, self._listenPort,
|
||||
self._connection, self._session, self._cacheDisk, self._cacheMem])
|
||||
|
||||
@ -144,10 +144,10 @@ class NXTransport(Transport):
|
||||
}
|
||||
|
||||
def isAvailableFor(self, userService, ip):
|
||||
'''
|
||||
"""
|
||||
Checks if the transport is available for the requested destination ip
|
||||
Override this in yours transports
|
||||
'''
|
||||
"""
|
||||
logger.debug('Checking availability for {0}'.format(ip))
|
||||
ready = self.cache.get(ip)
|
||||
if ready is None:
|
||||
|
@ -28,11 +28,11 @@
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
'''
|
||||
"""
|
||||
Created on Jul 29, 2011
|
||||
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
from uds.core.ui.UserInterface import gui
|
||||
@ -55,10 +55,10 @@ READY_CACHE_TIMEOUT = 30
|
||||
|
||||
|
||||
class TSNXTransport(Transport):
|
||||
'''
|
||||
"""
|
||||
Provides access via NX to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
typeName = _('NX v3.5')
|
||||
typeType = 'TSNXTransport'
|
||||
typeDescription = _('NX protocol v3.5. Tunneled connection.')
|
||||
@ -134,9 +134,9 @@ class TSNXTransport(Transport):
|
||||
self._cacheMem = ''
|
||||
|
||||
def marshal(self):
|
||||
'''
|
||||
"""
|
||||
Serializes the transport data so we can store it in database
|
||||
'''
|
||||
"""
|
||||
return str.join('\t', ['v1', gui.boolToStr(self._useEmptyCreds), self._fixedName, self._fixedPassword, self._listenPort,
|
||||
self._connection, self._session, self._cacheDisk, self._cacheMem, self._tunnelServer, self._tunnelCheckServer])
|
||||
|
||||
@ -161,10 +161,10 @@ class TSNXTransport(Transport):
|
||||
}
|
||||
|
||||
def isAvailableFor(self, userService, ip):
|
||||
'''
|
||||
"""
|
||||
Checks if the transport is available for the requested destination ip
|
||||
Override this in yours transports
|
||||
'''
|
||||
"""
|
||||
logger.debug('Checking availability for {0}'.format(ip))
|
||||
ready = self.cache.get(ip)
|
||||
if ready is None:
|
||||
|
@ -75,13 +75,15 @@ class BaseRDPTransport(Transport):
|
||||
tooltip=_('Screen size for this transport'),
|
||||
defvalue='-1x-1',
|
||||
values=[
|
||||
{'id': '640x480', 'text': '640x480' },
|
||||
{'id': '800x600', 'text': '800x600' },
|
||||
{'id': '1024x768', 'text': '1024x768' },
|
||||
{'id': '1366x768', 'text': '1366x768' },
|
||||
{'id': '1920x1080', 'text': '1920x1080' },
|
||||
{'id': '-1x-1', 'text': 'Full screen' },
|
||||
], tab=gui.DISPLAY_TAB)
|
||||
{'id': '640x480', 'text': '640x480'},
|
||||
{'id': '800x600', 'text': '800x600'},
|
||||
{'id': '1024x768', 'text': '1024x768'},
|
||||
{'id': '1366x768', 'text': '1366x768'},
|
||||
{'id': '1920x1080', 'text': '1920x1080'},
|
||||
{'id': '-1x-1', 'text': 'Full screen'},
|
||||
],
|
||||
tab=gui.DISPLAY_TAB
|
||||
)
|
||||
|
||||
colorDepth = gui.ChoiceField(
|
||||
label=_('Color depth'),
|
||||
@ -89,11 +91,13 @@ class BaseRDPTransport(Transport):
|
||||
tooltip=_('Color depth for this connection'),
|
||||
defvalue='24',
|
||||
values=[
|
||||
{'id': '8', 'text': '8' },
|
||||
{'id': '16', 'text': '16' },
|
||||
{'id': '24', 'text': '24' },
|
||||
{'id': '32', 'text': '32' },
|
||||
], tab=gui.DISPLAY_TAB)
|
||||
{'id': '8', 'text': '8'},
|
||||
{'id': '16', 'text': '16'},
|
||||
{'id': '24', 'text': '24'},
|
||||
{'id': '32', 'text': '32'},
|
||||
],
|
||||
tab=gui.DISPLAY_TAB
|
||||
)
|
||||
|
||||
wallpaper = gui.CheckBoxField(label=_('Wallpaper/theme'), order=32, tooltip=_('If checked, the wallpaper and themes will be shown on machine (better user experience, more bandwidth)'), tab=gui.DISPLAY_TAB)
|
||||
multimon = gui.CheckBoxField(label=_('Multiple monitors'), order=33, tooltip=_('If checked, all client monitors will be used for displaying (only works on windows clients)'), tab=gui.DISPLAY_TAB)
|
||||
|
@ -27,12 +27,12 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
Created on Jul 29, 2011
|
||||
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.core.util import OsDetector
|
||||
@ -92,10 +92,10 @@ class RDPFile(object):
|
||||
|
||||
@property
|
||||
def as_new_xfreerdp_params(self):
|
||||
'''
|
||||
"""
|
||||
Parameters for xfreerdp >= 1.1.0 with self rdp description
|
||||
Note that server is not added
|
||||
'''
|
||||
"""
|
||||
params = ['/t:UDS-Connection', '/cert-ignore'] # , '/sec:rdp']
|
||||
|
||||
if self.enableClipboard:
|
||||
@ -180,10 +180,10 @@ class RDPFile(object):
|
||||
|
||||
@property
|
||||
def as_rdesktop_params(self):
|
||||
'''
|
||||
"""
|
||||
Parameters for rdestop with self rdp description
|
||||
Note that server is not added
|
||||
'''
|
||||
"""
|
||||
|
||||
params = ['-TUDS Connection', '-P']
|
||||
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
@ -48,10 +48,10 @@ __updated__ = '2017-12-21'
|
||||
|
||||
|
||||
class RDPTransport(BaseRDPTransport):
|
||||
'''
|
||||
"""
|
||||
Provides access via RDP to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
typeName = _('RDP')
|
||||
typeType = 'RDPTransport'
|
||||
typeDescription = _('RDP Protocol. Direct connection.')
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
@ -56,10 +56,10 @@ READY_CACHE_TIMEOUT = 30
|
||||
|
||||
|
||||
class TRDPTransport(BaseRDPTransport):
|
||||
'''
|
||||
"""
|
||||
Provides access via RDP to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
typeName = _('RDP')
|
||||
typeType = 'TSRDPTransport'
|
||||
typeDescription = _('RDP Protocol. Tunneled connection.')
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
@ -52,10 +52,10 @@ READY_CACHE_TIMEOUT = 30
|
||||
|
||||
|
||||
class BaseSpiceTransport(Transport):
|
||||
'''
|
||||
"""
|
||||
Provides access via SPICE to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
iconFile = 'spice.png'
|
||||
protocol = protocols.SPICE
|
||||
allowedProviders = oVirtProvider.offers
|
||||
@ -114,11 +114,10 @@ class BaseSpiceTransport(Transport):
|
||||
tab=gui.ADVANCED_TAB
|
||||
)
|
||||
|
||||
|
||||
def isAvailableFor(self, userService, ip):
|
||||
'''
|
||||
"""
|
||||
Checks if the transport is available for the requested destination ip
|
||||
'''
|
||||
"""
|
||||
ready = self.cache.get(ip)
|
||||
if ready is None:
|
||||
userServiceInstance = userService.getInstance()
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.util import OsDetector
|
||||
@ -45,10 +45,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SPICETransport(BaseSpiceTransport):
|
||||
'''
|
||||
"""
|
||||
Provides access via SPICE to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
typeName = _('SPICE')
|
||||
typeType = 'SPICETransport'
|
||||
typeDescription = _('SPICE Protocol. Direct connection.')
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.ui.UserInterface import gui
|
||||
@ -53,10 +53,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TSPICETransport(BaseSpiceTransport):
|
||||
'''
|
||||
"""
|
||||
Provides access via SPICE to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
typeName = _('SPICE')
|
||||
typeType = 'TSSPICETransport'
|
||||
typeDescription = _('SPICE Protocol. Tunneled connection.')
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
@ -54,11 +54,12 @@ logger = logging.getLogger(__name__)
|
||||
READY_CACHE_TIMEOUT = 30
|
||||
SSH_KEY_LENGTH = 1024
|
||||
|
||||
|
||||
class BaseX2GOTransport(Transport):
|
||||
'''
|
||||
"""
|
||||
Provides access via X2GO to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
iconFile = 'x2go.png'
|
||||
protocol = protocols.X2GO
|
||||
supportedOss = (OsDetector.Linux, OsDetector.Windows)
|
||||
@ -77,18 +78,23 @@ class BaseX2GOTransport(Transport):
|
||||
tab=gui.PARAMETERS_TAB
|
||||
)
|
||||
|
||||
desktopType = gui.ChoiceField(label=_('Desktop'), order=11, tooltip=_('Desktop session'),
|
||||
values=[
|
||||
{'id': 'XFCE', 'text': 'Xfce'},
|
||||
{'id': 'MATE', 'text': 'Mate'},
|
||||
{'id': 'LXDE', 'text': 'Lxde'},
|
||||
{'id': 'GNOME', 'text': 'Gnome (see docs)'},
|
||||
{'id': 'KDE', 'text': 'Kde (see docs)'},
|
||||
# {'id': 'UNITY', 'text': 'Unity (see docs)'},
|
||||
{'id': 'gnome-session-cinnamon', 'text': 'Cinnamon 1.4 (see docs)'},
|
||||
{'id': 'gnome-session-cinnamon2d', 'text': 'Cinnamon 2.2 (see docs)'},
|
||||
{'id': 'UDSVAPP', 'text': 'UDS vAPP'},
|
||||
], tab=gui.PARAMETERS_TAB)
|
||||
desktopType = gui.ChoiceField(
|
||||
label=_('Desktop'),
|
||||
order=11,
|
||||
tooltip=_('Desktop session'),
|
||||
values=[
|
||||
{'id': 'XFCE', 'text': 'Xfce'},
|
||||
{'id': 'MATE', 'text': 'Mate'},
|
||||
{'id': 'LXDE', 'text': 'Lxde'},
|
||||
{'id': 'GNOME', 'text': 'Gnome (see docs)'},
|
||||
{'id': 'KDE', 'text': 'Kde (see docs)'},
|
||||
# {'id': 'UNITY', 'text': 'Unity (see docs)'},
|
||||
{'id': 'gnome-session-cinnamon', 'text': 'Cinnamon 1.4 (see docs)'},
|
||||
{'id': 'gnome-session-cinnamon2d', 'text': 'Cinnamon 2.2 (see docs)'},
|
||||
{'id': 'UDSVAPP', 'text': 'UDS vAPP'},
|
||||
],
|
||||
tab=gui.PARAMETERS_TAB
|
||||
)
|
||||
|
||||
customCmd = gui.TextField(
|
||||
order=12,
|
||||
@ -151,20 +157,31 @@ class BaseX2GOTransport(Transport):
|
||||
# '8-png-%', '64-png', '256-png', '512-png', '4k-png'
|
||||
# '32k-png', '64k-png', '256k-png', '2m-png', '16m-png-%'
|
||||
# '16m-rgb-%', '16m-rle-%'
|
||||
pack = gui.TextField(label=_('Pack'), order=32, tooltip=_('Pack format. Change with care!'),
|
||||
pack = gui.TextField(
|
||||
label=_('Pack'),
|
||||
order=32,
|
||||
tooltip=_('Pack format. Change with care!'),
|
||||
defvalue='16m-jpeg',
|
||||
tab=gui.ADVANCED_TAB
|
||||
)
|
||||
|
||||
quality = gui.NumericField(label=_('Quality'), order=33, tooltip=_('Quality value used on some pack formats.'),
|
||||
length=1, defvalue='6', minValue=1, maxValue=9, required=True,
|
||||
tab=gui.ADVANCED_TAB)
|
||||
quality = gui.NumericField(
|
||||
label=_('Quality'),
|
||||
order=33,
|
||||
tooltip=_('Quality value used on some pack formats.'),
|
||||
length=1,
|
||||
defvalue='6',
|
||||
minValue=1,
|
||||
maxValue=9,
|
||||
required=True,
|
||||
tab=gui.ADVANCED_TAB
|
||||
)
|
||||
|
||||
def isAvailableFor(self, userService, ip):
|
||||
'''
|
||||
"""
|
||||
Checks if the transport is available for the requested destination ip
|
||||
Override this in yours transports
|
||||
'''
|
||||
"""
|
||||
logger.debug('Checking availability for {0}'.format(ip))
|
||||
ready = self.cache.get(ip)
|
||||
if ready is None:
|
||||
@ -195,7 +212,7 @@ class BaseX2GOTransport(Transport):
|
||||
return self.processUserPassword(service, user, password)
|
||||
|
||||
def genKeyPairForSsh(self):
|
||||
'''
|
||||
"""
|
||||
Generates a key pair for use with x2go
|
||||
The private part is used by client
|
||||
the public part must be "appended" to authorized_keys if it is not already added.
|
||||
@ -207,7 +224,7 @@ class BaseX2GOTransport(Transport):
|
||||
C:\Program Files (x86)\\x2goclient>x2goclient.exe --session-conf=c:/temp/sessions --session=UDS/test-session --close-disconnect --hide --no-menu
|
||||
Linux (tested):
|
||||
HOME=[temporal folder, where we create a .x2goclient folder and a sessions inside] pyhoca-cli -P UDS/test-session
|
||||
'''
|
||||
"""
|
||||
key = paramiko.RSAKey.generate(SSH_KEY_LENGTH)
|
||||
privFile = six.StringIO()
|
||||
key.write_private_key(privFile)
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.ui.UserInterface import gui
|
||||
@ -51,10 +51,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TX2GOTransport(BaseX2GOTransport):
|
||||
'''
|
||||
"""
|
||||
Provides access via X2GO to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
typeName = _('X2Go')
|
||||
typeType = 'TX2GOTransport'
|
||||
typeDescription = _('X2Go access (Experimental). Tunneled connection.')
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.managers.UserPrefsManager import CommonPrefs
|
||||
@ -46,10 +46,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class X2GOTransport(BaseX2GOTransport):
|
||||
'''
|
||||
"""
|
||||
Provides access via X2GO to service.
|
||||
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
|
||||
'''
|
||||
"""
|
||||
typeName = _('X2Go')
|
||||
typeType = 'X2GOTransport'
|
||||
typeDescription = _('X2Go access (Experimental). Direct connection.')
|
||||
|
@ -22,7 +22,7 @@ def updateAuthorizedKeys(user, pubKey):
|
||||
|
||||
# Create .ssh on user home
|
||||
home = os.path.expanduser('~{}'.format(user))
|
||||
uid = pwd.getpwnam(user)
|
||||
|
||||
if not os.path.exists(home): # User not found, nothing done
|
||||
logError('Home folder for user {} not found'.format(user))
|
||||
return
|
||||
@ -60,4 +60,5 @@ def updateAuthorizedKeys(user, pubKey):
|
||||
|
||||
# Done
|
||||
|
||||
|
||||
updateAuthorizedKeys(USER, KEY)
|
||||
|
@ -67,4 +67,5 @@ def __init__():
|
||||
for l2 in clsSubCls:
|
||||
transports.factory().insert(l2)
|
||||
|
||||
|
||||
__init__()
|
||||
|
@ -25,9 +25,9 @@
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.urls import reverse
|
||||
|
Loading…
Reference in New Issue
Block a user