Skip to content

Commit

Permalink
1.新增在线编辑ansible playbook。2.修复tooltip显示bug
Browse files Browse the repository at this point in the history
  • Loading branch information
welliamcao committed Nov 30, 2017
1 parent 08aa1d2 commit d661159
Show file tree
Hide file tree
Showing 9 changed files with 480 additions and 43 deletions.
4 changes: 2 additions & 2 deletions OpsManage/data/DsMySQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ def insert(user,ans_id,ans_name,ans_content,ans_server=None):
ans_id = ans_id,
ans_content = ans_content,
)
except Exception,e:
print e
except Exception, ex:
print ex
return False
1 change: 1 addition & 0 deletions OpsManage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ class Ansible_Playbook(models.Model):
playbook_file = models.FileField(upload_to = './upload/playbook/',verbose_name='剧本路径')
playbook_auth_group = models.SmallIntegerField(verbose_name='授权组',blank=True,null=True)
playbook_auth_user = models.SmallIntegerField(verbose_name='授权用户',blank=True,null=True,)
playbook_type = models.SmallIntegerField(verbose_name='剧本类型',blank=True,null=True,default=0)
class Meta:
db_table = 'opsmanage_ansible_playbook'
permissions = (
Expand Down
2 changes: 1 addition & 1 deletion OpsManage/templates/apps/apps_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h1 class="page-header"><i class="fa fa-align-justify "></i>Ansible剧本列表
{{ds.playbook_uuid}}
</td class="text-center">
<td class="text-center">
{{ds.playbook_desc}}
{{ds.playbook_desc|default:""}}
</td>
<td class="text-center">
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal" onclick="getAnsiblePlayBookFile(this,{{ds.id}})"><i class="fa fa-eye "></i></button>
Expand Down
97 changes: 86 additions & 11 deletions OpsManage/templates/apps/apps_playbook_modf.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1 class="page-header"><i class="fa fa-wrench"></i><code>Ansible Playbook</cod
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-plus"></i> 添加剧本
<i class="fa fa-edit"></i> 修改剧本
</div>
<div class="panel-body">
<div class="row">
Expand All @@ -23,16 +23,22 @@ <h1 class="page-header"><i class="fa fa-wrench"></i><code>Ansible Playbook</cod
<input class="form-control" name="playbook_name" value={{playbook.playbook_name}} required>
<p class="help-block">例如系统初始化</p>
</div>
<!-- <div class="form-group"> -->
<!-- <label>剧本文件</label> -->
<!-- <input type="file" name="playbook_file"> -->
<!-- </div> -->
<div class="form-group">
<label>描述<i class="fa fa-info-circle" data-toggle="tooltip" title="功能描述"></i></label>
<textarea class="form-control" rows="3" name="playbook_desc">{{playbook.playbook_desc}}</textarea>
</div>
{% if playbook.playbook_type == 1 and playbook.playbook_contents %}
<div id="compile-editor">{{playbook.playbook_contents}}</div>
<br>
{% else %}
<div class="form-group">
<label>描述<i class="fa fa-info-circle" data-toggle="tooltip" title="功能描述"></i></label>
<textarea class="form-control" rows="3" name="playbook_desc">{{playbook.playbook_desc}}</textarea>
</div>
{% endif %}

<button type="reset" class="btn btn-default">撤销</button>
{% if playbook.playbook_type == 1 %}
<button type="button" class="btn btn-default" onclick="oBtAnsiblePlaybookOnline(this)">添加</button>
{% else %}
<button type="submit" class="btn btn-default">修改</button>
{% endif %}

</div>
<!-- /.col-lg-6 (nested) -->
Expand Down Expand Up @@ -97,7 +103,7 @@ <h1 class="page-header"><i class="fa fa-wrench"></i><code>Ansible Playbook</cod
<div id="custom_server" class="form-group" style="display:none;">
{% endif %}
<label>勾选目标服务器<i class="fa fa-info-circle" data-toggle="tooltip" title="自定选择服务器"></i></label>
<select multiple class="selectpicker" data-live-search="true" name="playbook_server">
<select multiple class="selectpicker" data-live-search="true" name="playbook_server" id="playbook_server">
{% for ds in serverList %}
{% if ds.count == 1 %}
<option name="playbook_server" value="{{ds.id}}" selected="selected">{{ds.ip}}</option>
Expand Down Expand Up @@ -156,14 +162,83 @@ <h1 class="page-header"><i class="fa fa-wrench"></i><code>Ansible Playbook</cod
</div>

<script type="text/javascript">
$(function () { $("[data-toggle='tooltip']").tooltip(); });
{% if playbook.playbook_type == 1 %}
$(function () {
var editor = ace.edit("compile-editor");
require("ace/ext/old_ie");
var langTools = ace.require("ace/ext/language_tools");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/yaml");
editor.setShowPrintMargin(false);
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});

});


function getMultiple(){
var select = document.getElementById("playbook_server");
var str = [];
for(i=0;i<select.length;i++){
if(select.options[i].selected){
str.push(select[i].value);
}
}
return str;
}


function oBtAnsiblePlaybookOnline(obt) {
var editor = ace.edit("compile-editor");
var contents = editor.getSession().getValue();
var playbook_name = document.getElementsByName("playbook_name")[0].value;
if ( contents.length == 0 || playbook_name.length == 0 ){
window.wxc.xcConfirm("剧本名称或者内容不能为空", window.wxc.xcConfirm.typeEnum.error);
return false;
};
$.ajax({
type: 'POST',
url: '/apps/playbook/online/modf/{{playbook.id}}/',
data: {
"playbook_name":playbook_name,
'server_model':document.getElementById("server_model").value,
"playbook_vars":document.getElementsByName("playbook_auth_user")[0].value,
"playbook_server":getMultiple(),
"playbook_auth_group":document.getElementsByName("playbook_auth_group")[0].value,
'playbook_auth_user':document.getElementsByName("playbook_auth_user")[0].value,
'ansible_service':document.getElementsByName("ansible_service")[0].value,
'ansible_group':document.getElementsByName("ansible_group")[0].value,
"playbook_vars":document.getElementsByName("playbook_vars")[0].value,
"playbook_content":contents
},
success:function(response){
if (response["code"]=="200"){
window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.success);
window.location.reload();
}
else{
window.wxc.xcConfirm("添加失败:" + response["msg"], window.wxc.xcConfirm.typeEnum.error);
};

},
error:function(response){
window.wxc.xcConfirm("添加失败", window.wxc.xcConfirm.typeEnum.error);
},
});
};
{% endif %}
{% if playbook.playbook_vars %}
var songResJson=JSON.parse(document.getElementById('playbook_vars').value);
$("#playbook_vars").text(JSON.stringify(songResJson,null,2));
{% endif %}
{% if errorInfo %}
window.wxc.xcConfirm("{{errorInfo}}", window.wxc.xcConfirm.typeEnum.error);
{% endif %}
$(function () { $("[data-toggle='tooltip']").tooltip(); });


function oBtAnsibleServerl(){
var obj = document.getElementById("server_model");
Expand Down
Loading

0 comments on commit d661159

Please sign in to comment.