使用'u id方法为azure python delete_获取正确的api版本

2024-06-17 09:12:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在根据附加到这些资源的标签自动删除Azure资源。在

我正在使用azuresdkforpython(https://github.com/Azure/azure-sdk-for-python)-我发现了如何获取我的资源列表,并且可以使用ResourceManagementClient使用删除它们resources.delete_按_id方法。 但是,此方法需要两个参数-资源id(我从ResourceManagementClient列出的资源中获取)和API版本(对于每种资源类型都不同)。在

如何确定应该将哪个API版本传递给该方法? 我试图在SDK的文档和代码中找到一些东西,但是我没有找到一个合适的解决方案。在

API版本甚至可以硬编码,但它需要适用于所有资源类型。在

当使用某些api版本(如2018-05-01)时,某些资源类型出现错误:

Azure Error: NoRegisteredProviderFound
Message: No registered resource provider found for location 'westeurope' and API version '['2018-05-01']' 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, 2018-04-01, 2018-06-01, 2018-10-01, 2019-03-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, francecentral, southafricanorth'.
ERROR: 'CloudError' object has no attribute '__traceback__'

Tags: the方法版本apiidfor资源preview
2条回答

我建议使用与CLI实现相同的方法,对ARM进行初始调用,以获取从资源提供者/资源类型到API版本的可能映射,并使用该方法在调用中注入正确的API版本。在

获取这个映射将是一个list providers call。在

编辑:我在pythonsdk团队的MS工作。在

如果我没搞错,resources.delete_by_id^{}restapi方法的包装器。当前此操作的最新API版本是2018-05-01。您可以在方法调用中使用它。在

相关问题 更多 >