Skip to content

Commit

Permalink
Merge pull request #128 from lavie/ipv6
Browse files Browse the repository at this point in the history
--ip6 support
  • Loading branch information
lavie authored Jan 29, 2025
2 parents 4463bfe + f4a4b7a commit 0f067ce
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
14 changes: 14 additions & 0 deletions fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,26 @@ sudocker run -d --name runlike_fixture5 \
--link runlike_fixture1 \
runlike_fixture

# Create IPv6 network for testing
sudocker network rm runlike_fixture_ipv6
sudocker network create --ipv6 --subnet=2001:db8::/64 runlike_fixture_ipv6

sudocker run -d --name runlike_fixture6 \
-p 127.0.0.1:602:600/udp \
-p 10.10.0.1:602:600/udp \
runlike_fixture \
bash -c 'bash sleep.sh'

# Create IPv6 network for testing
sudocker network rm runlike_fixture_ipv6
sudocker network create --ipv6 --subnet=2001:db8::/64 runlike_fixture_ipv6

sudocker run -d --name runlike_fixture8 \
--network runlike_fixture_ipv6 \
--ip6 2001:db8::42 \
runlike_fixture \
bash -c 'bash sleep.sh'

sudocker run -d --name runlike_fixture7 \
--rm \
--entrypoint /bin/bash \
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "runlike"
version = "1.5.6"
version = "1.6.0"
description = "Reverse-engineer docker run command line arguments based on running containers"
authors = ["Assaf Lavie <[email protected]>"]
readme = "README.md"
Expand Down
8 changes: 8 additions & 0 deletions runlike/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def parse_macaddress(self):
except Exception:
pass

def parse_ipv6(self):
networks = self.get_container_fact("NetworkSettings.Networks") or {}
for network in networks.values():
if network and network.get("IPAMConfig") and network["IPAMConfig"].get("IPv6Address"):
self.options.append(f"--ip6={network['IPAMConfig']['IPv6Address']}")
break

def parse_ports(self):
ports = self.get_container_fact("NetworkSettings.Ports") or {}
ports.update(self.get_container_fact("HostConfig.PortBindings") or {})
Expand Down Expand Up @@ -265,6 +272,7 @@ def format_cli(self):
self.parse_hostname()
self.parse_user()
self.parse_macaddress()
self.parse_ipv6()
self.parse_pid()
self.parse_cpuset()
self.parse_entrypoint()
Expand Down
8 changes: 6 additions & 2 deletions test_runlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class BaseTest(unittest.TestCase):
@classmethod
def start_runlike(cls, args: List[str]):
runner = CliRunner()
cls.outputs = [""] * 8
for i in range(1, 8):
cls.outputs = [""] * 9
for i in range(1, 9):
result = runner.invoke(cli, args + [f"runlike_fixture{i}"])
assert result.exit_code == 0, "runlike did not finish successfully"
cls.outputs[i] = result.output
Expand Down Expand Up @@ -164,6 +164,10 @@ def test_mac_address(self):
self.expect_substr("--mac-address=6a:00:01:ad:d9:e0", 4)
self.dont_expect_substr("--mac-address", 2)

def test_ipv6(self):
self.expect_substr("--ip6=2001:db8::42", 8)
self.dont_expect_substr("--ip6", 2)

def test_env(self):
val = '''FOO=thing="quoted value with 'spaces' and 'single quotes'"'''
self.expect_substr("""--env=%s""" % pipes.quote(val))
Expand Down

0 comments on commit 0f067ce

Please sign in to comment.