云RDS支持自定义IP端口

pull/46/head
starsliao 2 years ago
parent 5731198dba
commit 3d60889668

@ -7,7 +7,7 @@ skey_path = 'ConsulManager/assets/secret/skey'
if consul_kv.get_kv_dict(skey_path) == {}:
consul_kv.put_kv(skey_path,{'sk':''.join(str(uuid.uuid4()).split('-'))})
from views import login, blackbox, consul, jobs, nodes, selfnode, selfrds, avd, exp, jms, edit_cloud, ldap
from views import login, blackbox, consul, jobs, nodes, selfnode, selfrds, avd, exp, jms, edit_cloud, ldap, rds
from views.prom import cloud_mysql_metrics
from units.cloud import huaweicloud,alicloud,tencent_cloud
from units.avd import avd_list
@ -30,7 +30,7 @@ app.register_blueprint(jms.blueprint)
app.register_blueprint(edit_cloud.blueprint)
app.register_blueprint(cloud_mysql_metrics.blueprint)
app.register_blueprint(ldap.blueprint)
app.register_blueprint(rds.blueprint)
class Config(object):
JOBS = []
SCHEDULER_API_ENABLED = True

@ -34,10 +34,6 @@ class Nodes(Resource):
jobecs = consul_kv.get_keys_list('ConsulManager/jobs')
jobecs_list = [i.split('/jobs/')[1] for i in jobecs if '/ecs/' in i]
return {'code': 20000,'jobecs':jobecs_list}
elif stype == 'jobrds':
jobrds = consul_kv.get_keys_list('ConsulManager/jobs')
jobrds_list = [i.split('/jobs/')[1] for i in jobrds if '/rds/' in i]
return {'code': 20000,'jobrds':jobrds_list}
elif stype == 'ecs_services':
jobecs = consul_kv.get_keys_list('ConsulManager/jobs')
jobecs_list = [i.split('/jobs/')[1] for i in jobecs if '/ecs/' in i]
@ -46,18 +42,8 @@ class Nodes(Resource):
serivces = i.split("/")
services_list.append(f'{serivces[0]}_{serivces[1]}_{serivces[2]}')
return {'code': 20000,'services_list': sorted(set(services_list))}
elif stype == 'rds_services':
jobecs = consul_kv.get_keys_list('ConsulManager/jobs')
jobecs_list = [i.split('/jobs/')[1] for i in jobecs if '/rds/' in i]
services_list = []
for i in jobecs_list:
serivces = i.split("/")
services_list.append(f'{serivces[0]}_{serivces[1]}_{serivces[2]}')
return {'code': 20000,'services_list': sorted(set(services_list))}
elif stype == 'rules':
return gen_config.get_rules()
elif stype == 'rdsrules':
return gen_config.get_rdsrules()
elif stype == 'cstecsconf':
args = parser.parse_args()
iid = args['iid']
@ -86,10 +72,6 @@ class Nodes(Resource):
args = parser.parse_args()
services_dict = args['services_dict']
return gen_config.ecs_config(services_dict['services_list'],services_dict['ostype_list'])
elif stype == 'rdspconfig':
args = parser.parse_args()
services_dict = args['services_dict']
return gen_config.rds_config(services_dict['jobrds_list'],services_dict['cm_exporter'],services_dict['services_list'],services_dict['exporter'])
elif stype == 'cstecs':
args = parser.parse_args()
cst_ecs_dict = args['cst_ecs_dict']

