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


Python State.State类代码示例

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


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

示例1: checkOsManagerRelated

    def checkOsManagerRelated(self):
        osManager = self.userServiceInstance.osmanager()

        state = State.USABLE

        # and make this usable if os manager says that it is usable, else it pass to configuring state
        # This is an "early check" for os manager, so if we do not have os manager, or os manager
        # already notifies "ready" for this, we
        if osManager is not None and State.isPreparing(self.userService.os_state):
            logger.debug('Has valid osmanager for {}'.format(self.userService.friendly_name))

            stateOs = osManager.checkState(self.userService)
        else:
            stateOs = State.FINISHED

        logger.debug('State {}, StateOS {} for {}'.format(State.toString(state), State.toString(stateOs), self.userService.friendly_name))
        if stateOs == State.RUNNING:
            self.userService.setOsState(State.PREPARING)
        else:
            # If state is finish, we need to notify the userService again that os has finished
            # This will return a new task state, and that one will be the one taken into account
            self.userService.setOsState(State.USABLE)
            rs = self.userServiceInstance.notifyReadyFromOsManager('')
            if rs != State.FINISHED:
                self.checkLater()
                state = self.userService.state  # No not alter current state if after notifying os manager the user service keeps working
            else:
                self.logIp()

        return state
开发者ID:dkmstr,项目名称:openuds,代码行数:30,代码来源:opchecker.py

示例2: 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

示例3: 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

示例4: checkAndUpdateState

 def checkAndUpdateState(userService, userServiceInstance, state):
     """
     Checks the value returned from invocation to publish or checkPublishingState, updating the servicePoolPub database object
     Return True if it has to continue checking, False if finished
     """
     try:
         if State.isFinished(state):
             checkLater = False
             userServiceInstance.finish()
             userService.updateData(userServiceInstance)
             userService.setState(State.USABLE)  # Wi will only migrate fully functional services
         elif State.isErrored(state):
             checkLater = False
             userService.updateData(userServiceInstance)
             userService.setState(State.ERROR)
         else:
             checkLater = True  # The task is running
             userService.updateData(userServiceInstance)
         userService.save()
         if checkLater:
             ClusterMigrationTask.checkLater(userService, userServiceInstance)
     except Exception as e:
         logger.exception('Migrating service')
         log.doLog(userService, log.ERROR, 'Exception: {0}'.format(e), log.INTERNAL)
         userService.setState(State.ERROR)
         userService.save()
开发者ID:glyptodon,项目名称:openuds,代码行数:26,代码来源:ClusteredProviderManagement.py

示例5: __str__

 def __str__(self):
     return "User service {0}, cache_level {1}, user {2}, name {3}, state {4}:{5}".format(
         self.id,
         self.cache_level,
         self.user,
         self.friendly_name,
         State.toString(self.state),
         State.toString(self.os_state),
     )
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:9,代码来源:UserService.py

示例6: moveToLevel

    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()
        state = ci.moveToCache(cacheLevel)
        cache.cache_level = cacheLevel
        logger.debug('Service State: {0} {1} {2}'.format(State.toString(state), State.toString(cache.state), State.toString(cache.os_state)))
        if State.isRuning(state) and cache.isUsable():
            cache.setState(State.PREPARING)

        UserServiceOpChecker.makeUnique(cache, ci, state)
开发者ID:joaoguariglia,项目名称:openuds,代码行数:15,代码来源:UserServiceManager.py

示例7: checkAndUpdateState

    def checkAndUpdateState(userService, userServiceInstance, state):
        """
        Checks the value returned from invocation to publish or checkPublishingState, updating the servicePoolPub database object
        Return True if it has to continue checking, False if finished
        """
        try:
            # Fills up basic data
            userService.unique_id = userServiceInstance.getUniqueId()  # Updates uniqueId
            userService.friendly_name = userServiceInstance.getName()  # And name, both methods can modify serviceInstance, so we save it later
            userService.save(update_fields=['unique_id', 'friendly_name'])

            updater = {
                State.PREPARING: UpdateFromPreparing,
                State.REMOVING: UpdateFromRemoving,
                State.CANCELING: UpdateFromCanceling
            }.get(userService.state, UpdateFromOther)

            logger.debug('Updating from {} with updater {} and state {}'.format(State.toString(userService.state), updater, state))

            updater(userService, userServiceInstance).run(state)

        except Exception as e:
            logger.exception('Checking service state')
            log.doLog(userService, log.ERROR, 'Exception: {0}'.format(e), log.INTERNAL)
            userService.setState(State.ERROR)
            userService.save(update_fields=['data'])
开发者ID:dkmstr,项目名称:openuds,代码行数:26,代码来源:opchecker.py

示例8: getFields

 def getFields(self, parent):
     return [
         {"revision": {"title": _("Revision"), "type": "numeric", "width": "6em"}},
         {"publish_date": {"title": _("Publish date"), "type": "datetime"}},
         {"state": {"title": _("State"), "type": "dict", "dict": State.dictionary()}},
         {"reason": {"title": _("Reason")}},
     ]
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:7,代码来源:user_services.py

示例9: removeOrCancel

 def removeOrCancel(self, uService):
     if uService.isUsable() or State.isRemovable(uService.state):
         return self.remove(uService)
     elif uService.isPreparing():
         return self.cancel(uService)
     else:
         raise OperationException(_('Can\'t remove nor cancel {0} cause its states don\'t allow it'))
开发者ID:joaoguariglia,项目名称:openuds,代码行数:7,代码来源:UserServiceManager.py

示例10: __registerUser

