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'))
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)
def remove(self, uService): ''' Removes a uService element @return: the uService removed (marked for removal) ''' uService = UserService.objects.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')) ci = uService.getInstance() state = ci.destroy() uService.setState(State.REMOVING) UserServiceOpChecker.makeUnique(uService, ci, state)
def remove(self, uService): ''' Removes a uService element @return: the uService removed (marked for removal) ''' uService = UserService.objects.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')) ci = uService.getInstance() state = ci.destroy() uService.setState(State.REMOVING) UserServiceOpChecker.makeUnique(uService, ci, state)
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))
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 as e: raise PublishException(str(e))
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)