Skip to content

Commit a48cba8

Browse files
committed
T7982: simplifies run arguments into one
1 parent 70e98aa commit a48cba8

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

src/conf_mode/container.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -505,40 +505,43 @@ def generate_run_arguments(name, container_config, host_ident):
505505
if 'arguments' in container_config:
506506
command_arguments = container_config['arguments'].strip()
507507

508+
network = ''
508509
if 'allow_host_networks' in container_config:
509-
return f'{container_base_cmd} {healthcheck} --net host {entrypoint} {image} {command} {command_arguments}'.strip()
510-
511-
ip_param = ''
512-
addr_info = ''
513-
networks = ",".join(container_config['network'])
514-
for network in container_config['network']:
515-
network_name = network
516-
if 'address' not in container_config['network'][network]:
517-
continue
518-
for address in container_config['network'][network]['address']:
519-
if is_ipv6(address):
520-
ip_param += f' --ip6 {address}'
521-
else:
522-
ip_param += f' --ip {address}'
523-
524-
addr_info = ''.join(container_config['network'][network]['address'])
525-
526-
get_mac = dict_search(f'network.{network_name}.mac', container_config)
527-
if get_mac == 'auto' or get_mac is None:
528-
mac_add = gen_mac(name, addr_info, host_ident)
510+
network = '--net host'
529511
else:
530-
mac_add = get_mac
531-
532-
mac_address = f'--mac-address {mac_add}'
533-
534-
# Replace mac-auto with the generated mac address
535-
if get_mac == 'auto':
536-
mac_config_path = ['container', 'name', name, 'network', network_name, 'mac']
537-
538-
delete_cli_node(mac_config_path)
539-
add_cli_node(mac_config_path, value=mac_add)
540-
541-
return f'{container_base_cmd} {healthcheck} --net {networks} {ip_param} {mac_address} {entrypoint} {image} {command} {command_arguments}'.strip()
512+
ip_param = ''
513+
addr_info = ''
514+
networks = ",".join(container_config['network'])
515+
for network in container_config['network']:
516+
network_name = network
517+
if 'address' not in container_config['network'][network]:
518+
continue
519+
for address in container_config['network'][network]['address']:
520+
if is_ipv6(address):
521+
ip_param += f' --ip6 {address}'
522+
else:
523+
ip_param += f' --ip {address}'
524+
525+
addr_info = ''.join(container_config['network'][network]['address'])
526+
527+
get_mac = dict_search(f'network.{network_name}.mac', container_config)
528+
if get_mac == 'auto' or get_mac is None:
529+
mac_add = gen_mac(name, addr_info, host_ident)
530+
else:
531+
mac_add = get_mac
532+
533+
mac_address = f'--mac-address {mac_add}'
534+
535+
# Replace mac-auto with the generated mac address
536+
if get_mac == 'auto':
537+
mac_config_path = ['container', 'name', name, 'network', network_name, 'mac']
538+
539+
delete_cli_node(mac_config_path)
540+
add_cli_node(mac_config_path, value=mac_add)
541+
542+
network = f'--net {networks} {ip_param} {mac_address}'
543+
544+
return f'{container_base_cmd} {healthcheck} {network} {entrypoint} {image} {command} {command_arguments}'.strip()
542545

543546

544547
def generate(container):

0 commit comments

Comments
 (0)