예제 #1
0
def exec_rollback(request, ID):
    the_rollback = RollBack.objects.get(id=ID)
    if the_rollback.in_use:
        return http_error(request, u'正式环境为此版本')
    else:
        old_rollback = RollBack.objects.get(in_use=True)
        old_rollback.in_use = False
        old_rollback.save()
        the_project = Project.objects.get(name=the_rollback.project)
        ln_path = os.path.abspath(the_project.server_path)
        pro_server_path = os.path.abspath(
            the_project.server_path) + "_%s" % the_rollback.hash
        pro_host_list = list(eval(the_project.pro_host_list))
        host_list_str = ','.join(pro_host_list)
        salt = SaltApi(SALTAPI_URL, SALTAPI_USER, SALTAPI_PASSWORD)
        salt.login()
        salt.cmd(host_list_str, 'rm -f %s' % ln_path)
        salt.cmd(host_list_str, 'ln -s %s %s' % (pro_server_path, ln_path))
        salt.logout()
        the_rollback.in_use = True
        the_rollback.save()
        pro = ReleaseRecord(project=the_project.name,
                            branch=the_rollback.branch,
                            hash=the_rollback.hash,
                            release_user=request.user)
        pro.save()
        return http_success(request, u'版本回退成功')
예제 #2
0
파일: views.py 프로젝트: Jack614/saplatform
def exec_rollback(request, ID):
    the_rollback = RollBack.objects.get(id=ID)
    if the_rollback.in_use:
        return http_error(request, u'正式环境为此版本')
    else:
        old_rollback = RollBack.objects.get(in_use=True)
        old_rollback.in_use = False
        old_rollback.save()
        the_project = Project.objects.get(name=the_rollback.project)
        ln_path = os.path.abspath(the_project.server_path)
        pro_server_path = os.path.abspath(the_project.server_path) + "_%s" % the_rollback.hash
        pro_host_list = list(eval(the_project.pro_host_list))
        host_list_str = ','.join(pro_host_list)
        salt = SaltApi(SALTAPI_URL, SALTAPI_USER, SALTAPI_PASSWORD)
        salt.login()
        salt.cmd(host_list_str, 'rm -f %s' % ln_path)
        salt.cmd(host_list_str, 'ln -s %s %s' % (pro_server_path, ln_path))
        salt.logout()
        the_rollback.in_use = True
        the_rollback.save()
        pro = ReleaseRecord(project=the_project.name,
                            branch=the_rollback.branch,
                            hash=the_rollback.hash,
                            release_user=request.user)
        pro.save()
        return http_success(request, u'版本回退成功')
예제 #3
0
파일: views.py 프로젝트: zws0932/saplatform
def svn_pro_result(request, ID):
    the_svn = SvnControl.objects.get(id=str(ID))
    the_project = Project.objects.get(name=the_svn.project)
    the_auth = Auth.objects.get(id=the_project.auth)
    username = the_auth.username if the_auth.username else ''
    password = the_auth.password if the_auth.password else ''
    pro_host_list = list(eval(the_project.pro_host_list))
    pro_url = the_project.url.strip()
    pro_no_version = the_svn.no_version
    pro_server_path = os.path.abspath(the_project.server_path)
    pro_local_path = os.path.join('/ops/pro', pro_server_path.lstrip('/'), str(ID))
    svn_co(pro_url, pro_local_path, pro_no_version, username, password)
    for i in pro_host_list:
        stdout = rrsync(pro_local_path, i, pro_server_path, ['.svn*', '.git*'])
    pro = ReleaseRecord(project=the_project.name, environment=u'正式', no_version=pro_no_version, release_user=request.user)
    pro.save()
    loger = set_log(level='debug', filename='product_release_%s.log' % datetime.date.today().strftime('%Y-%m-%d'))
    loger.debug('product released by %s, detail : %s' % (request.user, stdout))
    result = stdout.replace('\n', '</br>')
    if request.user.email:
        mail_task.delay(subject=u'项目 %s 正式发布结果 版本号:%s' % (the_project.name, pro_no_version),
                        message=stdout,
                        from_email=EMAIL_HOST_USER,
                        recipient_list=[request.user.email],
                        fail_silently=False)
    return render_to_response('release/svn_pro_result.html', locals(), RequestContext(request))
