Сделать патч DHCP leases устойчивым к изменённому app.py
Этот коммит содержится в:
@@ -47,11 +47,21 @@ def dhcp_leases_hint(info: dict[str, Any], leases: list[dict[str, str]]) -> str:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
if 'def parse_dhcp_leases_output(' not in text:
|
if 'def parse_dhcp_leases_output(' not in text:
|
||||||
marker = '\n\ndef list_libvirt_networks() -> list[dict[str, str]]:'
|
markers = [
|
||||||
if marker not in text:
|
'\n\ndef libvirt_network_info() -> dict[str, Any]:',
|
||||||
raise SystemExit('list_libvirt_networks marker not found')
|
'\n\ndef network_context() -> dict[str, Any]:',
|
||||||
text = text.replace(marker, helpers + marker, 1)
|
'\n\ndef parse_virsh_list() -> list[dict[str, str]]:',
|
||||||
changed.append('DHCP leases parser added')
|
]
|
||||||
|
inserted = False
|
||||||
|
for marker in markers:
|
||||||
|
if marker in text:
|
||||||
|
text = text.replace(marker, helpers + marker, 1)
|
||||||
|
inserted = True
|
||||||
|
changed.append('DHCP leases parser added')
|
||||||
|
break
|
||||||
|
if not inserted:
|
||||||
|
print('WARN: DHCP helper marker not found, skip helper injection')
|
||||||
|
changed.append('DHCP leases parser skipped')
|
||||||
else:
|
else:
|
||||||
changed.append('DHCP leases parser already present')
|
changed.append('DHCP leases parser already present')
|
||||||
|
|
||||||
@@ -73,7 +83,7 @@ new_info = '''def libvirt_network_info() -> dict[str, Any]:
|
|||||||
info = run_cmd(['virsh', 'net-info', NETWORK_NAME], timeout=8)
|
info = run_cmd(['virsh', 'net-info', NETWORK_NAME], timeout=8)
|
||||||
leases = run_cmd(['virsh', 'net-dhcp-leases', NETWORK_NAME], timeout=8)
|
leases = run_cmd(['virsh', 'net-dhcp-leases', NETWORK_NAME], timeout=8)
|
||||||
leases_text = leases['stdout'] if leases['ok'] else leases['stderr']
|
leases_text = leases['stdout'] if leases['ok'] else leases['stderr']
|
||||||
lease_rows = parse_dhcp_leases_output(leases['stdout'] if leases['ok'] else '')
|
lease_rows = parse_dhcp_leases_output(leases['stdout'] if leases['ok'] else '') if 'parse_dhcp_leases_output' in globals() else []
|
||||||
data = {
|
data = {
|
||||||
'name': NETWORK_NAME,
|
'name': NETWORK_NAME,
|
||||||
'bridge': NAT_BRIDGE,
|
'bridge': NAT_BRIDGE,
|
||||||
@@ -87,7 +97,7 @@ new_info = '''def libvirt_network_info() -> dict[str, Any]:
|
|||||||
'lease_count': len(lease_rows),
|
'lease_count': len(lease_rows),
|
||||||
'lease_hint': '',
|
'lease_hint': '',
|
||||||
}
|
}
|
||||||
data['lease_hint'] = dhcp_leases_hint(data, lease_rows)
|
data['lease_hint'] = dhcp_leases_hint(data, lease_rows) if 'dhcp_leases_hint' in globals() else 'DHCP leases пусты.'
|
||||||
return data
|
return data
|
||||||
'''
|
'''
|
||||||
if old_info in text:
|
if old_info in text:
|
||||||
@@ -96,7 +106,8 @@ if old_info in text:
|
|||||||
elif "'lease_rows':" in text:
|
elif "'lease_rows':" in text:
|
||||||
changed.append('libvirt network info already enriched')
|
changed.append('libvirt network info already enriched')
|
||||||
else:
|
else:
|
||||||
raise SystemExit('libvirt_network_info marker not found')
|
print('WARN: libvirt_network_info marker not found, skip function rewrite')
|
||||||
|
changed.append('libvirt network info rewrite skipped')
|
||||||
|
|
||||||
app_path.write_text(text)
|
app_path.write_text(text)
|
||||||
|
|
||||||
@@ -145,7 +156,8 @@ if old_html in html:
|
|||||||
elif 'ctx.nat.lease_rows' in html:
|
elif 'ctx.nat.lease_rows' in html:
|
||||||
changed.append('DHCP leases UI already updated')
|
changed.append('DHCP leases UI already updated')
|
||||||
else:
|
else:
|
||||||
raise SystemExit('DHCP leases template marker not found')
|
print('WARN: DHCP leases template marker not found, skip UI rewrite')
|
||||||
|
changed.append('DHCP leases UI rewrite skipped')
|
||||||
|
|
||||||
template_path.write_text(html)
|
template_path.write_text(html)
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user