From 925077941b42d6df5150deb9fccb64a925a1544a Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Wed, 28 May 2025 14:49:17 +0800 Subject: [PATCH] azurelinux2-warning --- src/azure-cli/azure/cli/__main__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/__main__.py b/src/azure-cli/azure/cli/__main__.py index 71442beaecd..fee41ba5751 100644 --- a/src/azure-cli/azure/cli/__main__.py +++ b/src/azure-cli/azure/cli/__main__.py @@ -9,6 +9,7 @@ start_time = timeit.default_timer() import sys +import os from azure.cli.core import telemetry from azure.cli.core import get_default_cli @@ -22,6 +23,14 @@ logger = get_logger(__name__) +AZURELINUX2_WARNING_MESSAGE = ( + "Azure CLI 2.74.0 is the final version available on Azure Linux (Mariner) 2.0 and will not receive further " + "updates. " + "We recommend migrating to Azure Linux 3.0 to access newer versions of Azure CLI and continue receiving updates. " + "For more information: https://go.microsoft.com/fwlink/?linkid=2322402. " + "To disable this warning message, set AZURE_CLI_DISABLE_AZURELINUX2_WARNING environment variable to any value. " +) + def cli_main(cli, args): return cli.invoke(args) @@ -96,7 +105,6 @@ def cli_main(cli, args): else: upgrade_exit_code = subprocess.call(cmd, shell=platform.system() == 'Windows') else: - import os devnull = open(os.devnull, 'w') cmd.append('-y') upgrade_exit_code = subprocess.call(cmd, shell=platform.system() == 'Windows', stdout=devnull) @@ -115,6 +123,9 @@ def cli_main(cli, args): except Exception as ex: # pylint: disable=broad-except logger.debug("Intercept survey prompt failed. %s", str(ex)) + if 'AZURE_CLI_DISABLE_AZURELINUX2_WARNING' not in os.environ: + logger.warning(AZURELINUX2_WARNING_MESSAGE) + telemetry.set_init_time_elapsed("{:.6f}".format(init_finish_time - start_time)) telemetry.set_invoke_time_elapsed("{:.6f}".format(invoke_finish_time - init_finish_time)) telemetry.conclude()