首页 » Python » python3 高级篇 » 正文

django 发布系统–伪代码

思路

#第一步:
##紧接着,从models中获取到主机列表,代码地址
##循环主机,将代码分别推送到主机
## 自动化平台(salt-master 中下载代码(打包)
#import os
#import sys
#path = os.getcwd() + r'/project_path/'
##获取代码的path,然后通过subprocesslinux命令)进入path<mkdir $app_name; cd $app_name; git clone XXX; 打包 tar zcf>

#第二步:
##推送 --> slat-stack   state.sls
##state.sls规则的yaml文件
##通过python代码  salt_api调用state触发推送

#第三步:
##执行远端代码  -->  cd path ; 启动程序

views.py (如上的思路需要补充在此)

from django.shortcuts import render, HttpResponse, redirect
from django.views import View
from demo1 import models

# Create your views here.


def fabu(request):
    if request.method == "GET":
        env = models.RecordEnv.objects.all()
        return render(request, 'fabu.html', locals())
    else:
        env = request.POST.get('env')       ##拿到从前端传过来的envapp
        app = request.POST.get('app')
        obj_li = models.App.objects.filter(name=app, environment__name=env)

        host_li = [{'id':'test', 'path':'/app/www/payment'},]
        package = 'svn://xxxxx'
        app_name = "payment"

        return HttpResponse("ok")

fabu.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>发布系统</title>
</head>
<body>

<form method="post">
    <label>应用:</label>
    <input type="text" name="app">
        <select class="form-control" id="numbers" name="env">

            {% for item in env %}
                <option value="{{ item.name }}" >{{ item.name }}</option>
            {% endfor %}

        </select>
        <input type="submit" value="提交">

</form>

</body>
</html>

路径:

from django.contrib import admin
# from django.urls import path
from demo1 import views
from django.conf.urls import url, include

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^fabu/', views.fabu),
]
赞 (0)

发表评论