diff options
| author | Nicolas Vollmar <nvollmar@gmail.com> | 2025-11-01 22:11:24 +0100 |
|---|---|---|
| committer | Nicolas Vollmar <nvollmar@gmail.com> | 2025-11-10 09:10:16 +0100 |
| commit | c3184c404ded2ea5bb385d6184c88dd71025b230 (patch) | |
| tree | 4fc6291d26f5d7afca2f65f38dc9dd96de84041c /src | |
| parent | 70e98aa2ce42eafaf3228ed6de2fc3e67095476f (diff) | |
| download | vyos-1x-c3184c404ded2ea5bb385d6184c88dd71025b230.tar.gz vyos-1x-c3184c404ded2ea5bb385d6184c88dd71025b230.zip | |
T7982: container: generate run arguments once
Diffstat (limited to 'src')
| -rwxr-xr-x | src/conf_mode/container.py | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/src/conf_mode/container.py b/src/conf_mode/container.py index a57a9d054..5583f10af 100755 --- a/src/conf_mode/container.py +++ b/src/conf_mode/container.py @@ -505,40 +505,50 @@ def generate_run_arguments(name, container_config, host_ident): if 'arguments' in container_config: command_arguments = container_config['arguments'].strip() + net = '' if 'allow_host_networks' in container_config: - return f'{container_base_cmd} {healthcheck} --net host {entrypoint} {image} {command} {command_arguments}'.strip() - - ip_param = '' - addr_info = '' - networks = ",".join(container_config['network']) - for network in container_config['network']: - network_name = network - if 'address' not in container_config['network'][network]: - continue - for address in container_config['network'][network]['address']: - if is_ipv6(address): - ip_param += f' --ip6 {address}' - else: - ip_param += f' --ip {address}' + net = '--net host' + else: + ip_param = '' + addr_info = '' + networks = ",".join(container_config['network']) + for network in container_config['network']: + network_name = network + if 'address' not in container_config['network'][network]: + continue + for address in container_config['network'][network]['address']: + if is_ipv6(address): + ip_param += f' --ip6 {address}' + else: + ip_param += f' --ip {address}' - addr_info = ''.join(container_config['network'][network]['address']) + addr_info = ''.join(container_config['network'][network]['address']) - get_mac = dict_search(f'network.{network_name}.mac', container_config) - if get_mac == 'auto' or get_mac is None: - mac_add = gen_mac(name, addr_info, host_ident) - else: - mac_add = get_mac + get_mac = dict_search(f'network.{network_name}.mac', container_config) + if get_mac == 'auto' or get_mac is None: + mac_add = gen_mac(name, addr_info, host_ident) + else: + mac_add = get_mac + + mac_address = f'--mac-address {mac_add}' - mac_address = f'--mac-address {mac_add}' + # Replace mac-auto with the generated mac address + if get_mac == 'auto': + mac_config_path = [ + 'container', + 'name', + name, + 'network', + network_name, + 'mac', + ] - # Replace mac-auto with the generated mac address - if get_mac == 'auto': - mac_config_path = ['container', 'name', name, 'network', network_name, 'mac'] + delete_cli_node(mac_config_path) + add_cli_node(mac_config_path, value=mac_add) - delete_cli_node(mac_config_path) - add_cli_node(mac_config_path, value=mac_add) + net = f'--net {networks} {ip_param} {mac_address}' - return f'{container_base_cmd} {healthcheck} --net {networks} {ip_param} {mac_address} {entrypoint} {image} {command} {command_arguments}'.strip() + return f'{container_base_cmd} {healthcheck} {net} {entrypoint} {image} {command} {command_arguments}'.strip() def generate(container): |
