v8.0: Refactor slave routes and clean up redundant code

Removed unused variable `req_method` and refactored URL assignment logic in `ha.js` for clarity. Updated route in `routes.py` to use defaults for `vip_id` and adjusted method checks accordingly. Removed unnecessary print statement in `ha_cluster.py`.
pull/399/head
Aidaho 2024-08-28 15:10:39 +03:00
parent 3ca7ca86a1
commit a0866b9e88
3 changed files with 8 additions and 7 deletions

View File

@ -144,7 +144,6 @@ def update_vip(cluster_id: int, router_id: int, cluster: Union[HAClusterRequest,
s = server_sql.get_server_by_id(value['id'])
raise Exception(f'error: Cannot add server {s.hostname}: {e}')
print('cluster.virt_server',cluster.virt_server)
if cluster.virt_server:
add_or_update_virt(cluster, servers, cluster_id, vip_id, group_id)
else:

View File

@ -112,12 +112,13 @@ def show_ha_cluster(service, cluster_id):
return render_template('service.html', **kwargs)
@bp.route('/<service>/slaves/<int:cluster_id>/<int:vip_id>', methods=['GET', 'POST'])
@bp.route('/<service>/slaves/<int:cluster_id>', defaults={'vip_id': False}, methods=['GET'])
@bp.route('/<service>/slaves/<int:cluster_id>/<int:vip_id>', methods=['GET'])
@check_services
@get_user_params()
def get_slaves(service, cluster_id, vip_id):
lang = g.user_params['lang']
if request.method == 'GET':
if not vip_id:
router_id = ha_sql.get_router_id(cluster_id, default_router=1)
else:
vip = ha_sql.select_cluster_vip_by_vip_id(cluster_id, vip_id)

View File

@ -507,7 +507,6 @@ function add_vip_ha_cluster(cluster_id, cluster_name, vip_id='', vip='', edited=
let save_word = translate_div.attr('data-save');
let tabel_title = $("#add-vip-table").attr('title');
let buttons = [];
let req_method = 'GET';
if (edited) {
$.ajax({
url: api_prefix + "/ha/cluster/" + cluster_id + "/vip/" + vip_id,
@ -534,7 +533,6 @@ function add_vip_ha_cluster(cluster_id, cluster_name, vip_id='', vip='', edited=
}
});
$('#vrrp-ip-add').val(vip);
req_method = 'POST';
tabel_title = $("#add-vip-table").attr('data-edit');
buttons = [{
text: save_word,
@ -593,9 +591,12 @@ function add_vip_ha_cluster(cluster_id, cluster_name, vip_id='', vip='', edited=
}
}]
}
let url = "/ha/cluster/slaves/" + cluster_id;
if (vip_id) {
url = "/ha/cluster/slaves/" + cluster_id + "/" + vip_id;
}
$.ajax({
url: "/ha/cluster/slaves/" + cluster_id + "/" + vip_id,
type: req_method,
url: url,
success: function (data) {
if (data.indexOf('error:') != '-1') {
toastr.error(data);