@ -0,0 +1,92 @@
from flask import Blueprint
from flask_restful import reqparse, Resource, Api
from flask_apscheduler import APScheduler
#import sys
#sys.path.append("..")
from units import token_auth,consul_kv,gen_config,consul_svc
blueprint = Blueprint('rds',__name__)
api = Api(blueprint)
parser = reqparse.RequestParser()
parser.add_argument('job_id',type=str)
parser.add_argument('services_dict',type=dict)
parser.add_argument('cst_rds_dict',type=dict)
parser.add_argument('iid',type=str)
parser.add_argument('jobrds_name',type=str)
parser.add_argument('checked',type=str)
class Rds(Resource):
decorators = [token_auth.auth.login_required]
def get(self, stype):
job_id = parser.parse_args()['job_id']
if stype == 'jobrds':
jobrds = consul_kv.get_keys_list('ConsulManager/jobs')
jobrds_list = [i.split('/jobs/')[1] for i in jobrds if '/rds/' in i]
return {'code': 20000,'jobrds':jobrds_list}
elif stype == 'rds_services':
jobecs = consul_kv.get_keys_list('ConsulManager/jobs')
jobecs_list = [i.split('/jobs/')[1] for i in jobecs if '/rds/' in i]
services_list = []
for i in jobecs_list:
serivces = i.split("/")
services_list.append(f'{serivces[0]}_{serivces[1]}_{serivces[2]}')
return {'code': 20000,'services_list': sorted(set(services_list))}
elif stype == 'rdsrules':
return gen_config.get_rdsrules()
elif stype == 'cstrdsconf':
args = parser.parse_args()
iid = args['iid']
cst_rds_config = consul_kv.get_value(f'ConsulManager/assets/sync_rds_custom/{iid}')
cst_rds_config.update({'iid': iid,'ipswitch': False,'portswitch': False})
if 'ip' in cst_rds_config and cst_rds_config['ip'] != '':
cst_rds_config['ipswitch'] = True
if 'port' in cst_rds_config and cst_rds_config['port'] != '':
cst_rds_config['portswitch'] = True
return {'code': 20000, 'cst_rds': cst_rds_config}
elif stype == 'cstrdslist':
args = parser.parse_args()
jobrds_name = args['jobrds_name']
checked = args['checked']
cst_rds_dict = consul_kv.get_kv_dict('ConsulManager/assets/sync_rds_custom/')
cst_rds_keylist = [k.split('/')[-1] for k,v in cst_rds_dict.items() if v != {}]
rds_info = consul_kv.get_res_services(jobrds_name)
if checked == 'false':
return rds_info
else:
cst_rds_list = [i for i in rds_info['res_list'] if i['iid'] in cst_rds_keylist]
return {'code': 20000, 'res_list': cst_rds_list}
def post(self, stype):
if stype == 'rdspconfig':
args = parser.parse_args()
services_dict = args['services_dict']
return gen_config.rds_config(services_dict['jobrds_list'],services_dict['cm_exporter'],services_dict['services_list'],services_dict['exporter'])
elif stype == 'cstrds':
args = parser.parse_args()
cst_rds_dict = args['cst_rds_dict']
consul_rds_cst = {}
iid = cst_rds_dict['iid']
try:
sid_dict = consul_svc.get_sid(iid)['instance']
if cst_rds_dict['portswitch'] and cst_rds_dict['port'] != '':
consul_rds_cst['port'] = int(cst_rds_dict['port'])
sid_dict['Port'] = consul_rds_cst['port']
if cst_rds_dict['ipswitch'] and cst_rds_dict['ip'] != '':
consul_rds_cst['ip'] = cst_rds_dict['ip']
sid_dict['Address'] = consul_rds_cst['ip']
consul_kv.put_kv(f'ConsulManager/assets/sync_rds_custom/{iid}',consul_rds_cst)
del sid_dict['Weights']
del sid_dict['ContentHash']
del sid_dict['Datacenter']
sid_dict['name'] = sid_dict.pop('Service')
sid_dict['Meta']['instance'] = f"{sid_dict['Address']}:{sid_dict['Port']}"
sid_dict["check"] = { "tcp": sid_dict['Meta']['instance'],"interval": "60s" }
consul_svc.del_sid(iid)
consul_svc.add_sid(sid_dict)
return {'code': 20000, 'data': '自定义实例信息修改成功!'}
except Exception as e:
print(e,flush=True)
return {'code': 50000, "data": '提交自定义实例信息格式错误!'}
api.add_resource(Rds, '/api/rds/<stype>')

