From 844ea41420fb3f8a58585c0911390725e3e92987 Mon Sep 17 00:00:00 2001 From: Gabrielle Poncey Date: Thu, 3 Jul 2025 11:35:05 -0700 Subject: [PATCH 1/2] json-create supports hostnames node config json-create allows creation of a node or subnode with either ip address or hostname through the use of socket.gethostbyname PLAT-131 --- cli/scripts/cluster.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/scripts/cluster.py b/cli/scripts/cluster.py index d6a1fa42..8fccada3 100755 --- a/cli/scripts/cluster.py +++ b/cli/scripts/cluster.py @@ -8,10 +8,11 @@ import sys import getpass from tabulate import tabulate # type: ignore -from ipaddress import ip_address +import socket import os import re + BASE_DIR = "cluster" DEFAULT_REPO = "https://pgedge-download.s3.amazonaws.com/REPO" @@ -1042,9 +1043,11 @@ def get_cluster_info(cluster_name): ) try: if public_ip: - ip_address(public_ip) + socket.gethostbyname(public_ip) + if private_ip: - ip_address(private_ip) + socket.gethostbyname(private_ip) + except ValueError: validation_errors.append( f"Invalid IP address provided for node {node.get('name')}." @@ -1077,9 +1080,9 @@ def get_cluster_info(cluster_name): ) try: if public_ip: - ip_address(public_ip) + socket.gethostbyname(public_ip) if private_ip: - ip_address(private_ip) + socket.gethostbyname(private_ip) except ValueError: validation_errors.append( f"Invalid IP address provided for sub-node {sub_node.get('name')}." From cd0a520e8fc0d7836ef1dc4f86cb08ada68bda3c Mon Sep 17 00:00:00 2001 From: Gabrielle Poncey Date: Tue, 8 Jul 2025 10:00:55 -0700 Subject: [PATCH 2/2] fix: appropriate error caught invalid host/ip In the case that a hostname or ip address cannot be resolved by gethostbyname, socket error will be caught, appended to validation_errors and reported with the specific node from which it arose from. PLAT-131 --- cli/scripts/cluster.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/scripts/cluster.py b/cli/scripts/cluster.py index 8fccada3..d90619c3 100755 --- a/cli/scripts/cluster.py +++ b/cli/scripts/cluster.py @@ -1048,9 +1048,9 @@ def get_cluster_info(cluster_name): if private_ip: socket.gethostbyname(private_ip) - except ValueError: + except socket.gaierror as e: validation_errors.append( - f"Invalid IP address provided for node {node.get('name')}." + f"Error resolving hostname or ip adress for node {node.get('name')} : {e}." ) for sub_node in node.get("sub_nodes", []): @@ -1083,9 +1083,9 @@ def get_cluster_info(cluster_name): socket.gethostbyname(public_ip) if private_ip: socket.gethostbyname(private_ip) - except ValueError: + except socket.gaierror as e: validation_errors.append( - f"Invalid IP address provided for sub-node {sub_node.get('name')}." + f"Error resolving hostname or ip adress for sub-node {sub_node.get('name')}: {e}." ) if validation_errors: