allow ipv6 addresses in deployment addresses

This commit is contained in:
Jörg Thalheim
2023-11-28 10:01:32 +01:00
parent d033f523b8
commit 303df741e9
2 changed files with 13 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ import shlex
import subprocess import subprocess
import sys import sys
import time import time
import urllib.parse
from contextlib import ExitStack, contextmanager from contextlib import ExitStack, contextmanager
from enum import Enum from enum import Enum
from pathlib import Path from pathlib import Path
@@ -775,11 +776,11 @@ def parse_deployment_address(
for option in maybe_options[1].split("&"): for option in maybe_options[1].split("&"):
k, v = option.split("=") k, v = option.split("=")
options[k] = v options[k] = v
maybe_port = hostname.split(":") result = urllib.parse.urlsplit("//" + hostname)
port = None if not result.hostname:
if len(maybe_port) > 1: raise Exception(f"Invalid hostname: {hostname}")
hostname = maybe_port[0] hostname = result.hostname
port = int(maybe_port[1]) port = result.port
meta = meta.copy() meta = meta.copy()
meta["flake_attr"] = machine_name meta["flake_attr"] = machine_name
return Host( return Host(

View File

@@ -1,6 +1,12 @@
import subprocess import subprocess
from clan_cli.ssh import Host, HostGroup from clan_cli.ssh import Host, HostGroup, parse_deployment_address
def test_parse_ipv6() -> None:
host = parse_deployment_address("foo", "[fe80::1%eth0]:2222")
assert host.host == "fe80::1%eth0"
assert host.port == 2222
def test_run(host_group: HostGroup) -> None: def test_run(host_group: HostGroup) -> None: