Beispiel #1
0
    def high(cls, alert_item, **kwargs):
        if hasattr(alert_item, 'not_deleted') and alert_item.not_deleted != True:
            return None

        attrs_to_save = cls._get_attrs_to_save(kwargs)

        try:
            alert_state = cls.filter_by_item(alert_item).get(**kwargs)
        except cls.DoesNotExist:
            kwargs.update(attrs_to_save)

            if not 'alert_type' in kwargs:
                kwargs['alert_type'] = cls.__name__
            if not 'severity' in kwargs:
                kwargs['severity'] = cls.default_severity

            alert_state = cls(active = True,
                              dismissed = False,  # Users dismiss, not the software
                              alert_item = alert_item,
                              **kwargs)
            try:
                alert_state._message = alert_state.alert_message()
                alert_state.save()
                job_log.info("AlertState: Raised %s on %s "
                             "at severity %s" % (cls,
                                                 alert_state.alert_item,
                                                 alert_state.severity))
            except IntegrityError, e:
                job_log.warning("AlertState: IntegrityError %s saving %s : %s : %s" % (e, cls.__name__, alert_item, kwargs))
                # Handle colliding inserts: drop out here, no need to update
                # the .end of the existing record as we are logically concurrent
                # with the creator.
                return None
    def get_steps(self):
        from chroma_core.models import ConfParam
        from chroma_core.lib.job import job_log

        mgs = self.mgs.downcast()
        new_params = ConfParam.objects.filter(
            version__gt=mgs.conf_param_version_applied,
            mgs=mgs).order_by("version")
        steps = []

        new_param_count = new_params.count()
        if new_param_count > 0:
            job_log.info("ApplyConfParams %d, applying %d new conf_params" %
                         (self.id, new_param_count))
            # If we have some new params, create N ConfParamSteps and one ConfParamVersionStep
            highest_version = 0
            for param in new_params:
                # We must check that the parameter's object is still alive, to avoid trying
                # to set params on things that don't exist (HYD-2365)
                if param.object_exists():
                    steps.append((ConfParamStep, {"conf_param_id": param.id}))
                    highest_version = max(highest_version, param.version)
            steps.append((ConfParamVersionStep, {
                "mgs_id": self.mgs.id,
                "version": highest_version
            }))
        else:
            # If we have no new params, no-op
            job_log.warning(
                "ApplyConfParams %d, mgs %d has no params newer than %d" %
                (self.id, mgs.id, mgs.conf_param_version_applied))

        return steps