def __registerUser(authenticator, authInstance, username):
    """
    Check if this user already exists on database with this authenticator, if don't, create it with defaults
    This will work correctly with both internal or externals cause we first authenticate the user, if internal and user do not exists in database
    authenticate will return false, if external and return true, will create a reference in database
    """
    from uds.core.util.request import getRequest

    username = authInstance.transformUsername(username)
    logger.debug('Transformed username: {0}'.format(username))

    request = getRequest()

    usr = authenticator.getOrCreateUser(username, username)
    usr.real_name = authInstance.getRealName(username)
    usr.save()
    if usr is not None and State.isActive(usr.state):
        # Now we update database groups for this user
        usr.getManager().recreateGroups(usr)
        # And add an login event
        events.addEvent(authenticator, events.ET_LOGIN, username=username, srcip=request.ip)  # pylint: disable=maybe-no-member
        events.addEvent(authenticator, events.ET_PLATFORM, platform=request.os.OS, browser=request.os.Browser, version=request.os.Version)  # pylint: disable=maybe-no-member
        return usr

    return None
开发者ID:dkmstr,项目名称:openuds,代码行数:25,代码来源:auth.py

示例11: checkAndUpdateState

    def checkAndUpdateState(servicePoolPub, pi, state):
        """
        Checks the value returned from invocation to publish or checkPublishingState, updating the servicePoolPub database object
        Return True if it has to continue checking, False if finished
        """
        try:
            prevState = servicePoolPub.state
            checkLater = False
            if State.isFinished(state):
                # Now we mark, if it exists, the previous usable publication as "Removable"
                if State.isPreparing(prevState):
                    for old in servicePoolPub.deployed_service.publications.filter(state=State.USABLE):
                        old.state = State.REMOVABLE
                        old.save()

                        osm = servicePoolPub.deployed_service.osmanager
                        # If os manager says "machine is persistent", do not tray to delete "previous version" assigned machines
                        doPublicationCleanup = True if osm is None else not osm.getInstance().isPersistent()

                        if doPublicationCleanup:
                            pc = PublicationOldMachinesCleaner(old.id)
                            pc.register(GlobalConfig.SESSION_EXPIRE_TIME.getInt(True) * 3600, 'pclean-' + str(old.id), True)

                    servicePoolPub.setState(State.USABLE)
                    servicePoolPub.deployed_service.markOldUserServicesAsRemovables(servicePoolPub)
                elif State.isRemoving(prevState):
                    servicePoolPub.setState(State.REMOVED)
                else:  # State is canceling
                    servicePoolPub.setState(State.CANCELED)
                # Mark all previous publications deployed services as removables
                # and make this usable
                pi.finish()
                servicePoolPub.updateData(pi)
            elif State.isErrored(state):
                servicePoolPub.updateData(pi)
                servicePoolPub.state = State.ERROR
            else:
                checkLater = True  # The task is running
                servicePoolPub.updateData(pi)

            servicePoolPub.save()
            if checkLater:
                PublicationFinishChecker.checkLater(servicePoolPub, pi)
        except Exception:
            logger.exception('At checkAndUpdate for publication')
            PublicationFinishChecker.checkLater(servicePoolPub, pi)
开发者ID:glyptodon,项目名称:openuds,代码行数:46,代码来源:PublicationManager.py

示例12: unpublish

 def unpublish(self, servicePoolPub):  # pylint: disable=no-self-use
     '''
     Unpublishes an active (usable) or removable publication
     :param servicePoolPub: Publication to unpublish
     '''
     if State.isUsable(servicePoolPub.state) is False and State.isRemovable(servicePoolPub.state) is False:
         raise PublishException(_('Can\'t unpublish non usable publication')
                                )
     if servicePoolPub.userServices.exclude(state__in=State.INFO_STATES).count() > 0:
         raise PublishException(_('Can\'t unpublish publications with services in process'))
     try:
         pubInstance = servicePoolPub.getInstance()
         state = pubInstance.destroy()
         servicePoolPub.setState(State.REMOVING)
         PublicationFinishChecker.checkAndUpdateState(servicePoolPub, pubInstance, state)
     except Exception, e:
         raise PublishException(str(e))
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:17,代码来源:PublicationManager.py

示例13: getFields

 def getFields(self, parent):
     return [
         {'name': {'title': _('Username'), 'visible': True, 'type': 'icon', 'icon': 'fa fa-user text-success'}},
         {'real_name': {'title': _('Name')}},
         {'comments': {'title': _('Comments')}},
         {'state': {'title': _('state'), 'type': 'dict', 'dict': State.dictionary()}},
         {'last_access': {'title': _('Last access'), 'type': 'datetime'}},
     ]
开发者ID:glyptodon,项目名称:openuds,代码行数:8,代码来源:users_groups.py

示例14: getItems

 def getItems(self, parent, item):
     return [{
         'id': i.uuid,
         'revision': i.revision,
         'publish_date': i.publish_date,
         'state': i.state,
         'reason': State.isErrored(i.state) and i.getInstance().reasonOfError() or '',
         'state_date': i.state_date,
     } for i in parent.publications.all()]
开发者ID:dkmstr,项目名称:openuds,代码行数:9,代码来源:user_services.py

示例15: remove

    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))
            if uService.isUsable() is False and State.isRemovable(uService.state) is False:
                raise OperationException(_('Can\'t remove a non active element'))
            uService.setState(State.REMOVING)
            logger.debug("***** The state now is {}".format(State.toString(uService.state)))
            uService.setInUse(False)  # For accounting, ensure that it is not in use right now
            uService.save()

        ci = uService.getInstance()
        state = ci.destroy()

        UserServiceOpChecker.makeUnique(uService, ci, state)
开发者ID:joaoguariglia,项目名称:openuds,代码行数:19,代码来源:UserServiceManager.py


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