I am trying to get list of snapshots in azure subscription using below code. But ComputeManagementClient doesn't return response when list of snapshots is requested. The for loop is not iterate over list of snapshots.
rg_list=resource_client.resource_groups.list()
for item in rg_list:
logging.info(item.name)
snap_list=compute_client.snapshots.list_by_resource_group(item.name)
logging.info(snap_list)
for snap in snap_list:
logging.info(snap.name)
OUTPUT:
RGA-ResGrp
[06/08/2020 03:16:05] <azure.mgmt.compute.v2019_11_01.models._paged_models.SnapshotPaged object at 0x7f7d538fa1d0>
Could not reproduce your issue, there are three incremental snapshots in my resource group, it works on my side.
Try the code works for me:
from azure.mgmt.compute import ComputeManagementClient
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
tenant='<tenant-id>',
client_id='<client-id>',
secret='<client-secret>')
compute_client = ComputeManagementClient(credentials, "<subscription-id>")
snap_list=compute_client.snapshots.list_by_resource_group("<resource-group-name>")
print(snap_list)
for snap in snap_list:
print(snap.name)
Update:
To iterate over list of snapshots, make sure the service principal have the enough permission e.g. Contributor
role in the subscription.