mirror of
https://github.com/containers/podman-compose.git
synced 2025-04-18 06:28:55 +02:00
Merge single and multi network handling in get_net_args_from_networks()
The behavior has not changed, single-network has a special case. Modified-by: Povilas Kanapickas <povilas@radix.lt> Signed-off-by: Songmin Li <lisongmin@protonmail.com>
This commit is contained in:
parent
aa8c6fd598
commit
4a232f5e32
@ -983,7 +983,6 @@ def get_net_args_from_networks(compose, cnt):
|
||||
"is not supported"
|
||||
)
|
||||
|
||||
if len(multiple_nets) > 1:
|
||||
for net_, net_config_ in multiple_nets.items():
|
||||
net_desc = compose.networks[net_] or {}
|
||||
is_ext = net_desc.get("external")
|
||||
@ -1005,6 +1004,15 @@ def get_net_args_from_networks(compose, cnt):
|
||||
mac = mac_address
|
||||
mac_address = None
|
||||
|
||||
if len(multiple_nets) == 1:
|
||||
net_args.append(f"--network={net_name}")
|
||||
if ipv4:
|
||||
net_args.append(f"--ip={ipv4}")
|
||||
if ipv6:
|
||||
net_args.append(f"--ip6={ipv6}")
|
||||
if mac:
|
||||
net_args.append(f"--mac-address={mac}")
|
||||
else:
|
||||
net_options = []
|
||||
if ipv4:
|
||||
net_options.append(f"ip={ipv4}")
|
||||
@ -1017,27 +1025,6 @@ def get_net_args_from_networks(compose, cnt):
|
||||
net_args.append(f"--network={net_name}:" + ",".join(net_options))
|
||||
else:
|
||||
net_args.append(f"--network={net_name}")
|
||||
else:
|
||||
net = list(multiple_nets.keys())[0]
|
||||
net_config = list(multiple_nets.values())[0]
|
||||
|
||||
net_desc = compose.networks[net] or {}
|
||||
is_ext = net_desc.get("external")
|
||||
ext_desc = is_ext if isinstance(is_ext, str) else {}
|
||||
default_net_name = default_network_name_for_project(compose, net, is_ext)
|
||||
net_name = ext_desc.get("name") or net_desc.get("name") or default_net_name
|
||||
net_args.append(f"--network={net_name}")
|
||||
|
||||
ipv4 = net_config.get("ipv4_address")
|
||||
ipv6 = net_config.get("ipv6_address")
|
||||
aliases_on_net = norm_as_list(net_config.get("aliases"))
|
||||
|
||||
if ipv4:
|
||||
net_args.append(f"--ip={ipv4}")
|
||||
if ipv6:
|
||||
net_args.append(f"--ip6={ipv6}")
|
||||
if mac_address:
|
||||
net_args.append(f"--mac-address={mac_address}")
|
||||
|
||||
net_args.extend([f"--network-alias={alias}" for alias in aliases_on_container])
|
||||
net_args.extend([f"--network-alias={alias}" for alias in aliases_on_net])
|
||||
|
Loading…
Reference in New Issue
Block a user