Skip to content

Commit

Permalink
add run sls model
Browse files Browse the repository at this point in the history
  • Loading branch information
honglei5181 committed May 26, 2016
1 parent 24abab3 commit 993f9b0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
26 changes: 15 additions & 11 deletions states_config/views.py
Expand Up @@ -79,7 +79,7 @@ def add_sls(request):
for _b in _businesses:
_b_object = Businesses.objects.get(name=_b.strip())
_h.business.add(_b_object)
_success = "add sls "+ _name + " 0k!"
_success = "add sls "+ _name + " ok!"

else:
_error = "name already exists or too long!"
Expand Down Expand Up @@ -150,16 +150,20 @@ def highstate_result(request):
if request.POST:
sls_name = request.POST.get("sls_name")
host_list = request.POST.getlist("hosts_name")
host_str = ",".join(host_list)
jid = sapi.target_deploy(host_str, sls_name)
jids = "salt-run jobs.lookup_jid " + jid
time.sleep(60)
result = os.popen(jids).read()
if result == "":
result = "Execute time too long, Please see jid:" + jid + " history."
return render(request, 'states_config/highstate_result.html', {'result': result})
else:
return render(request, 'states_config/highstate_result.html', {'result': result})
execute = request.POST.get("execute")
if execute:
host_str = ",".join(host_list)
jid = sapi.target_deploy(host_str, sls_name)
while 1:
jids = "salt-run jobs.lookup_jid " + jid
result = os.popen(jids).read()
if len(result) > 0:
exit
if result == "":
result = "Execute time too long, Please see jid:" + jid + " history."
return render(request, 'states_config/highstate_result.html', {'result': result})
else:
return render(request, 'states_config/highstate_result.html', {'result': result})
return render(request, 'states_config/highstate_result.html')

#@login_required(login_url="/account/login/")
Expand Down
2 changes: 2 additions & 0 deletions templates/groups/manage_group.html
Expand Up @@ -345,6 +345,8 @@ <h4 id="success" class="modal-title">{{ success }}</h4>
var ids=[];
$('input[name="CHKlist"]:checked').each(function(){
var id=$(this).val();
//tr_index = $(this).parent().parent().index()
//td_name = $(this).parent().parent().children("td:eq(2)").text()
ids.push(id);
});
if (ids.length >0)
Expand Down
25 changes: 20 additions & 5 deletions templates/states_config/highstate.html
Expand Up @@ -254,7 +254,7 @@ <h4 id="success" class="modal-title">{{ success }}</h4>
<div class="panel-body">
<div class="dataTable_wrapper">
<label><a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" style="text-decoration:none">Target</a></label>
<form method="post" action="/states_config/highstate_result/" target="iframepage"> <!-- target iframe refresh highstate_result.html -->
<form id="run_sls" method="post" action="/states_config/highstate_result/" target="iframepage"> <!-- target iframe refresh highstate_result.html -->
<div id="collapseOne" class="panel-collapse collapse on">
<div class="panel-body" style="padding:0px">
<table class="table table-striped table-bordered table-hover">
Expand Down Expand Up @@ -320,9 +320,8 @@ <h4 id="success" class="modal-title">{{ success }}</h4>
<td id="informations" style="word-break:break-all;display: none">{{ s.informations }}</td>
<td id="enabled" style="word-break:break-all">{{ s.enabled|lower }}</td>
<td>
<button type="submit" type="button" class="btn btn-outline btn-success btn-xs">Execute</button>
<button type="submit" type="button" class="btn btn-outline btn-primary btn-xs">Test</button>
<button id="update" name="update_button" value="{{ sname }}" type="button" class="btn btn-outline btn-primary btn-xs" >Upload File</button>
<button form="run_sls" id="execute" name="execute" value={{ s.name }} type="submit" type="button" class="btn btn-outline btn-success btn-xs">Execute</button>
<button form="run_sls" id="test" name="test" value={{ s.name }} type="submit" type="submit" class="btn btn-outline btn-primary btn-xs">Test</button>
</td>
</tr>
{% endfor %}
Expand Down Expand Up @@ -447,12 +446,28 @@ <h4 id="success" class="modal-title">{{ success }}</h4>
})
// end modify //


// execute sls //
$('#execute').click(function(){
/*
sls = $(this).parent().parent().children("td:eq(2)").text()
var obj=document.getElementsByName('hosts_name')
var hosts = []
for(var i=0; i<obj.length; i++){
if (obj[i].checked){
var host = obj[i].value
hosts.push(host)
}
}
*/
$('#run_sls').submit();
})

//show success and error modal //
$('#success_modal').modal('show')
$('#error_modal').modal('show')
// end show success and error modal //
});

// select all
function selectAll(group){
var checklist = document.getElementsByClassName(group);
Expand Down

0 comments on commit 993f9b0

Please sign in to comment.