From 28b99f78a443e74a1523f2002cf770c8f645775f Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Thu, 17 Jul 2025 14:08:00 +0000 Subject: [PATCH 1/2] Adding try/except block to handle failed IP Addr check and comments --- .../rdbms/flexible_server_virtual_network.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py index f3ec944e82c..2d8b460437c 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py @@ -454,7 +454,17 @@ def prepare_private_dns_zone(db_context, resource_group, server_name, private_dn def prepare_public_network(public_access, yes): if public_access is None: - ip_address = get(IP_ADDRESS_CHECKER).text + try: + ''' + In USSec and USNat, the IP address checker is not available as the public Internet is not accessible. + When the user does not provide a public IP address or does not disble public access, + the `az cli postgres flexible-server create` command will fail with the error + HTTPSConnectionPool(host='api.ipify.org', port443): Max retries excceeded with url + ''' + ip_address = get(IP_ADDRESS_CHECKER).text + except Exception as ex: + raise CLIError("Unable to detect your current IP address. Please provide a valid IP address or CIDR range for --public-access parameter or set --public-access Disabled. Error: {}".format(ex)) + logger.warning("Detected current client IP : %s", ip_address) if yes: return ip_address, ip_address From 202b60b579cdd4fe4cfc9f47a239b87b54063d08 Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Thu, 17 Jul 2025 17:15:55 +0000 Subject: [PATCH 2/2] Making Pylint required changes to comments --- .../rdbms/flexible_server_virtual_network.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py index 2d8b460437c..9c5da250be8 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_virtual_network.py @@ -455,12 +455,10 @@ def prepare_private_dns_zone(db_context, resource_group, server_name, private_dn def prepare_public_network(public_access, yes): if public_access is None: try: - ''' - In USSec and USNat, the IP address checker is not available as the public Internet is not accessible. - When the user does not provide a public IP address or does not disble public access, - the `az cli postgres flexible-server create` command will fail with the error - HTTPSConnectionPool(host='api.ipify.org', port443): Max retries excceeded with url - ''' + # In USSec and USNat, the IP address checker is not available as the public Internet is not accessible. + # When the user does not provide a public IP address or does not disble public access, + # the `az cli postgres flexible-server create` command will fail with the error + # HTTPSConnectionPool(host='api.ipify.org', port443): Max retries excceeded with url ip_address = get(IP_ADDRESS_CHECKER).text except Exception as ex: raise CLIError("Unable to detect your current IP address. Please provide a valid IP address or CIDR range for --public-access parameter or set --public-access Disabled. Error: {}".format(ex))