Example #1
0
    def isReady(self, userService: UserService) -> bool:
        userService.refresh_from_db()
        logger.debug('Checking ready of %s', userService)

        if userService.state != State.USABLE or userService.os_state != State.USABLE:
            logger.debug('State is not usable for %s', userService.name)
            return False

        logger.debug('Service %s is usable, checking it via setReady',
                     userService)
        userServiceInstance = userService.getInstance()
        try:
            state = userServiceInstance.setReady()
        except Exception as e:
            logger.warn('Could not check readyness of %s: %s', userService, e)
            return False

        logger.debug('State: %s', state)

        if state == State.FINISHED:
            userService.updateData(userServiceInstance)
            return True

        userService.setState(State.PREPARING)
        UserServiceOpChecker.makeUnique(userService, userServiceInstance,
                                        state)

        return False
Example #2
0
 def notifyReadyFromOsManager(self, userService: UserService, data: typing.Any) -> None:
     try:
         userServiceInstance = userService.getInstance()
         logger.debug('Notifying user service ready state')
         state = userServiceInstance.notifyReadyFromOsManager(data)
         logger.debug('State: %s', state)
         if state == State.FINISHED:
             userService.updateData(userServiceInstance)
             logger.debug('Service is now ready')
         elif userService.state in (State.USABLE, State.PREPARING):  # We don't want to get active deleting or deleted machines...
             userService.setState(State.PREPARING)
             UserServiceOpChecker.makeUnique(userService, userServiceInstance, state)
         userService.save(update_fields=['os_state'])
     except Exception as e:
         logger.exception('Unhandled exception on notyfyReady: %s', e)
         userService.setState(State.ERROR)
         return