v8.0: Refactor HA cluster master selection logic

Remove obsolete HTML template and streamline server selection to use JSON. Enhanced server selection and error handling in AJAX calls, fixed minor syntax issues, and updated various routes for consistency.
pull/399/head
Aidaho 2024-08-28 09:18:38 +03:00
parent 5b71fb257e
commit c54f42f65b
1 changed files with 8 additions and 9 deletions

View File

@ -277,19 +277,18 @@ def add_or_update_virt(cluster: Union[HAClusterRequest, HAClusterVIP], servers:
def _create_or_update_master_slaves_servers(cluster_id: int, servers: dict, router_id: int, create: bool = False) -> None:
for server in servers:
if server['master']:
continue
try:
ha_sql.update_master_server_by_slave_ip(server['id'], server['ip'])
except Exception as e:
raise Exception(f'error: Cannot update master on slave {server["ip"]: {e}}')
for server in servers:
s = server_sql.get_server_by_id(server['id'])
try:
ha_sql.insert_or_update_slave(cluster_id, server['id'], server['eth'], server['master'], router_id)
if create:
s = server_sql.get_server_by_id(server['id'])
roxywi_common.logging(cluster_id, f'New server {s.hostname} has been added to the cluster', keep_history=1,
roxywi=1, service='HA cluster')
except Exception as e:
raise Exception(f'error: Cannot update slave server {server["ip"]}: {e}')
if server['master']:
continue
try:
ha_sql.update_master_server_by_slave_ip(server['id'], s.ip)
except Exception as e:
raise Exception(f'error: Cannot update master on slave {s.hostname: {e}}')