def deploy_add(request): if request.method == "GET": # serverList = Server_Assets.objects.all() groupList = Group.objects.all() return render( request, 'deploy/deploy_add.html', { "user": request.user, "groupList": groupList, 'baseAssets': getBaseAssets(), "project_dir": settings.WORKSPACES }) elif request.method == "POST": # serverList = Server_Assets.objects.all() ipList = request.POST.get('server') try: proAssets = Project_Assets.objects.get( id=request.POST.get('project_id')) except Exception, ex: return JsonResponse({ 'msg': "部署项目添加失败".format(ex=ex), "code": 500, 'data': [] }) try: project = Project_Config.objects.create( project=proAssets, project_service=request.POST.get('project_service'), project_type=request.POST.get('project_type'), project_env=request.POST.get('project_env'), project_name=request.POST.get('project_name'), project_repertory=request.POST.get('project_repertory'), project_address=request.POST.get('project_address'), project_repo_dir=request.POST.get('project_repo_dir'), project_remote_command=request.POST.get( 'project_remote_command'), project_local_command=request.POST.get( 'project_local_command'), project_dir=request.POST.get('project_dir'), project_uuid=uuid.uuid4(), project_exclude=request.POST.get('project_exclude', '.git').rstrip(), project_user=request.POST.get('project_user', 'root'), project_model=request.POST.get('project_model'), project_status=0, project_repo_user=request.POST.get('project_repo_user'), project_repo_passwd=request.POST.get('project_repo_passwd'), project_audit_group=request.POST.get('project_audit_group', None), ) recordProject.delay(project_user=str(request.user), project_id=project.id, project_name=project.project_name, project_content="添加项目") except Exception, ex: logger.error(msg="部署项目添加失败: {ex}".format(ex=ex)) return JsonResponse({ 'msg': "部署项目添加失败: {ex}".format(ex=ex), "code": 500, 'data': [] })
def user_center(request): if request.method == "GET": serverList = [] baseAssets = {} try: baseAssets = assets.getBaseAssets() config = Global_Config.objects.get(id=1) if config.webssh == 1 and request.user.is_superuser: serverList = Assets.objects.all().order_by("-id") elif config.webssh == 1: userServer = User_Server.objects.filter(user_id=int(request.user.id)) serverList = [] for s in userServer: ser = Server_Assets.objects.get(id=s.server_id) serverList.append(ser.assets) except: config = None orderList = Order_System.objects.filter(Q(order_user=User.objects.get(username=request.user).id) | Q(order_executor=User.objects.get(username=request.user).id)).order_by("id")[0:150] for order in orderList: if order.order_executor == request.user.id:order.perm = 1 order.order_user = User.objects.get(id=order.order_user).username order.order_executor = User.objects.get(id=order.order_executor).username return render(request,'users/user_center.html',{"user":request.user,"orderList":orderList, "serverList":serverList,"baseAssets":baseAssets, "config":config}) if request.method == "POST": if request.POST.get('password') == request.POST.get('c_password'): try: user = User.objects.get(username=request.user) user.set_password(request.POST.get('password')) user.save() return JsonResponse({"code":200,"data":None,"msg":"密码修改成功"}) except Exception,e: return JsonResponse({"code":500,"data":None,"msg":"密码修改失败:%s" % str(e)}) else:return JsonResponse({"code":500,"data":None,"msg":"密码不一致,密码修改失败。"})
def user_center(request): if request.method == "GET": serverList = [] baseAssets = {} try: baseAssets = assets.getBaseAssets() config = Global_Config.objects.get(id=1) if config.webssh == 1 and request.user.is_superuser: serverList = Assets.objects.all().order_by("-id") elif config.webssh == 1: userServer = User_Server.objects.filter(user_id=int(request.user.id)) serverList = [] for s in userServer: ser = Server_Assets.objects.get(id=s.server_id) serverList.append(ser.assets) except: config = None orderList = Project_Order.objects.filter(Q(order_user=User.objects.get(username=request.user)) | Q(order_audit=User.objects.get(username=request.user))).order_by("id")[0:150] return render(request,'users/user_center.html',{"user":request.user,"orderList":orderList, "serverList":serverList,"baseAssets":baseAssets, "config":config}) if request.method == "POST": if request.POST.get('password') == request.POST.get('c_password'): try: user = User.objects.get(username=request.user) user.set_password(request.POST.get('password')) user.save() return JsonResponse({"code":200,"data":None,"msg":"密码修改成功"}) except Exception,e: return JsonResponse({"code":500,"data":None,"msg":"密码修改失败:%s" % str(e)}) else:return JsonResponse({"code":500,"data":None,"msg":"密码不一致,密码修改失败。"})
def deploy_add(request): if request.method == "GET": serverList = Server_Assets.objects.all() groupList = Group.objects.all() return render(request,'deploy/deploy_add.html',{"user":request.user,"groupList":groupList, "serverList":serverList,'baseAssets':getBaseAssets()}) elif request.method == "POST": serverList = Server_Assets.objects.all() ipList = request.POST.getlist('server') try: proAssets = Project_Assets.objects.get(id=request.POST.get('project_id')) except Exception, ex: return render(request,'deploy/deploy_add.html',{"user":request.user,"errorInfo":"部署服务器信息添加错误:%s" % str(ex)},) try: project = Project_Config.objects.create( project = proAssets, project_service = request.POST.get('project_service'), project_env = request.POST.get('project_env'), project_repertory = request.POST.get('project_repertory'), project_address = request.POST.get('project_address'), project_repo_dir = request.POST.get('project_repo_dir'), project_remote_command = request.POST.get('project_remote_command'), project_local_command = request.POST.get('project_local_command'), project_dir = request.POST.get('project_dir'), project_uuid = uuid.uuid4(), project_exclude = request.POST.get('project_exclude','.git').rstrip(), project_user = request.POST.get('project_user','root'), project_model = request.POST.get('project_model'), project_status = 0, project_repo_user = request.POST.get('project_repo_user'), project_repo_passwd = request.POST.get('project_repo_passwd'), project_audit_group = request.POST.get('project_audit_group',None), ) recordProject.delay(project_user=str(request.user),project_id=project.id,project_name=proAssets.project_name,project_content="添加项目") except Exception,e: return render(request,'deploy/deploy_add.html',{"user":request.user, "serverList":serverList,"errorInfo":"部署服务器信息添加错误:%s" % str(e)},)
def deploy_add(request): if request.method == "GET": serverList = Server_Assets.objects.all() groupList = Group.objects.all() return render(request,'deploy/deploy_add.html',{"user":request.user,"groupList":groupList, "serverList":serverList,'baseAssets':getBaseAssets(), "project_dir":settings.WORKSPACES}) elif request.method == "POST": serverList = Server_Assets.objects.all() ipList = request.POST.get('server') try: proAssets = Project_Assets.objects.get(id=request.POST.get('project_id')) except Exception, ex: return JsonResponse({'msg':"部署项目添加失败".format(ex=ex),"code":500,'data':[]}) try: project = Project_Config.objects.create( project = proAssets, project_service = request.POST.get('project_service'), project_type = request.POST.get('project_type'), project_env = request.POST.get('project_env'), project_name = request.POST.get('project_name'), project_repertory = request.POST.get('project_repertory'), project_address = request.POST.get('project_address'), project_repo_dir = request.POST.get('project_repo_dir'), project_remote_command = request.POST.get('project_remote_command'), project_local_command = request.POST.get('project_local_command'), project_dir = request.POST.get('project_dir'), project_uuid = uuid.uuid4(), project_exclude = request.POST.get('project_exclude','.git').rstrip(), project_user = request.POST.get('project_user','root'), project_model = request.POST.get('project_model'), project_status = 0, project_repo_user = request.POST.get('project_repo_user'), project_repo_passwd = request.POST.get('project_repo_passwd'), project_audit_group = request.POST.get('project_audit_group',None), ) recordProject.delay(project_user=str(request.user),project_id=project.id,project_name=project.project_name,project_content="添加项目") except Exception, ex: logger.error(msg="部署项目添加失败: {ex}".format(ex=ex)) return JsonResponse({'msg':"部署项目添加失败: {ex}".format(ex=ex),"code":500,'data':[]})
def deploy_add(request): if request.method == "GET": serverList = Server_Assets.objects.all() groupList = Group.objects.all() return render( request, 'deploy/deploy_add.html', { "user": request.user, "groupList": groupList, 'baseAssets': getBaseAssets(), "serverList": serverList, "project_dir": settings.WORKSPACES }) elif request.method == "POST": try: proAssets = Project_Assets.objects.get( id=request.POST.get('project_id')) jenAssets = Jenkins_Assets.objects.get( id=request.POST.get('jenkins_id')) k8sAssets = K8s_Assets.objects.get(id=request.POST.get('k8s_id')) svcAssets = Service_Assets.objects.get( id=request.POST.get('service_id')) except Exception as ex: return JsonResponse({ 'msg': "部署项目添加失败".format(ex=ex), "code": 500, 'data': [] }) try: project = Project_Config.objects.create( project=proAssets, project_env=request.POST.get('project_env'), project_local_command=request.POST.get( 'project_local_command'), project_dir=request.POST.get('project_dir'), project_uuid=uuid.uuid4(), project_status=0, project_repo_dir=request.POST.get('project_repo_dir'), project_address=request.POST.get('project_address'), project_repo_user=request.POST.get('project_repo_user'), project_repo_passwd=request.POST.get('project_repo_passwd'), project_branch=request.POST.get('project_branch'), project_type=request.POST.get('project_type'), project_repertory=request.POST.get('project_repertory'), jenkins=jenAssets, k8s=k8sAssets, service=svcAssets, project_service_port=request.POST.get('project_service_port'), project_debug_port=request.POST.get('project_debug_port'), project_env_var=request.POST.get('project_env_var'), project_mount_path=request.POST.get('project_mount_path')) recordProject(project_user=str(request.user), project_id=proAssets.id, project_name=proAssets.project_name, project_content="添加代码发布项目") except Exception as ex: logger.error(msg="部署项目添加失败: {ex}".format(ex=ex)) return JsonResponse({ 'msg': "部署项目添加失败: {ex}".format(ex=ex), "code": 500, 'data': [] }) return JsonResponse({'msg': "部署项目添加成功", "code": 200, 'data': []})
def deploy_add(request): if request.method == "GET": serverList = Server_Assets.objects.all() groupList = Group.objects.all() return render(request,'deploy/deploy_add.html',{"user":request.user,"groupList":groupList, "serverList":serverList,'baseAssets':getBaseAssets()}) elif request.method == "POST": serverList = Server_Assets.objects.all() ipList = request.POST.getlist('server') try: proAssets = Project_Assets.objects.get(id=request.POST.get('project_id')) except Exception, ex: return render(request,'deploy/deploy_add.html',{"user":request.user,"errorInfo":"部署服务器信息添加错误:%s" % str(ex)},) try: project = Project_Config.objects.create( project = proAssets, project_service = request.POST.get('project_service'), project_env = request.POST.get('project_env'), project_repertory = request.POST.get('project_repertory'), project_address = request.POST.get('project_address'), project_repo_dir = request.POST.get('project_repo_dir'), project_remote_command = request.POST.get('project_remote_command'), project_local_command = request.POST.get('project_local_command'), project_dir = request.POST.get('project_dir'), project_uuid = uuid.uuid4(), project_exclude = request.POST.get('project_exclude','.git').rstrip(), project_user = request.POST.get('project_user','root'), project_model = request.POST.get('project_model'), project_status = 0, project_repo_user = request.POST.get('project_repo_user'), project_repo_passwd = request.POST.get('project_repo_passwd'), project_audit_group = request.POST.get('project_audit_group',None), ) recordProject.delay(project_user=str(request.user),project_id=project.id,project_name=proAssets.project_name,project_content="添加项目") except Exception,e: return render(request,'deploy/deploy_add.html',{"user":request.user, "serverList":serverList,"errorInfo":"部署服务器信息添加错误:%s" % str(e)},)