mirror of https://github.com/Aidaho12/haproxy-wi
v8.0: Handle missing system info and refactor server installation
Introduce a custom exception `RoxywiResourceNotFound` to manage cases where system information cannot be found. Refactor the server installation process to use server IDs instead of IPs, improving data consistency and reliability.pull/399/head
parent
a0866b9e88
commit
791cd1ed57
|
@ -112,6 +112,8 @@ def is_system_info(server_id):
|
||||||
def select_os_info(server_id):
|
def select_os_info(server_id):
|
||||||
try:
|
try:
|
||||||
return SystemInfo.get(SystemInfo.server_id == server_id).os_info
|
return SystemInfo.get(SystemInfo.server_id == server_id).os_info
|
||||||
|
except SystemInfo.DoesNotExist:
|
||||||
|
raise RoxywiResourceNotFound
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import app.modules.server.server as server_mod
|
||||||
import app.modules.roxywi.common as roxywi_common
|
import app.modules.roxywi.common as roxywi_common
|
||||||
import app.modules.config.section as section_mod
|
import app.modules.config.section as section_mod
|
||||||
import app.modules.config.common as config_common
|
import app.modules.config.common as config_common
|
||||||
|
from app.modules.roxywi.exception import RoxywiResourceNotFound
|
||||||
|
|
||||||
|
|
||||||
def get_correct_service_name(service: str, server_id: int) -> str:
|
def get_correct_service_name(service: str, server_id: int) -> str:
|
||||||
|
@ -109,6 +110,8 @@ def get_correct_apache_service_name(server_ip=None, server_id=None) -> str:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os_info = server_sql.select_os_info(server_id)
|
os_info = server_sql.select_os_info(server_id)
|
||||||
|
except RoxywiResourceNotFound:
|
||||||
|
raise RoxywiResourceNotFound('Cannot find system information')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f'error: cannot get server info: {e}')
|
raise Exception(f'error: cannot get server info: {e}')
|
||||||
|
|
||||||
|
|
|
@ -178,15 +178,15 @@ def generate_service_inv(json_data: ServiceInstall, installed_service: str) -> o
|
||||||
os.system('ansible-galaxy install nginxinc.nginx,0.24.3 -f --roles-path /var/www/haproxy-wi/app/scripts/ansible/roles/')
|
os.system('ansible-galaxy install nginxinc.nginx,0.24.3 -f --roles-path /var/www/haproxy-wi/app/scripts/ansible/roles/')
|
||||||
|
|
||||||
for v in json_data['servers']:
|
for v in json_data['servers']:
|
||||||
server_ip = v['ip']
|
s = server_sql.get_server_by_id(v['id'])
|
||||||
if installed_service == 'apache':
|
if installed_service == 'apache':
|
||||||
correct_service_name = service_common.get_correct_apache_service_name(server_ip=server_ip, server_id=None)
|
correct_service_name = service_common.get_correct_apache_service_name(server_id=v['id'])
|
||||||
if service_dir == '/etc/httpd' and correct_service_name == 'apache2':
|
if service_dir == '/etc/httpd' and correct_service_name == 'apache2':
|
||||||
service_dir = '/etc/apache2'
|
service_dir = '/etc/apache2'
|
||||||
elif service_dir == '/etc/apache2' and correct_service_name == 'httpd':
|
elif service_dir == '/etc/apache2' and correct_service_name == 'httpd':
|
||||||
service_dir = '/etc/httpd'
|
service_dir = '/etc/httpd'
|
||||||
|
|
||||||
inv['server']['hosts'][server_ip] = {
|
inv['server']['hosts'][s.ip] = {
|
||||||
"STAT_PORT": stats_port,
|
"STAT_PORT": stats_port,
|
||||||
"DOCKER": is_docker,
|
"DOCKER": is_docker,
|
||||||
"STATS_USER": stats_user,
|
"STATS_USER": stats_user,
|
||||||
|
@ -198,7 +198,7 @@ def generate_service_inv(json_data: ServiceInstall, installed_service: str) -> o
|
||||||
"STAT_PAGE": stats_page,
|
"STAT_PAGE": stats_page,
|
||||||
"service": installed_service,
|
"service": installed_service,
|
||||||
}
|
}
|
||||||
server_ips.append(server_ip)
|
server_ips.append(s.ip)
|
||||||
|
|
||||||
return inv, server_ips
|
return inv, server_ips
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue