Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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()
Esempio n. 5
0
 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)
Esempio n. 6
0
 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()
Esempio n. 7
0
 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)
Esempio n. 8
0
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')
Esempio n. 9
0
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
Esempio n. 10
0
def update_deploy_info(deploy_id, host, is_success, msg):
    OperationLogDal.update_deploy_info(deploy_id, host, is_success, msg)
Esempio n. 11
0
def list_operation_log(**kwargs):
    return OperationLogDal.list_operation_log(kwargs)
Esempio n. 12
0
 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'})
Esempio n. 13
0
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')
Esempio n. 14
0
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
Esempio n. 15
0
 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'})
Esempio n. 16
0
def get_dns_log_detail(id):
    OperationLogDal.get_log_detail(id)
Esempio n. 17
0
def update_deploy_info(deploy_id, host, is_success, msg):
    OperationLogDal.update_deploy_info(deploy_id, host, is_success, msg)