Azure / azure-cli

Azure Command-Line Interface
MIT License
4.03k stars 3.01k forks source link

az network nic show doesn't work for NIC names with a hyphen #26633

Open rai-m opened 1 year ago

rai-m commented 1 year ago

Describe the bug

When using the az network nic show CLI command with --ids parameters, the commandlet wrongly derives the nic name from the resource id, ignoring anything after it first encounters a hyphen in the name, Notice the name derived in the get request URI in debug logs

Related command

az network nic show --ids '/subscriptions/---/resourceGroups/---/providers/Microsoft.Compute/virtualMachineScaleSets/***/virtualMachines/9/networkInterfaces/AEMPUBDEV1WW1-nic01'

Errors

(ResourceNotFound) The Resource 'Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1' under resource group '***' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix Code: ResourceNotFound

Notice the name of the nic derived as against what is present in the resource id.

Issue script & Debug output

az network nic show --ids '/subscriptions/---/resourceGroups//providers/Microsoft.Compute/virtualMachineScaleSets//virtualMachines/9/networkInterfaces/AEMPUBDEV1WW1-nic01' --debug cli.knack.cli: Command arguments: ['network', 'nic', 'show', '--ids', '/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachineScaleSets/AEMPUBDEV1WW1/virtualMachines/9/networkInterfaces/AEMPUBDEV1WW1-nic01', '--debug'] cli.knack.cli: init debug log: Enable color in terminal. cli.knack.cli: Event: Cli.PreExecute [] cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x10e32a320>, <function OutputProducer.on_global_arguments at 0x10e3bb400>, <function CLIQuery.on_global_arguments at 0x10e4148b0>] cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate [] cli.azure.cli.core: Modules found from index for 'network': ['azure.cli.command_modules.network', 'azure.cli.command_modules.privatedns'] cli.azure.cli.core: Loading command modules: cli.azure.cli.core: Name Load Time Groups Commands cli.azure.cli.core: network 0.826 112 352 cli.azure.cli.core: privatedns 0.005 14 66 cli.azure.cli.core: Total (2) 0.831 126 418 cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next'] cli.azure.cli.core: Loading extensions: cli.azure.cli.core: Name Load Time Groups Commands Directory cli.azure.cli.core: Total (0) 0.000 0 0
cli.azure.cli.core: Loaded 125 groups, 418 commands. cli.azure.cli.core: Found a match in the command table. cli.azure.cli.core: Raw command : network nic show cli.azure.cli.core: Command table: network nic show cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x10edb7640>] cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/Users/a548714/.azure/commands/2023-06-07.18-32-41.network_nic_show.29550.log'. az_command_data_logger: command args: network nic show --ids {} --debug cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x10ee60160>] cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad [] cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x10ee91ea0>, <function register_cache_arguments..add_cache_arguments at 0x10ee91fc0>] cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded [] cli.knack.cli: Event: CommandInvoker.OnPreParseArgs [] cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x10e3bb490>, <function CLIQuery.handle_query_parameter at 0x10e414940>, <function register_ids_argument..parse_ids_arguments at 0x10ee91f30>] cli.azure.cli.core.auth.persistence: build_persistence: location='/Users/a548714/.azure/msal_token_cache.json', encrypt=False cli.azure.cli.core.auth.binary_cache: load: /Users/a548714/.azure/msal_http_cache.bin urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None) msal.authority: openid_config = {'token_endpoint': 'https://login.microsoftonline.com/***/oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt', 'client_secret_basic'], 'jwks_uri': 'https://login.microsoftonline.com/***/discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'], 'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer': 'https://login.microsoftonline.com/***/v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://graph.microsoft.com/oidc/userinfo', 'authorization_endpoint': 'https://login.microsoftonline.com/***/oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.microsoftonline.com/***/oauth2/v2.0/devicecode', 'http_logout_supported': True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.microsoftonline.com/3***/oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name', 'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint': 'https://login.microsoftonline.com/***/kerberos', 'tenant_region_scope': 'EU', 'cloud_instance_name': 'microsoftonline.com', 'cloud_graph_host_name': 'graph.windows.net', 'msgraph_host': 'graph.microsoft.com', 'rbac_url': 'https://pas.windows.net'} msal.application: Broker enabled? False cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token: scopes=('https://management.core.windows.net//.default',), kwargs={} cli.azure.cli.core.auth.msal_authentication: UserCredential.get_token: scopes=('https://management.core.windows.net//.default',), claims=None, kwargs={} msal.application: Cache hit an AT msal.telemetry: Generate or reuse correlation_id: ea648dff-74fe-4d52-a2d9-a718fd3f1497 cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions/***/resourceGroups/***/providers/Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1?api-version=2022-01-01' cli.azure.cli.core.sdk.policies: Request method: 'GET' cli.azure.cli.core.sdk.policies: Request headers: cli.azure.cli.core.sdk.policies: 'Accept': 'application/json' cli.azure.cli.core.sdk.policies: 'x-ms-client-request-id': '9571083c-0533-11ee-a20a-acde48001122' cli.azure.cli.core.sdk.policies: 'CommandName': 'network nic show' cli.azure.cli.core.sdk.policies: 'ParameterSetName': '--ids --debug' cli.azure.cli.core.sdk.policies: 'User-Agent': 'AZURECLI/2.48.1 (HOMEBREW) (AAZ) azsdk-python-core/1.26.0 Python/3.10.11 (macOS-13.4-x86_64-i386-64bit)' cli.azure.cli.core.sdk.policies: 'Authorization': '**' cli.azure.cli.core.sdk.policies: Request body: cli.azure.cli.core.sdk.policies: This request has no body urllib3.connectionpool: Starting new HTTPS connection (1): management.azure.com:443 urllib3.connectionpool: https://management.azure.com:443 "GET /subscriptions//resourceGroups//providers/Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1?api-version=2022-01-01 HTTP/1.1" 404 244 cli.azure.cli.core.sdk.policies: Response status: 404 cli.azure.cli.core.sdk.policies: Response headers: cli.azure.cli.core.sdk.policies: 'Cache-Control': 'no-cache' cli.azure.cli.core.sdk.policies: 'Pragma': 'no-cache' cli.azure.cli.core.sdk.policies: 'Content-Type': 'application/json; charset=utf-8' cli.azure.cli.core.sdk.policies: 'Expires': '-1' cli.azure.cli.core.sdk.policies: 'x-ms-failure-cause': 'gateway' cli.azure.cli.core.sdk.policies: 'x-ms-request-id': '0de684f4-024f-46c3-8a11-a722cbae778e' cli.azure.cli.core.sdk.policies: 'x-ms-correlation-request-id': '0de684f4-024f-46c3-8a11-a722cbae778e' cli.azure.cli.core.sdk.policies: 'x-ms-routing-request-id': 'JIOINDIAWEST:20230607T130242Z:0de684f4-024f-46c3-8a11-a722cbae778e' cli.azure.cli.core.sdk.policies: 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains' cli.azure.cli.core.sdk.policies: 'X-Content-Type-Options': 'nosniff' cli.azure.cli.core.sdk.policies: 'Date': 'Wed, 07 Jun 2023 13:02:41 GMT' cli.azure.cli.core.sdk.policies: 'Content-Length': '244' cli.azure.cli.core.sdk.policies: Response content: cli.azure.cli.core.sdk.policies: {"error":{"code":"ResourceNotFound","message":"The Resource 'Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1' under resource group 'APP-DEV-AEM-DEV1-WW1-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"}} cli.azure.cli.core.azclierror: Traceback (most recent call last): File "/usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/azure/cli/core/commands/init.py", line 663, in execute raise ex File "/usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/azure/cli/core/commands/init.py", line 726, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/azure/cli/core/commands/init.py", line 697, in _run_job result = cmd_copy(params) File "/usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/azure/cli/core/aaz/_command.py", line 149, in call return self._handler(args, kwargs) File "/usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/azure/cli/command_modules/network/aaz/latest/network/nic/_show.py", line 33, in _handler self._execute_operations() File "/usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/azure/cli/command_modules/network/aaz/latest/network/nic/_show.py", line 64, in _execute_operations self.NetworkInterfacesGet(ctx=self.ctx)() File "/usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/azure/cli/command_modules/network/aaz/latest/network/nic/_show.py", line 88, in call return self.on_error(session.http_response) File "/usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/azure/cli/core/aaz/_operation.py", line 323, in on_error raise error_type(response=response) azure.core.exceptions.ResourceNotFoundError: (ResourceNotFound) The Resource 'Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1' under resource group 'APP-DEV-AEM-DEV1-WW1-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix Code: ResourceNotFound Message: The Resource 'Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1' under resource group 'APP-DEV-AEM-DEV1-WW1-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix

