Skip to content

Commit

Permalink
chore: clean up redundant default_net
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Jul 31, 2024
1 parent e0b3a1e commit f13b657
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,14 +851,12 @@ async def assert_cnt_nets(compose, cnt):
net = cnt.get("network_mode", None)
if net and not net.startswith("bridge"):
return
nets = compose.networks
default_net = compose.default_net
cnt_nets = cnt.get("networks", None)
if cnt_nets and is_dict(cnt_nets):
cnt_nets = list(cnt_nets.keys())
cnt_nets = norm_as_list(cnt_nets or default_net)
cnt_nets = norm_as_list(cnt_nets or compose.default_net)
for net in cnt_nets:
net_desc = nets[net] or {}
net_desc = compose.networks[net] or {}
is_ext = net_desc.get("external", None)
ext_desc = is_ext if is_dict(is_ext) else {}
default_net_name = default_network_name_for_project(compose, net, is_ext)
Expand Down Expand Up @@ -907,8 +905,6 @@ def get_net_args(compose, cnt):
sys.exit(1)
else:
is_bridge = True
default_net = compose.default_net
nets = compose.networks
cnt_nets = cnt.get("networks", None)

aliases = [service_name]
Expand Down Expand Up @@ -944,10 +940,10 @@ def get_net_args(compose, cnt):
# sort dict by priority
prioritized_cnt_nets.sort(reverse=True)
cnt_nets = [net_key for _, net_key in prioritized_cnt_nets]
cnt_nets = norm_as_list(cnt_nets or default_net)
cnt_nets = norm_as_list(cnt_nets or compose.default_net)
net_names = []
for net in cnt_nets:
net_desc = nets[net] or {}
net_desc = compose.networks[net] or {}
is_ext = net_desc.get("external", None)
ext_desc = is_ext if is_dict(is_ext) else {}
default_net_name = default_network_name_for_project(compose, net, is_ext)
Expand Down Expand Up @@ -983,7 +979,7 @@ def get_net_args(compose, cnt):
)

for net_, net_config_ in multiple_nets.items():
net_desc = nets[net_] or {}
net_desc = compose.networks[net_] or {}
is_ext = net_desc.get("external", None)
ext_desc = is_ext if is_dict(is_ext) else {}
default_net_name = default_network_name_for_project(compose, net_, is_ext)
Expand Down Expand Up @@ -1921,10 +1917,9 @@ def _parse_compose_file(self):
self.default_net = "default"
else:
self.default_net = None
default_net = self.default_net
allnets = set()
for name, srv in services.items():
srv_nets = srv.get("networks", None) or default_net
srv_nets = srv.get("networks", None) or self.default_net
srv_nets = list(srv_nets.keys()) if is_dict(srv_nets) else norm_as_list(srv_nets)
allnets.update(srv_nets)
given_nets = set(nets.keys())
Expand Down

0 comments on commit f13b657

Please sign in to comment.