def update_depoly_job(self): job = OperationLogDal.get_deploy_job(self.job_id) data = dict(op_result='ok') data['op_after'] = json.loads(job.op_after) if self.unfinished: data['op_result'] = 'fail' data['op_after']['unfinished'] = self.unfinished data['op_after'] = json.dumps(data['op_after']) send_alert_email(u'主机更新named.conf失败, 主机信息:\n%s' % json.dumps(self.unfinished, indent=4)) OperationLogDal.update_opration_log(self.job_id, data)
def init_zone(self): hosts = self.deploy_info.get('hosts', []) if not hosts: OperationLogDal.update_opration_log(self.job_id, {'op_result': 'ok'}) group_name = self.deploy_info['group'] zone = self.deploy_info['zone'] for host in hosts: try: result = DnsUpdaterApi(host_ip=host).notify_update(self.deploy_type, group_name, deploy_id=self.job_id, zone=zone) log.info('notify %s to update %s success, %s' % (host, self.deploy_type, result)) except Exception as e: log.error('notify %s to update %s failed, %s' % (host, self.deploy_type, e)) self.notify_failed.append(e)
def update_acl(self): hosts = self.deploy_info.get('hosts', {}) acl_files = self.deploy_info.get('acl_files', []) if not hosts or not acl_files: OperationLogDal.update_opration_log(self.job_id, {'op_result': 'ok'}) for group_name, hosts in hosts.items(): for host in hosts: try: result = DnsUpdaterApi(host_ip=host).notify_update(self.deploy_type, group_name, deploy_id=self.job_id, acl_files=acl_files) log.info('notify %s to update %s success, %s' % (host, self.deploy_type, result)) except Exception as e: log.error('notify %s to update %s failed, %s' % (host, self.deploy_type, e)) self.notify_failed.append(e)
def run(self): with self.app.app_context(): job = OperationLogDal.get_deploy_job(self.job_id) if not job or job.op_result != 'wait': raise DeployException( 'No deploy job id=%s or job state=wait.' % self.job_id) OperationLogDal.update_opration_log(self.job_id, {'op_result': 'start'}) self.deploy_info = json.loads(job.op_before) self.deploy_type = job.op_domain if job.op_domain == 'named.conf': self.update_named_conf() elif job.op_domain == 'acl': self.update_acl() if self.notify_failed: pass self.check_normal_update()
def update_acl(self): hosts = self.deploy_info.get('hosts', {}) acl_files = self.deploy_info.get('acl_files', []) if not hosts or not acl_files: OperationLogDal.update_opration_log(self.job_id, {'op_result': 'ok'}) for group_name, hosts in hosts.iteritems(): for host in hosts: try: print DnsUpdaterApi(host_ip=host).notify_update( self.deploy_type, group_name, deploy_id=self.job_id, acl_files=acl_files) except Exception as e: log.error('notify %s to update %s failed, %s' % (host, self.deploy_type, e)) self.notify_failed.append(e)
def init_zone(self): hosts = self.deploy_info.get('hosts', []) if not hosts: OperationLogDal.update_opration_log(self.job_id, {'op_result': 'ok'}) group_name = self.deploy_info['group'] zone = self.deploy_info['zone'] for host in hosts: try: result = DnsUpdaterApi(host_ip=host).notify_update( self.deploy_type, group_name, deploy_id=self.job_id, zone=zone) log.info('notify %s to update %s success, %s' % (host, self.deploy_type, result)) except Exception as e: log.error('notify %s to update %s failed, %s' % (host, self.deploy_type, e)) self.notify_failed.append(e)
def run(self): with self.app.app_context(): job = OperationLogDal.get_deploy_job(self.job_id) if not job or job.op_result != 'wait': raise DeployException('No deploy job id=%s or job state=wait.' % self.job_id) OperationLogDal.update_opration_log(self.job_id, { 'op_result': 'start' }) self.deploy_info = json.loads(job.op_before) self.deploy_type = job.op_domain if job.op_domain == 'named.conf': self.update_named_conf() elif job.op_domain == 'acl': self.update_acl() elif job.op_domain == 'zone': self.init_zone() if self.notify_failed: pass with self.app.app_context(): self.check_normal_update()
def check_normal_update(self): time.sleep(self.expire) job = OperationLogDal.get_deploy_job(self.job_id) if job.op_result == 'start': OperationLogDal.update_opration_log(self.job_id, {'op_result': 'fail'})