本文整理汇总了Python中uds.core.managers.UserServiceManager.UserServiceManager.manager方法的典型用法代码示例。如果您正苦于以下问题:Python UserServiceManager.manager方法的具体用法?Python UserServiceManager.manager怎么用?Python UserServiceManager.manager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uds.core.managers.UserServiceManager.UserServiceManager
的用法示例。
在下文中一共展示了UserServiceManager.manager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: growL1Cache
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
def growL1Cache(self, sp, cacheL1, cacheL2, assigned):
'''
This method tries to enlarge L1 cache.
If for some reason the number of deployed services (Counting all, ACTIVE
and PREPARING, assigned, L1 and L2) is over max allowed service deployments,
this method will not grow the L1 cache
'''
logger.debug("Growing L1 cache creating a new service for {0}".format(sp))
# First, we try to assign from L2 cache
if cacheL2 > 0:
valid = None
with transaction.atomic():
for n in sp.cachedUserServices().select_for_update().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).order_by('creation_date'):
if n.needsOsManager():
if State.isUsable(n.state) is False or State.isUsable(n.os_state):
valid = n
break
else:
valid = n
break
if valid is not None:
valid.moveToLevel(services.UserDeployment.L1_CACHE)
return
try:
UserServiceManager.manager().createCacheFor(sp.activePublication(), services.UserDeployment.L1_CACHE)
except MaxServicesReachedException as e:
log.doLog(sp, log.ERROR, 'Max number of services reached for this service', log.INTERNAL)
logger.error(str(e))
except:
logger.exception('Exception')
示例2: cancel
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
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)
示例3: process
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
def process(self, userService, msg, data, options=None):
"""
We understand this messages:
* msg = info, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class), old method
* msg = information, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class), new method
* msg = logon, data = Username, Informs that the username has logged in inside the machine
* msg = logoff, data = Username, Informs that the username has logged out of the machine
* msg = ready, data = None, Informs machine ready to be used
"""
logger.info("Invoked LinuxOsManager for {0} with params: {1},{2}".format(userService, msg, data))
# We get from storage the name for this userService. If no name, we try to assign a new one
ret = "ok"
notifyReady = False
doRemove = False
state = userService.os_state
if msg in ('ready', 'ip'):
if not isinstance(data, dict): # Old actors, previous to 2.5, convert it information..
data = {
'ips': [v.split('=') for v in data.split(',')],
'hostname': userService.friendly_name
}
# Old "info" state, will be removed in a near future
if msg == "info":
ret = self.infoVal(userService)
state = State.PREPARING
elif msg == "information":
ret = self.infoValue(userService)
state = State.PREPARING
elif msg == "log":
self.doLog(userService, data, log.ACTOR)
elif msg == "login":
self.loggedIn(userService, data)
ip, hostname = userService.getConnectionSource()
deadLine = userService.deployed_service.getDeadline()
ret = "{0}\t{1}\t{2}".format(ip, hostname, 0 if deadLine is None else deadLine)
elif msg == "logout":
self.loggedOut(userService, data)
doRemove = self.isRemovableOnLogout(userService)
elif msg == "ip":
# This ocurss on main loop inside machine, so userService is usable
state = State.USABLE
self.notifyIp(userService.unique_id, userService, data)
elif msg == "ready":
self.toReady(userService)
state = State.USABLE
notifyReady = True
self.notifyIp(userService.unique_id, userService, data)
userService.setOsState(state)
# If notifyReady is not true, save state, let UserServiceManager do it for us else
if doRemove is True:
userService.release()
else:
if notifyReady:
UserServiceManager.manager().notifyReadyFromOsManager(userService, '')
logger.debug('Returning {0}'.format(ret))
return ret
示例4: process
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
def process(self, service, msg, data, options):
'''
We understand this messages:
* msg = info, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class) (old method)
* msg = information, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class) (new method)
* msg = logon, data = Username, Informs that the username has logged in inside the machine
* msg = logoff, data = Username, Informs that the username has logged out of the machine
* msg = ready, data = None, Informs machine ready to be used
'''
logger.info("Invoked WindowsOsManager for {0} with params: {1},{2}".format(service, msg, data))
# We get from storage the name for this service. If no name, we try to assign a new one
ret = "ok"
notifyReady = False
doRemove = False
state = service.os_state
if msg == "info":
ret = self.infoVal(service)
state = State.PREPARING
elif msg == "information":
ret = self.infoValue(service)
state = State.PREPARING
elif msg == "log":
self.doLog(service, data, log.ACTOR)
elif msg == "logon" or msg == 'login':
if '\\' not in data:
self.loggedIn(service, data, False)
service.setInUse(True)
# We get the service logged hostname & ip and returns this
ip, hostname = service.getConnectionSource()
ret = "{0}\t{1}".format(ip, hostname)
elif msg == "logoff" or msg == 'logout':
self.loggedOut(service, data, False)
if self._onLogout == 'remove':
doRemove = True
elif msg == "ip":
# This ocurss on main loop inside machine, so service is usable
state = State.USABLE
self.notifyIp(service.unique_id, service, data)
elif msg == "ready":
state = State.USABLE
notifyReady = True
self.notifyIp(service.unique_id, service, data)
service.setOsState(state)
# If notifyReady is not true, save state, let UserServiceManager do it for us else
if doRemove is True:
service.remove()
else:
if notifyReady is False:
service.save()
else:
logger.debug('Notifying ready')
UserServiceManager.manager().notifyReadyFromOsManager(service, '')
logger.debug('Returning {} to {} message'.format(ret, msg))
if options is not None and options.get('scramble', True) is False:
return ret
return scrambleMsg(ret)
示例5: run
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
def run(self):
removeFrom = getSqlDatetime() - timedelta(seconds=10) # We keep at least 10 seconds the machine before removing it, so we avoid connections errors
removables = UserService.objects.filter(state=State.REMOVABLE, state_date__lt=removeFrom,
deployed_service__service__provider__maintenance_mode=False)[0:UserServiceRemover.removeAtOnce]
for us in removables:
try:
UserServiceManager.manager().remove(us)
except Exception:
logger.exception('Exception invoking remove user service {}'.format(us))
示例6: moveToLevel
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
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)
示例7: getService
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
def getService(request, idService, idTransport, doTest=True):
kind, idService = idService[0], idService[1:]
logger.debug('Kind of service: {0}, idService: {1}'.format(kind, idService))
if kind == 'A': # This is an assigned service
logger.debug('Getting A service {}'.format(idService))
ads = UserService.objects.get(uuid=idService)
ads.deployed_service.validateUser(request.user)
else:
ds = DeployedService.objects.get(uuid=idService)
# We first do a sanity check for this, if the user has access to this service
# If it fails, will raise an exception
ds.validateUser(request.user)
# Now we have to locate an instance of the service, so we can assign it to user.
ads = UserServiceManager.manager().getAssignationForUser(ds, request.user)
if ads.isInMaintenance() is True:
raise ServiceInMaintenanceMode()
logger.debug('Found service: {0}'.format(ads))
trans = Transport.objects.get(uuid=idTransport)
# Ensures that the transport is allowed for this service
if trans not in ads.deployed_service.transports.all():
raise InvalidServiceException()
# If transport is not available for the request IP...
if trans.validForIp(request.ip) is False:
raise InvalidServiceException()
if doTest is False:
return (None, ads, None, trans, None)
# Test if the service is ready
if ads.isReady():
log.doLog(ads, log.INFO, "User {0} from {1} has initiated access".format(request.user.name, request.ip), log.WEB)
# If ready, show transport for this service, if also ready ofc
iads = ads.getInstance()
ip = iads.getIp()
events.addEvent(ads.deployed_service, events.ET_ACCESS, username=request.user.name, srcip=request.ip, dstip=ip, uniqueid=ads.unique_id)
if ip is not None:
itrans = trans.getInstance()
if itrans.isAvailableFor(ip):
ads.setConnectionSource(request.ip, 'unknown')
log.doLog(ads, log.INFO, "User service ready", log.WEB)
UserServiceManager.manager().notifyPreconnect(ads, itrans.processedUser(ads, request.user), itrans.protocol)
return (ip, ads, iads, trans, itrans)
else:
log.doLog(ads, log.WARN, "User service is not accessible (ip {0})".format(ip), log.TRANSPORT)
logger.debug('Transport is not ready for user service {0}'.format(ads))
else:
logger.debug('Ip not available from user service {0}'.format(ads))
else:
log.doLog(ads, log.WARN, "User {0} from {1} tried to access, but machine was not ready".format(request.user.name, request.ip), log.WEB)
return None
示例8: process
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
def process(self, service, msg, data, options):
'''
We understand this messages:
* msg = info, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class), old method
* msg = information, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class), new method
* msg = logon, data = Username, Informs that the username has logged in inside the machine
* msg = logoff, data = Username, Informs that the username has logged out of the machine
* msg = ready, data = None, Informs machine ready to be used
'''
logger.info("Invoked LinuxOsManager for {0} with params: {1},{2}".format(service, msg, data))
# We get from storage the name for this service. If no name, we try to assign a new one
ret = "ok"
notifyReady = False
doRemove = False
state = service.os_state
# Old "info" state, will be removed in a near future
if msg == "info":
ret = self.infoVal(service)
state = State.PREPARING
elif msg == "information":
ret = self.infoValue(service)
state = State.PREPARING
elif msg == "log":
self.doLog(service, data, log.ACTOR)
elif msg == "login":
self.loggedIn(service, data, False)
elif msg == "logout":
self.loggedOut(service, data, False)
if self._onLogout == 'remove':
doRemove = True
elif msg == "ip":
# This ocurss on main loop inside machine, so service is usable
state = State.USABLE
self.notifyIp(service.unique_id, service, data)
elif msg == "ready":
state = State.USABLE
notifyReady = True
self.notifyIp(service.unique_id, service, data)
service.setOsState(state)
# If notifyReady is not true, save state, let UserServiceManager do it for us else
if doRemove is True:
service.remove()
else:
if notifyReady is False:
service.save()
else:
UserServiceManager.manager().notifyReadyFromOsManager(service, '')
logger.debug('Returning {0}'.format(ret))
return ret
示例9: growL2Cache
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
def growL2Cache(self, sp, cacheL1, cacheL2, assigned):
'''
Tries to grow L2 cache of service.
If for some reason the number of deployed services (Counting all, ACTIVE
and PREPARING, assigned, L1 and L2) is over max allowed service deployments,
this method will not grow the L1 cache
'''
logger.debug("Growing L2 cache creating a new service for {0}".format(sp))
try:
UserServiceManager.manager().createCacheFor(sp.activePublication(), services.UserDeployment.L2_CACHE)
except MaxServicesReachedException as e:
logger.error(str(e))
示例10: setInUse
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
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()
if state is False: # Service released, check y we should mark it for removal
# If our publication is not current, mark this for removal
UserServiceManager.manager().checkForRemoval(self)
示例11: isReady
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
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)
示例12: serviceList
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
def serviceList(self):
# We look for services for this authenticator groups. User is logged in in just 1 authenticator, so his groups must coincide with those assigned to ds
groups = list(self._user.getGroups())
availServices = DeployedService.getDeployedServicesForGroups(groups)
availUserServices = UserService.getUserAssignedServices(self._user)
# Extract required data to show to user
services = []
# Select assigned user services
for svr in availUserServices:
# Skip maintenance services...
trans = []
for t in svr.transports.all().order_by('priority'):
typeTrans = t.getType()
if t.validForIp(self._request.ip) and t.getType().providesConnetionInfo():
trans.append({'id': t.uuid, 'name': t.name, 'needsJava': t.getType().needsJava})
services.append({'id': 'A' + svr.uuid,
'name': svr['name'],
'transports': trans,
'maintenance': svr.deployed_service.service.provider.maintenance_mode,
'in_use': svr.in_use})
logger.debug(services)
# Now generic user service
for svr in availServices:
trans = []
for t in svr.transports.all().order_by('priority'):
if t.validForIp(self._request.ip) and t.getType().providesConnetionInfo():
typeTrans = t.getType()
trans.append({'id': t.uuid, 'name': t.name, 'needsJava': typeTrans.needsJava})
# Locate if user service has any already assigned user service for this
ads = UserServiceManager.manager().getExistingAssignationForUser(svr, self._user)
if ads is None:
in_use = False
else:
in_use = ads.in_use
services.append({'id': 'F' + svr.uuid,
'name': svr.name,
'transports': trans,
'maintenance': svr.service.provider.maintenance_mode,
'in_use': in_use})
logger.debug('Services: {0}'.format(services))
services = sorted(services, key=lambda s: s['name'].upper())
return Connection.result(result=services)
示例13: setInUse
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
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()
self.save(update_fields=['in_use', 'in_use_date'])
# Start/stop accounting
if state is True:
self.startUsageAccounting()
else:
self.stopUsageAccounting()
if state is False: # Service released, check y we should mark it for removal
# If our publication is not current, mark this for removal
UserServiceManager.manager().checkForRemoval(self)
示例14: process
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
def process(self, userService, msg, data, options=None):
"""
We understand this messages:
* msg = info, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class) (old method)
* msg = information, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class) (new method)
* msg = logon, data = Username, Informs that the username has logged in inside the machine
* msg = logoff, data = Username, Informs that the username has logged out of the machine
* msg = ready, data = None, Informs machine ready to be used
"""
logger.info("Invoked WindowsOsManager for {0} with params: {1},{2}".format(userService, msg, data))
if msg in ('ready', 'ip'):
if not isinstance(data, dict): # Old actors, previous to 2.5, convert it information..
data = {
'ips': [v.split('=') for v in data.split(',')],
'hostname': userService.friendly_name
}
# We get from storage the name for this userService. If no name, we try to assign a new one
ret = "ok"
notifyReady = False
doRemove = False
state = userService.os_state
if msg == "info":
ret = self.infoVal(userService)
state = State.PREPARING
elif msg == "information":
ret = self.infoValue(userService)
state = State.PREPARING
elif msg == "log":
self.doLog(userService, data, log.ACTOR)
elif msg == "logon" or msg == 'login':
if '\\' not in data:
self.loggedIn(userService, data, False)
userService.setInUse(True)
# We get the userService logged hostname & ip and returns this
ip, hostname = userService.getConnectionSource()
deadLine = userService.deployed_service.getDeadline()
if userService.getProperty('actor_version', '0.0.0') >= '2.0.0':
ret = "{0}\t{1}\t{2}".format(ip, hostname, 0 if deadLine is None else deadLine)
else:
ret = "{0}\t{1}".format(ip, hostname)
elif msg == "logoff" or msg == 'logout':
self.loggedOut(userService, data, False)
if userService.in_use == False and self._onLogout == 'remove':
doRemove = True
elif msg == "ip":
# This ocurss on main loop inside machine, so userService is usable
state = State.USABLE
self.notifyIp(userService.unique_id, userService, data)
elif msg == "ready":
self.toReady(userService)
state = State.USABLE
notifyReady = True
self.notifyIp(userService.unique_id, userService, data)
self.readyReceived(userService, data)
userService.setOsState(state)
# If notifyReady is not true, save state, let UserServiceManager do it for us else
if doRemove is True:
userService.release()
else:
if notifyReady is False:
userService.save()
else:
logger.debug('Notifying ready')
UserServiceManager.manager().notifyReadyFromOsManager(userService, '')
logger.debug('Returning {} to {} message'.format(ret, msg))
if options is not None and options.get('scramble', True) is False:
return ret
return scrambleMsg(ret)
示例15: index
# 需要导入模块: from uds.core.managers.UserServiceManager import UserServiceManager [as 别名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import manager [as 别名]
#.........这里部分代码省略.........
'not_accesible': not servicePool.isAccessAllowed(),
'in_use': svr.in_use,
'to_be_replaced': False, # Manually assigned will not be autoremoved never
'comments': servicePool.comments,
})
logger.debug(services)
# Now generic user service
for svr in availServices:
trans = []
for t in svr.transports.all().order_by('priority'):
typeTrans = t.getType()
if typeTrans is None: # This may happen if we "remove" a transport type but we have a transport of that kind on DB
continue
if t.validForIp(request.ip) and typeTrans.supportsOs(os['OS']) and t.validForOs(os['OS']):
if typeTrans.ownLink is True:
link = reverse('TransportOwnLink', args=('F' + svr.uuid, t.uuid))
else:
link = html.udsAccessLink(request, 'F' + svr.uuid, t.uuid)
trans.append(
{
'id': t.uuid,
'name': t.name,
'link': link
}
)
if svr.image is not None:
imageId = svr.image.uuid
else:
imageId = 'x'
# Locate if user service has any already assigned user service for this
ads = UserServiceManager.manager().getExistingAssignationForUser(svr, request.user)
if ads is None:
in_use = False
else:
in_use = ads.in_use
group = svr.servicesPoolGroup.as_dict if svr.servicesPoolGroup is not None else ServicesPoolGroup.default().as_dict
tbr = svr.toBeReplaced()
if tbr is not None:
tbr = formats.date_format(tbr, "SHORT_DATETIME_FORMAT")
tbrt = ugettext('This service is about to be replaced by a new version. Please, close the session before {} and save all your work to avoid loosing it.').format(tbr)
else:
tbrt = ''
services.append({
'id': 'F' + svr.uuid,
'name': svr.name,
'visual_name': svr.visual_name,
'description': svr.comments,
'group': group,
'transports': trans,
'imageId': imageId,
'show_transports': svr.show_transports,
'allow_users_remove': svr.allow_users_remove,
'maintenance': svr.isInMaintenance(),
'not_accesible': not svr.isAccessAllowed(),
'in_use': in_use,
'to_be_replaced': tbr,
'to_be_replaced_text': tbrt,
'comments': svr.comments,
})