4

I have written python code to get azure resources for a subscription using azure-python sdk, the function to list all the resources inside a resource group is not working, this was working fine a week before, may be the microsoft have changed their api?? I am getting an attribute error, AttributeError: 'ResourceGroupsOperations' object has no attribute 'list_resources'

Please Find the code below,

from azure.common.credentials import ServicePrincipalCredentials from azure.mgmt.resource.resources import ResourceManagementClient from azure.mgmt.compute import ComputeManagementClient from azure.mgmt.network import NetworkManagementClient subscription_id = '' credentials = ServicePrincipalCredentials( client_id = '', secret = '', tenant = '', ) resource_client = ResourceManagementClient(credentials,subscription_id) resource_client.providers.register('Microsoft.Batch') def get_resources(): for rg in resource_client.resource_groups.list(): for item in resource_client.resource_groups.list_resources(rg.name): print "%s,%s,%s,%s,"%(item.name,item.type,item.location,rg.name) get_resources() 

Plz do help on this! thanks in advance !

2 Answers 2

9

Just an summary , you can find a description of the list_resources method has been removed in 2017-05-04 from SDK source code version statement.

resource_groups.list_resources has been moved to resources.list_by_resource_group 

Python SDK upgrade should be the reason for your issue.

Please modify your code as below and it will work.

from azure.common.credentials import ServicePrincipalCredentials from azure.mgmt.resource.resources import ResourceManagementClient from azure.mgmt.compute import ComputeManagementClient from azure.mgmt.network import NetworkManagementClient subscription_id = '' credentials = ServicePrincipalCredentials( client_id = '', secret = '', tenant = '', ) resource_client = ResourceManagementClient(credentials,subscription_id) resource_client.providers.register('Microsoft.Batch') def get_resources(): for rg in resource_client.resource_groups.list(): for item in resource_client.resources.list_by_resource_group(rg.name): print "%s,%s,%s,%s,"%(item.name,item.type,item.location,rg.name) get_resources() 
Sign up to request clarification or add additional context in comments.

2 Comments

@user2795938 It's all right .You could mark the answer for others' reference on the forum.Have a nice day !
Done! Have a great day.
1

Thats because there is no such operation, you are looking for list_by_resource_group operation.

https://learn.microsoft.com/es-es/python/api/azure.mgmt.resource.resources.v2017_05_10.operations.resourcesoperations?view=azure-python#azure_mgmt_resource_resources_v2017_05_10_operations_ResourcesOperations_list_by_resource_group

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.