本文整理汇总了Python中uds.core.managers.UserServiceManager.UserServiceManager类的典型用法代码示例。如果您正苦于以下问题:Python UserServiceManager类的具体用法?Python UserServiceManager怎么用?Python UserServiceManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserServiceManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: growL1Cache
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')
开发者ID:aiminickwong,项目名称:openuds,代码行数:32,代码来源:ServiceCacheUpdater.py
示例2: cancel
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)
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:7,代码来源:UserService.py
示例3: process
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
开发者ID:dkmstr,项目名称:openuds,代码行数:59,代码来源:LinuxOsManager.py
示例4: process
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)
开发者ID:aiminickwong,项目名称:openuds,代码行数:58,代码来源:WindowsOsManager.py
示例5: run
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))
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:9,代码来源:UserServiceCleaner.py
示例6: moveToLevel
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)
开发者ID:glyptodon,项目名称:openuds,代码行数:9,代码来源:UserService.py
示例7: getService
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
开发者ID:aiminickwong,项目名称:openuds,代码行数:56,代码来源:service.py
示例8: process
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
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:52,代码来源:LinuxOsManager.py
示例9: growL2Cache
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))
开发者ID:aiminickwong,项目名称:openuds,代码行数:13,代码来源:ServiceCacheUpdater.py
示例10: setInUse
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)
开发者ID:aiminickwong,项目名称:openuds,代码行数:15,代码来源:UserService.py
示例11: reduceL2Cache
def reduceL2Cache(self, sp, cacheL1, cacheL2, assigned):
logger.debug("Reducing L2 cache erasing a service in cache for {0}".format(sp))
if cacheL2 > 0:
cacheItems = sp.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).order_by('creation_date')
# TODO: Look first for non finished cache items and cancel them
cache = cacheItems[0]
cache.removeOrCancel()
开发者ID:aiminickwong,项目名称:openuds,代码行数:7,代码来源:ServiceCacheUpdater.py
示例12: reduceL1Cache
def reduceL1Cache(self, sp, cacheL1, cacheL2, assigned):
logger.debug("Reducing L1 cache erasing a service in cache for {0}".format(sp))
# We will try to destroy the newest cacheL1 element that is USABLE if the deployer can't cancel a new service creation
cacheItems = sp.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L1_CACHE)).order_by('-creation_date')
if len(cacheItems) == 0:
logger.debug('There is more services than configured, but could not reduce cache cause its already empty')
return
if cacheL2 < sp.cache_l2_srvs:
valid = None
for n in cacheItems:
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.L2_CACHE)
return
cache = cacheItems[0]
cache.removeOrCancel()
开发者ID:aiminickwong,项目名称:openuds,代码行数:25,代码来源:ServiceCacheUpdater.py
示例13: isReady
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)
开发者ID:glyptodon,项目名称:openuds,代码行数:7,代码来源:UserService.py
示例14: setInUse
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)
开发者ID:dkmstr,项目名称:openuds,代码行数:23,代码来源:UserService.py
示例15: serviceList
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)
开发者ID:aiminickwong,项目名称:openuds,代码行数:50,代码来源:connection.py
示例16: index
#.........这里部分代码省略.........
'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,
})
开发者ID:glyptodon,项目名称:openuds,代码行数:66,代码来源:index.py
示例17: index
def index(request):
'''
Renders the main page.
:param request: http request
'''
# Session data
os = request.os
# 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(request.user.getGroups())
availServices = DeployedService.getDeployedServicesForGroups(groups)
availUserServices = UserService.getUserAssignedServices(request.user)
# Information for administrators
nets = ''
validTrans = ''
logger.debug('OS: {0}'.format(os['OS']))
if request.user.isStaff():
nets = ','.join([n.name for n in Network.networksFor(request.ip)])
tt = []
for t in Transport.objects.all():
if t.validForIp(request.ip):
tt.append(t.name)
validTrans = ','.join(tt)
# Extract required data to show to user
services = []
# Select assigned user services
for svr in availUserServices:
trans = []
for t in svr.transports.all().order_by('priority'):
typeTrans = t.getType()
if t.validForIp(request.ip) and typeTrans.supportsOs(os['OS']):
if typeTrans.ownLink is True:
link = reverse('TransportOwnLink', args=('A' + svr.uuid, t.uuid))
else:
link = html.udsAccessLink(request, 'A' + svr.uuid, t.uuid)
trans.append(
{
'id': t.uuid,
'name': t.name,
'link': link
}
)
if svr.deployed_service.image is not None:
imageId = svr.deployed_service.image.uuid
else:
imageId = 'x' # Invalid
services.append({
'id': 'A' + svr.uuid,
'name': svr['name'],
'transports': trans,
'imageId': imageId,
'show_transports': svr.deployed_service.show_transports,
'maintenance': svr.deployed_service.service.provider.maintenance_mode,
'in_use': svr.in_use,
})
logger.debug(services)
# Now generic user service
for svr in availServices:
# Generate ticket
trans = []
for t in svr.transports.all().order_by('priority'):
typeTrans = t.getType()
if t.validForIp(request.ip) and typeTrans.supportsOs(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
services.append({
'id': 'F' + svr.uuid,
'name': svr.name,
'transports': trans,
'imageId': imageId,
'show_transports': svr.show_transports,
#.........这里部分代码省略.........
开发者ID:aiminickwong,项目名称:openuds,代码行数:101,代码来源:index.py
示例18: servicesPoolsNeedingCacheUpdate
def servicesPoolsNeedingCacheUpdate(self):
# State filter for cached and inAssigned objects
# First we get all deployed services that could need cache generation
DeployedService.objects.update()
# We start filtering out the deployed services that do not need caching at all.
whichNeedsCaching = DeployedService.objects.filter(Q(initial_srvs__gte=0) | Q(cache_l1_srvs__gte=0)).filter(max_srvs__gt=0, state=State.ACTIVE,
service__provider__maintenance_mode=False)[:]
# We will get the one that proportionally needs more cache
servicesPools = []
for sp in whichNeedsCaching:
sp.userServices.update() # Cleans cached queries
# If this deployedService don't have a publication active and needs it, ignore it
if sp.activePublication() is None and sp.service.getInstance().publicationType is not None:
logger.debug('Needs publication but do not have one, cache test ignored')
continue
# If it has any running publication, do not generate cache anymore
if sp.publications.filter(state=State.PREPARING).count() > 0:
logger.debug('Stopped cache generation for deployed service with publication running: {0}'.format(sp))
continue
if sp.isRestrained():
ServiceCacheUpdater.__notifyRestrain(sp)
continue
# Get data related to actual state of cache
inCacheL1 = sp.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L1_CACHE)).count()
inCacheL2 = sp.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).count()
inAssigned = sp.assignedUserServices().filter(UserServiceManager.getStateFilter()).count()
# if we bypasses max cache, we will reduce it in first place. This is so because this will free resources on service provider
logger.debug("Examining {0} with {1} in cache L1 and {2} in cache L2, {3} inAssigned".format(
sp, inCacheL1, inCacheL2, inAssigned))
totalL1Assigned = inCacheL1 + inAssigned
# We have more than we want
if totalL1Assigned > sp.max_srvs:
logger.debug('We have more services than max configured')
servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))
continue
# We have more in L1 cache than needed
if totalL1Assigned > sp.initial_srvs and inCacheL1 > sp.cache_l1_srvs:
logger.debug('We have more services in cache L1 than configured')
servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))
continue
# If we have more in L2 cache than needed, decrease L2 cache, but int this case, we continue checking cause L2 cache removal
# has less priority than l1 creations or removals, but higher. In this case, we will simply take last l2 oversized found and reduce it
if inCacheL2 > sp.cache_l2_srvs:
logger.debug('We have more services in L2 cache than configured, decreasing it')
servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))
continue
# If this service don't allows more starting user services, continue
if UserServiceManager.manager().canInitiateServiceFromDeployedService(sp) is False:
logger.debug('This provider has the max allowed starting services running: {0}'.format(sp))
continue
# If wee need to grow l2 cache, annotate it
# Whe check this before checking the total, because the l2 cache is independent of max services or l1 cache.
# It reflects a value that must be keeped in cache for futre fast use.
if inCacheL2 < sp.cache_l2_srvs:
logger.debug('Needs to grow L2 cache for {}'.format(sp))
servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))
continue
# We skip it if already at max
if totalL1Assigned == sp.max_srvs:
continue
if totalL1Assigned < sp.initial_srvs or inCacheL1 < sp.cache_l1_srvs:
logger.debug('Needs to grow L1 cache for {}'.format(sp))
servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))
# We also return calculated values so we can reuse then
return servicesPools
开发者ID:aiminickwong,项目名称:openuds,代码行数:74,代码来源:ServiceCacheUpdater.py
示例19: getServicesData
def getServicesData(request):
# Session data
os = request.os
# 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(request.user.getGroups())
availServices = DeployedService.getDeployedServicesForGroups(groups)
availMetas = MetaPool.getForGroups(groups)
# Information for administrators
nets = ''
validTrans = ''
logger.debug('OS: {0}'.format(os['OS']))
if request.user.isStaff():
nets = ','.join([n.name for n in Network.networksFor(request.ip)])
tt = []
for t in Transport.objects.all():
if t.validForIp(request.ip):
tt.append(t.name)
validTrans = ','.join(tt)
logger.debug('Checking meta pools: %s', availMetas)
services = []
# Add meta pools data first
for meta in availMetas:
# Check that we have access to at least one transport on some of its children
hasUsablePools = False
in_use = False
for pool in meta.pools.all():
# if pool.isInMaintenance():
# continue
for t in pool.transports.all():
typeTrans = t.getType()
if t.getType() and t.validForIp(request.ip) and typeTrans.supportsOs(os['OS']) and t.validForOs(os['OS']):
hasUsablePools = True
break
if not in_use:
assignedUserService = UserServiceManager.manager().getExistingAssignationForUser(pool, request.user)
if assignedUserService:
in_use = assignedUserService.in_use
# Stop when 1 usable pool is found
if hasUsablePools:
break
# If no usable pools, this is not visible
if hasUsablePools:
group = meta.servicesPoolGroup.as_dict if meta.servicesPoolGroup else ServicesPoolGroup.default().as_dict
services.append({
'id': 'M' + meta.uuid,
'name': meta.name,
'visual_name': meta.visual_name,
'description': meta.comments,
'group': group,
'transports': [{
'id': 'meta',
'name': 'meta',
'link': html.udsMetaLink(request, 'M' + meta.uuid),
'priority': 0
}],
'imageId': meta.image and meta.image.uuid or 'x',
'show_transports': False,
'allow_users_remove': False,
'allow_users_reset': False,
'maintenance': meta.isInMaintenance(),
'not_accesible': not meta.isAccessAllowed(),
'in_use': in_use,
'to_be_replaced': None,
'to_be_replaced_text': '',
})
# Now generic user service
for svr in availServices:
# Skip pools that are part of meta pools
if svr.is_meta:
continue
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,
'priority': t.priority
}
)
#.........这里部分代码省略.........
开发者ID:dkmstr,项目名称:openuds,代码行数:101,代码来源:services.py
示例20: process
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 = Sta
|
请发表评论