cli.azure.cli.core.azclierror: (ResourceNotFound) The Resource 'Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1' under resource group 'APP-DEV-AEM-DEV1-WW1-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix Code: ResourceNotFound Message: The Resource 'Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1' under resource group 'APP-DEV-AEM-DEV1-WW1-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix az_command_data_logger: (ResourceNotFound) The Resource 'Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1' under resource group 'APP-DEV-AEM-DEV1-WW1-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix Code: ResourceNotFound Message: The Resource 'Microsoft.Network/networkInterfaces/AEMPUBDEV1WW1' under resource group 'APP-DEV-AEM-DEV1-WW1-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x10edb7880>] az_command_data_logger: exit code: 3 cli.main: Command ran in 2.036 seconds (init: 0.208, invoke: 1.828) telemetry.main: Begin splitting cli events and extra events, total events: 1 telemetry.client: Accumulated 0 events. Flush the clients. telemetry.main: Finish splitting cli events and extra events, cli events: 1 telemetry.save: Save telemetry record of length 3948 in cache telemetry.check: Returns Positive. telemetry.main: Begin creating telemetry upload process. telemetry.process: Creating upload process: "/usr/local/Cellar/azure-cli/2.48.1/libexec/bin/python /usr/local/Cellar/azure-cli/2.48.1/libexec/lib/python3.10/site-packages/azure/cli/telemetry/init.py /Users/a548714/.azure" telemetry.process: Return from creating process telemetry.main: Finish creating telemetry upload process.

