Пример #1
0
    def _mark_deleted(self):
        """Mark a record as deleted, returns nothing.

        Looks up the model instance by pk, sets the not_deleted attribute
        to None and saves the model instance.

        Additionally marks any AlertStates referring to this item as inactive.

        This is provided as a class method which takes an ID rather than as an
        instance method, in order to use ._base_manager rather than .objects -- this
        allows us to find the object even if it was already deleted, making this
        operation idempotent rather than throwing a DoesNotExist on the second try.
        """
        # Not implemented as an instance method because
        # we will need to use _base_manager to ensure
        # we can get at the object
        from django.db.models import signals

        signals.pre_delete.send(sender=self.__class__, instance=self)

        with transaction.atomic():
            if self.not_deleted:
                self.not_deleted = None
                self.save()

            from chroma_core.lib.job import job_log
            from chroma_core.models.alert import AlertState

            updated = AlertState.filter_by_item_id(self.__class__, self.id).update(active=None)
            job_log.info("Lowered %d alerts while deleting %s %s" % (updated, self.__class__, self.id))

        signals.post_delete.send(sender=self.__class__, instance=self)
Пример #2
0
    def can_run(cls, host):
        if host.immutable_state:
            return False

        cnt = LustreClientMount.objects.filter(state="mounted",
                                               host=host).count()

        return (host.state not in ["removed", "undeployed", "unconfigured"]
                and cnt > 0 and not AlertState.filter_by_item(host).filter(
                    active=True,
                    alert_type__in=[
                        HostOfflineAlert.__name__, HostContactAlert.__name__
                    ]).exists())
    def can_run(cls, host):
        if not host.is_worker:
            return False

        search = lambda cm: (cm.host == host and cm.state == 'mounted')
        mounted = ObjectCache.get(LustreClientMount, search)
        return (host.state not in ['removed', 'undeployed', 'unconfigured']
                and len(mounted) > 0
                and not AlertState.filter_by_item(host).filter(
                    active=True,
                    alert_type__in=[
                        HostOfflineAlert.__name__, HostContactAlert.__name__
                    ]).exists())