Skip to content

Commit

Permalink
Batch: use specified network IP address (#6095)
Browse files Browse the repository at this point in the history
  • Loading branch information
d4l3k committed Mar 20, 2023
1 parent fedac8c commit 293c6c7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions moto/batch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,9 @@ def run(self) -> None:
else {}
)

network_mode = settings.moto_network_mode()
network_name = settings.moto_network_name()

for kwargs in container_kwargs:
environment = kwargs["environment"]
environment["MOTO_HOST"] = settings.moto_server_host()
Expand All @@ -732,8 +735,6 @@ def run(self) -> None:
"MOTO_HTTP_ENDPOINT"
] = f'{environment["MOTO_HOST"]}:{environment["MOTO_PORT"]}'

network_name = settings.moto_network_name()
network_mode = settings.moto_network_mode()
if network_name:
kwargs["network"] = network_name
elif network_mode:
Expand All @@ -753,7 +754,12 @@ def run(self) -> None:
for kwargs in container_kwargs:
if len(containers) > 0:
env = kwargs["environment"]
ip = containers[0].attrs["NetworkSettings"]["IPAddress"]
network_settings = containers[0].attrs["NetworkSettings"]
networks = network_settings["Networks"]
if network_name in networks:
ip = networks[network_name]["IPAddress"]
else:
ip = network_settings["IPAddress"]
env["AWS_BATCH_JOB_MAIN_NODE_PRIVATE_IPV4_ADDRESS"] = ip
container = self.docker_client.containers.run(
detach=True,
Expand Down

0 comments on commit 293c6c7

Please sign in to comment.