Expected behavior

The resource exists and the names are parsed properly.

Environment Summary

azure-cli 2.48.1 *

core 2.48.1 * telemetry 1.0.8

Extensions: aks-preview 0.5.137 azure-devops 0.26.0

Dependencies: msal 1.20.0 azure-mgmt-resource 22.0.0

Python location '/usr/local/Cellar/azure-cli/2.48.1/libexec/bin/python' Extensions directory '/Users/a548714/.azure/cliextensions'

Python (Darwin) 3.10.11 (main, Apr 7 2023, 07:31:31) [Clang 14.0.0 (clang-1400.0.29.202)]

Legal docs and information: aka.ms/AzureCliLegal

Additional context

No response

azure-client-tools-bot-prd[bot] commented 1 year ago

Hi @rai-m,

2.48.1 is not the latest Azure CLI(2.49.0).

Please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

yonzhan commented 1 year ago

Thank you for opening this issue, we will look into it.

rai-m commented 1 year ago

Update: The issue persists with the latest version of Az CLI as well.

necusjz commented 1 year ago

Your NIC is under VMSS, please use https://learn.microsoft.com/en-us/cli/azure/vmss/nic?view=azure-cli-latest#az-vmss-nic-list-vm-nics (or something like that) instead.

rai-m commented 1 year ago

When using az vmss nic show it does work for a VMSS instance, however you might want to check if the same works for a standalone Azure VM with such a NIC name.