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 !
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()
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With