|
11 | 11 | import subprocess |
12 | 12 | import sys |
13 | 13 | import time |
| 14 | +import ipaddress |
14 | 15 |
|
15 | 16 | import click |
16 | 17 | import requests |
@@ -596,7 +597,14 @@ def update_dqlite(cluster_cert, cluster_key, voters, host): |
596 | 597 | with open("{}/info.yaml".format(cluster_backup_dir)) as f: |
597 | 598 | data = yaml.safe_load(f) |
598 | 599 | if "Address" in data: |
599 | | - port = data["Address"].split(":")[1] |
| 600 | + port = data["Address"].rsplit(":")[-1] |
| 601 | + |
| 602 | + # If host is an IPv6 address, wrap it in square brackets |
| 603 | + try: |
| 604 | + if ipaddress.ip_address(host).version == 6: |
| 605 | + host = "[{}]".format(host) |
| 606 | + except ValueError: |
| 607 | + pass |
600 | 608 |
|
601 | 609 | init_data = {"Cluster": voters, "Address": "{}:{}".format(host, port)} |
602 | 610 | with open("{}/init.yaml".format(cluster_dir), "w") as f: |
@@ -640,7 +648,7 @@ def join_dqlite(connection_parts, verify=False, worker=False): |
640 | 648 | :param connection_parts: connection string parts |
641 | 649 | """ |
642 | 650 | token = connection_parts[1] |
643 | | - master_ep = connection_parts[0].split(":") |
| 651 | + master_ep = connection_parts[0].rsplit(":", 1) |
644 | 652 | master_ip = master_ep[0] |
645 | 653 | master_port = master_ep[1] |
646 | 654 | fingerprint = None |
@@ -825,7 +833,7 @@ def join_etcd(connection_parts, verify=True): |
825 | 833 | :param connection_parts: connection string parts |
826 | 834 | """ |
827 | 835 | token = connection_parts[1] |
828 | | - master_ep = connection_parts[0].split(":") |
| 836 | + master_ep = connection_parts[0].rsplit(":", 1) |
829 | 837 | master_ip = master_ep[0] |
830 | 838 | master_port = master_ep[1] |
831 | 839 | callback_token = generate_callback_token() |
|
0 commit comments