forked from shaba/openuds
* Activated worker so we can automatically remove certain services (those assigned but not in use).
To do this, the os Manager must inform if it can "process" unused machines (assigned but not in use). If the os manager wants this, there is a background worker, that works every 10 minutes by default,that will pass every service in that state since more than the last execution of the background worker. With this, for example, linux and windows os managers, will set this if we mark the action on logout as "remove", and every machine assigned and not in use, for a os manager marked as "remove", will be removed automatically. Has to test this extensively!!! :-)
This commit is contained in:
parent
510c69e6fc
commit
3d6d478aed
@ -40,7 +40,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class AssignedAndUnused(object): # When derived from Job, it will be auto-registered
|
||||
class AssignedAndUnused(Job):
|
||||
frecuency = GlobalConfig.CHECK_UNUSED_TIME.getInt()
|
||||
friendly_name = 'Unused services checker'
|
||||
|
||||
@ -52,7 +52,7 @@ class AssignedAndUnused(object): # When derived from Job, it will be auto-regist
|
||||
osm = ds.osmanager.getInstance()
|
||||
if osm.processUnusedMachines is True:
|
||||
logger.debug('Processing unused services for {0}'.format(osm))
|
||||
since_state = getSqlDatetime() - timedelta( seconds = GlobalConfig.CHECK_UNUSED_TIME.getInt() / 2 )
|
||||
since_state = getSqlDatetime() - timedelta( seconds = GlobalConfig.CHECK_UNUSED_TIME.getInt() )
|
||||
for us in ds.assignedUserServices().select_for_update().filter(in_use=False,since_state__lt=since_state):
|
||||
logger.debug('Found unused assigned service {0}'.format(us))
|
||||
osm.processUnused(us)
|
@ -47,11 +47,16 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
typeDescription = _('Os Manager to control linux virtual machines (basically renames machine and notify state)')
|
||||
iconFile = 'losmanager.png'
|
||||
|
||||
|
||||
|
||||
onLogout = gui.ChoiceField( label = _('On Logout'), order = 10, rdonly = False, tooltip = _('What to do when user logout from service'),
|
||||
values = [ {'id' : 'keep', 'text' : _('Keep service assigned') },
|
||||
{'id' : 'remove', 'text' : _('Remove service') }
|
||||
], defvalue = 'keep' )
|
||||
|
||||
def __setProcessUnusedMachines(self):
|
||||
self.processUnusedMachines = self._onLogout == 'remove'
|
||||
|
||||
def __init__(self,environment, values):
|
||||
super(LinuxOsManager, self).__init__(environment, values)
|
||||
if values is not None:
|
||||
@ -59,6 +64,7 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
else:
|
||||
self._onLogout = ''
|
||||
|
||||
self.__setProcessUnusedMachines()
|
||||
|
||||
def release(self, service):
|
||||
pass
|
||||
@ -144,6 +150,15 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
logger.debug('Returning {0}'.format(ret))
|
||||
return ret
|
||||
|
||||
def processUnused(self, userService):
|
||||
'''
|
||||
This will be invoked for every assigned and unused user service that has been in this state at least 1/2 of Globalconfig.CHECK_UNUSED_TIME
|
||||
This function can update userService values. Normal operation will be remove machines if this state is not valid
|
||||
'''
|
||||
if self._onLogout == 'remove':
|
||||
userService.remove()
|
||||
|
||||
|
||||
def checkState(self,service):
|
||||
logger.debug('Checking state for service {0}'.format(service))
|
||||
return State.RUNNING
|
||||
@ -158,6 +173,7 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
data = s.split('\t')
|
||||
if data[0] == 'v1':
|
||||
self._onLogout = data[1]
|
||||
self.__setProcessUnusedMachines()
|
||||
|
||||
def valuesDict(self):
|
||||
return { 'onLogout' : self._onLogout }
|
||||
|
@ -55,6 +55,9 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
raise osmanagers.OSManager.ValidationException(_('Length must be betwen 1 and six'))
|
||||
return len
|
||||
|
||||
def __setProcessUnusedMachines(self):
|
||||
self.processUnusedMachines = self._onLogout == 'remove'
|
||||
|
||||
def __init__(self,environment, values):
|
||||
super(WindowsOsManager, self).__init__(environment, values)
|
||||
if values is not None:
|
||||
@ -62,6 +65,8 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
else:
|
||||
self._onLogout = ''
|
||||
|
||||
self.__setProcessUnusedMachines()
|
||||
|
||||
def release(self, service):
|
||||
pass
|
||||
|
||||
@ -161,6 +166,14 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
logger.debug('Returning {0}'.format(ret))
|
||||
return scrambleMsg(ret)
|
||||
|
||||
def processUnused(self, userService):
|
||||
'''
|
||||
This will be invoked for every assigned and unused user service that has been in this state at least 1/2 of Globalconfig.CHECK_UNUSED_TIME
|
||||
This function can update userService values. Normal operation will be remove machines if this state is not valid
|
||||
'''
|
||||
if self._onLogout == 'remove':
|
||||
userService.remove()
|
||||
|
||||
def checkState(self,service):
|
||||
logger.debug('Checking state for service {0}'.format(service))
|
||||
return State.RUNNING
|
||||
@ -176,6 +189,8 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
if data[0] == 'v1':
|
||||
self._onLogout = data[1]
|
||||
|
||||
self.__setProcessUnusedMachines()
|
||||
|
||||
def valuesDict(self):
|
||||
return { 'onLogout' : self._onLogout }
|
||||
|
Loading…
Reference in New Issue
Block a user