1

我想通过以下方式获取/检查 azure 资源ID

from azure.mgmt.resource import ResourceManagementClient
resource_client = ResourceManagementClient(credentials, subscription_id)
resource_client.resources.check_existence_by_id(
'/subscriptions/<any_subscr>/resourceGroups/random_group'
'/providers/Microsoft.Compute/virtualMachines/test_vm', 
api_version='2017-12-01')

失败:

ClientRequestError: Error occurred in request., RetryError: HTTPSConnectionPool(host='management.azure.com', port=443): Max retries exceeded with url: /subscriptions/<any_subscr>/resourceGroups/random_group/providers/Microsoft.Compute/virtualMachines/test_vm?api-version=2017-12-01 (Caused by ResponseError('too many 503 error responses',))

api_version取自另一个错误。如果我尝试运行相同的命令api_version=resource_client.api_version并获得:

CloudError: Azure Error: NoRegisteredProviderFound
Message: No registered resource provider found for location 'eastus2' and API version '2017-05-10' for type 'virtualMachines'. The supported api-versions are '2015-05-01-preview, 2015-06-15, 2016-03-30, 2016-04-30-preview, 2016-08-30, 2017-03-30, 2017-12-01'. The supported locations are 'eastus, eastus2, westus, centralus, northcentralus, southcentralus, northeurope, westeurope, eastasia, southeastasia, japaneast, japanwest, australiaeast, australiasoutheast, brazilsouth, southindia, centralindia, westindia, canadacentral, canadaeast, westus2, westcentralus, uksouth, ukwest, koreacentral, koreasouth'.

.get_by_id()同样的api_version工作正常。

有什么问题check_existence_by_id吗?

4

1 回答 1

1

check_existence_by_id是 RestAPI 上的一个瘦包装器,或多或少只是提供简单的身份验证。您需要提供的 API 版本确实是链接到您想要的资源类型的版本(如果您的情况Microsoft.Compute/virtualMachines)。

您可以使用具有资源客户端属性的 CLI 和az provider list/或 SDK获取此信息。providers

请注意您关于 CLI 不需要 ApiVersion 的评论,如果您在--debug模式下执行命令,您会看到 CLIaz provider list在解析资源 ID 以获取要使用的正确 ApiVersion 后确实在幕后执行。

(我在 Azure SDK for Python 团队工作)

于 2018-01-02T17:40:33.777 回答