mirror of https://github.com/openspug/spug
A api update
parent
cf5bfc81bb
commit
f9365b3e37
|
@ -4,5 +4,5 @@ from .views import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('request/', RequestView.as_view()),
|
path('request/', RequestView.as_view()),
|
||||||
path('request/<int:r_id>/', do_deploy),
|
path('request/<int:r_id>/', RequestDetailView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
|
@ -58,16 +58,28 @@ class RequestView(View):
|
||||||
return json_response(error=error)
|
return json_response(error=error)
|
||||||
|
|
||||||
|
|
||||||
def do_deploy(request, r_id):
|
class RequestDetailView(View):
|
||||||
req = DeployRequest.objects.filter(pk=r_id).first()
|
def get(self, request, r_id):
|
||||||
if not req:
|
req = DeployRequest.objects.filter(pk=r_id).first()
|
||||||
return json_response(error='未找到指定发布申请')
|
if not req:
|
||||||
if req.status != '2':
|
return json_response(error='为找到指定发布申请')
|
||||||
return json_response(error='该申请单当前状态还不能执行发布')
|
return json_response({
|
||||||
hosts = Host.objects.filter(id__in=json.loads(req.host_ids))
|
'app_name': req.app.name,
|
||||||
token = uuid.uuid4().hex
|
'env_name': req.app.env.name,
|
||||||
Thread(target=deploy_dispatch, args=(request, req, token)).start()
|
'status': req.status,
|
||||||
outputs = {str(x.id): {'data': ''} for x in hosts}
|
'status_alias': req.get_status_display()
|
||||||
outputs.update(local={'data': f'{human_time()} 建立接连... '})
|
})
|
||||||
targets = [{'id': x.id, 'title': f'{x.name}({x.hostname}:{x.port})'} for x in hosts]
|
|
||||||
return json_response({'token': token, 'outputs': outputs, 'targets': targets})
|
def post(self, request, r_id):
|
||||||
|
req = DeployRequest.objects.filter(pk=r_id).first()
|
||||||
|
if not req:
|
||||||
|
return json_response(error='未找到指定发布申请')
|
||||||
|
if req.status != '2':
|
||||||
|
return json_response(error='该申请单当前状态还不能执行发布')
|
||||||
|
hosts = Host.objects.filter(id__in=json.loads(req.host_ids))
|
||||||
|
token = uuid.uuid4().hex
|
||||||
|
Thread(target=deploy_dispatch, args=(request, req, token)).start()
|
||||||
|
outputs = {str(x.id): {'data': ''} for x in hosts}
|
||||||
|
outputs.update(local={'data': f'{human_time()} 建立接连... '})
|
||||||
|
targets = [{'id': x.id, 'title': f'{x.name}({x.hostname}:{x.port})'} for x in hosts]
|
||||||
|
return json_response({'token': token, 'outputs': outputs, 'targets': targets})
|
||||||
|
|
Loading…
Reference in New Issue