请求快照列表时,Azure ComputeManagementClient 没有 return 响应

Azure ComputeManagementClient doesn't return response when list of snapshots is requested

我正在尝试使用以下代码获取 azure 订阅中的快照列表。但是当请求快照列表时,ComputeManagementClient 不会 return 响应。 for 循环不会遍历快照列表。

    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)

输出:

RGA-ResGrp
[06/08/2020 03:16:05] <azure.mgmt.compute.v2019_11_01.models._paged_models.SnapshotPaged object at 0x7f7d538fa1d0>

无法重现您的问题,我的资源组中有三个增量快照,它在我这边有效。

试试适合我的代码:

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)

更新:

要遍历快照列表,请确保服务主体具有足够的权限,例如Contributor 订阅中的角色。