@ -40,13 +40,6 @@ export function getResList(job_id) {
})
}
export function getJobRds() {
return request({
url: '/api/nodes/jobrds',
method: 'get'
})
}
export function getJobEcs() {
return request({
url: '/api/nodes/jobecs',
@ -59,26 +52,6 @@ export function getServicesList() {
method: 'get'
})
}
export function getRdsServicesList() {
return request({
url: '/api/nodes/rds_services',
method: 'get'
})
}
export function getRdsConfig(services_dict) {
return request({
url: '/api/nodes/rdspconfig',
method: 'post',
data: { services_dict }
})
}
export function getRdsRules() {
return request({
url: '/api/nodes/rdsrules',
method: 'get'
})
}
export function getConfig(services_dict) {
return request({
url: '/api/nodes/config',

@ -0,0 +1,61 @@
import request from '@/utils/request-ops'
export function getResList(job_id) {
return request({
url: '/api/nodes/res',
method: 'get',
params: { job_id }
})
}
export function getJobRds() {
return request({
url: '/api/rds/jobrds',
method: 'get'
})
}
export function getRdsServicesList() {
return request({
url: '/api/rds/rds_services',
method: 'get'
})
}
export function getRdsConfig(services_dict) {
return request({
url: '/api/rds/rdspconfig',
method: 'post',
data: { services_dict }
})
}
export function getRdsRules() {
return request({
url: '/api/rds/rdsrules',
method: 'get'
})
}
export function postCstRds(cst_rds_dict) {
return request({
url: '/api/rds/cstrds',
method: 'post',
data: { cst_rds_dict }
})
}
export function getCstRdsConfig(iid) {
return request({
url: '/api/rds/cstrdsconf',
method: 'get',
params: { iid }
})
}
export function getCstRdsList(jobrds_name, checked) {
return request({
url: '/api/rds/cstrdslist',
method: 'get',
params: { jobrds_name, checked }
})
}

@ -28,7 +28,7 @@
<el-form-item style="text-align: center">
<el-button type="primary" @click="submitForm('ruleForm')"></el-button>
<!-- <el-button @click="resetForm('ruleForm')"></el-button> -->
<el-button type="danger" @click="delForm()">DLAP</el-button>
<el-button type="danger" @click="delForm()">LDAP</el-button>
</el-form-item>
</el-form>
</el-tab-pane>

@ -3,12 +3,38 @@
<el-select v-model="jobrds_name" placeholder="请选择需要查询的云MySQL列表" filterable collapse-tags clearable style="width: 350px" class="filter-item" @change="fetchRds(jobrds_name)">
<el-option v-for="item in jobrds_list" :key="item" :label="item" :value="item" />
</el-select>
<el-checkbox v-model="checked" style="margin-left: 10px;" label="仅显示修改过的" border @change="cstRdsList(jobrds_name,checked)" />
<el-tooltip class="item" effect="light" content="刷新当前RDS列表" placement="top">
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-refresh" circle @click="fetchRds(jobrds_name)" />
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-refresh" circle @click="fetchEcs(jobrds_name)" />
</el-tooltip>
<div style="float: right;margin-left: 10px;">
<el-input v-model="iname" prefix-icon="el-icon-search" placeholder="请输入名称、实例或实例ID进行筛选" clearable style="width: 300px" class="filter-item" />
</div>
<el-dialog title="自定义实例信息" :visible.sync="dialogFormVisible" width="45%">
<el-form ref="dataForm" :model="cst_rds" label-position="right" label-width="auto" style="width: 90%; margin-left: 20px;">
<el-form-item label="自定义端口">
<el-switch v-model="cst_rds.portswitch" />
</el-form-item>
<el-form-item v-if="cst_rds.portswitch" required label="端口:">
<el-input v-model="cst_rds.port" />
</el-form-item>
<el-form-item label="自定义IP">
<el-switch v-model="cst_rds.ipswitch" />
</el-form-item>
<el-form-item v-if="cst_rds.ipswitch" required label="IP">
<el-input v-model="cst_rds.ip" />
</el-form-item>
<font size="3px" color="#ff0000">如需恢复同步该实例的IP端口信息请关闭开启的自定义选项后再同步一次所属数据源</font>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">
取消
</el-button>
<el-button type="primary" @click="createData">
确认
</el-button>
</div>
</el-dialog>
<el-table
v-loading="listLoading"
@ -37,12 +63,19 @@
<el-table-column prop="disk" label="磁盘" sortable align="center" width="80" />
<el-table-column prop="exp" label="到期日" sortable align="center" width="120" />
<el-table-column prop="iid" label="实例ID" sortable align="center" />
<el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
<template slot-scope="{row}">
<el-button type="primary" size="mini" @click="handleUpdate(row.iid)">
自定义实例
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
import { getResList, getJobRds } from '@/api/node-exporter'
import { getResList, getJobRds, postCstRds, getCstRdsConfig, getCstRdsList } from '@/api/rds'
export default {
data() {
return {
@ -52,7 +85,8 @@ export default {
jobrds_name: '',
iname: '',
jobrds_list: [],
rds_list: []
rds_list: [],
cst_rds: { iid: '', portswitch: false, ipswitch: false, port: '', ip: '' }
}
},
created() {
@ -72,6 +106,37 @@ export default {
}
},
methods: {
cstRdsList(jobrds_name, checked) {
this.listLoading = true
getCstRdsList(jobrds_name, checked).then(response => {
this.rds_list = response.res_list
this.listLoading = false
})
},
handleUpdate(iid) {
this.listLoading = true
this.dialogFormVisible = true
getCstRdsConfig(iid).then(response => {
this.cst_rds = response.cst_rds
this.listLoading = false
this.dialogFormVisible = true
})
},
createData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.dialogFormVisible = false
this.listLoading = true
postCstRds(this.cst_rds).then(response => {
this.fetchRds(this.jobrds_name)
this.$message({
message: response.data,
type: 'success'
})
})
}
})
},
fetchJobRds() {
getJobRds().then(response => {
this.jobrds_list = response.jobrds

@ -19,7 +19,7 @@
</template>
<script>
import { getRdsServicesList, getRdsConfig, getJobRds } from '@/api/node-exporter'
import { getRdsServicesList, getRdsConfig, getJobRds } from '@/api/rds'
export default {
data() {
return {

@ -8,7 +8,7 @@
</template>
<script>
import { getRdsRules } from '@/api/node-exporter'
import { getRdsRules } from '@/api/rds'
export default {
data() {
return {

Loading…
Cancel
Save