Ejemplo n.º 1
0
    def remove(self, userService: UserService) -> UserService:
        """
        Removes a uService element
        """
        with transaction.atomic():
            userService = UserService.objects.select_for_update().get(
                id=userService.id)
            logger.debug('Removing userService %a', userService)
            if userService.isUsable() is False and State.isRemovable(
                    userService.state) is False:
                raise OperationException(
                    _('Can\'t remove a non active element'))
            userService.setState(State.REMOVING)
            logger.debug("***** The state now is %s *****",
                         State.toString(userService.state))
            userService.setInUse(
                False
            )  # For accounting, ensure that it is not in use right now
            userService.save()

        userServiceInstance = userService.getInstance()
        state = userServiceInstance.destroy()

        # Data will be serialized on makeUnique process
        UserServiceOpChecker.makeUnique(userService, userServiceInstance,
                                        state)

        return userService
Ejemplo n.º 2
0
    def removeOrCancel(self, userService: UserService):
        if userService.isUsable() or State.isRemovable(userService.state):
            return self.remove(userService)

        if userService.isPreparing():
            return self.cancel(userService)

        raise OperationException(_('Can\'t remove nor cancel {} cause its state don\'t allow it').format(userService.name))