parse out ip from ip field

This commit is contained in:
clore 2024-03-28 21:11:35 +00:00
parent 884c9d8428
commit 90eae3ed7f
1 changed files with 22 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from lib import wireguard
from lib import logging as logging_lib
import shutil
import os
import re
log = logging_lib.log
config = config_module.config
@ -15,7 +16,20 @@ for default_network in config.clore_default_networks:
if "name" in default_network:
default_network_names.append(default_network["name"])
def get_last_ip_occurrence_and_text(input_string):
# Find all occurrences of "--ip" in the string
matches = re.finditer(r'--ip', input_string)
last_occurrence = None
for match in matches:
last_occurrence = match
if last_occurrence:
# Get the text after the last occurrence of "--ip"
text_after_last_ip = input_string[last_occurrence.end():]
return last_occurrence.group(), text_after_last_ip
else:
return None, None
def configure(containers):
valid_containers = []
@ -41,6 +55,13 @@ def configure(containers):
if index < len(custom_entrypoint_state):
ok_custom_entrypoint = custom_entrypoint_state[index]
startup_script_name = f"{container['name']}.sh"
if "ip" in container and len(container["ip"])>6 and type(container["ip"])==str:
if container["ip"][:8] == "; echo '":
last_occurrence, text_after_last_ip = get_last_ip_occurrence_and_text(container["ip"])
if last_occurrence:
container["ip"] = text_after_last_ip.strip().split(' ',1)[0]
else:
del container["ip"]
if "wireguard" in container and "name" in container:
wireguard.generate_config(container)
used_wireguard_configs.append(container["name"])