예제 #4
0
def pro_release(request, ID):
    try:
        the_pre_record = PreRecord.objects.get(id=ID)
        the_release = Test.objects.all().get(id=the_pre_record.test_id)
        the_project = Project.objects.get(name=the_release.project)
        pro_host_list = list(eval(the_project.pro_host_list))
        ln_path = os.path.abspath(the_project.server_path)
        test_server_path = os.path.abspath(the_release.server_path)
        pro_server_path = os.path.abspath(
            the_project.server_path) + "_%s" % the_release.last_hash
        local_path = os.path.join('/ops/%s' % the_project.name,
                                  test_server_path.lstrip('/'),
                                  str(the_pre_record.test_id))
        host_list_str = ','.join(pro_host_list)
        salt = SaltApi(SALTAPI_URL, SALTAPI_USER, SALTAPI_PASSWORD)
        salt.login()
        for i in pro_host_list:
            stdout = rrsync(local_path, i, pro_server_path, ['.git*'])
            result = stdout.replace('\n', '</br>')

        #import os
        cmd_rm = 'rm -rf %s' % ln_path
        cmd_ln = 'ln -s %s %s' % (pro_server_path, ln_path)
        cmd_ansible_rm = "ansible php1 -i /etc/ansible/hosts -mshell -a '%s'" % cmd_rm
        cmd_ansible_ln = "ansible php1 -i /etc/ansible/hosts -mshell -a '%s' " % cmd_ln
        #print cmd_ansible_ln
        #cmd="echo %s > /tmp/1.log"%cmd_ansible_rm
        #os.system(cmd)
        os.system(cmd_ansible_rm)
        os.system(cmd_ansible_ln)

        salt.cmd(host_list_str, 'rm -rf %s' % ln_path)
        salt.cmd(host_list_str, 'ln -s %s %s' % (pro_server_path, ln_path))
        print 'ln -s %s %s' % (pro_server_path, ln_path)

        salt.logout()

        try:
            the_rollback = RollBack.objects.get(in_use=True)
            the_rollback.in_use = False
            the_rollback.save()
        except:
            pass
        i_rollback = RollBack(project=the_project.name,
                              branch=the_release.last_branch,
                              hash=the_release.last_hash,
                              in_use=True)
        i_rollback.save()
        pro = ReleaseRecord(project=the_project.name,
                            branch=the_release.last_branch,
                            hash=the_release.last_hash,
                            release_user=request.user)
        pro.save()
        return render_to_response('release/release_result.html', locals(),
                                  RequestContext(request))
    except:
        return http_error(request, u'发布出现错误,请检查预发布记录')
예제 #5
0
파일: views.py 프로젝트: Jack614/saplatform
def pro_release(request, ID):
    try:
        the_pre_record = PreRecord.objects.get(id=ID)
        the_release = Test.objects.all().get(id=the_pre_record.test_id)
        the_project = Project.objects.get(name=the_release.project)
        pro_host_list = list(eval(the_project.pro_host_list))
        ln_path = os.path.abspath(the_project.server_path)
        test_server_path = os.path.abspath(the_release.server_path)
        pro_server_path = os.path.abspath(the_project.server_path) + "_%s" % the_release.last_hash
        local_path = os.path.join('/ops/%s' % the_project.name, test_server_path.lstrip('/'),
                                  str(the_pre_record.test_id))
        host_list_str = ','.join(pro_host_list)
        salt = SaltApi(SALTAPI_URL, SALTAPI_USER, SALTAPI_PASSWORD)
        salt.login()
        for i in pro_host_list:
            stdout = rrsync(local_path, i, pro_server_path, ['.git*'])
            result = stdout.replace('\n', '</br>')
        salt.cmd(host_list_str, 'rm -rf %s' % ln_path)
        salt.cmd(host_list_str, 'ln -s %s %s' % (pro_server_path, ln_path))
        salt.logout()
        try:
            the_rollback = RollBack.objects.get(in_use=True)
            the_rollback.in_use = False
            the_rollback.save()
        except:
            pass
        i_rollback = RollBack(project=the_project.name,
                               branch=the_release.last_branch,
                               hash=the_release.last_hash,
                               in_use=True)
        i_rollback.save()
        pro = ReleaseRecord(project=the_project.name,
                            branch=the_release.last_branch,
                            hash=the_release.last_hash,
                            release_user=request.user)
        pro.save()
        return render_to_response('release/release_result.html', locals(), RequestContext(request))
    except:
        return http_error(request, u'发布出现错误,请检查预发布记录')