Getting proper api version for azure python delete_by_id method

Question:

I’m working on automated deletion of Azure resources based on tags attached to these resources.

I’m using Azure SDK for python (https://github.com/Azure/azure-sdk-for-python) – I found how to get a list of my resources and that I can delete them with ResourceManagementClient with resources.delete_by_id method.
However, this method requires 2 arguments – resource id (which I have from resources listed by ResourceManagementClient) and API version (which is different for every resource type.

How can I determine which API version should be passed to the method?
I’ve tried to find something in docs and code of SDK, but I couldn’t come up with a proper solution.

API version can be even hardcoded, but it needs to work for all resource types.

When using some api versions (e.g. 2018-05-01) I get error for some of resource types:

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__'
Asked By: Dysproz

||

Answers:

If I am not mistaken, resources.delete_by_id is a wrapper over Delete By Id REST API method. Currently the latest API Version for this operation is 2018-05-01. You can use that in your method call.

Answered By: Gaurav Mantri

I would recommend the same approach than the CLI implementation, do an initial call to ARM to get the possible mappings from Resource Provider / Resource Type to API version(s), and use that to inject the correct api version in your call.

Get this mapping would be a list providers call.

Adding a Mgmt sample repo, look for ResourceManagementClient:
https://github.com/Azure-Samples/azure-samples-python-management

Edit: I work at MS in the Python SDK team.

Answered By: Laurent Mazuel
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.