mirror of https://github.com/openspug/spug
U - 主机管理 - 批量执行选择主机,选择模版添加搜索条件。
parent
fc07efabf3
commit
6979e523f1
|
@ -19,17 +19,19 @@ blueprint = Blueprint(__name__, __name__)
|
||||||
def get():
|
def get():
|
||||||
form, error = JsonParser(Argument('page', type=int, default=1, required=False),
|
form, error = JsonParser(Argument('page', type=int, default=1, required=False),
|
||||||
Argument('pagesize', type=int, default=10, required=False),
|
Argument('pagesize', type=int, default=10, required=False),
|
||||||
Argument('host_zone', type=str, required=False),).parse(request.args)
|
Argument('host_query', type=dict, required=False), ).parse(request.args)
|
||||||
if error is None:
|
if error is None:
|
||||||
|
print('host_ng', form)
|
||||||
|
host_data = Host.query
|
||||||
if form.page == -1:
|
if form.page == -1:
|
||||||
hosts_data = Host.query.all()
|
return json_response({'data': [x.to_json() for x in host_data.all()], 'total': -1})
|
||||||
return json_response({'data': [x.to_json() for x in hosts_data], 'total': -1})
|
if form.host_query.get('name_field'):
|
||||||
elif form.host_zone:
|
host_data = host_data.filter(Host.name.like('%{}%'.format(form.host_query['name_field'])))
|
||||||
hosts = Host.query.filter_by(zone=form.host_zone)
|
if form.host_query.get('zone_field'):
|
||||||
else:
|
host_data = host_data.filter_by(zone=form.host_query['zone_field'])
|
||||||
hosts = Host.query
|
|
||||||
hosts_data = hosts.limit(form.pagesize).offset((form.page - 1) * form.pagesize).all()
|
result = host_data.limit(form.pagesize).offset((form.page - 1) * form.pagesize).all()
|
||||||
return json_response({'data': [x.to_json() for x in hosts_data], 'total': hosts.count()})
|
return json_response({'data': [x.to_json() for x in result], 'total': host_data.count()})
|
||||||
return json_response(message=error)
|
return json_response(message=error)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="8">
|
<el-col :span="16">
|
||||||
<el-select v-model="host_zone" @change="zone_Search()" clearable placeholder="区域">
|
<el-form :inline="true" :model="host_query">
|
||||||
<el-option v-for="item in zone_options" :key="item" :value="item"></el-option>
|
<el-form-item>
|
||||||
</el-select>
|
<el-input v-model="host_query.name_field" clearable placeholder="主机名称"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-select v-model="host_query.zone_field" @change="zone_Search()" clearable placeholder="区域">
|
||||||
|
<el-option v-for="item in zone_options" :key="item" :value="item"></el-option>
|
||||||
|
</el-select>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="search" @click="fetch()">查询</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="8" :offset="8" style="text-align: right">
|
<el-col :span="8" style="text-align: right">
|
||||||
<el-button @click="refresh()">刷新</el-button>
|
<el-button @click="refresh()">刷新</el-button>
|
||||||
<el-button v-if="has_permission('assets_host_add')" type="primary" @click="handleAdd">添加主机</el-button>
|
<el-button v-if="has_permission('assets_host_add')" type="primary" @click="handleAdd">添加主机</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
@ -58,7 +65,7 @@
|
||||||
</el-pagination>
|
</el-pagination>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-dialog :title="title" :visible.sync="dialogVisible" :close-on-click-modal="false">
|
<el-dialog :title="title" :visible.sync="dialogVisible" width="80%" :close-on-click-modal="false">
|
||||||
<el-tabs v-model="activeName" >
|
<el-tabs v-model="activeName" >
|
||||||
<el-tab-pane label="单条记录" name="first">
|
<el-tab-pane label="单条记录" name="first">
|
||||||
<el-form :model="form" label-width="80px">
|
<el-form :model="form" label-width="80px">
|
||||||
|
@ -130,6 +137,10 @@
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
host_zone: '',
|
host_zone: '',
|
||||||
|
host_query: {
|
||||||
|
name_field: '',
|
||||||
|
zone_field: '',
|
||||||
|
},
|
||||||
dialogVisible: false,
|
dialogVisible: false,
|
||||||
btnSaveLoading: false,
|
btnSaveLoading: false,
|
||||||
btnDelLoading: {},
|
btnDelLoading: {},
|
||||||
|
@ -177,7 +188,7 @@
|
||||||
if (!page) page = 1;
|
if (!page) page = 1;
|
||||||
this.tableLoading = true;
|
this.tableLoading = true;
|
||||||
let api_uri = '/api/assets/hosts/';
|
let api_uri = '/api/assets/hosts/';
|
||||||
this.$http.get(api_uri, {params: {page: page, host_zone: this.host_zone}}).then(res => {
|
this.$http.get(api_uri, {params: {page: page, host_query: this.host_query}}).then(res => {
|
||||||
this.hosts = res.result
|
this.hosts = res.result
|
||||||
}, res => this.$layer_message(res.result)).finally(() => this.tableLoading = false)
|
}, res => this.$layer_message(res.result)).finally(() => this.tableLoading = false)
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<el-col :span="16">
|
<el-col :span="16">
|
||||||
<el-form :inline="true" :model="tpl_query">
|
<el-form :inline="true" :model="tpl_query">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-input v-model="tpl_query.name_field" placeholder="请输入模板名称"></el-input>
|
<el-input v-model="tpl_query.name_field" clearable placeholder="请输入模板名称"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-select v-model="tpl_query.type_field" placeholder="模板类型" clearable>
|
<el-select v-model="tpl_query.type_field" placeholder="模板类型" clearable>
|
||||||
<el-option v-for="v in tpl_options" :value="v" :key="v"></el-option>
|
<el-option v-for="v in tpl_options" :value="v" :key="v"></el-option>
|
||||||
|
@ -64,15 +64,27 @@
|
||||||
</div>
|
</div>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
|
||||||
<el-dialog title="主机列表" :visible.sync="dialog_host_view" :close-on-click-modal="false">
|
<el-dialog title="主机列表" :visible.sync="dialog_host_view" width="80%" :close-on-click-modal="false">
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="8">
|
<el-col :span="16">
|
||||||
<el-select v-model="host_zone" @change="zone_Search()" clearable placeholder="区域">
|
<!--<el-select v-model="host_zone" @change="zone_Search()" clearable placeholder="区域">-->
|
||||||
<el-option v-for="item in zone_options" :key="item" :value="item"></el-option>
|
<!--<el-option v-for="item in zone_options" :key="item" :value="item"></el-option>-->
|
||||||
</el-select>
|
<!--</el-select>-->
|
||||||
|
<el-form :inline="true" :model="host_query">
|
||||||
|
<el-form-item>
|
||||||
|
<el-input v-model="host_query.name_field" clearable placeholder="主机名称"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-select v-model="host_query.zone_field" @change="zone_Search()" clearable placeholder="区域">
|
||||||
|
<el-option v-for="item in zone_options" :key="item" :value="item"></el-option>
|
||||||
|
</el-select>
|
||||||
|
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="search" @click="get_hosts()">查询</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-table :data="hosts.data" ref="multipleTable" @selection-change="handleSelectionChange"
|
<el-table :data="hosts.data" ref="multipleTable" v-loading="hostLoading" @selection-change="handleSelectionChange"
|
||||||
@row-click="handleClickRow" style="width: 100%">
|
@row-click="handleClickRow" style="width: 100%">
|
||||||
<el-table-column type="selection" width="50">
|
<el-table-column type="selection" width="50">
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
@ -81,6 +93,14 @@
|
||||||
<el-table-column prop="type" label="类型"></el-table-column>
|
<el-table-column prop="type" label="类型"></el-table-column>
|
||||||
<el-table-column prop="ssh_ip" label="SSH连接"></el-table-column>
|
<el-table-column prop="ssh_ip" label="SSH连接"></el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
<!--主机列表分页-->
|
||||||
|
<div class="pagination-bar" v-if="hosts.total > 10">
|
||||||
|
<el-pagination
|
||||||
|
@current-change="hostCurrentChange"
|
||||||
|
:current-page="hostCurrentPage" layout="total, prev, pager, next"
|
||||||
|
:total="hosts.total">
|
||||||
|
</el-pagination>
|
||||||
|
</div>
|
||||||
<div slot="footer">
|
<div slot="footer">
|
||||||
<el-button @click="dialog_host_view=false">取消</el-button>
|
<el-button @click="dialog_host_view=false">取消</el-button>
|
||||||
<el-button type="primary" @click="save_select_host">确定</el-button>
|
<el-button type="primary" @click="save_select_host">确定</el-button>
|
||||||
|
@ -112,10 +132,13 @@
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
<el-dialog title="执行模板" :visible.sync="dialog_exec_tpl_view" :close-on-click-modal="false">
|
<el-dialog title="执行模板" :visible.sync="dialog_exec_tpl_view" :close-on-click-modal="false" width="80%">
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="16">
|
<el-col :span="16">
|
||||||
<el-form :inline="true" :model="tpl_query">
|
<el-form :inline="true" :model="tpl_query">
|
||||||
|
<el-form-item>
|
||||||
|
<el-input v-model="tpl_query.name_field" clearable placeholder="请输入模板名称"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
<el-select v-model="tpl_query.type_field" placeholder="模板类型">
|
<el-select v-model="tpl_query.type_field" placeholder="模板类型">
|
||||||
<el-option v-for="v in tpl_options" :value="v" :key="v"></el-option>
|
<el-option v-for="v in tpl_options" :value="v" :key="v"></el-option>
|
||||||
|
@ -127,7 +150,8 @@
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-table ref="singleTable" highlight-current-row :data="tpl.data" @current-change="handleSelectChange"
|
<el-table ref="singleTable" highlight-current-row :data="tpl.data"
|
||||||
|
@current-change="handleSelectChange"
|
||||||
v-loading="tableLoading" style="width: 100%; margin-top: 20px">
|
v-loading="tableLoading" style="width: 100%; margin-top: 20px">
|
||||||
<el-table-column prop="tpl_name" label="模板名称"></el-table-column>
|
<el-table-column prop="tpl_name" label="模板名称"></el-table-column>
|
||||||
<el-table-column prop="tpl_type" label="模板类型"></el-table-column>
|
<el-table-column prop="tpl_type" label="模板类型"></el-table-column>
|
||||||
|
@ -169,11 +193,17 @@
|
||||||
hosts: [],
|
hosts: [],
|
||||||
tpl:[],
|
tpl:[],
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
|
hostCurrentPage: 1,
|
||||||
tpl_query: {
|
tpl_query: {
|
||||||
name_field: '',
|
name_field: '',
|
||||||
type_field: '',
|
type_field: '',
|
||||||
},
|
},
|
||||||
|
host_query: {
|
||||||
|
name_field: '',
|
||||||
|
zone_field: '',
|
||||||
|
},
|
||||||
tableLoading: false,
|
tableLoading: false,
|
||||||
|
hostLoading: true,
|
||||||
editLoading:false,
|
editLoading:false,
|
||||||
btnDelLoading: {},
|
btnDelLoading: {},
|
||||||
exec_command: '',
|
exec_command: '',
|
||||||
|
@ -229,12 +259,12 @@
|
||||||
this.$refs.multipleTable.toggleRowSelection(row)
|
this.$refs.multipleTable.toggleRowSelection(row)
|
||||||
},
|
},
|
||||||
get_hosts (page) {
|
get_hosts (page) {
|
||||||
if (!page) page = -1;
|
if (!page) page = 1;
|
||||||
this.tableLoading = true;
|
this.hostLoading = true;
|
||||||
let api_uri = '/api/assets/hosts/';
|
let api_uri = '/api/assets/hosts/';
|
||||||
this.$http.get(api_uri, {params: {page: page, host_zone: this.host_zone}}).then(res => {
|
this.$http.get(api_uri, {params: {page: page, host_query: this.host_query}}).then(res => {
|
||||||
this.hosts = res.result
|
this.hosts = res.result
|
||||||
}, res => this.$layer_message(res.result)).finally(() => this.tableLoading = false)
|
}, res => this.$layer_message(res.result)).finally(() => this.hostLoading = false)
|
||||||
},
|
},
|
||||||
get_tpl (page) {
|
get_tpl (page) {
|
||||||
if (!page) page = 1;
|
if (!page) page = 1;
|
||||||
|
@ -366,6 +396,10 @@
|
||||||
this.currentPage = val;
|
this.currentPage = val;
|
||||||
this.get_tpl(this.currentPage);
|
this.get_tpl(this.currentPage);
|
||||||
},
|
},
|
||||||
|
hostCurrentChange(val) {
|
||||||
|
this.hostCurrentPage = val;
|
||||||
|
this.get_hosts(this.hostCurrentPage);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue