Azure / azure-cli

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

Device identity creation on IoT Hub fails #27180

Closed sandervandevelde closed 1 year ago

sandervandevelde commented 1 year ago

Describe the bug

When creating a device identity on an existing IoT Hub, I get an error. This happens:

Related command

iot hub device-identity create --device-id test1 --edge-enabled true --hub-name uks-test-ih

Errors

via az interactive

az>> iot hub device-identity create --device-id test1 --edge-enabled true --hub-name uks-test-ih
The command failed with an unexpected error. Here is the traceback:
'IotHubResourceOperations' object has no attribute 'config'
Traceback (most recent call last):
  File "/home/sander/.azure/cliextensions/interactive/azext_interactive/azclishell/app.py", line 908, in cli_execute
    result = invocation.execute(args)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/usr/lib64/az/lib/python3.9/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/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/hub.py", line 87, in iot_device_create
    target = get_iot_hub_connection_string(cmd, hub_name, resource_group_name, login=login)
  File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 158, in get_iot_hub_connection_string
    result['subscription'] = client.config.subscription_id
AttributeError: 'IotHubResourceOperations' object has no attribute 'config'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
az>>

via cmd

sander@Azure:~$ az iot hub device-identity create --hub-name uks-test-ih --device-id testdevice --edge-enabled true
The command failed with an unexpected error. Here is the traceback:
'IotHubResourceOperations' object has no attribute 'config'
Traceback (most recent call last):
  File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/usr/lib64/az/lib/python3.9/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/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/hub.py", line 87, in iot_device_create
    target = get_iot_hub_connection_string(cmd, hub_name, resource_group_name, login=login)
  File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 158, in get_iot_hub_connection_string
    result['subscription'] = client.config.subscription_id
AttributeError: 'IotHubResourceOperations' object has no attribute 'config'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
sander@Azure:~$

Issue script & Debug output

sander@Azure:~$ az iot hub device-identity create --hub-name uks-test-ih --device-id testdevice --edge-enabled true --debug cli.knack.cli: Command arguments: ['iot', 'hub', 'device-identity', 'create', '--hub-name', 'uks-test-ih', '--device-id', 'testdevice', '--edge-enabled', 'true', '--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 0x7fb8c239e1f0>, <function OutputProducer.on_global_arguments at 0x7fb8c22b8d30>, <function CLIQuery.on_global_arguments at 0x7fb8c2250310>] cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate [] cli.azure.cli.core: Modules found from index for 'iot': ['azure.cli.command_modules.iot', 'azext_iot'] cli.azure.cli.core: Loading command modules: cli.azure.cli.core: Name Load Time Groups Commands cli.azure.cli.core: iot 0.182 19 82 cli.azure.cli.core: Total (1) 0.182 19 82 cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_next'] cli.azure.cli.core: Loading extensions: cli.azure.cli.core: Name Load Time Groups Commands Directory cli.azure.cli.core: ai-examples 0.078 1 1 /usr/lib/python3.9/site-packages/azure-cli-extensions/ai-examples cli.azure.cli.core: azure-cli-iot-ext 0.008 27 93 /home/sander/.azure/cliextensions/azure-cli-iot-ext cli.azure.cli.core: Total (2) 0.086 28 94 cli.azure.cli.core: Loaded 42 groups, 176 commands. cli.azure.cli.core: Found a match in the command table. cli.azure.cli.core: Raw command : iot hub device-identity create cli.azure.cli.core: Command table: iot hub device-identity create cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7fb8c16f4430>] cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/sander/.azure/commands/2023-08-16.08-21-43.iot_hub_device-identity_create.448.log'. az_command_data_logger: command args: iot hub device-identity create --hub-name {} --device-id {} --edge-enabled {} --debug cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x7fb8c16a1040>] cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad [] cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x7fb8c16d00d0>, <function register_cache_arguments..add_cache_arguments at 0x7fb8c1659ee0>] cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded [] cli.knack.cli: Event: CommandInvoker.OnPreParseArgs [] cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7fb8c22b8dc0>, <function CLIQuery.handle_query_parameter at 0x7fb8c22503a0>, <function register_ids_argument..parse_ids_arguments at 0x7fb8c1659e50>, <function handler at 0x7fb8c167e9d0>] az_command_data_logger: extension name: azure-cli-iot-ext az_command_data_logger: extension version: 0.8.9 cli.azure.cli.core.commands.client_factory: Getting management service client client_type=IotHubClient urllib3.connectionpool: Starting new HTTP connection (1): localhost:50342 urllib3.connectionpool: http://localhost:50342 "POST /oauth2/token HTTP/1.1" 200 2194 msrestazure.azure_active_directory: MSI: Retrieving a token from http://localhost:50342/oauth2/token, with payload {'resource': 'https://management.core.windows.net/'} cli.azure.cli.core.auth.adal_authentication: MSIAuthenticationWrapper.get_token: scopes=('https://management.core.windows.net//.default',), kwargs={} urllib3.connectionpool: Starting new HTTP connection (1): localhost:50342 urllib3.connectionpool: http://localhost:50342 "POST /oauth2/token HTTP/1.1" 200 2194 msrestazure.azure_active_directory: MSI: Retrieving a token from http://localhost:50342/oauth2/token, with payload {'resource': 'https://management.core.windows.net/'} cli.azure.cli.core.auth.adal_authentication: Normalize expires_on: '1692177152' -> 1692177152 cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions/ad331ace-d1e3-4655-af8f-84013ad41d6c/providers/Microsoft.Devices/IotHubs?api-version=2021-07-02' 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': 'eec2f394-3c0d-11ee-b6e3-323b76e196af' cli.azure.cli.core.sdk.policies: 'CommandName': 'iot hub device-identity create' cli.azure.cli.core.sdk.policies: 'ParameterSetName': '--hub-name --device-id --edge-enabled --debug' cli.azure.cli.core.sdk.policies: 'User-Agent': 'AZURECLI/2.51.0 (RPM) azsdk-python-azure-mgmt-iothub/2.3.0 Python/3.9.14 (Linux-5.4.0-1109-azure-x86_64-with-glibc2.35) cloud-shell/1.0' 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/ad331ace-d1e3-4655-af8f-84013ad41d6c/providers/Microsoft.Devices/IotHubs?api-version=2021-07-02 HTTP/1.1" 200 3273 cli.azure.cli.core.sdk.policies: Response status: 200 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: 'Content-Encoding': 'gzip' cli.azure.cli.core.sdk.policies: 'Expires': '-1' cli.azure.cli.core.sdk.policies: 'Vary': 'Accept-Encoding' cli.azure.cli.core.sdk.policies: 'x-ms-original-request-ids': ', ' cli.azure.cli.core.sdk.policies: 'x-ms-ratelimit-remaining-subscription-reads': '11996' cli.azure.cli.core.sdk.policies: 'x-ms-request-id': 'f67e7746-3052-45fd-a58b-3c9863b54fd5' cli.azure.cli.core.sdk.policies: 'x-ms-correlation-request-id': 'f67e7746-3052-45fd-a58b-3c9863b54fd5' cli.azure.cli.core.sdk.policies: 'x-ms-routing-request-id': 'WESTEUROPE:20230816T082145Z:f67e7746-3052-45fd-a58b-3c9863b54fd5' 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, 16 Aug 2023 08:21:44 GMT' cli.azure.cli.core.sdk.policies: 'Content-Length': '3273' cli.azure.cli.core.sdk.policies: Response content: cli.azure.cli.core.sdk.policies: {"value":[{"id":"/subscriptions/ad331ace-d1e3-4655-af8f-84013ad41d6c/resourceGroups/edgedemo-rg/providers/Microsoft.Devices/IotHubs/edgedemo-ih","name":"edgedemo-ih","type":"Microsoft.Devices/IotHubs","location":"westeurope","tags":{"Creator":"sandervandevelde","Usecase":"Test hub for IoT demos"},"subscriptionid":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourcegroup":"edgedemo-rg","etag":"AAAADH37Tqw=","properties":{"locations":[{"location":"West Europe","role":"primary"},{"location":"North Europe","role":"secondary"}],"state":"Active","provisioningState":"Succeeded","ipFilterRules":[],"networkRuleSets":{"defaultAction":"Allow","applyToBuiltInEventHubEndpoint":true,"ipRules":[]},"hostName":"edgedemo-ih.azure-devices.net","eventHubEndpoints":{"events":{"retentionTimeInDays":1,"partitionCount":4,"partitionIds":["0","1","2","3"],"path":"edgedemo-ih","endpoint":"sb://iothub-ns-edgedemo-i-623166-df00203bc4.servicebus.windows.net/"}},"routing":{"endpoints":{"serviceBusQueues":[],"serviceBusTopics":[],"eventHubs":[{"connectionString":"Endpoint=sb://edgedemo-ehns.servicebus.windows.net:5671/;SharedAccessKeyName=iothubroutes_edgedemo-ih;SharedAccessKey=;EntityPath=hotpath","name":"hotpathep","id":"40e06f6d-1e22-46ae-ae71-708c5cfde313","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"edgedemo-rg"},{"connectionString":"Endpoint=sb://edgedemo-ehns.servicebus.windows.net:5671/;SharedAccessKeyName=iothubroutes_edgedemo-ih;SharedAccessKey=;EntityPath=warmpath","name":"warmpathep","id":"b32090de-b853-4148-b574-0f1ffe3f6ecc","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"edgedemo-rg"}],"storageContainers":[{"connectionString":"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=edgedemostor;AccountKey=","containerName":"pnpblobstorage","fileNameFormat":"{iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}.json","batchFrequencyInSeconds":60,"maxChunkSizeInBytes":10485760,"encoding":"json","authenticationType":"keyBased","name":"PnpBlobStorageEndpoint","id":"fae02970-d213-42e1-b10a-700147a8c42a","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"edgedemo-rg"},{"connectionString":"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=edgedemostor;AccountKey=","containerName":"adtblobstorage","fileNameFormat":"{iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}.json","batchFrequencyInSeconds":100,"maxChunkSizeInBytes":104857600,"encoding":"json","authenticationType":"keyBased","name":"AzureDigitalTwinBlobStorageEndpoint","id":"ebf0ccb2-ef94-48d6-aa3c-3f842a0476a2","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"edgedemo-rg"},{"connectionString":"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=edgedemostor;AccountKey=","containerName":"lifecycleblobstorage","fileNameFormat":"{iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}.json","batchFrequencyInSeconds":100,"maxChunkSizeInBytes":104857600,"encoding":"json","authenticationType":"keyBased","name":"LifeCycleBlobStorageEndpoint","id":"346f72da-b5c7-4a17-9140-54d577145466","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"edgedemo-rg"},{"connectionString":"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=edgedemostor;AccountKey=","containerName":"connectionblobstorage","fileNameFormat":"{iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}.json","batchFrequencyInSeconds":100,"maxChunkSizeInBytes":104857600,"encoding":"json","authenticationType":"keyBased","name":"ConnectionBlobStorageRoute","id":"6f331dda-6531-49a8-ad5c-115ab4ddc30d","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"edgedemo-rg"}]},"enrichments":[{"key":"deviceid","value":"$twin.tags.deviceid","endpointNames":["events"]}],"routes":[{"name":"default","source":"DeviceMessages","condition":"true","endpointNames":["events"],"isEnabled":true},{"name":"warmpath","source":"DeviceMessages","condition":"command-type = 'atos-titecConverter-json'","endpointNames":["warmpathep"],"isEnabled":true},{"name":"hotpath","source":"DeviceMessages","condition":"command-type = 'application/edge-output1-heartbeat-json'","endpointNames":["hotpathep"],"isEnabled":true},{"name":"DeviceTwinChangesRoute","source":"TwinChangeEvents","condition":"true","endpointNames":["PnpBlobStorageEndpoint"],"isEnabled":true},{"name":"DigitalTwinChangesRoute","source":"DigitalTwinChangeEvents","condition":"true","endpointNames":["AzureDigitalTwinBlobStorageEndpoint"],"isEnabled":true},{"name":"LifeCycleRoute","source":"DeviceLifecycleEvents","condition":"true","endpointNames":["LifeCycleBlobStorageEndpoint"],"isEnabled":true},{"name":"ConnectionStateRoute","source":"DeviceConnectionStateEvents","condition":"true","endpointNames":["ConnectionBlobStorageRoute"],"isEnabled":true}],"fallbackRoute":{"name":"$fallback","source":"DeviceMessages","condition":"true","endpointNames":["events"],"isEnabled":false}},"storageEndpoints":{"$default":{"sasTtlAsIso8601":"PT1H","connectionString":"DefaultEndpointsProtocol=https;AccountName=edgedemostor;AccountKey=","containerName":"edgedemoih"}},"messagingEndpoints":{"fileNotifications":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"enableFileUploadNotifications":false,"cloudToDevice":{"maxDeliveryCount":10,"defaultTtlAsIso8601":"PT1H","feedback":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"features":"GWV2","publicNetworkAccess":"Enabled"},"sku":{"name":"S1","tier":"Standard","capacity":2},"identity":{"type":"None"},"systemData":{"createdAt":"2018-08-01T23:03:58.917Z"}},{"id":"/subscriptions/ad331ace-d1e3-4655-af8f-84013ad41d6c/resourceGroups/beerlift-weu-rg/providers/Microsoft.Devices/IotHubs/beerlift-weu-ih","name":"beerlift-weu-ih","type":"Microsoft.Devices/IotHubs","location":"westeurope","tags":{},"subscriptionid":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourcegroup":"beerlift-weu-rg","etag":"AAAADH3+65E=","properties":{"locations":[{"location":"West Europe","role":"primary"},{"location":"North Europe","role":"secondary"}],"state":"Active","provisioningState":"Succeeded","ipFilterRules":[],"hostName":"beerlift-weu-ih.azure-devices.net","eventHubEndpoints":{"events":{"retentionTimeInDays":1,"partitionCount":4,"partitionIds":["0","1","2","3"],"path":"beerlift-weu-ih","endpoint":"sb://iothub-ns-beerlift-w-5588750-508d14b7dc.servicebus.windows.net/"}},"routing":{"endpoints":{"serviceBusQueues":[],"serviceBusTopics":[],"eventHubs":[],"storageContainers":[{"connectionString":"DefaultEndpointsProtocol=https;AccountName=beerliftweustor;AccountKey=","containerName":"beerliftcool","fileNameFormat":"{iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}.json","batchFrequencyInSeconds":100,"maxChunkSizeInBytes":104857600,"encoding":"json","name":"coolstorageendpoint","id":"36627170-54fc-4f7e-95ae-0281d61aad04","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"beerlift-weu-rg"},{"connectionString":"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=beerliftweustor;AccountKey=","containerName":"deviceconnectionstateevents","fileNameFormat":"{iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}.json","batchFrequencyInSeconds":100,"maxChunkSizeInBytes":104857600,"encoding":"json","authenticationType":"keyBased","name":"DeviceConnectionStateEventsEndpoint","id":"98177360-f9a1-436f-82c9-172f83fb32f6","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"beerlift-weu-rg"},{"connectionString":"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=beerliftweustor;AccountKey=","containerName":"devicelifecycleevents","fileNameFormat":"{iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}.json","batchFrequencyInSeconds":100,"maxChunkSizeInBytes":104857600,"encoding":"json","authenticationType":"keyBased","name":"DeviceLifecycleEventsEndpoint","id":"63bf0463-5d59-429d-a39e-8ce750783662","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"beerlift-weu-rg"},{"connectionString":"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=beerliftweustor;AccountKey=****","containerName":"devicetwinstateevents","fileNameFormat":"{iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}.json","batchFrequencyInSeconds":100,"maxChunkSizeInBytes":104857600,"encoding":"json","authenticationType":"keyBased","name":"DeviceTwinStateEventsEndpoint","id":"fd17dee1-ceef-4866-a93a-73213d45efb3","subscriptionId":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourceGroup":"beerlift-weu-rg"}]},"enrichments":[{"key":"model","value":"$twin.tags.model","endpointNames":["coolstorageendpoint","events"]},{"key":"make","value":"$twin.tags.make","endpointNames":["coolstorageendpoint","events"]},{"key":"version","value":"$twin.tags.version","endpointNames":["coolstorageendpoint","events"]},{"key":"module","value":"$twin.tags.module","endpointNames":["coolstorageendpoint","events"]}],"routes":[{"name":"coolroute","source":"DeviceMessages","condition":"true","endpointNames":["coolstorageendpoint"],"isEnabled":true},{"name":"builtinroute","source":"DeviceMessages","condition":"true","endpointNames":["events"],"isEnabled":true},{"name":"DeviceConnectionStateEventsRoute","source":"DeviceConnectionStateEvents","condition":"true","endpointNames":["DeviceConnectionStateEventsEndpoint"],"isEnabled":true},{"name":"DeviceLifecycleEventsRoute","source":"DeviceLifecycleEvents","condition":"true","endpointNames":["DeviceLifecycleEventsEndpoint"],"isEnabled":true},{"name":"DeviceTwinChangeEventsRoute","source":"TwinChangeEvents","condition":"true","endpointNames":["DeviceTwinStateEventsEndpoint"],"isEnabled":true}],"fallbackRoute":{"name":"$fallback","source":"DeviceMessages","condition":"true","endpointNames":["events"],"isEnabled":true}},"storageEndpoints":{"$default":{"sasTtlAsIso8601":"PT1H","connectionString":"","containerName":""}},"messagingEndpoints":{"fileNotifications":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"enableFileUploadNotifications":false,"cloudToDevice":{"maxDeliveryCount":10,"defaultTtlAsIso8601":"PT1H","feedback":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"features":"GWV2","allowedFqdnList":[]},"sku":{"name":"S1","tier":"Standard","capacity":1},"identity":{"type":"None"},"systemData":{"createdAt":"2020-10-29T11:10:08.643Z"}},{"id":"/subscriptions/ad331ace-d1e3-4655-af8f-84013ad41d6c/resourceGroups/rg-az220/providers/Microsoft.Devices/IotHubs/iot-az220-training-sve220101","name":"iot-az220-training-sve220101","type":"Microsoft.Devices/IotHubs","location":"westeurope","tags":{},"subscriptionid":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourcegroup":"rg-az220","etag":"AAAADH6S2QY=","properties":{"locations":[{"location":"West Europe","role":"primary"},{"location":"North Europe","role":"secondary"}],"state":"Active","provisioningState":"Succeeded","ipFilterRules":[],"hostName":"iot-az220-training-sve220101.azure-devices.net","eventHubEndpoints":{"events":{"retentionTimeInDays":1,"partitionCount":4,"partitionIds":["0","1","2","3"],"path":"iot-az220-training-sve220","endpoint":"sb://iothub-ns-iot-az220-20479578-efeb3befe1.servicebus.windows.net/"}},"routing":{"endpoints":{"serviceBusQueues":[],"serviceBusTopics":[],"eventHubs":[],"storageContainers":[]},"enrichments":[{"key":"KeyOne","value":"ValueOne","endpointNames":["events"]}],"routes":[{"name":"RouteToEventGrid","source":"DeviceMessages","condition":"true","endpointNames":["eventgrid"],"isEnabled":true},{"name":"defaultroute","source":"DeviceMessages","condition":"true","endpointNames":["events"],"isEnabled":true}],"fallbackRoute":{"name":"$fallback","source":"DeviceMessages","condition":"true","endpointNames":["events"],"isEnabled":true}},"storageEndpoints":{"$default":{"sasTtlAsIso8601":"PT1H","connectionString":"","containerName":""}},"messagingEndpoints":{"fileNotifications":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"enableFileUploadNotifications":false,"cloudToDevice":{"maxDeliveryCount":10,"defaultTtlAsIso8601":"PT1H","feedback":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"features":"GWV2","allowedFqdnList":[]},"sku":{"name":"S1","tier":"Standard","capacity":1},"identity":{"type":"None"},"systemData":{"createdAt":"2022-07-25T12:33:42.8566667Z"}},{"id":"/subscriptions/ad331ace-d1e3-4655-af8f-84013ad41d6c/resourceGroups/os-config-test-weu-rg/providers/Microsoft.Devices/IotHubs/os-config-test-weu-ih","name":"os-config-test-weu-ih","type":"Microsoft.Devices/IotHubs","location":"westeurope","tags":{},"subscriptionid":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourcegroup":"os-config-test-weu-rg","etag":"AAAADH7NAa0=","properties":{"locations":[{"location":"West Europe","role":"primary"},{"location":"North Europe","role":"secondary"}],"state":"Active","provisioningState":"Succeeded","ipFilterRules":[],"hostName":"os-config-test-weu-ih.azure-devices.net","eventHubEndpoints":{"events":{"retentionTimeInDays":1,"partitionCount":4,"partitionIds":["0","1","2","3"],"path":"os-config-test-weu-ih","endpoint":"sb://iothub-ns-os-config-25183399-5ae92d927b.servicebus.windows.net/"}},"routing":{"endpoints":{"serviceBusQueues":[],"serviceBusTopics":[],"eventHubs":[],"storageContainers":[]},"routes":[],"fallbackRoute":{"name":"$fallback","source":"DeviceMessages","condition":"true","endpointNames":["events"],"isEnabled":true}},"storageEndpoints":{"$default":{"sasTtlAsIso8601":"PT1H","connectionString":"","containerName":""}},"messagingEndpoints":{"fileNotifications":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"enableFileUploadNotifications":false,"cloudToDevice":{"maxDeliveryCount":10,"defaultTtlAsIso8601":"PT1H","feedback":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"features":"None","disableLocalAuth":false,"allowedFqdnList":[],"enableDataResidency":false},"sku":{"name":"S1","tier":"Standard","capacity":1},"identity":{"type":"None"},"systemData":{"createdAt":"2023-08-06T19:16:03.4066667Z"}},{"id":"/subscriptions/ad331ace-d1e3-4655-af8f-84013ad41d6c/resourceGroups/uks-test-rg/providers/Microsoft.Devices/IotHubs/uks-test-ih","name":"uks-test-ih","type":"Microsoft.Devices/IotHubs","location":"uksouth","tags":{},"subscriptionid":"ad331ace-d1e3-4655-af8f-84013ad41d6c","resourcegroup":"uks-test-rg","etag":"AAAADH7iqQE=","properties":{"locations":[{"location":"UK South","role":"primary"},{"location":"UK West","role":"secondary"}],"state":"Active","provisioningState":"Succeeded","ipFilterRules":[],"hostName":"uks-test-ih.azure-devices.net","eventHubEndpoints":{"events":{"retentionTimeInDays":1,"partitionCount":4,"partitionIds":["0","1","2","3"],"path":"uks-test-ih","endpoint":"sb://iothub-ns-uks-test-i-25198403-8c46edcc7a.servicebus.windows.net/"}},"routing":{"endpoints":{"serviceBusQueues":[],"serviceBusTopics":[],"eventHubs":[],"storageContainers":[]},"routes":[],"fallbackRoute":{"name":"$fallback","source":"DeviceMessages","condition":"true","endpointNames":["events"],"isEnabled":true}},"storageEndpoints":{"$default":{"sasTtlAsIso8601":"PT1H","connectionString":"","containerName":""}},"messagingEndpoints":{"fileNotifications":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"enableFileUploadNotifications":false,"cloudToDevice":{"maxDeliveryCount":10,"defaultTtlAsIso8601":"PT1H","feedback":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"features":"None","disableLocalAuth":false,"allowedFqdnList":[],"enableDataResidency":false},"sku":{"name":"S1","tier":"Standard","capacity":1},"identity":{"type":"None"},"systemData":{"createdAt":"2023-08-16T08:02:26.1666667Z"}}]} cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions/ad331ace-d1e3-4655-af8f-84013ad41d6c/resourceGroups/uks-test-rg/providers/Microsoft.Devices/IotHubs/uks-test-ih/IotHubKeys/iothubowner/listkeys?api-version=2021-07-02' cli.azure.cli.core.sdk.policies: Request method: 'POST' 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': 'eec2f394-3c0d-11ee-b6e3-323b76e196af' cli.azure.cli.core.sdk.policies: 'CommandName': 'iot hub device-identity create' cli.azure.cli.core.sdk.policies: 'ParameterSetName': '--hub-name --device-id --edge-enabled --debug' cli.azure.cli.core.sdk.policies: 'User-Agent': 'AZURECLI/2.51.0 (RPM) azsdk-python-azure-mgmt-iothub/2.3.0 Python/3.9.14 (Linux-5.4.0-1109-azure-x86_64-with-glibc2.35) cloud-shell/1.0' 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: https://management.azure.com:443 "POST /subscriptions/ad331ace-d1e3-4655-af8f-84013ad41d6c/resourceGroups/uks-test-rg/providers/Microsoft.Devices/IotHubs/uks-test-ih/IotHubKeys/iothubowner/listkeys?api-version=2021-07-02 HTTP/1.1" 200 None cli.azure.cli.core.sdk.policies: Response status: 200 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: 'Transfer-Encoding': 'chunked' cli.azure.cli.core.sdk.policies: 'Content-Type': 'application/json; charset=utf-8' cli.azure.cli.core.sdk.policies: 'Content-Encoding': 'gzip' cli.azure.cli.core.sdk.policies: 'Expires': '-1' cli.azure.cli.core.sdk.policies: 'Vary': 'Accept-Encoding' cli.azure.cli.core.sdk.policies: 'Server': 'Microsoft-HTTPAPI/2.0' cli.azure.cli.core.sdk.policies: 'x-ms-ratelimit-remaining-subscription-writes': '1198' cli.azure.cli.core.sdk.policies: 'x-ms-request-id': 'eda7c95c-5548-4a9d-b569-f7d7fc5aba1d' cli.azure.cli.core.sdk.policies: 'x-ms-correlation-request-id': 'eda7c95c-5548-4a9d-b569-f7d7fc5aba1d' cli.azure.cli.core.sdk.policies: 'x-ms-routing-request-id': 'WESTEUROPE:20230816T082146Z:eda7c95c-5548-4a9d-b569-f7d7fc5aba1d' 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, 16 Aug 2023 08:21:45 GMT' cli.azure.cli.core.sdk.policies: Response content: cli.azure.cli.core.sdk.policies: {"keyName":"iothubowner","primaryKey":"Pur0T20Y+3Ek+WjLi5Anaw8vDUp1vCPWjAIoTDJqfT8=","secondaryKey":"ThcSCF7sKk6Ug1PWl3ichqU4/4/ed3kuOAIoTJNj+bU=","rights":"RegistryWrite, ServiceConnect, DeviceConnect"} cli.azure.cli.core.azclierror: Traceback (most recent call last): File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 663, in execute raise ex File "/usr/lib64/az/lib/python3.9/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/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 697, in _run_job result = cmd_copy(params) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 333, in call return self.handler(*args, kwargs) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler return op(command_args) File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/hub.py", line 87, in iot_device_create target = get_iot_hub_connection_string(cmd, hub_name, resource_group_name, login=login) File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 158, in get_iot_hub_connection_string result['subscription'] = client.config.subscription_id AttributeError: 'IotHubResourceOperations' object has no attribute 'config'

cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback: az_command_data_logger: The command failed with an unexpected error. Here is the traceback: cli.azure.cli.core.azclierror: 'IotHubResourceOperations' object has no attribute 'config' Traceback (most recent call last): File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 663, in execute raise ex File "/usr/lib64/az/lib/python3.9/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/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 697, in _run_job result = cmd_copy(params) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 333, in call return self.handler(args, kwargs) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler return op(command_args) File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/hub.py", line 87, in iot_device_create target = get_iot_hub_connection_string(cmd, hub_name, resource_group_name, login=login) File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 158, in get_iot_hub_connection_string result['subscription'] = client.config.subscription_id AttributeError: 'IotHubResourceOperations' object has no attribute 'config' az_command_data_logger: 'IotHubResourceOperations' object has no attribute 'config' Traceback (most recent call last): File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 663, in execute raise ex File "/usr/lib64/az/lib/python3.9/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/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 697, in _run_job result = cmd_copy(params) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 333, in call return self.handler(args, kwargs) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler return op(command_args) File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/hub.py", line 87, in iot_device_create target = get_iot_hub_connection_string(cmd, hub_name, resource_group_name, login=login) File "/home/sander/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 158, in get_iot_hub_connection_string result['subscription'] = client.config.subscription_id AttributeError: 'IotHubResourceOperations' object has no attribute 'config' To check existing issues, please visit: https://github.com/Azure/azure-cli/issues cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7fb8c16f4670>] az_command_data_logger: exit code: 1 cli.main: Command ran in 3.099 seconds (init: 0.122, invoke: 2.978) sander@Azure:~$

Expected behavior

After completion, an edge device with the correct name should be added to the iot hub.

Environment Summary

sander@Azure:~$ az --version azure-cli 2.51.0

core 2.51.0 telemetry 1.1.0

Extensions: ai-examples 0.2.5 azure-cli-iot-ext 0.8.9 azure-iot 0.21.5 interactive 0.5.3 ml 2.19.1 ssh 2.0.1 stream-analytics 0.1.2

Dependencies: msal 1.24.0b1 azure-mgmt-resource 23.1.0b2

Python location '/usr/bin/python3.9' Extensions directory '/home/sander/.azure/cliextensions' Extensions system directory '/usr/lib/python3.9/site-packages/azure-cli-extensions'

Python (Linux) 3.9.14 (main, Feb 8 2023, 03:39:52) [GCC 11.2.0]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date. sander@Azure:~$

Additional context

This is the UK South region.

See also this MS Learn Q&A question https://learn.microsoft.com/en-us/answers/questions/1346230/issue-creating-iot-device-identity?page=1&orderby=Helpful&comment=answer-1300740#newest-answer-comment

No response

yonzhan commented 1 year ago

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

microsoft-github-policy-service[bot] commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/azure-iot-cli-triage.

navba-MSFT commented 1 year ago

@sandervandevelde Thanks for reaching out to us and reporting this issue. Looking at the error message, I see that the legacy IoT extension azure-cli-iot-ext is also loaded. This has been deprecated for quite sometime now. the new iot extension for Azure CLI is azure-iot.

Please remove azure-cli-iot-ext from your environment to avoid any conflict with azure-iot. Then test this again. Awaiting your reply.

sandervandevelde commented 1 year ago

Yes, this was the solution. I'm now able to add the device as expected. Thanks.