当前位置: 首页>>代码示例>>Python>>正文


Python UserServiceManager.UserServiceManager类代码示例

本文整理汇总了Python中uds.core.managers.UserServiceManager.UserServiceManager的典型用法代码示例。如果您正苦于以下问题:Python UserServiceManager类的具体用法?Python UserServiceManager怎么用?Python UserServiceManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserServiceManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的uds.core.managers.UserServiceManager.UserServiceManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。