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 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 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() 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 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 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 retry_deploy_job(job_id, username): if not OperationLogDal.reset_deploy_job(username, job_id): raise DeployException('Reset deploy job %s failed' % job_id) thread = DeployThread(job_id, is_retry=True) thread.start() return dict(code=0, data='ok')
def start_deploy_job(user, deploy_info, conf_type, unfinished): job_id = OperationLogDal.create_deploy_job(user, deploy_info, conf_type, unfinished) thread = DeployThread(job_id) thread.start() return job_id
def update_deploy_info(deploy_id, host, is_success, msg): OperationLogDal.update_deploy_info(deploy_id, host, is_success, msg)
def list_operation_log(**kwargs): return OperationLogDal.list_operation_log(kwargs)
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'})
def retry_deploy_job(job_id, username): if not OperationLogDal.reset_deploy_job(username, job_id): raise DeployException('Reset deploy job %s failed' % job_id) thread = DeployThread(job_id, is_retry=True) thread.start() return dict(code=0, data='ok')
def start_deploy_job(user, deploy_info, conf_type, unfinished): job_id = OperationLogDal.create_deploy_job(user, deploy_info, conf_type, unfinished) thread = DeployThread(job_id) thread.start() return job_id
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'})
def get_dns_log_detail(id): OperationLogDal.get_log_detail(id)
def update_deploy_info(deploy_id, host, is_success, msg): OperationLogDal.update_deploy_info(deploy_id, host, is_success, msg)