Пример #1
0
    def restartProcess(self):
        if type(self.target) == list:
            for item in self.target:
                changed = 0
                failures = 0
                unreachable = 0

                if item["errorType"] == "host":
                    res = playbook.PlayBook(
                        playbook="common.yml",
                        callbacks=notification.SMSCallbacks(),
                        runner_callbacks=notification.SMSRunnerCallbacks(self.stats),
                        stats=self.stats,
                        subset=item["host"],
                        # check = True
                    ).run()
                elif item["errorType"] == "process":
                    logging.info("ready to restart the process - [%(processList)s] of the %(host)s" % item)
                    res = playbook.PlayBook(
                        playbook="common.yml",
                        callbacks=notification.SMSCallbacks(),
                        runner_callbacks=notification.SMSRunnerCallbacks(self.stats),
                        stats=self.stats,
                        only_tags=item["processList"].split(","),
                        skip_tags=["common"],
                        subset=item["host"],
                    ).run()
                for host, status in res.items():
                    failures = status["failures"]
                    unreachable = status["unreachable"]
                    msg = ""
                    if item["errorType"] == "host":
                        msg += "after the host %(host)s crash down"
                    if failures == 0 and unreachable == 0:
                        msg += "all process - [%(processList)s] of %(host)s restart SUCCESSFULLY"
                        logging.info(msg % item)
                    else:
                        msg += (
                            "some process of %(host)s restart encounter problems,please check it manually in %(host)s"
                        )
                        logging.warn(msg % item)
Пример #2
0
 def on_unreachable(self,host,res):
     if type(res) == dict:
         data = res.copy()
         logging.warn('the process of %s restart UNREACHABLE because %s' %(host,data['msg']))
     logging.warn('%s occurred UNREACHABLE because %s' %(host,res))
Пример #3
0
 def on_failed(self,host,res,ignore_errors=False):
     if type(res) == dict:
         if 'verbose_override' not in res:
             data = res.copy()
             invocation = data['invocation']
             logging.warn('the process - [%s:%s] of %s restart FAIL because %s' % (invocation['module_name'],invocation['module_args'],host,data['msg']))